centroid property
Point
get
centroid
Returns the LinearRing's centroid. The centroid is the Point that is the center of the LinearRing. Example:
LinearRing ring = LinearRing([
Coordinate(0, 0),
Coordinate(0, 1),
Coordinate(1, 1),
Coordinate(1, 0),
Coordinate(0, 0),
]);
print(ring.centroid); // Point(Coordinate(0.5, 0.5))
Implementation
Point get centroid {
double lat = 0;
double long = 0;
// Don't want the closing coordinate to count twice
for (var point in coordinates.sublist(0, coordinates.length - 2)) {
lat += point.latitude;
long += point.longitude;
}
lat /= (coordinates.length - 1);
long /= (coordinates.length - 1);
return Point.fromLatLong(lat, long);
}