MBR Within not accurate in mysql

[亡魂溺海] 提交于 2019-12-12 14:02:23

问题


I have been using the MBRWithin function for quite a lot of times. Suddenly I notice on google map this POINT(101.11857 4.34475) is out of the geo fence which I specify but it still give a value of 1 in mysql any reason or tweaking need to be done?

SELECT MBRWithin(GeomFromText('POINT(101.11857 4.34475)'),GeomFromText('POLYGON((101.12112522125244 4.3531723687957164,101.11846446990967 4.351417913665312,101.13138198852539 4.336397898951581,101.13477230072021 4.33211863778494,101.14065170288086 4.321933898868271,101.14992141723633 4.306699328215635,101.15455627441406 4.30978050198082,101.1397933959961 4.334600612212089,101.12112522125244 4.3531723687957164,101.12112522125244 4.3531723687957164))')) As geoFenceStatus


回答1:


MySQL 5.6.1 and later have exact geometry algorithms in addition to the earlier functions that only operated on MBR.

You can use ST_WITHIN rather than MBR_WITHIN. See documentation. Like this

SELECT ST_Within(GeomFromText('POINT(101.11857 4.34475)'),
  GeomFromText('POLYGON((101.12112522125244 4.3531723687957164,101.11846446990967 
    4.351417913665312,101.13138198852539 4.336397898951581,101.13477230072021 
    4.33211863778494,101.14065170288086 4.321933898868271,101.14992141723633 
    4.306699328215635,101.15455627441406 4.30978050198082,101.1397933959961 
    4.334600612212089,101.12112522125244 4.3531723687957164,101.12112522125244 
    4.3531723687957164))')) As geoFenceStatus



回答2:


MBRWithin() will return results based on the minimum bounding rectangle of it's parameters. Your polygon contains both larger and smaller values for both coordinates than the point, so it will be within the polygon's MBR.

MySQL has no built-in point in polygon algorithm, so you'll either have to roll your own or find one elsewhere. This one seems to be a good candidate.



来源:https://stackoverflow.com/questions/7782873/mbr-within-not-accurate-in-mysql

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