如何在OpenStreetMap / PostGIS数据库中找到POI的最近城市?


9

我有兴趣为OSM数据库中的POI查找其他数据。

当前,我可以使用以下SQL来获取所有POI的名称+ long + lat

SELECT name, 
         x(transform(way, 4326)) AS lon, 
         y(transform(way, 4326)) AS lat
  FROM planet_osm_point 
  WHERE tourism='museum'
UNION
  SELECT name, 
         x(centroid(transform(way, 4326))) AS lon, 
         y(centroid(transform(way, 4326))) AS lat
  FROM planet_osm_polygon 
  WHERE tourism='museum'

我还想知道最近的城镇名称或POI所在的城镇名称。


您是否已经设置了反向地理编码(位置到名称)系统?
BradHards

Answers:



0

相关问题中得出的答案:

假设您有经纬度,这非常容易。

  1. 转换lat / lng为osm数据
  2. 计算到您在数据库中关注的所有POI的距离。
  3. 选择距离最小的行。
  4. 此外,您可能希望将搜索范围限制为感兴趣的半径(例如5公里。)

例如,让我们在POI附近找到5个最近的加油站。

SELECT osm_id,
       name,
       brand,
OPERATOR,
       ST_Distance(barabara_point.way, st_transform( st_setsrid(st_makepoint(36.768676, -1.289927), 4326), 900913)) AS distance
FROM barabara_point
WHERE ST_DWithin(barabara_point.way, st_transform( st_setsrid(st_makepoint(36.768676, -1.289927), 4326), 900913), 5000)
  AND amenity = 'fuel'
ORDER BY distance;

结果集

-[ RECORD 1 ]--------------
osm_id   | 1334386299
name     |
brand    | Kobil
operator |
distance | 244.544617525396
-[ RECORD 2 ]--------------
osm_id   | 915386940
name     | BP
brand    |
operator |
distance | 1012.76398108684
-[ RECORD 3 ]--------------
osm_id   | 1916188670
name     | Shell
brand    |
operator |
distance | 1160.48349020106
-[ RECORD 4 ]--------------
osm_id   | 558923017
name     | Kenol
brand    |
operator |
distance | 1310.22002620899
-[ RECORD 5 ]--------------
osm_id   | 30092081
name     | Caltex
brand    |
operator |
distance | 1419.61102322244
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.