segments property

List<LineString> get segments

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; // [LineString([Coordinate(1, 2), Coordinate(3, 4)]), LineString([Coordinate(3, 4), Coordinate(5, 6)])]

Implementation

List<LineString> 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 segments;
}