使用SQL地理学获取特定点半径内的位置 [英] Get places in radius of a certain point using SQL geography

查看:51
本文介绍了使用SQL地理学获取特定点半径内的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an SQL table column with the Geography type:

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

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

How can I get all events in a radius of 40 km? Is this possible?

谢谢, 米格尔(Miguel)

Thank You, Miguel

推荐答案

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

Assuming you have latitude and longitude of the point from which you want to search:

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;

这篇关于使用SQL地理学获取特定点半径内的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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