union method

MultiPolygon union({
  1. MultiPolygon? multi,
  2. Polygon? poly,
})

Returns a MultiPolygon that is the union of this MultiPolygon and another MultiPolygon or Polygon. The resulting MultiPolygon will have the same properties as this MultiPolygon.

Example:

MultiPolygon([[LinearRing([Coordinate(1, 2), Coordinate(3, 4), Coordinate(5, 6), Coordinate(1, 2)])]]).union(multi: MultiPolygon([[LinearRing([Coordinate(7, 8), Coordinate(9, 10), Coordinate(11, 12), Coordinate(7, 8)])]])); // MultiPolygon([[LinearRing([Coordinate(1, 2), Coordinate(3, 4), Coordinate(5, 6), Coordinate(1, 2)])], [LinearRing([Coordinate(7, 8), Coordinate(9, 10), Coordinate(11, 12), Coordinate(7, 8)])]])

Implementation

MultiPolygon union({MultiPolygon? multi, Polygon? poly}) {
  if (poly == null && multi == null) {
    throw ArgumentError('multi or poly must be provided');
  }
  return MultiPolygon([
    ...coordinates,
    ...(multi != null ? multi.coordinates : []),
    ...(poly != null ? [poly.coordinates] : []),
  ], properties: properties);
}