2017-02-24 61 views
0

多邊形我想返回從表中值,其中點在多邊形場
我寫了查詢,但不準確究竟存在,返回值平衡點是圍繞多邊形如何返回值,如果點正好裏面在MySQL

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

回答

1

在MySQL中,而非MBR(最小邊界矩形),你應該使用ST_CONTAINS

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

ST_CONTAINS返回true,只有當一個功能包含其它並且由於事實,你正在檢查點,使日是應該給你一個更好的結果

+0

感謝,但不起作用,例如這個多邊形'35.745816 \t \t \t 51.22839,35.750552 \t \t \t 51.227703,35.748323 \t \t \t 51.221008,35.745537 \t \t \t 51.221695,35.735993 \t \t \t 51.221266 ,35.731046 \t \t \t 51.242294,35.72798 \t \t \t 51.253281,35.746234 \t \t \t 51.254826,51.254826 \t \t \t 51.254654,35.745816 \t \t \t 51.22839'我要尋找的點'35.72798 51.25328'結果顯示什麼 – amirali

+0

這是來自https://dev.mysql.com/doc/refman/5.6/en/spatial-relation -functions-object-shapes.html#function_st-contains ...確保你有適當的幾何類型..和值 – scaisEdge

相關問題