openstreetmaposmium

Osmium: complement tag addr:city to amenity=school query


I'm using a .pbf file containing the OpenStreetMap data from Switzerland and I the following Osmium command to extract every entry that contains the tag amenity=school,college:

osmium tags-filter switzerland-exact.osm.pbf nwr/amenity=school,college \ 
    -o schools-in-switzerland.osm.pbf

Afterwards I export the data as JSON and process it with a python script to bring the data to the following format:

[
    {
        "name": "school1",
        "city": "city1",
        "postcode": "plz1",
        "country": "switzerland"
    },
    {
        "name": "school2",
        "city": null,
        "postcode": "plz2",
        "country": "switzerland"
    },
    ...
]

I use the following tag to property mappings in the python script: addr:city->city, addr:postcode->postcode.

The resulting problem is that some schools (e.g. school2 in the example) do not contain a city and/or do not contain a postcode. Since OSM theoretically has all the data needed to identify in which place a school is, I thought it should be possible to somehow complement the missing tags in the extraction process.

I'm not bound to use Osmium and, therefore, am open for other solutions.


Solution

  • I've found a brute-force method... In the pbf file I've got the coordinates of the shape and I just use the very first longitude and latitude to query the address on https://nominatim.org/,. e.g.: https://nominatim.openstreetmap.org/reverse?format=json&lat=33.2038405&lon=-96.7436876