Share via


st_centroid function

Applies to: check marked yes Databricks Runtime 17.1 and above

Important

This feature is in Public Preview.

Returns the centroid of the input GEOMETRY as a 2D point GEOMETRY.

Syntax

st_centroid ( geoExpr )

Arguments

  • geoExpr: A GEOMETRY value.

Returns

Returns the centroid (as a 2D point) of the input GEOMETRY (represented as a GEOMETRY value or using a standard geospatial format) as a geometry. More precisely:

  • If the input GEOMETRY is empty, the 2D empty point is returned.
  • If the input GEOMETRY consists of points only, the centroid is the average of the X and Y coordinates of the points.
  • If the input GEOMETRY contains linear segments (but no areal geometries), the centroid is the weighted average of the midpoints of the linear segments, where the weights are the lengths of the segments.
  • If the input GEOMETRY contains polygons, the centroid is the weighted average of the centroids of the polygons, where the weights are the areas of the polygons.

In case of mixed topological dimension components, the centroid computation is based on the components of highest topological dimension. The SRID value of the output GEOMETRY is the same as that of the input value.

Examples

> SELECT st_asewkt(st_centroid(st_geomfromtext('POLYGON((1 0, 0.5 0.866, -0.5 0.866, -1 0, -0.5 -0.866, 0.5 -0.866, 1 0))', 3857)))
  SRID=3857;POINT(0 0)