osmnx: how can I filter the the highway type?

Viewed 1677

I tried with custom_filter, it worked for some small road network, but as for a big road network like the whole Sydney network, it didn't work. In the output file, there were still some other highway types that I didn't want.

custom_filter='["highway"~"motorway|motorway_link|trunk|trunk_link|primary|primary_link|secondary|secondary_link|tertiary|tertiary_link|road|road_link|service|service_link\
                unclassified|unclassified_link"]'
G=ox.core.graph_from_place('Sydney,Australia',network_type='drive', \
                           simplify=True, infrastructure='way["highway"]', custom_filter=custom_filter)
1 Answers

Here's a simple example to get only motorways and their links (note that network_type=None):

import osmnx as ox
ox.config(use_cache=True, log_console=True)
cf = '["highway"~"motorway|motorway_link"]'
G = ox.graph_from_place('Sydney, Australia', simplify=True, custom_filter=cf)
print(ox.graph_to_gdfs(G, nodes=False)['highway'].value_counts())
Related