which function is good to check whether the given lat & lng is inside the polygon?

为君一笑 提交于 2019-12-13 04:26:17

问题


I have found the following mysql spatial functions which can check a given lattitude and longtitude is inside the polygon or not.

1 - MBR_Contains

2 - MBR_Within

Please guide me, which will give fast and accurate result to check a given point is inside or outside of the polygon in MySql server by the query itself.

Also Suggest me, If you found any better solution than this ( It should be checked by query in Mysql Server.)?

Regards, ArunRaj


回答1:


They're likely the same (in terms of speed), but you should run your own tests using both functions.

That said, Assuming you can use MySQL 5.6.1, you should refrain from the MBR functions and use the ST functions:

ST_Contains()
ST_Within()

The reason, MBR stands for minimum bounding rectangle, therefore a point can be within the minimum bounding rectangle, but not actually within the Polygon. The ST methods are exact to the shape and will give you a more precise answer.

Edit, Addressing which one should I use? I believe you can use either as you're testing a point within a polygon, but again test on a point you know to be in a polygon for safety.



来源:https://stackoverflow.com/questions/22094603/which-function-is-good-to-check-whether-the-given-lat-lng-is-inside-the-polygo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!