Python Geospatial Analysis Cookbook

Over 60 recipes to work with topology, overlays, indoor routing, and web application analysis with Python

Python Geospatial Analysis Cookbook

Cookbook
Michael Diener

3 customer reviews
Over 60 recipes to work with topology, overlays, indoor routing, and web application analysis with Python
$39.99
$49.99
RRP $39.99
RRP $49.99
eBook
Print + eBook

Instantly access this course right now and get the skills you need in 2017

With unlimited access to a constantly growing library of over 4,000 eBooks and Videos, a subscription to Mapt gives you everything you need to learn new skills. Cancel anytime.

Free Sample

Book Details

ISBN 139781783555079
Paperback310 pages

Book Description

Geospatial development links your data to places on the Earth’s surface. Its analysis is used in almost every industry to answer location type questions. Combined with the power of the Python programming language, which is becoming the de facto spatial scripting choice for developers and analysts worldwide, this technology will help you to solve real-world spatial problems.

This book begins by tackling the installation of the necessary software dependencies and libraries needed to perform spatial analysis with Python. From there, the next logical step is to prepare our data for analysis; we will do this by building up our tool box to deal with data preparation, transformations, and projections. Now that our data is ready for analysis, we will tackle the most common analysis methods for vector and raster data. To check or validate our results, we will explore how to use topology checks to ensure top-quality results. This is followed with network routing analysis focused on constructing indoor routes within buildings, over different levels.

Finally, we put several recipes together in a GeoDjango web application that demonstrates a working indoor routing spatial analysis application. The round trip will provide you all the pieces you need to accomplish your own spatial analysis application to suit your requirements.

Table of Contents

Chapter 1: Setting Up Your Geospatial Python Environment
Introduction
Installing virtualenv and virtualenvwrapper
Installing pyproj and NumPy
Installing shapely, matplotlib, and descartes
Installing pyshp, geojson, and pandas
Installing SciPy, PySAL, and IPython
Installing GDAL and OGR
Installing GeoDjango and PostgreSQL with PostGIS
Chapter 2: Working with Projections
Introduction
Discovering projection(s) of a Shapefile or GeoJSON dataset
Listing projection(s) from a WMS server
Creating a projection definition for a Shapefile if it does not exist
Batch setting the projection definition of a folder full of Shapefiles
Reprojecting a Shapefile from one projection to another
Chapter 3: Moving Spatial Data from One Format to Another
Introduction
Converting a Shapefile to a PostGIS table using ogr2ogr
Batch importing a folder of Shapefiles into PostGIS using ogr2ogr
Batch exporting a list of tables from PostGIS to Shapefiles
Converting an OpenStreetMap (OSM) XML to a Shapefile
Converting a Shapefile (vector) to a GeoTiff (raster)
Converting a raster (GeoTiff) to a vector (Shapefile) using GDAL
Creating a Shapefile from point data stored in Microsoft Excel
Converting an ESRI ASCII DEM to an image height map
Chapter 4: Working with PostGIS
Introduction
Executing a PostGIS ST_Buffer analysis query and exporting it to GeoJSON
Finding out whether a point is inside a polygon
Splitting LineStrings at intersections using ST_Node
Checking the validity of LineStrings
Executing a spatial join and assigning point attributes to a polygon
Conducting a complex spatial analysis query using ST_Distance()
Chapter 5: Vector Analysis
Introduction
Clipping LineStrings to an area of interest
Splitting polygons with lines
Finding the location of a point on a line using linear referencing
Snapping a point to the nearest line
Calculating 3D ground distance and total elevation gain
Chapter 6: Overlay Analysis
Introduction
Punching holes in polygons with a symmetric difference operation
Union polygons without merging
Union polygons with merging (dissolving)
Performing an identity function (difference + intersection)
Chapter 7: Raster Analysis
Introduction
Loading a DEM USGS ACSII CDED into PostGIS
Creating an elevation profile
Creating a hillshade raster from your DEM with ogr
Generating slope and aspect images from your DEM
Merging rasters to generate a color relief map
Chapter 8: Network Routing Analysis
Introduction
Finding the Dijkstra shortest path with pgRouting
Finding the Dijkstra shortest path with NetworkX in pure Python
Generating evacuation polygons based on an indoor shortest path
Creating centerlines from polygons
Building an indoor routing system in 3D
Calculating indoor route walk time
Chapter 9: Topology Checking and Data Validation
Introduction
Creating a rule – only one point inside a polygon
A point must be on the starting and ending nodes of a line only
LineStrings must not overlap
A LineString must not have dangles
A polygon centroid must be within a specific distance of a line
Chapter 10: Visualizing Your Analysis
Introduction
Generating a leaflet web map with Folium
Setting up TileStache to serve tiles
Visualizing DEM data with Three.js
Draping an orthophoto over a DEM
Chapter 11: Web Analysis with GeoDjango
Introduction
Setting up a GeoDjango web application
Creating an indoor web routing service
Visualizing an indoor routing service
Creating an indoor route-type service
Creating an indoor route from room to room

