【发布时间】:2014-08-28 11:06:40
【问题描述】:
我正在尝试获取多边形内的所有点,经过几次测试,我终于抓住了。
STIntersects 始终为我的所有实体返回 1,即使在“视觉上”不在多边形中的点的情况下也是如此。
我找到了有关多边形创建方向的帖子并尝试了它,但它没有帮助我:)
所以我决定创建一个简单的案例:
- 在俄罗斯某处具有 4 个顶点的多边形(角:55 37、56 38)
- 这个多边形内的一个点
- 还有一个在外面
这里是a link 到谷歌地图点
这个测试的结果让我摆脱了困境
declare @cw geography, @ccw geography, @pointIn geography, @pointOut geography
-- counterclockwise direction from bottom left corner
set @ccw = geography::STPolyFromText (
'POLYGON((
55.0 37.0
,55.0 38.0
,56.0 38.0
,56.0 37.0
,55.0 37.0
))', 4326
)
-- clockwise direction from bottom left corner
set @cw = geography::STPolyFromText (
'POLYGON((
55.0 37.0
,56.0 37.0
,56.0 38.0
,55.0 38.0
,55.0 37.0
))', 4326
)
set @pointIn = geography::Point(55.5, 37.5, 4326)
set @pointOut = geography::Point(54, 36, 4326)
select @pointIn.STIntersects(@ccw) ccw, @pointIn.STIntersects(@cw) cw
-- result: 1 0
--here i should get inversed values, but it didnt happens
select @pointOut.STIntersects(@ccw) ccw, @pointOut.STIntersects(@cw) cw
-- result: 1 0
为什么会这样?我只是无法理解我错过了什么
我希望pointIn 在我的多边形很小时返回 1,当我的多边形是整个世界减去选定区域时返回 0,pointOut 在第一种情况下应该返回 0,在第二种情况下返回 1
但是两个点在逆时针多边形中都返回 1。
更新
最后
我的错误是geography::STPolyFromText的输入参数的顺序
第一个应该是 lng,第二个是 lat。
并且扩展顺序是不同的
msdn says:Point ( Lat, Long, SRID )
【问题讨论】:
标签: google-maps tsql spatial sqlgeography