shapely.centroid#
- centroid(geometry, **kwargs)#
Compute 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
Geometry or geometries for which to compute the centroid.
- **kwargs
See NumPy ufunc docs for other keyword arguments.
Examples
>>> import shapely >>> from shapely import LineString, MultiPoint, Polygon >>> shapely.centroid(Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)])) <POINT (5 5)> >>> shapely.centroid(LineString([(0, 0), (2, 2), (10, 10)])) <POINT (5 5)> >>> shapely.centroid(MultiPoint([(0, 0), (10, 10)])) <POINT (5 5)> >>> shapely.centroid(Polygon()) <POINT EMPTY>