Summary and Schedule
This module teaches advanced methods of spatial analysis in Python. It is written for social scientists who already know the everyday operations (buffers, overlays, map algebra and zonal statistics), which are taught in the Data Processing module.
Each episode explains one method on this site, then links to three short Colab notebooks (Beginner, Intermediate and Advanced), each about 20 to 30 minutes.
| Episode | Question it answers | Tools |
|---|---|---|
| Network Analysis | How far is it by road, and how long does it take? |
osmnx, networkx
|
| Spatial Autocorrelation with PySAL | Are similar values clustered, and where? |
libpysal, esda, splot
|
| Spatial Clustering | Where do points concentrate into hotspots? |
scikit-learn, scipy
|
| NDVI Analysis | How green is the landscape in a satellite image? |
rasterio, numpy,
scikit-learn
|
The episodes can be taken in any order, though Spatial Clustering builds lightly on ideas from PySAL. Geocoding (turning addresses into points and downloading OpenStreetMap features) is taught in the Data Collection module and is good preparation for Network Analysis. QGIS users will find raster analysis of elevation and satellite imagery in Workshop 2026 Track A (DEM analysis, NDVI and flood mapping), and network analysis in the Case Studies module’s Grocery Access Part 2.
Prerequisites
- A Google account, to open the notebooks in Google Colab
- Basic Python,
pandasand GeoPandas (Foundations notebooks 2a to 4c); the Data Processing module’s Geoprocessing in Python episode is recommended - A free Census API key of your own (needed for the PySAL episode)
New to Python or Colab? Start with the Foundations module, then read the Setup page.
This module is part of Enabling the Geospatial Turn in the Social Sciences, a set of training modules developed at Purdue University with support from the National Science Foundation.
| Setup Instructions | Download files required for the lesson | |
| Duration: 00h 00m | 1. Network Analysis |
How can a road map be represented as a graph? How do we download and visualize road networks from OpenStreetMap? How do we find the shortest route and measure travel time? How do routes turn into measures of access, and what can go wrong? |
| Duration: 01h 25m | 2. Spatial Autocorrelation with PySAL |
What does it mean for data to be spatially autocorrelated? How do we tell the computer which places are neighbors? How do Global and Local Moran’s I measure and locate clustering? What choices and pitfalls affect the results? |
| Duration: 02h 50m | 3. Spatial Clustering |
What is spatial clustering and when is it useful? Why must coordinates be in meters before clustering? How do K-Means, hierarchical clustering, DBSCAN and HDBSCAN differ? When is a cluster of points really a hotspot? |
| Duration: 04h 15m | 4. NDVI Analysis |
What is NDVI and why is it useful? How do we read Landsat bands and compute NDVI in Python? How can we classify NDVI into land cover groups? What affects NDVI values, and how should they be interpreted? |
| Duration: 05h 40m | Finish |
The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.
The Python episodes run in Google Colab, a free online notebook service, so you do not need to install Python.
What you need
- A Google account
- A web browser (Chrome, Firefox, Edge or Safari)
- A free Census API key. Every learner needs their own. Request one at https://api.census.gov/data/key_signup.html; it arrives by email within a few minutes, and you must click the activation link in that email before it works. The PySAL episode cannot run without it.
Opening a notebook
- Click a notebook link in the Notebooks table at the end of any episode. It opens in Colab.
- Click File > Save a copy in Drive. Your own copy keeps your changes; the original stays read only.
- Run cells from top to bottom. Click a cell and press Shift + Enter, or click the play button to its left.
- The first time you run a cell, Colab may warn that the notebook was not written by Google. Click Run anyway.
Colab tips
- Run cells in order. Most errors come from skipping a cell, for example the one that reads the data.
- Start over cleanly with Runtime > Restart session and run all.
- Data lives in memory, so it disappears when the session ends. Rerun
the notebook to get it back. To keep an optional output (such as
ndvi.tif), open the Files panel on the left, right click the file and choose Download. - Cells that start with
!pip installadd libraries Colab does not include by default. They take a few seconds and only need to run once per session.
Data
You never need to download data. Every notebook reads its data
straight from the web into memory: pd.read_csv() and
gpd.read_file() accept a web address (including zipped
shapefiles), and rasterio.open() reads satellite images the
same way.
| Episode | Data | Source |
|---|---|---|
| Network Analysis | Road network of West Lafayette, Indiana | OpenStreetMap, through OSMnx |
| PySAL | Indiana counties and Marion County tracts, ACS 2023 5-year estimates | U.S. Census Bureau API and cartographic boundary files |
| Spatial Clustering | One year of Chicago crime reports
(CrimesChicago20220225.csv) |
Chicago Data Portal |
| NDVI | Landsat 8/9 Collection 2 Level-2 bands over Indiana
(band2.TIF to band5.TIF) |
USGS |
The Landsat bands are about 90 MB each, so reading them takes a few seconds.
Working offline or on your own computer (optional)
If you prefer to run the notebooks locally, install Anaconda and create an environment with the libraries used in this module:
BASH
conda create -n spatialturn -c conda-forge python=3.11 geopandas osmnx rasterio libpysal esda splot mapclassify scikit-learn folium geopy jupyterlab
conda activate spatialturn
jupyter lab
Then download a notebook from GitHub (File > Download > Download .ipynb in Colab) and open it in JupyterLab. The data is still read from the web, so you need an internet connection.