LineString.fromWKT constructor
Creates a LineString from a WKT string
Example:
LineString.fromWKT('LINESTRING(0 0, 1 2)'); // LineString([Coordinate(0, 0), Coordinate(1, 2)])
Implementation
@override
factory LineString.fromWKT(String wkt) {
if (!wkt.startsWith('LINESTRING')) {
throw ArgumentError('wkt is not a LineString');
}
final coordinates = wkt.split('(')[1].split(')')[0].split(RegExp(r",\s*"));
return LineString(
coordinates.map((c) => Coordinate.fromWKT(c)).toList(),
);
}