SQL Server-从经度和纬度到几何数据类型 [英] SQL Server - From longitude and latitude to geometry data type

查看:176
本文介绍了SQL Server-从经度和纬度到几何数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
SQL Server 2008空间:在多边形中找到一个点

Possible Duplicate:
SQL Server 2008 Spatial: find a point in polygon

我正在使用SQL Server 2008数据库的应用程序上工作.在此数据库中,我有一个名为Session的表,该表具有两个字段经度和纬度,用于指示用户的位置.在另一个名为Zone的表上,我有一个area属性,它是几何类型.如何检查用户的经度和纬度坐标是否属于某个几何?

I am working on an application that uses an SQL Server 2008 database. In this database I have a table named Session that has two fields Longitude and latitude, which indicate the location of a user. On another table called Zone, I have an area attribute which is of type geometry. How can I check if the user's longitude and latitude coordinates belong to a certain geometry?

谢谢

推荐答案

您有一个以欧几里得几何形状存储形状的几何,并且您想要将地球上由纬度和经度表示的一个点与之关联,看它是否在里面.由于SQL存储数据的方式,这将无法正常工作.您可能需要使用地理"数据类型进行检查-纬度和经度是球体上的点(实际上是大地测量数据,因为地球不是一个球体.)

You have a geometry, which stores a shape in Euclidean geometry, and you want to associate a point on the globe, represented by a latitude and longitude, with it, to see if it is inside. This won't work, due to the way SQL stores the data. You probably need to use Geography data types to check this - Latitude and longitude are points on a sphere (Actually geodetic data, since the earth is not quite a sphere.)

有关它们为何不同的更多信息,请参见来自Microsoft的说明.也是关于stackoverflow的答案: GEOMETRY和GEOGRAPHY区别SQL Server 2008

For more information on why they are different, see this explanation from microsoft. Also this answer on stackoverflow: GEOMETRY and GEOGRAPHY difference SQL Server 2008

要将数据从几何转换为地理,请尝试: Geography :: STGeomFromText(cast(GeomCol as varchar(max)),4326)

To convert your data from geometry to geography, try: Geography::STGeomFromText(cast(GeomCol as varchar(max)), 4326)

然后,您可以使用Microsoft 此处.

Then you can use the STIntersects method, documented by microsoft here.

这篇关于SQL Server-从经度和纬度到几何数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