- Categories:
ST_ CENTROID¶
Returns the Point representing the geometric center of a GEOGRAPHY or GEOMETRY object.
Syntax¶
Arguments¶
geography_or_geometry_expressionThe argument must be an expression of type GEOGRAPHY or GEOMETRY.
Returns¶
Returns a GEOGRAPHY or GEOMETRY object for the Point that represents geometric center of the input object.
Usage notes¶
- Returns NULL if the input is NULL.
- If the input object is a GeometryCollection that contains different types of objects (Polygons, LineStrings, and Points),
ST_CENTROID uses the type with the highest dimension to determine the geometric
center. For example:
- If the GeometryCollection contains Polygons, LineStrings, and Points, ST_CENTROID uses the Polygons and ignores the LineStrings and Points in the collection.
- If the GeometryCollection contains LineStrings and Points, ST_CENTROID uses the LineStrings and ignores the Points in the collection.
- For GEOMETRY objects, the returned GEOMETRY object has the same SRID as the input.
Examples¶
GEOGRAPHY examples¶
The following example returns the Point that represents the geometric center of a LineString.
The following example returns the Point that represents the geometric center of a Polygon.
The following example returns the Point that represents the geometric center of a GeometryCollection. This collection contains a Polygon, LineString, and Point. ST_CENTROID only uses the Polygon (and ignores the LineString and Point) when determining the geometric center.
GEOMETRY examples¶
The following example computes the centroid of a simple rectangular Polygon. Note how the result differs from the result when using ST_CENTROID with a GEOGRAPHY object