MultiPolygon.from constructor

MultiPolygon.from(
  1. Iterable<Iterable<Iterable<Position>>> polygons, {
  2. Box? bounds,
})

A multi polygon with an array of polygons (each with an array of rings).

An optional bounds can used set a minimum bounding box for a geometry.

Each polygon is represented by a Iterable<Iterable<Position>> instance containing one exterior and 0 to N interior rings. The first element is the exterior ring, and any other rings are interior rings (or holes). All rings must be closed linear rings. As specified by GeoJSON, they should "follow the right-hand rule with respect to the area it bounds, i.e., exterior rings are counterclockwise, and holes are clockwise".

The coordinate type of all positions in rings should be the same.

Examples:

// a multi polygon with one polygon from 2D positions
MultiPolygon.from(
  [
    // polygon
    [
      // an exterior ring with five (x, y) positions
      [
        [10.0, 20.0].xy,
        [12.5, 22.5].xy,
        [15.0, 25.0].xy,
        [11.5, 27.5].xy,
        [10.0, 20.0].xy,
      ],
    ],
  ],
);

// a multi polygon with one polygon from 3D positions
MultiPolygon.from(
  [
    // polygon
    [
      // an exterior ring with five (x, y, z) positions
      [
        [10.0, 20.0, 30.0].xyz,
        [12.5, 22.5, 32.5].xyz,
        [15.0, 25.0, 35.0].xyz,
        [11.5, 27.5, 37.5].xyz,
        [10.0, 20.0, 30.0].xyz,
      ],
    ],
  ],
);

Implementation

factory MultiPolygon.from(
  Iterable<Iterable<Iterable<Position>>> polygons, {
  Box? bounds,
}) =>
    MultiPolygon(
      polygons
          .map(
            (polygon) =>
                polygon.map(PositionSeries.from).toList(growable: false),
          )
          .toList(growable: false),
      bounds: bounds,
    );