0

I have a OSM database on postgres/postGIS. Data are downloaded from https://download.geofabrik.de/ and created in postgres with osm2pgsql using schema osm2pgsql.

Now I'm looking for a postalcode on a given GPS position. How can I find this in the OSM database?

  • 3
    You didn't mention which database schema you are using. Tools such as osm2pgsql, imposm, ogr ... create different database schema, so the SQL is different. Have a look to wiki.openstreetmap.org/wiki/… – etrimaille Apr 10 at 10:54
  • Also, the concept of finding a postal code for a geolocation is highly country specific, and doesn't even apply at all in some cases. Then there's the question of coverage in the OSM data. It would be better to rephrase your question a bit. – mmd Apr 11 at 16:28
  • Right! I used this only for germany: – Gerd Apr 12 at 12:37
0

The SQL Query is i.e.:

SELECT tags->'postal_code', tags, st_asgeojson(way) 
FROM planet_polygon 
WHERE boundary = 'postal_code' AND 
ST_Contains(way, ST_Transform( ST_GeomFromText('POINT(10.5830 48.7657)', 4326), 900913))

The query search over all 'postal_code' polygons and find the matching post_code (in German PLZ = Postleitzahl)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.