sql server空间精度问题

时间:2014-08-13 05:46:17

标签: sql-server spatial

我遇到SQL Server 2008 R2中STIntersects的不准确结果的问题。也许有人可以说明我可能做错了什么 - 我不能相信这是SQL Server空间查询的准确性限制?

--example 1
DECLARE @pt1 geography;
DECLARE @pt2 geography;
DECLARE @polygon geography;
SET @polygon = geography::STPolyFromText('POLYGON((-172.0000000000 54.0000000000,-164.0000000000 54.0000000000,-164.0000000000 56.0000000000,-172.0000000000 56.0000000000,-172.0000000000 54.0000000000))',4326);
SET @pt1 = geography::STPointFromText('POINT(-170.0000000000 54.04)',4326);
SET @pt2 = geography::STPointFromText('POINT(-170.0000000000 56.04)',4326);
SELECT @polygon.STIntersects(@pt1); --should be 1, but returns 0 (error is .04 * 60 nautical miles per degree - something like 4.4 km) 
SELECT @polygon.STIntersects(@pt2); --should be 0, but returns 1


--example 2
DECLARE @pt1 geography;
DECLARE @pt2 geography;
DECLARE @polygon geography;
SET @polygon = geography::STPolyFromText('POLYGON((-171.0000000000 54.0000000000,-170.0000000000 54.0000000000,-170.0000000000 54.5000000000,-171.0000000000 54.5000000000,-171.0000000000 54.0000000000))',4326);
SET @pt1 = geography::STPointFromText('POINT(-170.5000000000 54.001)',4326);
SET @pt2 = geography::STPointFromText('POINT(-170.5000000000 54.01)',4326);
SELECT @polygon.STIntersects(@pt1); --should be 1, returns 0
SELECT @polygon.STIntersects(@pt2); --should be 1, returns 1 (less error than in example 1, perhaps due to smaller polygon?)

1 个答案:

答案 0 :(得分:1)

对于准确性没有限制,它完全取决于地理类型使用的弯曲地球。您在示例1中绘制的矩形实际上具有弯曲边缘,而不是直线(由于曲面上的距离)。北半球的水平边缘在中间自然向上弯曲。

因此,@ pt1将始终为false,因为它位于多边形的“弯曲”边缘之外。就这样(缓冲,所以你可以看到这一点)。

Poly with PT1

同样地,@ pt2实际上位于弯曲边缘内部,因此总是如此(显示为缓冲和多边形中的孔)。

Poly with PT2

如果你使用Geometry(平面模型)渲染这些,你会得到你想要的答案,但不一定是正确答案。