LineString.parseCoords constructor
LineString.parseCoords(})
Parses a line string geometry from coordinates
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 line string from 2D positions
LineString.parseCoords(
// values for three (x, y) positions
'10.0,20.0,12.5,22.5,15.0,25.0',
type: Coords.xy,
);
// a line string from 3D positions
LineString.parseCoords(
// values for three (x, y, z) positions
'10.0,20.0,30.0,12.5,22.5,32.5,15.0,25.0,35.0',
type: Coords.xyz,
);
// a line string from measured 2D positions
LineString.parseCoords(
// values for three (x, y, m) positions
'10.0,20.0,40.0,12.5,22.5,42.5,15.0,25.0,45.0',
type: Coords.xym,
);
// a line string from measured 3D positions
LineString.parseCoords(
// values for three (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',
type: Coords.xyzm,
);
// a line string from 2D positions using an alternative delimiter
LineString.parseCoords(
// values for three (x, y) positions
'10.0;20.0;12.5;22.5;15.0;25.0',
type: Coords.xy,
delimiter: ';',
);
// a line string from 2D positions with x before y
LineString.parseCoords(
// values for three (x, y) positions
'20.0,10.0,22.5,12.5,25.0,15.0',
type: Coords.xy,
swapXY: true,
);
// a line string from 2D positions with the internal storage using single
// precision floating point numbers (`Float32List` in this case)
LineString.parseCoords(
// values for three (x, y) positions
'10.0,20.0,12.5,22.5,15.0,25.0',
type: Coords.xy,
singlePrecision: true,
);
Implementation
factory LineString.parseCoords(
String coordinates, {
Pattern delimiter = ',',
Coords type = Coords.xy,
bool swapXY = false,
bool singlePrecision = false,
}) {
final str = coordinates.trim();
if (str.isEmpty) {
return LineString(PositionSeries.empty(type));
}
// NOTE: validate line string (at least two points)
return LineString(
parsePositionSeriesFromTextDim1(
str,
delimiter: delimiter,
type: type,
swapXY: swapXY,
singlePrecision: singlePrecision,
),
);
}