MultiPolygon.parseCoords constructor
MultiPolygon.parseCoords(})
Parses a multi polygon geometry from polygons
with each polygon
containing rings that are formatted as texts (with coordinate values
separated by delimiter
).
Use the required optional type
to explicitely set the coordinate type.
If swapXY
is true, then swaps x and y for all positions in the result.
If singlePrecision
is true, then coordinate values of positions are
stored in Float32List
instead of the Float64List
(default).
Examples:
// a multi polygon with one polygon from 2D positions
MultiPolygon.parseCoords(
[
// 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.parseCoords(
[
// 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,
);
// a multi polygon with one polygon from 2D positions using an
// alternative delimiter
MultiPolygon.parseCoords(
[
// 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,
delimiter: ';',
),
// a multi polygon with one polygon from 2D positions with x before y
MultiPolygon.parseCoords(
[
// polygon
[
// an exterior ring with values of five (x, y) positions
'20.0,10.0,'
'22.5,12.5,'
'25.0,15.0,'
'27.5,11.5,'
'20.0,10.0'
],
],
type: Coords.xy,
swapXY: true,
);
// a multi polygon with one polygon from 2D positions with the
// internal storage using single precision floating point numbers
// (`Float32List` in this case)
MultiPolygon.parseCoords(
[
// 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,
singlePrecision: true,
);
Implementation
factory MultiPolygon.parseCoords(
Iterable<Iterable<String>> polygons, {
Pattern delimiter = ',',
Coords type = Coords.xy,
bool swapXY = false,
bool singlePrecision = false,
}) {
if (polygons.isEmpty) {
return MultiPolygon.build(const []);
} else {
return MultiPolygon(
polygons
.map(
(polygon) => polygon
.map(
(ring) => parsePositionSeriesFromTextDim1(
ring,
delimiter: delimiter,
type: type,
swapXY: swapXY,
singlePrecision: singlePrecision,
),
)
.toList(growable: false),
)
.toList(growable: false),
);
}
}