MultiPolygon.build constructor
Builds a multi polygon from an array of polygons
(each with an array of
rings).
Use type
to specify the type of coordinates, by default Coords.xy
is
expected.
An optional bounds
can used set a minimum bounding box for a geometry.
Each polygon is represented by a Iterable<Iterable<double>>
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".
Each ring in the polygon is represented by an Iterable<double>
array.
Such arrays contain coordinate values as a flat structure. For example for
Coords.xyz
the first three coordinate values are x, y and z of the first
position, the next three coordinate values are x, y and z of the second
position, and so on.
Examples:
// a multi polygon with one polygon from 2D positions
MultiPolygon.build(
[
// polygon
[
// an exterior ring with values of five (x, y) positions
[
10.0, 20.0,
12.5, 22.5,
15.0, 25.0,
11.5, 27.5,
10.0, 20.0,
],
],
],
type: Coords.xy,
);
// a multi polygon with one polygon from 3D positions
MultiPolygon.build(
[
// polygon
[
// an exterior ring with values of five (x, y, z) positions
[
10.0, 20.0, 30.0,
12.5, 22.5, 32.5,
15.0, 25.0, 35.0,
11.5, 27.5, 37.5,
10.0, 20.0, 30.0,
],
],
],
type: Coords.xyz,
);
Implementation
factory MultiPolygon.build(
Iterable<Iterable<Iterable<double>>> polygons, {
Coords type = Coords.xy,
Box? bounds,
}) =>
MultiPolygon(
polygons
.map(
(rings) => rings
.map(
(ring) => PositionSeries.view(
ring is List<double> ? ring : toFloatNNList(ring),
type: type,
),
)
.toList(growable: false),
)
.toList(growable: false),
bounds: bounds,
);