OSMnx Bus Routes – Bus Lines/Routes from OpenStreetMap Using OSMnx

openstreetmaposmnxpython

I am trying to obtain bus lines/routes from OpenStreetMap using OSMnx. For example busline 284 in Nootdorp, Netherlands: https://www.openstreetmap.org/relation/2024408#map=15/52.0463/4.3967&layers=T

How do I obtain the exact route (i.e. as a list of nodes) as shown in OSM?

I tried using osmnx.features.features_from_place:

import osmnx as ox

gdf_busline = ox.features.features_from_place("Nootdorp, Netherlands", tags={'type': 'route', 'route': 'bus'})

print(gdf_busline)

But it returns an Empty Dataframe. (I also tried a some other combinations of tags, but no success)

Best Answer

You can use overpass turbo as workaround an download the geojson:

For all buslines https://overpass-turbo.eu/s/1H8y

[out:json][timeout:25];
// gather results
nwr["network"="Haaglanden Streek"]({{bbox}});
// print results
out geom;

or specific https://overpass-turbo.eu/s/1H8E

[out:json][timeout:25];
// gather results
nwr["network"="Haaglanden Streek"]["ref"="284"]({{bbox}});
// print results
out geom;

You could try to use overpass turbo api to get your data into python without downloading:

https://stackoverflow.com/questions/72664156/data-from-osm-overpy-to-geodataframe-with-polygons

https://stackoverflow.com/questions/76372216/how-to-translate-a-request-from-overpass-turbo-format-to-a-raw-request-and-make

Related Question