加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – 某一点上最近的地方

发布时间:2020-12-13 16:14:51 所属栏目:百科 来源:网络整理
导读:我有下表 create table places(lat_lng point,place_name varchar(50));insert into places values (POINT(-126.4,45.32),'Food Bar'); 什么应该是让所有地方接近特定纬度/经度的查询? gis已安装. 如果您确实想使用PostGIS: create table places( lat_lng
我有下表
create table places(lat_lng point,place_name varchar(50));

insert into places values (POINT(-126.4,45.32),'Food Bar');

什么应该是让所有地方接近特定纬度/经度的查询?

gis已安装.

如果您确实想使用PostGIS:
create table places(
    lat_lng geography(Point,4326),place_name varchar(50)
);

-- Two ways to make a geography point
insert into places values (ST_MakePoint(-126.4,'Food Bar1');
insert into places values ('POINT(-126.4 45.32)','Food Bar2');

-- Spatial index
create index places_lat_lng_idx on places using gist(lat_lng);

现在找到1公里(或1000米)范围内的所有地方:

select *,ST_Distance(lat_lng,ST_MakePoint(-126.4,45.32)::geography)
from places
where ST_DWithin(lat_lng,45.32)::geography,1000)
order by ST_Distance(lat_lng,45.32)::geography);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读