kap*_*pso 8 postgresql postgis postgresql-9.1
我有下表
create table places(lat_lng point, place_name varchar(50));
insert into places values (POINT(-126.4, 45.32), 'Food Bar');
Run Code Online (Sandbox Code Playgroud)
什么应该是让所有地方接近特定纬度/经度的查询?
gis已安装.
Mik*_*e T 10
如果您确实想使用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, 45.32), '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);
Run Code Online (Sandbox Code Playgroud)
现在找到1公里(或1000米)范围内的所有地方:
select *, ST_Distance(lat_lng, ST_MakePoint(-126.4, 45.32)::geography)
from places
where ST_DWithin(lat_lng, ST_MakePoint(-126.4, 45.32)::geography, 1000)
order by ST_Distance(lat_lng, ST_MakePoint(-126.4, 45.32)::geography);
Run Code Online (Sandbox Code Playgroud)
select *
from places
where lat_lng <-> POINT(-125.4, 46.32) < 1
order by lat_lng <-> POINT(-125.4, 46.32)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4376 次 |
最近记录: |