且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL Server 中的 Geography 数据类型与 Geometry 数据类型

更新时间:2023-02-06 12:35:24

地理类型比几何类型限制更多.它不能跨越不同的半球,必须逆时针绘制外环.

The geography type is a little bit more restrictive than geometry. It can't cross different hemispheres and the outer ring must be drawn counter-clockwise.

不幸的是(有些人认为这是一件好事),当您创建无效的地理位置时,SQL Server 2012 不再抛出错误.您需要反转 Roben Island 几何中点的顺序,例如:

Unfortunately (some find this a good thing), SQL Server 2012 no longer throws an error when you create the invalid geography. You need to invert the order of the points in the Roben Island geometry, like:

DECLARE @robben_island geography = ('POLYGON((18.351803 -33.788421, 18.354464 -33.822369,18.386736 -33.820515, 18.382788 -33.787494, 18.351803 -33.788421))')
DECLARE @point_in_robben_island geography= ('POINT(18.369226 -33.80554)')
DECLARE @point_in_alcatraz geography= ('POINT(-122.423401 37.827006)')

SELECT @robben_island.STContains(@point_in_robben_island)   --returns 'True'
SELECT @robben_island.STContains(@point_in_alcatraz)        --returns 'False'