How to extract streets with name, location/polygon AND village-name, city-name, from downloaded OSM data file (pbf), using osmfilter preferably

You could use GeoDesk for this. Here’s an example for extracting U.S. states and counties. Once you have the admin area of interest, it’s trivial to obtain all the streets within it.

Or, you could work in reverse: Query all streets first, then retrieve the admin areas using a containing() query:

import geodesk

france = geodesk.Features('france.gol')

streets = france("w[highway][highway!=footway,path,steps][name]")
admin_areas = france("a[boundary=administrative][name]")
for street in streets:
    print(f"{street.name} is in:")
    for area in admin_areas.containing(street.nodes.first.centroid):
        print(f"- {area.name} ({area.admin_level})")

For each street, this will print something like:

Route de Creully is in:
- Cairon (8)
- Normandie (4)
- Calvados (6)
- Caen (7)
- France (2)
- France métropolitaine (3)

To get started, download the GOL Tool and pip install geodesk.

You can build a GOL (Geo-Object Library, a compact single-file OSM database) from any PBF file (or download a pre-made GOL for any region).

1 Like