Skip to main content

st_centroid function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 17.1 and above

Preview

This feature is in Public Preview.

note

This feature is not available on Databricks SQL Classic warehouses. To learn more about Databricks SQL warehouses, see SQL warehouse types.

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

Syntax

st_centroid ( geoExpr )

Arguments

  • geoExpr: A GEOMETRY value.

Returns

Returns the centroid (as a 2D point) of the input GEOMETRY value as a geometry. More precisely:

  • If the input GEOMETRY value is empty, the 2D empty point is returned.
  • If the input GEOMETRY value consists of points only, the centroid is the average of the X and Y coordinates of the points.
  • If the input GEOMETRY value 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 value 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 value is the same as that of the input value.

Examples

SQL
> 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)