Far*_*han 23 sql-server spatial geospatial sql-server-2008 sql-server-2008-r2
我正在使用SQL Server 2008空间数据类型.我有一个表所有状态(作为多边形)作为数据类型GEOMETRY.现在我想检查作为数据类型GEOGRAPHY的点的坐标(纬度,经度)是否在该状态内.
我找不到使用新空间数据类型的任何示例.目前,我有一个多年前实施的解决方法,但它有一些缺点.
我有SQL Server 2008和2012.如果新版本有一些增强功能,我也可以开始使用它.
谢谢.
更新1:
我正在添加一个代码示例,以便更清晰.
declare @s geometry --GeomCol is of this type too.
declare @z geography --GeogCol is of this type too.
select @s = GeomCol
from AllStates
where STATE_ABBR = 'NY'
select @z = GeogCol
from AllZipCodes
where ZipCode = 10101
Run Code Online (Sandbox Code Playgroud)
Ben*_*hul 29
我认为地理方法STIntersects()会做你想要的:
DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STGeomFromText('POLYGON((-122.358 47.653, -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326);
SET @h = geography::Point(47.653, -122.358, 4326)
SELECT @g.STIntersects(@h)
Run Code Online (Sandbox Code Playgroud)