STIntersect地理,几何数据类型

时间:2016-08-29 07:21:22

标签: sql-server geospatial spatial

我有一个圆和点,点在几何中与圆相交但在地理上不相交。

DECLARE @circle GEOGRAPHY = GEOGRAPHY::Point(39.10591303215, 21.923140028856, 4120).STBuffer(500)
DECLARE @geogpoint GEOGRAPHY = GEOGRAPHY::Point(51.590294, 25.16387, 4120)
select @circle,@geogpoint.ToString(),@geogpoint,@circle.STIntersects(@geogpoint)


DECLARE @circle1 geometry = geometry::Point(39.10591303215, 21.923140028856, 4120).STBuffer(500)
DECLARE @geomgpoint geometry = geometry::Point(51.590294, 25.16387, 4120)
select @circle1,@geomgpoint.ToString(),@geomgpoint,@circle1.STIntersects(@geomgpoint)

我有很多圈子和点,问题是几何几乎所有和地理相交很少。

1 个答案:

答案 0 :(得分:1)

对于Geography,缓冲区以SRID为单位。对于4120:

SELECT unit_of_measure FROM sys.spatial_reference_systems WHERE spatial_reference_id = 4120

给出'米'

因此,您需要为您的点添加500米的缓冲区。现在,你的两个(无缓冲)点之间的距离是什么?

DECLARE @circle GEOGRAPHY = GEOGRAPHY::Point(39.10591303215, 21.923140028856, 4120)
DECLARE @geogpoint GEOGRAPHY = GEOGRAPHY::Point(51.590294, 25.16387, 4120)
SELECT @circle.STDistance(@geogpoint)

1410017.60306578 metres

解释了为什么STIntersects返回false。

对于Geometery,您正在使用'单位'。你们两点之间的距离是多少?

DECLARE @circle1 geometry = geometry::Point(39.10591303215, 21.923140028856, 4120)
DECLARE @geomgpoint geometry = geometry::Point(51.590294, 25.16387, 4120)
select  @circle1.STDistance(@geomgpoint)

12.898143234446 'units' (in this case degrees)

这就是你的第二个查询返回true的原因。

查看“#34;空间数据类型中的测量”部分" https://msdn.microsoft.com/en-us/library/bb964711.aspx