SQL Server 2008 Spatial:在多边形中查找一个点

SQL Server 2008 Spatial: find a point in polygon(SQL Server 2008 Spatial:在多边形中查找一个点)
本文介绍了SQL Server 2008 Spatial:在多边形中查找一个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SQL Server 2008 空间数据类型.我有一个表,所有状态(作为多边形)作为数据类型 GEOMETRY.现在我想检查一个点的坐标(纬度、经度)作为数据类型 GEOGRAPHY 是否在该州内.

I am using SQL Server 2008 spatial data types. I have a table with all States (as polygons) as data type GEOMETRY. Now I want to check if a point's coordinates (latitudes, longitudes) as data type GEOGRAPHY, is inside that State or not.

我找不到任何使用新空间数据类型的示例.目前,我有一个多年前实施的解决方法,但它有一些缺点.

I could not find any example using the new spatial data types. Currently, I have a workaround which was implemented many years ago, but it has some drawbacks.

我同时拥有 SQL Server 2008 和 2012.如果新版本有一些增强,我也可以开始使用它.

I've both SQL Server 2008 and 2012. If the new version has some enhancements, I can start working in it too.

谢谢.

更新 1:

为了更清楚,我添加了一个代码示例.

I am adding a code sample for a bit more clarity.

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

推荐答案

我认为 geography 方法 STIntersects() 会做你想做的:

I think the geography method STIntersects() will do what you want:

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)

这篇关于SQL Server 2008 Spatial:在多边形中查找一个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)