shapely.centroid#

centroid(geometry, **kwargs)#

Computes the geometric center (center-of-mass) of a geometry.

For multipoints this is computed as the mean of the input coordinates. For multilinestrings the centroid is weighted by the length of each line segment. For multipolygons the centroid is weighted by the area of each polygon.

Parameters
geometryGeometry or array_like
**kwargs

For other keyword-only arguments, see the NumPy ufunc docs.

Examples

>>> from shapely import LineString, MultiPoint, Polygon
>>> centroid(Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]))
<POINT (5 5)>
>>> centroid(LineString([(0, 0), (2, 2), (10, 10)]))
<POINT (5 5)>
>>> centroid(MultiPoint([(0, 0), (10, 10)]))
<POINT (5 5)>
>>> centroid(Polygon())
<POINT EMPTY>