length property
double
get
length
Returns the total distance of the MultiLineString in meters. This is the sum of the distances of each LineString in the MultiLineString. The distance is calculated using the Haversine formula.
Example:
MultiLineString([[Coordinate(1, 2), Coordinate(3, 4)]]).distance(); // 314283.2550736839
Implementation
double get length {
double getLength(List<Coordinate> coordinates) {
if (coordinates.length < 2) {
return 0.0;
}
double length = 0.0;
for (int i = 0; i < coordinates.length - 1; i++) {
length += coordinates[i].distanceTo(coordinates[i + 1]);
}
return length;
}
return coordinates.fold(0.0, (a, b) => a + getLength(b));
}