st_centroid function
Applies to: Databricks SQL
Databricks Runtime 17.1 and above
Preview
This feature is in Public Preview.
注記
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: AGEOMETRYvalue.
Returns
Returns the centroid (as a 2D point) of the input GEOMETRY value as a geometry.
More precisely:
- If the input
GEOMETRYvalue is empty, the 2D empty point is returned. - If the input
GEOMETRYvalue consists of points only, the centroid is the average of the X and Y coordinates of the points. - If the input
GEOMETRYvalue 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
GEOMETRYvalue 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)