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 pgRouting


There are a few Python libraries out there, such as networkX and scikit-image, that can find the shortest path over a raster or NumPy array. We want to focus on routing over a vector source and returning a vector dataset; therefore, pgRouting is a natural choice for us. Custom Python Dijkstra or the A Star (A*) shortest path algorithms exist but one that performs well on large networks is hard to find. The pgRouting extension of PostgreSQL is used by OSM and many other projects and is well tested.

Our example will have us load a Shapefile of an indoor network from one floor for simplicity's sake. An indoor network is comprised of network lines that go along the hallways and open walkable spaces within a building, leading to a door in most cases.

Getting ready

For this recipe, we are going to need to set up our PostGIS database with the pgRouting extension. On a Windows machine, you can install pgRouting by downloading a ZIP file for Postgresql...