I would like to extract into a network (i.e. a graph with a topology that can be used for routing), all pathways that can be 'legally' walked by pedestrians in an geographical area.
I am currently using osmnx to get OSM data.


I assume that the query used by osmnx rely on the Overpass API in the background.

I'm not sure how to build the query correctly / exhaustively.
Do you know how to set up a query with logical AND or OR using osmnx infrastructure and custom_filter?

What I've done so far:

This is a small example of Geneva neighborhoods that I run in a jupyter-notebook on firefox:

import os, sys, numpy as np
import matplotlib.pyplot as plt
import networkx as nx
import osmnx as ox
import folium

ox.config(log_console=True, use_cache=True)

if True:
    # Checking what is inside the proposed 'walk' filter:    
    osmFilter = ox.core.get_osm_filter('walk')
    print("OSM filter:\n{}".format(osmFilter))

    # Parameters:    
    bbox = (46.209, 46.199, 6.155, 6.143,)
    maptiles = ('cartodbpositron','openstreetmap')
    network_type = ('walk',)

    TEST = True
    if TEST: # Checking with custom filter parameters:    
        infrastructures = ('way["highway"~"footway|pedestrian|cycleway|path|steps|living_street|tertiary|unclassified|residental|service"]',)
        custom_filters = ('["footway"~"sidewalk"]["foot"~"designated|yes"]',)

    edge_colors = ('#22ffcc',)

    # Getting graph:
    if TEST:
        G = ox.graph_from_bbox(bbox_GE[0],bbox_GE[1],bbox_GE[2],bbox_GE[3], 
                               custom_filter=custom_filters[0], # comment this line to deactivate the custom filter but keeping the custom infrastructures
        G = ox.graph_from_bbox(bbox_GE[0],bbox_GE[1],bbox_GE[2],bbox_GE[3], 

    # Plotting graph either directly (if True) or on leaflet using folium (if False):
    if False:
        fig, ax = ox.plot_graph(G)
        graph_map = ox.plot.plot_graph_folium(G, graph_map=None, 



  1. With the proposed 'walk' osmnx base filter without any additional custom parameters (TEST = False): With the proposed 'walk' filter without any additional custom parameters (<code>TEST = False</code>)
  2. With both custom parameters infrastructure and custom_filter (TEST = True): With both custom parameters <code>infrastructure</code> and <code>custom_filter</code> (<code>TEST = True</code>)
  3. With custom infrastructure only (TEST = True) but #custom_filter is commented: With custom <code>infrastructure</code> only (<code>TEST = True</code>) but <code>#custom_filter</code> is commented

On the first map, the road "Quai Général-Guisan" is not allowed for pedestrian, so it should not be extracted.

On the second map, with the custom_filter enabled, I only get the path where the foot key is set to designated, skipping the part "footway"~"sidewalk" from my custom_filter variable which should be taken into account as it is an "OR" case (I probably miss something with the query syntax here?!).

On the last map, there is a road called "Rue du Rhône" which was extracted with both its sidewalks. Here, pedestrian should only be able to walk on sidewalks. But where sidewalks miss such as on really small residential roads or alleys, I want to be able to use the small roads where the OSM foot keys is set to yes or designated (why my custom_filter) to get a connected graph. Or to use cycleway where pedestrians are allowed to walk on e.g.
I don't know if it's possible to set each infrastructure type a custom_filter or to use the custom_filter only where it applies? Because when I enable the custom_filter in my example, I get almost nothing from my query...

In addition, the zoom option of plot_graph_folium seems to have no effect on the map rendering in the notebook. I don't know why. It may be a bug.

System information:

Ubuntu 18.04 64 bit: 5.0.0-32-generic x86_64 GNU/Linux
Python version: 3.6.8
The version of the notebook server is: 5.7.7
numpy: 1.17.3
matplotlib: 3.1.1
networkx: 2.4
osmnx: 0.10
folium: 0.10.0

  • Note that querying for alternative infrastructure types has been drastically simplified in recent releases of OSMnx. See for example this answer or this example. – gboeing Jun 6 '20 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.