Isochrones and GeoPandas
Sharing something I was playing with today.
I'd never heard of an 'isochrone' until I visited Open Route Service. This amazing service allows you to plan routes using an API. It's free to use as well.
An isochrone shows the point at which you are a particular commute time away from a destination. So I couldn't resist rolling this into some property price analysis I've also been playing with!
First crack open Jupyter. Import all the required libraries, specifically pandas, geopandas, and openrouteservice. If you don't have these, you'll need to pip install them. The openrouteservice module contains a client that you can use to access the Open route Service API.
I've opened a data frame containing coordinates of all postcodes in the Land Registry Price Paid dataset. When creating a GeoDataFrame as above, a geometry column containing shapely geometry objects is created. The dissolve method of a geodatafarme allows aggregation of shapes in a similar way to aggregations using a groupby in a normal pandas dataframe.
The next step is to use apply, to add a column containing the postal districts. This is found by taking the first part of the postcode, and stripping any whitespace.
Now we load a file containing the coordinates of the most populous 100 places in the UK. We can iterate over that for each place, lat, lng and use the openrouteservice client api
This saves each GeoJson response for each isochrone into a file for use later. Each file can be read into a GeoDataFrame containing the 15, 30, 45 and 60 minute commute times for each place. This dataframe now contains 784 isochrone polygons.
Now we use the powerful sjoin (spatial join) method to identify postal districts that fall in each polygon. After using sjoin, and reshaping the dataframe, we have a useful commute time matrix that looks like the following.
Using the folium module allows us to plot the polygons into an openstreetmap map. Openstreetmap is a free GIS database that comes with several map tile options.
The following map shows all postal districts within 45 minutes of Heathrow aiport as a blue circle. This is entirely data driven, so adding the destination name will show the travel times and isochrones for any location we have stored in our list of places.
VP Process Excellence at InterContinental Hotels Group
4yFascinating. So much can be done with APIs and open source.