toPolygon method
If the LineString is a closed ring, it will be converted to a Polygon. Any properties will be applied to the Polygon.
Example:
LineString([Coordinate(1, 2), Coordinate(3, 4), Coordinate(1, 4), Coordinate(1, 2)]).toPolygon(); // Polygon([Coordinate(1, 2), Coordinate(3, 4), Coordinate(1, 4), Coordinate(1, 2)])
Implementation
Polygon toPolygon() {
if (!isClosedRing) {
throw ArgumentError('LineString is not a closed ring');
}
return Polygon([LinearRing(coordinates)], properties: properties);
}