Finding the Dijkstra shortest path with NetworkX in pure Python
This recipe is a pure Python solution to calculate the shortest path on a network. NetworkX is the library we will use with many algorithms to solve the shortest path problem, including Dijkstra (http://networkx.github.io/). NetworkX relies on numpy
and scipy
to perform some graph calculations and help with performance. In this recipe, we will only use Python libraries to create our shortest path based on the same input Shapefile used in our previous recipe.
Getting ready
Start with installing NetworkX on your machine with the pip
installer as follows:
>> pip install networkx
For the network graph algorithms, NetworkX requires numpy
and scipy
, so take a look at Chapter 1, Setting Up ...
Get Python Geospatial Analysis Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.