在多边形中找到一个点的位置或在mysql中循环

时间:2015-07-07 14:38:03

标签: mysql geocoding

如何确定给定(纬度,经度)的点是否在由(纬度,经度)列表定义的多边形内? 现在,如果我将形状保存为(纬度,经度,半径)定义的圆,我该如何处理? 请解释这个场景.... thanx

1 个答案:

答案 0 :(得分:1)

多边形是具有直边并且最终连接未打开的形状。圈子不需要申请。他们是扮演者。

在时间允许的情况下进行精彩编辑。

修改

create table polyThing
(
    id int auto_increment primary key,
    boundary polygon not null
);

insert polyThing (boundary)
VALUES(
PolygonFromText(
'POLYGON(( 
9.190586853 45.464518970,
9.190602686 45.463993916,
9.191572471 45.464001929,
9.191613325 45.463884676,
9.192136130 45.463880767,
9.192111509 45.464095594,
9.192427961 45.464117804,
9.192417811 45.464112862,
9.192509035 45.464225851,
9.192493139 45.464371079,
9.192448471 45.464439002,
9.192387444 45.464477861,
9.192051402 45.464483037,
9.192012814 45.464643592,
9.191640825 45.464647090,
9.191622331 45.464506215,
9.190586853 45.464518970))'
)
);

insert polyThing (boundary) 
select PolygonFromText(
"POLYGON
((
121.44842136764532 121.44842136764532,
121.45076025390631 31.221990825071376,
121.45402182006842 31.218366658611853,
121.45091045761114 31.217054584347302,
121.44842136764532 31.22119260287111
))
")

-- mysql 5.6.1 and later I believe:
select p.id, ST_Contains(p.boundary,GeomFromText('POINT(23.9999 38.224)'))
from polyThing p

-- older version
select p.id, Contains(p.boundary,GeomFromText('POINT(23.9999 38.224)'))
from polyThing p

select p.id, Contains(p.boundary,GeomFromText('POINT(121.44842136764532 121.44842136764532)'))
from polyThing p

GIS Spatial

包含可能与否。瞄准5.6.1及更高版本并使用ST_Contains