O'Reilly logo

Python Geospatial Analysis Cookbook by Michael Diener

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required