MultiLineString.parseCoords constructor
MultiLineString.parseCoords(})
Parses a multi line string geometry from lineStrings
with each line
string formatted as a text containing 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 line string with two line strings both with three 2D positions
MultiLineString.parseCoords(
[
'10.0,20.0,12.5,22.5,15.0,25.0',
'12.5,23.0,11.5,24.0,12.5,24.0',
],
type: Coords.xy,
);
// a multi line string with two line strings both with three 3D positions
MultiLineString.parseCoords(
[
'10.0,20.0,30.0,12.5,22.5,32.5,15.0,25.0,35.0',
'12.5,23.0,32.5,11.5,24.0,31.5,12.5,24.0,32.5',
],
type: Coords.xyz,
);
// a multi line string with two line strings both with three 2D positions
// using an alternative delimiter
MultiLineString.parseCoords(
[
'10.0;20.0;12.5;22.5;15.0;25.0',
'12.5;23.0;11.5;24.0;12.5;24.0',
],
type: Coords.xy,
delimiter: ';',
);
// a multi line string with two line strings both with three 2D positions
// with x before y
MultiLineString.parseCoords(
[
'20.0,10.0,22.5,12.5,25.0,15.0',
'23.0,12.5,24.0,11.5,24.0,12.5',
],
type: Coords.xy,
swapXY: true,
);
// a multi line string with two line strings both with three 2D positions
// with the internal storage using single precision floating point numbers
// (`Float32List` in this case)
MultiLineString.parseCoords(
[
'10.0,20.0,12.5,22.5,15.0,25.0',
'12.5,23.0,11.5,24.0,12.5,24.0',
],
type: Coords.xy,
singlePrecision: true,
);
Implementation
factory MultiLineString.parseCoords(
Iterable<String> lineStrings, {
Pattern delimiter = ',',
Coords type = Coords.xy,
bool swapXY = false,
bool singlePrecision = false,
}) {
if (lineStrings.isEmpty) {
return MultiLineString.build(const []);
} else {
return MultiLineString(
lineStrings
.map(
(lineString) => parsePositionSeriesFromTextDim1(
lineString,
delimiter: delimiter,
type: type,
swapXY: swapXY,
singlePrecision: singlePrecision,
),
)
.toList(growable: false),
);
}
}