OSMnx Part 2. Creating driving time heatmap.

Maksym Kozlenko 🇺🇦
2 min readOct 16, 2021

--

In first part we discussed how to load data from Open Street Maps and find shortest route between two points. Now I would like to calculate driving time to each reachable node on road network in Greater Sydney.

Open Street map data contains information about maximum travel speed and road length. This can be used to estimate travel time between two points.

Required imports:

import osmnx as ox
from io import BytesIO
from urllib.request import urlopen
from zipfile import ZipFile
import tempfile
import geopandas as gpd
import networkx as nx
import matplotlib.colors as mcolors
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import contextily as ctx

I setting origin point to Pyrmont, NSW.

origin_address = "Pyrmont, NSW"

Download GraphML file with road network for Greater Sydney, unzip it to temporary directory and load it into memory:

Configure network by adding maximum speed, travel time to each network edge and converting projection to ESPG 3857

To build map of roads in Sydney have maximum speed over 50 km/h we can filter data frame by speed_kph value and use it as heat map colour. Check scale on right side for colour to speed mapping.

Roads in Sydney with maximum speed more than 50 km/h

Now to get travel time from origin address we will find nearest network node by geocoding address and finding node closest to these coordinates:

Find travel times for each node on network and maximum travel time

Create heat map using “jet” colour map using node’s “travel_time” attribute. Base map allows us to add suburb names on top of heat map.

Driving time in minutes from Pyrmont, NSW accross Greater Sydney

As you can see longest driving time from Pyrmont in Greater Sydney is Blackheath in Blue Mountain with travel time over 80 minutes.

Obviously Google Maps navigation will give you more precise time based on current traffic, road closures. Unfortunately its licensing conditions do not allow to store this data for further analysis and processing.

Complete code example to run in Google Colab
(please restart runtime after packages installed using pip)

Source code on GitHub

--

--