Context
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.
Question
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)
ox.__version__
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],
network_type=network_type[0],
infrastructure=infrastructures[0],
custom_filter=custom_filters[0], # comment this line to deactivate the custom filter but keeping the custom infrastructures
retain_all=False)
else:
G = ox.graph_from_bbox(bbox_GE[0],bbox_GE[1],bbox_GE[2],bbox_GE[3],
network_type=network_type[0],
retain_all=False)
# Plotting graph either directly (if True) or on leaflet using folium (if False):
if False:
fig, ax = ox.plot_graph(G)
else:
graph_map = ox.plot.plot_graph_folium(G, graph_map=None,
popup_attribute=None,
tiles=maptiles[0],
zoom=19,
fit_bounds=True,
edge_color=edge_colors[0],
edge_width=2,
edge_opacity=.64)
graph_map
Results:
- With the proposed 'walk' osmnx base filter without any additional custom parameters (
TEST = False
): - With both custom parameters
infrastructure
andcustom_filter
(TEST = True
): - With custom
infrastructure
only (TEST = True
) but#custom_filter
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