segments property Null safety
Returns each segment (a 2-coordinate LineString) of the LineString in a FeatureCollection
Example:
LineString([Coordinate(1, 2), Coordinate(3, 4), Coordinate(5, 6)]).segments; // FeatureCollection([LineString([Coordinate(1, 2), Coordinate(3, 4)]), LineString([Coordinate(3, 4), Coordinate(5, 6)])])
Implementation
FeatureCollection get segments {
List<LineString> segments = [];
for (int i = 0; i < coordinates.length - 1; i++) {
final start = coordinates[i];
final end = coordinates[i + 1];
final segment = LineString([start, end]);
segments.add(segment);
}
return FeatureCollection(segments);
}