geokit/centroid

Centroid (geometric centre) of a Geometry.

For a Point, the centroid is the point itself. For a LineString it is the arithmetic mean of its vertices. For a Polygon it is the centroid of the exterior ring weighted by the signed area of each triangle, which is the correct mean for a planar polygon (Turfjs / Shapely use the same formula).

All computations treat the Earth as a flat plane in lat/lng — no projection is applied. For polygons spanning more than a few degrees, project to Web Mercator first (see geokit/mercator) for an area-accurate centroid.

Types

Errors returned by compute.

pub type CentroidError {
  EmptyGeometry
}

Constructors

  • EmptyGeometry

    The geometry contained no points.

Values

pub fn compute(
  geometry geometry: geometry.Geometry,
) -> Result(latlng.LatLng, CentroidError)

Compute the centroid of geometry.

Search Document