Polygon.build constructor
Builds a polygon geometry from one exterior and 0 to N interior 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 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.
An empty polygon has no rings.
For "normal" polygons the rings
list must be non-empty. 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".
Examples:
// a polygon (with an exterior ring only) from 2D positions
Polygon.build(
[
// 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 polygon (with an exterior and one interior ring) from 2D positions
Polygon.build(
[
// 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,
],
// an interior ring with values of four (x, y) positions
[
12.5, 23.0,
11.5, 24.0,
12.5, 24.0,
12.5, 23.0,
],
],
type: Coords.xy,
);
// a polygon (with an exterior ring only) from 3D positions
Polygon.build(
[
// 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,
);
// a polygon (with an exterior ring only) from measured 2D positions
Polygon.build(
[
// an exterior ring with values of five (x, y, m) positions
[
10.0, 20.0, 40.0,
12.5, 22.5, 42.5,
15.0, 25.0, 45.0,
11.5, 27.5, 47.5,
10.0, 20.0, 40.0,
],
],
type: Coords.xym,
);
// a polygon (with an exterior ring only) from measured 3D positions
Polygon.build(
[
// an exterior ring with values of five (x, y, z, m) positions
[
10.0, 20.0, 30.0, 40.0,
12.5, 22.5, 32.5, 42.5,
15.0, 25.0, 35.0, 45.0,
11.5, 27.5, 37.5, 47.5,
10.0, 20.0, 30.0, 40.0,
],
],
type: Coords.xyzm,
);
Implementation
factory Polygon.build(
Iterable<Iterable<double>> rings, {
Coords type = Coords.xy,
Box? bounds,
}) =>
Polygon(
rings
.map(
(ring) => PositionSeries.view(
ring is List<double> ? ring : toFloatNNList(ring),
type: type,
),
)
.toList(growable: false),
bounds: bounds,
);