Fetching the structure of regions, sub-regions, cities, streets and postal codes by hierarchy

I have a seemingly simple but, for me as a newcomer to the OpenStreetMap topic, difficult task to complete. I would like to display a complete list of regions and sub-regions of a selected State. At the lowest level is the city and then the streets belonging to the selected city and the postal codes corresponding to the streets.

I am aware of performing the following queries:

  1. display all regions at level 0 from a given State (in the case of the US, I should get 51 states).
  2. select one of the displayed States and display the sub-regions belonging to the selected State… etc. until I get to the cities.
    3 I display all the streets and then retrieve all the zip codes assigned to the selected street

I currently have imported Europe data from Geofabrik into my PostreSQL database using Osm2pgsql

Thank you in advance for your help.

Most streets in OSM do not have zip codes, zip codes are places on address nodes and buildings, see:

https://wiki.openstreetmap.org/wiki/Addresses

To get the zip codes for a area you can use overpass turbo. Overpass can also work with named area’s.

For your PostreSQL database you should be also able to do a query on “addr:postcode” and limit that query to a given area.

1 Like