2014-01-27 56 views
0

我有一个问题在SQL Server 2012中当我试图让两个多边形的交集:SQL Server的地理多边形交集

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

Spatial Data Types

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

而且,事实上,如果我扭转该点为@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))