Book Image

Python Geospatial Analysis Cookbook

Book Image

Python Geospatial Analysis Cookbook

Overview of this book

Table of Contents (20 chapters)
Python Geospatial Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Other Geospatial Python Libraries
Mapping Icon Libraries
Index

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 Your Geospatial Python Environment, for instructions on these. We also use Shapely to generate our geometry outputs to create GeoJSON files, so check whether you have installed Shapely. One hidden requirement is that GDAL/OGR is used in the back...