Python for Geospatial Analysis
About this course
Python has a full stack for spatial data. The main libraries are GeoPandas and Shapely for vector data, Rasterio and xarray for rasters and gridded data, pyproj for projections, and PySAL for spatial statistics. An analysis written with these libraries can be re-run when the data changes, versioned in Git, reviewed and handed to a colleague. The analysis also keeps working when the dataset outgrows what a desktop GIS will open.
The course starts from Python itself, so you do not need to know the language beforehand. Days One to Three build the foundations the spatial work depends on. Day One covers the language and file handling, Day Two covers Pandas for tabular analysis and reporting, and Day Three covers NumPy, time-series, simulation, clustering and anomaly detection. These foundations are what let you write your own analysis afterwards, rather than adapt someone else's.
Day Four focuses on spatial analysis. You work with geometries and attribute tables together, and read the formats your data actually arrives in. You also convert between raster and vector in both directions: masking a raster to a polygon, rasterising geometries, and vectorising regions back to polygons. Projections get real attention. A projection mismatch does not raise an error, and gives you the wrong answer without warning. The worked example runs into exactly that failure before fixing it. You then detect features in aerial infra-red imagery, measure them, and check the result against a ground-truthed survey.
Day Five covers the wider scientific stack, faster numerical code, and datasets that no longer fit in memory.
Worked examples use real data from environmental, satellite and public statistical sources, rather than tidied teaching sets. Every topic mixes instruction with hands-on exercises, and the trainer works through them with you.
Bring your own datasets and we will work through them with you. Our trainers work with spatial data for a living, so they can take a problem they have not seen before and solve it in the room. The questions that come out of your own data are usually the ones you came for.
Who this course is for
GIS analysts, scientists, engineers, surveyors and data analysts who work with spatial data and want to move that work into Python. The course suits people who produce their maps and analysis by clicking through a desktop GIS such as QGIS or ArcGIS, or in spreadsheets, and who repeat the same sequence of steps every time the source data is refreshed.
This course also suits teams in environment and water agencies, transport and infrastructure, mining and resources, emergency services, local government, and health and statistical agencies, where spatial analysis has to be reproduced, reviewed and handed on.
Prerequisites
Some familiarity with programming concepts in any language is helpful, but prior programming experience is not required. You do not need to have written Python before.
You should have a working understanding of spatial data, such as what a projection is and the difference between raster and vector. The first three days build the Python, data-handling and analysis foundations the geospatial material depends on, so no Pandas, NumPy or Python library experience is assumed.
What you will learn
- Read, write and analyse vector data with GeoPandas and Shapely, including overlays and spatial joins
- Diagnose and fix projection and coordinate reference system problems, and reproject datasets so they line up
- Work with raster and multi-dimensional gridded data using Rasterio and xarray, and convert between raster and vector representations
- Extract information from aerial imagery with image processing, and check the result against ground-truthed survey data
- Produce maps that combine statistical data with spatial boundaries
- Build spatial workflows in Python that are repeatable and that keep working on datasets larger than memory
Syllabus
Day 1: Python foundations
- Working in Jupyter, and the Python language essentials
- Data structures, control flow and writing your own functions
- Working with files and the standard library
- Retrieving data from web APIs: query parameters, rate limits and results
Day 2: Handling, analysing and presenting data
- Reading and writing data from files and databases
- Tabular analysis with Pandas: indexing, joins and group-by
- Reshaping data and building pivot tables
- Statistical graphics for exploring and presenting results
- Producing automated reports from a notebook
Day 3: Time-series, simulation, inference and modelling
- Dates, times and time-series analysis
- Numerical data and linear algebra with NumPy
- Monte Carlo sampling and simulation
- Cluster analysis, including clustering of imagery and time-series
- Detecting outliers and anomalies
Day 4: Spatial analysis in Python
- Vector geometries with Shapely: predicates, transformations and formats
- Vector data with GeoPandas: reading spatial files and PostGIS, overlays, spatial joins, and mapping a data column across spatial boundaries
- Projections and coordinate reference systems with pyproj
- Reading and writing rasters with Rasterio, masking with a vector boundary, and converting between raster and vector
- Multi-dimensional gridded data with xarray and netCDF
- Detecting features in aerial imagery with scikit-image, and comparing the result against ground-truthed survey data
- Interpolating gridded and n-dimensional image data
- Spatial connectivity and autocorrelation with PySAL
Day 5: Scientific computing and scaling up
- Scientific computing with SciPy: interpolation, optimisation and curve fitting
- Differential equations, classical statistics and linear algebra
- Faster numerical code: vectorisation, numexpr, Numba and Cython
- Working with datasets larger than memory using Dask
- Bringing the pieces together on your own data