Was this helpful?
Centroid
CENTROID(g Geometry)
Alias: ST_CENTROID
Returns the center of g. The center can be outside g.
Result type: point
Examples:
Find the center of a polygon:
SELECT ASTEXT(CENTROID(POLYFROMTEXT('POLYGON((0 0, 10 0, 10 2, 2 2, 2 8, 10 8, 10 10, 0 10, 0 0))')));
--------------------------------
col1
--------------------------------
POINT (4.0769230769230766 5)
--------------------------------
Find the center of a multipoint shape:
SELECT ASTEXT(CENTROID(MPOINTFROMTEXT('MULTIPOINT((0 0), (1 1), (0.5 1), (2 0.5), (10 10), (9 9), (8.5 9))')));
---------------------------------
col1                             
---------------------------------
POINT (4.4285714285714288 4.3571428571428568)
---------------------------------
Last modified date: 01/30/2023