Search code examples
openstreetmaposmnx

Download OSM network (with OSMNx) filtering based on the union of tag values


I would like to download a network from OSM with union of 2 filters based on highway and cycleway tags.

    network=ox.core.graph_from_place ( place_name, custom_filter='["highway"~"cycleway"]["bicycle"!~"no”]’  

This command makes the intersection of the 2 filters. So it gets all edges with highway = cycleway, and with cycleway tag different from value “no”.

However if I would like to make the union with the filter ["cycleway”~"lane”] I don’t know the boolean ‘OR’ operatore for OSM.

I tried the following but it doesn’t work:

    network=ox.core.graph_from_place ( place_name, custom_filter='["highway"~"cycleway"]["bicycle"!~"no”] or ["cycleway”~"lane”]’

    network=ox.core.graph_from_place ( place_name, custom_filter='["highway"~"cycleway"]["bicycle"!~"no”] | ["cycleway”~"lane”]’ 

Is there an easy way to write the custom filter making the union of tag values? or should I download more than I need and then remove out edges as suggested in #151 ?


Solution

  • This is how I extract networks based on union of infrastructure filters.

    # get graphs of different infrastructure types, then combine
    place = 'Berkeley, California, USA'
    G1 = ox.graph_from_place(place, custom_filter='["highway"~"cycleway"]')
    G2 = ox.graph_from_place(place, custom_filter='["cycleway”~"lane”]')
    G = nx.compose(G1, G2)