简体   繁体   中英

How to return value if point exactly inside polygon in mysql

I want to return value from table where point exactly exist in polygon field
I wrote query but is not accurate, value returned even point be around the polygon

"select `name`,`loc_id` FROM `locations` where MBRContains(`polygons`,ST_GeomFromText('Point($loc[0] $loc[1])'))= 1"

In mysql instead of MBR ( minimum bounding rectangle) you should use ST_CONTAINS

"select `name`,`loc_id` 
    FROM `locations` 
    where ST_CONTAINS(`polygons`,ST_GeomFromText('Point($loc[0] $loc[1])'))= 1"

ST_CONTAINS returns true only if one feature contains the other and due the fact that your are checking for point so this should give you a better result

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM