Mysql select where polygon contains point always false

天涯浪子 提交于 2019-12-22 08:34:24

问题


I have tried various functions like MBRWithin, MBRContains, Intersects, Contains (all of them found in a plenty of posts around here) but no luck yet. This is the simplified query:

SELECT * FROM  users
WHERE Intersects( GeomFromText( 'POINT(50 50)' ), GeomFromText( 'POLYGON(0 0, 100 0, 100 100, 0 100, 0 0)' ) );

I expected it to evaluate that condition as true (like 1=1) and return all users, however this did not happen. Please tell me, what am I doing wrong?

I am running MySql 5.5


回答1:


This worked for me:

SELECT
    *
FROM 
    users
WHERE
    MBRContains(
        GeomFromText('Polygon((0 0,0 100,100 100,100 0,0 0))'),
        GeomFromText('Point(50 50)')) = 1;


来源:https://stackoverflow.com/questions/16659897/mysql-select-where-polygon-contains-point-always-false

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