ST_CENTROID()
All functions > GEOSPATIAL > ST_CENTROID()
Returns the geometric center of mass (centroid) of a geometry.
Signatures
Centroid
Returns: The centroid as a Point (GEOM_POINT)
ST_CENTROID(geo: T) → Point sql
| Parameter | Type | Required | Description |
|---|---|---|---|
geo | T | Yes | Geometry value of any sub kind |
With:
T: Custom types: GEOM_POINT | GEOM_LINESTRING | GEOM_POLYGON | GEOM_MULTIPOINT | GEOM_MULTILINESTRING | GEOM_MULTIPOLYGON | GEOM_MULTIANY
Signature notes:
- GEOMETRY only: GEOGRAPHY has no spherical form here; convert with ST_TOGEOMETRY for a planar answer
- Accepts any sub kind; always returns a Point
- For a Point input, returns the same point
- For a Polygon, returns the center of mass of the surface
- For a LineString, returns the center of mass of the line
- Returns an empty point for empty geometries
- Returns NULL if the input is NULL
Availability
| Status | Backends |
|---|---|
| Not available | clickhouse, bigquery, mysql |
Examples
Geometry
FeatureQL
RETURN
-- Centroid of a square
f1 := ST_ASTEXT(
ST_CENTROID(ST_GEOMFROMTEXT('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'))
),
-- Centroid of a horizontal line
f2 := ST_ASTEXT(ST_CENTROID(ST_GEOMFROMTEXT('LINESTRING (0 0, 10 0)')))
;Result
| f1 VARCHAR | f2 VARCHAR |
|---|---|
| POINT (5 5) | POINT (5 0) |
On this page