SQL Server地理多边形交叉点

时间:2014-01-27 09:48:42

标签: sql-server sql-server-2012

我在SQL Server 2012中遇到了一个问题。当我尝试获取两个多边形的交集时:

DECLARE @boundingRect geography;
SET @boundingRect = N'POLYGON((27 30, 170 30, 170 80, 27 80, 27 30))'
DECLARE @boundingRect2 geography;
SET @boundingRect2 = N'POLYGON((84 56, 84.1 56, 84.1 56.1, 84 56.1, 84 56))'
SELECT @boundingRect.STIntersection(@boundingRect2).ToString()

它返回GEOMETRYCOLLECTION EMPTY。但它必须返回第二个多边形,因为@boundingRect包含@boundingRect2。如果我改为

SET @boundingRect = N'POLYGON((27 20, 170 20, 170 80, 27 80, 27 20))'

它工作正常。为什么?我做错了什么?

1 个答案:

答案 0 :(得分:1)

来自Spatial Data Types

  

在椭圆体系中,多边形没有意义,或者没有方向的含糊不清。例如,赤道周围的环是否描述了北半球或南半球?如果我们使用 geography 数据类型来存储空间实例,我们必须指定环的方向并准确描述实例的位置。椭球系统中多边形的内部由左手定则定义。

事实上,如果我颠倒为@boundingRect指定点的顺序,它会返回一个结果:

DECLARE @boundingRect geography;
SET @boundingRect = N'POLYGON((27 30, 27 80, 170 80, 170 30, 27 30))'
DECLARE @boundingRect2 geography;
SET @boundingRect2 = N'POLYGON((84 56, 84.1 56, 84.1 56.1, 84 56.1, 84 56))'
SELECT @boundingRect.STIntersection(@boundingRect2).ToString()

结果:

POLYGON ((84 56.1, 84 56, 84.1 56, 84.1 56.1, 84 56.1))