[GIS] How to find the nearest city for a POI in a OpenStreetMap/PostGIS database

openstreetmappoint-of-interestpostgis

I'm interested in finding additional data for the POIs in OSM database.

Currently I can use the following SQL for getting the name+long+lat for all the POIs

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'

I would also like to have the name of the nearest town/city or the town/city the POI is situated in.

Best Answer

not quite the answer I wanted, but usable in an application: create a query to Nominatim

http://nominatim.openstreetmap.org/search?q=45.8364043,24.8345179&format=xml&addressdetails=1

Related Question