Skip to main content

ST_Centroid

Returns the geometric center (centroid) of a geometry.

Syntax

ST_Centroid(geometry)

Parameters

ParameterTypeDescription
geometryGeometryInput geometry

Returns

TypeDescription
Binary (WKB)Centroid point as WKB with geoarrow.wkb metadata

Examples

Centroid of Polygon

SELECT ST_Centroid(ST_GeomFromText('POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))'));
-- Returns: POINT(2 2)

Centroid of LineString

SELECT ST_Centroid(ST_GeomFromText('LINESTRING(0 0, 4 0)'));
-- Returns: POINT(2 0)

Calculate Centroids for Labeling

SELECT id, name, ST_Centroid(geom) as label_point
FROM regions;

Chain with Buffer

SELECT id, ST_Buffer(ST_Centroid(geom), 100) as center_buffer
FROM parcels;

Notes

  • For Points, returns the same point
  • For LineStrings, returns the midpoint along the line
  • For Polygons, returns the center of mass
  • For concave polygons, centroid may be outside the polygon boundary
  • Use ST_PointOnSurface for a point guaranteed to be inside

See Also