【问题标题】:Get places in radius of a certain point using SQL geography使用 SQL 地理获取某个点半径内的位置
【发布时间】:2014-04-28 22:37:31
【问题描述】:

我有一个地理类型的 SQL 表列:

create table dbo.Events
(
  Id int identity not null 
    constraint PK_Events_Id primary key clustered (Id),
  Localization geography not null
);

如何获取 40 公里半径内的所有事件?这可能吗?

谢谢你, 米格尔

【问题讨论】:

    标签: sql sql-server geocoding geospatial


    【解决方案1】:
    DECLARE @h geography;
    SET @h = geography::STGeomFromText('POINT(-122.34900 47.65100)', 4326); --set here GPS from where you want to search 40 km
    SELECT Localization.STDistance(@h) from dbo.events
    

    STDistance() 的结果将以米为单位。

    【讨论】:

      【解决方案2】:

      假设您有要搜索的点的纬度和经度:

      DECLARE @Origin GEOGRAPHY,
              -- distance defined in meters
              @Distance INTEGER = 40000;        
      
      -- center point
      SET @Origin = GEOGRAPHY::STGeomFromText('POINT(-122.084039 37.42227)', 4326);
      
      -- return all rows from events in 40km radius
      SELECT * FROM dbo.Events WHERE @Origin.STDistance(Localizaton) <= @Distance;
      

      【讨论】:

      • 我不使用 STGeoFromText 而只是做 "SET @Origin = geography::Point(-34.5923540,138.7460620,4326)"
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-30
      • 1970-01-01
      • 1970-01-01
      • 2018-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多