Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用SQL geography获取某个点半径内的位置_Sql_Sql Server_Geocoding_Geospatial - Fatal编程技术网

使用SQL geography获取某个点半径内的位置

使用SQL geography获取某个点半径内的位置,sql,sql-server,geocoding,geospatial,Sql,Sql Server,Geocoding,Geospatial,我有一个SQL表列,其地理类型为: create table dbo.Events ( Id int identity not null constraint PK_Events_Id primary key clustered (Id), Localization geography not null ); 如何获取半径为40公里的所有事件?这可能吗 谢谢,, 米格尔 STDistance的结果将以米为单位 假设您有要搜索的点的纬度和经度: DECLARE @Origin

我有一个SQL表列,其地理类型为:

create table dbo.Events
(
  Id int identity not null 
    constraint PK_Events_Id primary key clustered (Id),
  Localization geography not null
);
如何获取半径为40公里的所有事件?这可能吗

谢谢,, 米格尔


STDistance的结果将以米为单位

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

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,我只需要设置@Origin=geography::Point-34.5923540138.74606204326
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;