6
我不想將我的地理數據轉換爲幾何圖形,所以它在STIntersect中返回true。SQL內部多邊形內的地理點不在STIntersect上返回true(但使用幾何圖元返回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平面,幾何是平面地圖,但如果點在多邊形中,我正在使用地球進行計算。
PS:它不STContains,STWithin,STOverlaps
使用Microsoft SQL Server 2012
謝謝,爲我工作。 – MilkTea027
這是一個很好的博客條目,解釋_left-hand_規則:http://danielwertheim.se/2012/12/03/sqlgeography-in-sql-server-2012-polygon-must-start-on-correct-position- no/ 例如:如果一個點位於多邊形的所有行的_left_中,則它會_intersect_多邊形。 – bounav
上面解釋左側規則的博客帖子的URL應該是:http://danielwertheim.se/sqlgeography-in-sql-server-2012-polygon-must-start-on-correct-position-no/ – Daniel