PostGISGeometry Processing

ST_Centroid

What is ST_Centroid?

ST_Centroid is a PostGIS function that returns the geometric centre of its input geometry — the dimension-weighted average of all its coordinates. For polygons the centroid is the centre of mass of the area, for lines it is the midpoint weighted by length, and for point sets it is the arithmetic mean.

SQL
1ST_Centroid(geometry geom)geometry
2ST_Centroid(geography geog, boolean use_spheroid = true) → geography

The centroid is always returned as a Point. It may fall outside the geometry itself — for a crescent-shaped polygon, for example, the centroid can land outside the shape.

When would you use ST_Centroid?

Use ST_Centroid when you need a representative single-point location for each feature — labelling countries on a world map, computing distances between polygon pairs, or aggregating features by nearest point. It is the most common way to reduce a polygon layer to a points layer for visualisation or join operations.

SQL
1SELECT name, ST_Centroid(geom) AS label_point
2FROM admin_boundaries;

FAQs

What's the difference between ST_Centroid and ST_PointOnSurface?

ST_Centroid returns the geometric centre of mass, which can lie outside the geometry for concave or doughnut-shaped features. ST_PointOnSurface guarantees the result lies inside the geometry — use it when you need a point that is always "on" the feature, for example for labelling or picking.

Does ST_Centroid work on the geography type?

Yes. The geography overload computes the centroid on the spheroid (or sphere if use_spheroid is false), which is important for features that span large portions of the globe where planar computation would be inaccurate.

How does ST_Centroid handle MultiPolygons?

For a MultiPolygon, the centroid is the area-weighted mean of each component polygon's centroid. Larger parts pull the centroid toward them, which is usually desirable but can place the result far from any individual piece if the parts are widely separated.

What happens with empty or point geometries?

An empty geometry returns POINT EMPTY. A single Point returns itself, a MultiPoint returns the arithmetic mean of its points, and a LineString returns the midpoint weighted by segment length.