What Is a Centroid?
A centroid is the geometric center of a shape — the point at which the geometry would balance if it were a flat, uniform surface. For a simple rectangle, the centroid is the intersection of the diagonals. For complex polygons, the centroid is calculated as the weighted average of all the vertices, where each triangle formed by consecutive edge segments contributes proportionally to its area.
This tool calculates the centroid of any GeoJSON geometry and returns it as a Point feature. The centroid is displayed on the map alongside the original geometry so you can visually verify its position.
How Centroid Calculation Works
The algorithm computes the centroid across all features in your GeoJSON using the Turf.js centroid function. For FeatureCollections with multiple features, it finds the centroid of the combined geometry. The result is a GeoJSON Point feature with the centroid coordinates.
Note that the centroid of a concave polygon may fall outside the polygon boundary. For example, a crescent-shaped polygon has its centroid in the empty space between the arms. If you need a point guaranteed to be inside the polygon, consider using a "point on surface" algorithm instead, which Turf.js provides as turf.pointOnFeature().
Centroid vs. Center of Mass vs. Point on Surface
These three concepts are related but serve different purposes in geospatial work:
- Centroid — the arithmetic mean of all coordinates, weighted by area for polygons. Fast to compute but may lie outside concave shapes.
- Center of mass — identical to the centroid for uniform-density shapes, but can account for weighted features if needed.
- Point on surface — always guaranteed to be inside or on the boundary of the geometry. Useful for label placement on complex shapes like countries with archipelagos or irregularly shaped districts.
For most web mapping and label placement tasks, the centroid is the right choice. Use point-on-surface only when you need the guarantee that the result lies within the shape.
Common Use Cases
- Placing labels at the center of polygon features on a map
- Finding the geographic center of a city, county, or region
- Creating marker positions from polygon boundary data
- Calculating distances between the centers of two regions
- Aggregating point data by computing group centroids
- Setting the initial map view center from a set of features
Programmatic Equivalent
In JavaScript with Turf.js:
JavaScriptconst centroid = turf.centroid(featureCollection);
console.log(centroid.geometry.coordinates);
// [-73.97, 40.78]In Python with Shapely:
Pythonfrom shapely.geometry import shape
polygon = shape(geojson_geometry)
print(polygon.centroid.coords[0])Related tools: area calculator, bounding box calculator, length calculator.