Creating a route planner for a road network
In this recipe, we build upon several techniques described in the previous recipes in order to create a simple GPS-like route planner in Python. We will retrieve California's road network data from the United States Census Bureau in order to find shortest paths in the road network graph. This will allow us to display road itineraries between any two locations in California.
Getting ready
You need Smopy for this recipe. You can install it with pip install git+https://github.com/rossant/smopy
. In order for NetworkX to read Shapefile datasets, you also need GDAL/OGR. You can install it with conda install gdal
.
Tip
At the time of this writing, gdal does not appear to work well with conda and Python 3.6. You may need to downgrade Python to Python 3.5 with conda install python=3.5
.
How to do it...
- Let's import the packages:
>>> import io import zipfile import requests import networkx as nx import numpy as np import pandas...