Python Geospatial Analysis Cookbook

Book description

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

About This Book

  • Explore the practical process of using geospatial analysis to solve simple to complex problems with reusable recipes
  • Concise step-by-step instructions to teach you about projections, vector, raster, overlay, indoor routing and topology analysis
  • Create a basic indoor routing application with geodjango

Who This Book Is For

If you are a student, teacher, programmer, geospatial or IT administrator, GIS analyst, researcher, or scientist looking to do spatial analysis, then this book is for you. Anyone trying to answer simple to complex spatial analysis questions will get a working demonstration of the power of Python with real-world data. Some of you may be beginners with GIS, but most of you will probably have a basic understanding of geospatial analysis and programming.

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

In Detail

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.

Style and approach

Easy-to-follow, step-by-step recipes, explaining from start to finish how to accomplish real-world tasks.

Table of contents

  1. Python Geospatial Analysis Cookbook
    1. Table of Contents
    2. Python Geospatial Analysis Cookbook
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Sections
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      5. Conventions
      6. Reader feedback
      7. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    8. 1. Setting Up Your Geospatial Python Environment
      1. Introduction
      2. Installing virtualenv and virtualenvwrapper
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more…
      3. Installing pyproj and NumPy
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Installing shapely, matplotlib, and descartes
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Installing pyshp, geojson, and pandas
        1. Getting ready
        2. How to do it...
        3. How it works...
      6. Installing SciPy, PySAL, and IPython
        1. Getting ready
        2. How to do it...
        3. How it works...
      7. Installing GDAL and OGR
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      8. Installing GeoDjango and PostgreSQL with PostGIS
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
    9. 2. Working with Projections
      1. Introduction
      2. Discovering projection(s) of a Shapefile or GeoJSON dataset
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      3. Listing projection(s) from a WMS server
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Creating a projection definition for a Shapefile if it does not exist
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Batch setting the projection definition of a folder full of Shapefiles
        1. How to do it...
        2. How it works...
      6. Reprojecting a Shapefile from one projection to another
        1. How to do it...
        2. How it works...
        3. See also
    10. 3. Moving Spatial Data from One Format to Another
      1. Introduction
      2. Converting a Shapefile to a PostGIS table using ogr2ogr
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      3. Batch importing a folder of Shapefiles into PostGIS using ogr2ogr
        1. How to do it...
        2. How it works...
        3. There's more…
      4. Batch exporting a list of tables from PostGIS to Shapefiles
        1. How to do it...
        2. How it works...
        3. There's more...
      5. Converting an OpenStreetMap (OSM) XML to a Shapefile
        1. Getting ready
        2. How to do it...
        3. How it works...
      6. Converting a Shapefile (vector) to a GeoTiff (raster)
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      7. Converting a raster (GeoTiff) to a vector (Shapefile) using GDAL
        1. Getting ready
        2. How to do it...
        3. How it works...
      8. Creating a Shapefile from point data stored in Microsoft Excel
        1. Getting ready
        2. How to do it...
        3. How it works...
      9. Converting an ESRI ASCII DEM to an image height map
        1. Getting ready
        2. How to do it...
        3. How it works...
    11. 4. Working with PostGIS
      1. Introduction
      2. Executing a PostGIS ST_Buffer analysis query and exporting it to GeoJSON
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Finding out whether a point is inside a polygon
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      4. Splitting LineStrings at intersections using ST_Node
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Checking the validity of LineStrings
        1. How to do it...
      6. Executing a spatial join and assigning point attributes to a polygon
        1. Getting ready
        2. How to do it...
        3. How it works...
      7. Conducting a complex spatial analysis query using ST_Distance()
        1. Getting ready
        2. How to do it...
        3. How it works...
    12. 5. Vector Analysis
      1. Introduction
      2. Clipping LineStrings to an area of interest
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Splitting polygons with lines
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Finding the location of a point on a line using linear referencing
        1. How to do it...
        2. How it works...
        3. See also
      5. Snapping a point to the nearest line
        1. How to do it...
        2. How it works...
      6. Calculating 3D ground distance and total elevation gain
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
    13. 6. Overlay Analysis
      1. Introduction
      2. Punching holes in polygons with a symmetric difference operation
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Union polygons without merging
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Union polygons with merging (dissolving)
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Performing an identity function (difference + intersection)
        1. How to do it...
        2. How it works...
    14. 7. Raster Analysis
      1. Introduction
      2. Loading a DEM USGS ACSII CDED into PostGIS
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Creating an elevation profile
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Creating a hillshade raster from your DEM with ogr
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Generating slope and aspect images from your DEM
        1. Getting ready
        2. How to do it...
        3. How it works...
      6. Merging rasters to generate a color relief map
        1. Getting ready
        2. How to do it...
        3. How it works...
    15. 8. Network Routing Analysis
      1. Introduction
      2. Finding the Dijkstra shortest path with pgRouting
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Finding the Dijkstra shortest path with NetworkX in pure Python
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Generating evacuation polygons based on an indoor shortest path
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Creating centerlines from polygons
        1. Getting ready
        2. How to do it...
        3. How it works...
      6. Building an indoor routing system in 3D
        1. Getting ready
        2. How to do it...
        3. How it works...
      7. Calculating indoor route walk time
        1. How to do it...
        2. How it works...
    16. 9. Topology Checking and Data Validation
      1. Introduction
      2. Creating a rule – only one point inside a polygon
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. A point must be on the starting and ending nodes of a line only
        1. How to do it...
        2. How it works...
      4. LineStrings must not overlap
        1. How to do it...
        2. How it works...
      5. A LineString must not have dangles
        1. How to do it...
        2. How it works...
      6. A polygon centroid must be within a specific distance of a line
        1. How to do it...
        2. How it works...
    17. 10. Visualizing Your Analysis
      1. Introduction
      2. Generating a leaflet web map with Folium
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Setting up TileStache to serve tiles
        1. Getting ready
        2. How to do it...
      4. Visualizing DEM data with Three.js
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Draping an orthophoto over a DEM
        1. Getting ready
        2. How to do it...
        3. How it works...
    18. 11. Web Analysis with GeoDjango
      1. Introduction
      2. Setting up a GeoDjango web application
        1. Getting ready
        2. How to do it...
      3. Creating an indoor web routing service
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Visualizing an indoor routing service
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Creating an indoor route-type service
        1. Getting ready
        2. How to do it...
        3. How it works...
      6. Creating an indoor route from room to room
        1. Getting ready
        2. How to do it...
        3. How it works...
    19. A. Other Geospatial Python Libraries
    20. B. Mapping Icon Libraries
    21. Index

Product information

  • Title: Python Geospatial Analysis Cookbook
  • Author(s): Michael Diener
  • Release date: November 2015
  • Publisher(s): Packt Publishing
  • ISBN: 9781783555079