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)
From the OSMnx Getting Started guide:
Accordingly, remember that you are searching for matching elements, using tags. That is, if you seek the nodes of the route, then the elements you are searching for are nodes, not relations, and you seek them by their tags.
Also from the features module documentation:
So if you do want a relation itself, it must be of type multipolygon or boundary.
For example, if you want all the bus stops (i.e., the nodes of a bus line):
Also, if you know the OSM ID of the relation you want to retrieve, you can use the
geocodermodule to retrieve it directly. See the docs. This uses the Nominatim API under the hood. However, be aware that Nominatim doesn't support all relations. For example, searching Nominatim for Nootdorp by ID works but searching for Bus 284 by ID doesn't because it cannot be found in Nominatim:See also this issue at Nominatim.