A couple of days ago, I came across the incredible looking
osmnx Python package, originally created by Geoff Boeing at UC Berkeley in support of his PhD, via one of his blog posts: OSMnx: Python for Street Networks (there is a citeable paper, but that’s not what I originally found…) There are also some great example notebooks:
I spent a chunk of today having a play with is, and have posted a notebook walkthrough here.
It’s quite incredible…
Pretty much a one-liner lets you pull back all the roads in a particular area, searched for by name:
osmnx package represents routes as a
networkx graph – so we can do graphy things with it, like finding the shortest distance between two points, aka route planning:
The route can also be plotted on an interactive map. An option lets you hover on a route and display a context sensitive tooltip, in this case the name of the road:
Retrieving routes by area name is handy, but we can also pull back routes within a certain distance of a specified location, or routes that are contained within a particular region specified by a shapefile.
In a previous post (Trying Out Spatialite Support in Datasette) I showed how to put Ordnance Survey BoundaryLine data into a SpatiaLite database and then access the geojson boundary files from a datasette API. We can use that approach again, here wrapped up in a dockerised context:
Using the retrieved boundary shapefile, we can then use
osmnx to just grab the roads contained within that region, in this case my local parish:
Once again, we can use an interactive map to display the results:
If we overlay the parish boundary, we see that the routes returned correspond to the graph between nodes that lay within the boundary. Some roads pass straight through the boundary, others appear to lay just outside the boundary.
However, it looks like we can tweak various parameters to get the full extent of the roads within the region:
As well as routes, we can also get building footprints from OpenStreetMap:
If you know where to look, you can see our house!
Building footprints can also be overlaid on routes:
If we generate a distance to time mapping, the graph representation means we can also colouring nodes according to how far in walking time, for example, they are from a particular location:
We can also overlay routes on isochrone areas to show travel times along routes – so where’s within half an hour’s walk of the Pointer Inn in Newchurch?
Living on a holiday island, I wonder if there’s any mileage (!) in offering a simple service for campsites, hotels etc that would let them print off isochrone walking maps centred on the campsite, hotel etc with various points of interest, and estimated walking times, highlighted?
I’m also wondering how much work would be required in order to add additional support to the
osmnx package so that it could use Ordnance Survey, rather than OSM, data?
And finally, one other thing I’d like to explore is how to generate tulip diagrams from route graphs… If anyone has any ideas about that, please let me know via the comments…
PS for building outlines in the UK derived from Ordnance Survey data, see for example Alasdair Rae’s OS OpenMap Local – All Buildings in Great Britain.
PPS And building footprints for the US, courtesy of Microsoft: https://github.com/Microsoft/USBuildingFootprints