Is the centroid method implemented in MySQL spatial?
문제
Simple question, I'm wondering if the centroid method is implemented in the MySQL spatial extensions. I've looked at the documentation but wasn't able to find a definitive answer.
다른 팁
In general: Yes
MultiPolygon: No
The OpenGIS specification also defines the following functions, which MySQL does not implement:
Centroid(mpoly)
Returns the mathematical centroid for the MultiPolygon value mpoly as a Point. The result is not guaranteed to be on the MultiPolygon.
http://dev.mysql.com/doc/refman/5.1/en/geometry-property-functions.html#function_centroid
You can get the centroid of each polygon, within a multipolygon, though this is not documented in the MySQL manual, by using the geometryn
function. For exmaple,
select astext(centroid(geometryn(geomfromtext('MultiPolygon(((0 0,0 3,3 3,3 0,0 0)),((10 10,10 20,20 20,20 10,10 10)))'),2)));
returns
POINT(15 15)
which is the centroid of the 2nd polygon within the MultiPolygon. It probably doesn't make much sense for a MultiPolygon to have a centroid, anyway.
Yes, you can read it from the MySQL - Polygon Property Functions. Look below the page for the first user comment. It says there:
there are more than just these functions available. I think this not clear enough in the docs. for example, the MultiPolygon 'Centroid' function works for Polygons as well.
Example:
mysql> SET @poly = 'Polygon((0 0,0 3,3 3,3 0,0 0))';
mysql> select astext( Centroid(PolygonFromText(@poly)));