多边形内的SQL Geography点在ST​​Intersect上不返回true(但使用Geometry返回true)

标签 sql geometry polygon point geography

我不想诉诸于将我的地理数据转换为几何图形,以至于它在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点在ST​​Intersect上不返回true(但使用Geometry返回true),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20653424/

相关文章:

objective-c - 对四边形的坐标进行排序

sql 使连接的表成为一张表可能是什么?

mysql - SQL 为每一行查找以前的值

algorithm - 三角形的三点中有多少个整数点?

javascript - SVG 多边形形状与图像

python - geopandas 属性错误 : 'MultiPolygon' object has no attribute 'exterior'

sql - 这两个查询在获得两个不同的结果集时有什么区别?

sql - Postgres 使用其他表插入冲突更新

geometry - 在哪里学习计算几何?

animation - 在 SVG 中定义圆/弧动画