首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Server 2012,geography.STContains,结果错误吗?

Server 2012,geography.STContains,结果错误吗?
EN

Stack Overflow用户
提问于 2012-11-30 11:48:02
回答 1查看 2.1K关注 0票数 3

我正在使用Server 2012,geography.STContains (文档),我不明白为什么下面的代码会失败。

如果我切换到geometry,它就能工作。

有人能解释一下吗?

//丹尼尔

代码语言:javascript
复制
declare @geo geography
set @geo = geography::STPolyFromText('POLYGON ((17.519133203852 59.8297423369731, 17.5190071588812 59.8296936773323, 17.5189979955459 59.8298203729009, 17.5191345140461 59.8298223425544, 17.519133203852 59.8297423369731))', 4326)

-- Is not within
declare @p1 geography
set @p1 = geography::STPointFromText('POINT(17.5184709839477 59.829925754067)', 4326)

-- Is within
declare @p2 geography
set @p2 = geography::STPointFromText('POINT(17.519060 59.829774)', 4326) 

select
    @geo.STContains(@p1), -- should be 0 is 1
    @geo.STContains(@p2) -- should be 1 is 0

更新了:--如果我将它们倒置--它工作得很好,但是我不明白这一点:

代码语言:javascript
复制
declare @geo geography
set @geo = geography::STPolyFromText('POLYGON ((17.519133203852 59.8297423369731, 17.5190071588812 59.8296936773323, 17.5189979955459 59.8298203729009, 17.5191345140461 59.8298223425544, 17.519133203852 59.8297423369731))', 4326)

select
    @geo.STAsText() Polygon,
    @geo.STPointN(1).STAsText() Point1,
    @geo.STPointN(1).Lat Point1Latitud,
    @geo.STPointN(1).Long Point1Longitude

其结果是:

代码语言:javascript
复制
Polygon 
POLYGON ((17.519133203852 59.8297423369731, 17.5190071588812 59.8296936773323, 17.5189979955459 59.8298203729009, 17.5191345140461 59.8298223425544, 17.519133203852 59.8297423369731))

Point1  
POINT (17.519133203852 59.8297423369731)

Point1Latitud   
59,8297423369731

Point1Longitude
17,519133203852
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-30 15:35:45

现在我发现了这个问题。用户画多边形,从右下角开始,顺时针方向移动.如果我从最大纬度重新排序,然后用long排序反方向,lat是有效的。为它找个帮手,但只有当你“知道这是错的”时才能做到:

代码语言:javascript
复制
if(sqlGeography.EnvelopeAngle() > 90)
    sqlGeography ? sqlGeography.ReorientObject();

只需组合一个小的解决方案,它将修复我的值:https://github.com/danielwertheim/GeographyFactory

还有一篇关于它的博客:http://danielwertheim.se/sqlgeography-in-sql-server-2012-polygon-must-start-on-correct-position/

关于真正的“问题”,左手法则:

http://danielwertheim.se/sqlgeography-in-sql-server-2012-polygon-must-start-on-correct-position-no/

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13644669

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档