Selecting geographical points within area

时光怂恿深爱的人放手 提交于 2019-12-31 02:50:08

问题


I have a SQL Server 2008 table with a column of the geography datatype. The value is a point (latitude and longitude).

How do I query the table to return all rows where the location is within a 10 kilometer radius of a given coordinate?


回答1:


You probably want the STDistance method: http://msdn.microsoft.com/en-us/library/bb933952.aspx

Or the STWithin method: http://msdn.microsoft.com/en-us/library/bb933991.aspx




回答2:


This query eventually solved my problem:

DECLARE @geoMyPoint geography
SET @geoMyPoint = geography::STGeomFromText('POINT(56.5667 9.0333)', 4326);

SELECT vchZipCode, nvcCity, vchLat, vchLong,
  (geography::STGeomFromText('POINT(' + vchLat + ' ' + vchLong + ')', 4326)).STDistance(@geoMyPoint) 
FROM MyTable


来源:https://stackoverflow.com/questions/550445/selecting-geographical-points-within-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!