This topic describes the ST_Centroid function. This function calculates the center of a geometry object or geography object.
Syntax
geometry ST_Centroid(geometry g1);
geography ST_Centroid(geography g1 , boolean useSpheroid);Parameters
| Parameter | Description |
|---|---|
| g1 | The geometry object or geography object that you want to specify. |
| useSpheroid | Specifies whether to use an ellipsoid. This parameter is valid if you specify a geography object. Default value: True. |
Examples
- Calculate the center of a MultiPoint object.
SELECT ST_AsText(ST_Centroid('MULTIPOINT(1 1,-1 -1)'::geometry)); st_astext ------------ POINT(0 0) (1 row) - Calculate the center of a LineString object.
SELECT ST_AsText(ST_Centroid('LINESTRING(0 0,0 1,1 2)'::geometry)); st_astext ------------------------------------------- POINT(0.292893218813453 1.085786437626905) (1 row)