

© 2025 by The Clinic. Powered and secured by Wix
MySQL:
ST_CENTROID
ST_Centroid({poly|mpoly})
Returns the mathematical centroid for the Polygon or MultiPolygon
argument as a Point. The result is not guaranteed to be on the
MultiPolygon.
This function processes geometry collections by computing the centroid
point for components of highest dimension in the collection. Such
components are extracted and made into a single MultiPolygon,
MultiLineString, or MultiPoint for centroid computation.
ST_Centroid() handles its arguments as described in the introduction to
this section, with these exceptions:
o The return value is NULL for the additional condition that the
argument is an empty geometry collection.
o If the geometry has an SRID value for a geographic spatial reference
system (SRS), an ER_NOT_IMPLEMENTED_FOR_GEOGRAPHIC_SRS
(https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference
.html#error_er_not_implemented_for_geographic_srs) error occurs.
URL: https://dev.mysql.com/doc/refman/8.0/en/gis-polygon-property-functions.html
Example
mysql> SET @poly =
ST_GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5))');
mysql> SELECT ST_GeometryType(@poly),ST_AsText(ST_Centroid(@poly));
+------------------------+--------------------------------------------+
| ST_GeometryType(@poly) | ST_AsText(ST_Centroid(@poly)) |
+------------------------+--------------------------------------------+
| POLYGON | POINT(4.958333333333333 4.958333333333333) |
+------------------------+--------------------------------------------+