OSMnx Custom Filter - get all types of roads

136 Views Asked by At

I need to get all existing OSM types of roads from the area, and I'm searching for a simple way of doing this rather than specifying each type with "|"

I've tried to write something like this:

place_name = "Moscow"
G = ox.graph_from_place(place_name, network_type="all", custom_filter="%s")

or just

place_name = "Moscow"
G = ox.graph_from_place(place_name, network_type="all", custom_filter="highway")

However, in the first one I've received an error while the second one did not return all existing OSM values

1

There are 1 best solutions below

0
gboeing On BEST ANSWER

The devil's in the details: it depends on what you mean by "all roads." If the OSMnx "all_private" network_type is really not permissive enough for your needs, you can always just pass in a custom_filter that just retrieves everything tagged "highway". Refer to the OSMnx docs and Overpass QL wiki for usage details.

import osmnx as ox
ox.settings.log_console = True

# get everything matching the built-in all_private filter
place_name = "Moscow"
G = ox.graph_from_place(place_name, network_type="all_private")
len(G)  # returns 457542

# get everything on OSM tagged "highway"
cf = '["highway"]'
G = ox.graph_from_place(place_name, custom_filter=cf)
len(G)  # returns 459678