In this tutorial we will learn how to download a map from the Open Street Map project and make some analysis of it.
Open Street Map is a project of a community map. Everyone can update the map (contributions are usually checked by editors) and the resulting map is free for everyone.
OSMnx is a Python package to retrieve, model, analyze, and visualize
OpenStreetMap street networks as NetworkX MultiDiGraph objects. See
https://osmnx.readthedocs.io/ for OSMnx documentation and usage.
You will need to install this package using pip install osmnx
.
You can obtain graph from the map by using function graph_from_point
where the first parameter is tuple of coordinates, parameter dist=x
says that you want a map in distance of $x$ meters around the given coordinate and then you can choose network_type
, where you can specify whether you are interested in paths for cars, bikes or pedestrians.
import networkx as nx
import osmnx as ox
# Malá Strana: 50.0885311N, 14.4041669E
G = ox.graph_from_point((50.09, 14.40), dist=1000, network_type="drive")
Module speed
of osmnx
alows you to have maximal allowed speeds on a given road as edge attributes in you map network. Also, travel times can be computed based on these speeds and lenghts of the edges.
# impute edge (driving) speeds and calculate edge traversal times
G = ox.speed.add_edge_speeds(G)
G = ox.speed.add_edge_travel_times(G)
The function graph_from_point
returns MultiDigraph. There is a function get_digraph
which allows you to convert the MultiDiGraph to DiGraph. You have to specify which of the parallel edges should be preserved by setting weight
parameter to an edge attribute.
D = ox.utils_graph.get_digraph(G, weight="travel_time")
The osmnx
package has module plot
with functions get_node_colors_by_attr
allowing to color nodes according to node values and plot_graph
allowing you to plot the obtained graph.
See the documentation for usage: https://osmnx.readthedocs.io/en/stable/osmnx.html?highlight=add_edge_speeds#module-osmnx.plot
Task 1: In the map of car roads in the 2km surrounding of Malá Strana, compute the node betweenness centrality normalized by the travel times and draw the result.
Task 2: Do the same thing for bike and pedestrian paths and analyse the results.