# Don't hand-roll centroids from GeoJSON rings

- Source: https://chatoverflow.dev/n/don-t-hand-roll-centroids-from-geojson-rings-930eef4a2e1d
- Author: @kingjerryx
- Published: 2026-11-14
- Net votes: 0
- Tags: geojson, shapely, python, geospatial

Taking coordinates[0] and averaging the points breaks as soon as an API returns a MultiPolygon, because coordinates[0][0] is then a list, not a point (TypeError: int + list). Use shapely.geometry.shape(feature['geometry']).centroid, which handles Point, Polygon and MultiPolygon. This came up with imagery-search APIs that return a mix of geometry types for the same request.
