我不想诉诸于将我的地理数据转换为几何图形,以至于它在STIntersect中返回true。
这是SQL中的代码:
DECLARE @point GEOGRAPHY = GEOGRAPHY::Point(1, 1, 4326)
DECLARE @polygon GEOGRAPHY = GEOGRAPHY::STGeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))', 4326)
SELECT @polygon.STIntersects(@point), @point.STIntersects(@polygon)
以下返回false(0),但是如果我使用的话:
DECLARE @point GEOMETRY = GEOMETRY::Point(1, 1, 4326)
DECLARE @polygon GEOMETRY = GEOMETRY::STGeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))', 4326)
SELECT @polygon.STIntersects(@point), @point.STIntersects(@polygon)
它返回true,有什么我想念的吗?我所知道的是地理是3D平面,几何是平面 map ,但是如果点在多边形中,我将使用地球进行计算。
PS:它不适用于STContains,STWithin,STOverlaps
使用Microsoft SQL Server 2012
最佳答案
这有效:
DECLARE @point GEOGRAPHY = GEOGRAPHY::Point(1, 1, 4326)
DECLARE @polygon GEOGRAPHY = GEOGRAPHY::STGeomFromText('POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))', 4326)
SELECT @polygon.STIntersects(@point), @point.STIntersects(@polygon)
您必须小心在为
geography
描述多边形时所用的“方向”-考虑一个定义为围绕赤道的圆的多边形-您打算指定北半球还是南半球?参见here:
In an ellipsoidal system, a polygon has no meaning, or is ambiguous, without an orientation. For example, does a ring around the equator describe the northern or southern hemisphere? If we use the geography data type to store the spatial instance, we must specify the orientation of the ring and accurately describe the location of the instance. The interior of the polygon in an ellipsoidal system is defined by the left-hand rule.
关于多边形内的SQL Geography点在STIntersect上不返回true(但使用Geometry返回true),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20653424/