开发者

Is the centroid method implemented in MySQL spatial?

开发者 https://www.devze.com 2022-12-21 03:39 出处:网络
Simple question, I\'m wondering if the centroid method is implemented in the MySQL spat开发者_StackOverflowial extensions.I\'ve looked at the documentation but wasn\'t able to find a definitive answer

Simple question, I'm wondering if the centroid method is implemented in the MySQL spat开发者_StackOverflowial 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)));


As of Mysql 8 centroid is not there anymore.

The proper solution to get the center of the polygon|m-polygon is st_centroid() method.

Here is an example:

select st_astext(ST_Centroid(st_geomfromtext('MultiPolygon(((0 0,0 3,3 3,3 0,0 0)),((10 10,10 20,20 20,20 10,10 10)))'))) as center_point;

The reference Mysql st_centroid() method

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号