What You Will Learn

  • Discover the projection and coordinate system information of your data and learn how to transform that data into different projections
  • Import or export your data into different data formats to prepare it for your application or spatial analysis
  • Use the power of PostGIS with Python to take advantage of the powerful analysis functions
  • Execute spatial analysis functions on vector data including clipping, spatial joins, measuring distances, areas, and combining data to new results
  • Create your own set of topology rules to perform and ensure quality assurance rules in Python
  • Find the shortest indoor path with network analysis functions in easy, extensible recipes revolving around all kinds of network analysis problems
  • Visualize your data on a map using the visualization tools and methods available to create visually stunning results
  • Build an indoor routing web application with GeoDjango to include your spatial analysis tools built from the previous recipes

Authors

Table of Contents

Chapter 1: Setting Up Your Geospatial Python Environment
Introduction
Installing virtualenv and virtualenvwrapper
Installing pyproj and NumPy
Installing shapely, matplotlib, and descartes
Installing pyshp, geojson, and pandas
Installing SciPy, PySAL, and IPython
Installing GDAL and OGR
Installing GeoDjango and PostgreSQL with PostGIS
Chapter 2: Working with Projections
Introduction
Discovering projection(s) of a Shapefile or GeoJSON dataset
Listing projection(s) from a WMS server
Creating a projection definition for a Shapefile if it does not exist
Batch setting the projection definition of a folder full of Shapefiles
Reprojecting a Shapefile from one projection to another
Chapter 3: Moving Spatial Data from One Format to Another
Introduction
Converting a Shapefile to a PostGIS table using ogr2ogr
Batch importing a folder of Shapefiles into PostGIS using ogr2ogr
Batch exporting a list of tables from PostGIS to Shapefiles
Converting an OpenStreetMap (OSM) XML to a Shapefile
Converting a Shapefile (vector) to a GeoTiff (raster)
Converting a raster (GeoTiff) to a vector (Shapefile) using GDAL
Creating a Shapefile from point data stored in Microsoft Excel
Converting an ESRI ASCII DEM to an image height map
Chapter 4: Working with PostGIS
Introduction
Executing a PostGIS ST_Buffer analysis query and exporting it to GeoJSON
Finding out whether a point is inside a polygon
Splitting LineStrings at intersections using ST_Node
Checking the validity of LineStrings
Executing a spatial join and assigning point attributes to a polygon
Conducting a complex spatial analysis query using ST_Distance()
Chapter 5: Vector Analysis
Introduction
Clipping LineStrings to an area of interest
Splitting polygons with lines
Finding the location of a point on a line using linear referencing
Snapping a point to the nearest line
Calculating 3D ground distance and total elevation gain
Chapter 6: Overlay Analysis
Introduction
Punching holes in polygons with a symmetric difference operation
Union polygons without merging
Union polygons with merging (dissolving)
Performing an identity function (difference + intersection)
Chapter 7: Raster Analysis
Introduction
Loading a DEM USGS ACSII CDED into PostGIS
Creating an elevation profile
Creating a hillshade raster from your DEM with ogr
Generating slope and aspect images from your DEM
Merging rasters to generate a color relief map
Chapter 8: Network Routing Analysis
Introduction
Finding the Dijkstra shortest path with pgRouting
Finding the Dijkstra shortest path with NetworkX in pure Python
Generating evacuation polygons based on an indoor shortest path
Creating centerlines from polygons
Building an indoor routing system in 3D
Calculating indoor route walk time
Chapter 9: Topology Checking and Data Validation
Introduction
Creating a rule – only one point inside a polygon
A point must be on the starting and ending nodes of a line only
LineStrings must not overlap
A LineString must not have dangles
A polygon centroid must be within a specific distance of a line
Chapter 10: Visualizing Your Analysis
Introduction
Generating a leaflet web map with Folium
Setting up TileStache to serve tiles
Visualizing DEM data with Three.js
Draping an orthophoto over a DEM
Chapter 11: Web Analysis with GeoDjango
Introduction
Setting up a GeoDjango web application
Creating an indoor web routing service
Visualizing an indoor routing service
Creating an indoor route-type service
Creating an indoor route from room to room

Book Details

ISBN 139781783555079
Paperback310 pages
Read More
From 3 reviews

Read More Reviews