ST_CENTROID()

All functions > GEOSPATIAL > ST_CENTROID()

Returns the geometric center of mass (centroid) of a geometry or geography.

Signatures

Centroid

Returns: The centroid as a Point (GEOM_POINT or GEOG_POINT matching the input family)

ST_CENTROID(geo: T) → Point
sql
ParameterTypeRequiredDescription
geoTYesGeometry or geography value of any sub kind

With:

  • T : Custom types: GEOM_POINT | GEOM_LINESTRING | GEOM_POLYGON | GEOM_MULTIPOINT | GEOM_MULTILINESTRING | GEOM_MULTIPOLYGON | GEOM_MULTIANY | GEOG_POINT | GEOG_LINESTRING | GEOG_POLYGON | GEOG_MULTIPOINT | GEOG_MULTILINESTRING | GEOG_MULTIPOLYGON | GEOG_MULTIANY

Signature notes:

  • 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

Examples

Geometry

FeatureQL
SELECT
    f1 := ST_ASTEXT(ST_CENTROID(ST_GEOMFROMTEXT('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'))), -- Centroid of a square
    f2 := ST_ASTEXT(ST_CENTROID(ST_GEOMFROMTEXT('LINESTRING (0 0, 10 0)'))) -- Centroid of a horizontal line
;
Result
f1 VARCHARf2 VARCHAR
POINT (5 5)POINT (5 0)

Last update at: 2026/05/26 17:22:09