Selecting geographical points within area

后端 未结 2 769
臣服心动
臣服心动 2021-01-22 02:13

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

相关标签:
2条回答
  • 2021-01-22 02:31

    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

    0 讨论(0)
  • 2021-01-22 02:56

    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
    
    0 讨论(0)
提交回复
热议问题