Notebook 1: Python for Geospatial Data
Hands-on with GeoPandas and Rasterio
Session 3 Hands-On Notebook
This notebook accompanies Session 3: Python for Geospatial Data. You’ll learn to work with vector data using GeoPandas and raster data using Rasterio.
Learning Objectives
By completing this notebook, you will:
- Load, filter and map Philippine administrative boundaries with GeoPandas
- Use projected coordinate systems for areas, buffers and dissolves
- Search a STAC catalogue and stream a Sentinel-2 L2A subset (Cloud-Optimized GeoTIFF) with Rasterio
- Convert Sentinel-2 digital numbers to reflectance (including the post-2022 offset)
- Compute and interpret NDVI and NDWI
- Clip rasters to boundaries and compute zonal statistics
- Save results as GeoTIFF and GeoPackage
Getting Started
Option 1: Open in Google Colab (Recommended)
Click the button below to open this notebook in Google Colab:
Advantages: - No installation required - Runs on a free CPU runtime (no GPU needed for this notebook) - Can save outputs to your Google Drive
Option 2: Download Notebook
Download the Jupyter notebook to run locally or upload to your own Colab:
Requirements for local use:
pip install numpy pandas matplotlib geopandas rasterio pystac-client planetary-computer contextilyOption 3: View Online
You can also view the notebook content below without running any code.
Notebook Preview
This is a hands-on exercise notebook. For the best learning experience, open it in Google Colab or Jupyter to run the code cells interactively.
Topics Covered
- Environment setup (Colab or local) and a short Python recap
- GeoPandas with Natural Earth boundaries: inspect, filter, dissolve Metro Manila, 50 km buffer, maps with a basemap
- Rasterio + STAC: Sentinel-2 L2A over Puerto Princesa, Palawan from Microsoft Planetary Computer; reflectance conversion, band statistics, true/false colour composites, NDVI
- Vector + raster: reprojection, clipping to the Palawan boundary, overlay, zonal statistics, saving results
- Best practices (memory, CRS, nodata) and a recap
Prerequisites
Before starting this notebook, ensure you have:
- Completed the Setup Guide
- Google account (for Colab)
- Basic Python knowledge
- Understanding of Session 3 concepts
Notebook Contents
The full interactive notebook includes:
- About 30 code cells, all runnable without an account
- Two exercises (home province map; NDWI water index) with hidden solutions
- A table of common errors and fixes
Support
During the Training
- Ask questions in the live session (instructor-led cohorts)
- Work through the exercises at your own pace
After the Training
- Review the Cheat Sheets
- Check the FAQ
- Access the Glossary
Next Steps
After completing this notebook:
- ✅ Practice with your own Philippine data
- ✅ Move on to Session 4: Google Earth Engine
- ✅ Try Notebook 2: Google Earth Engine
Ready to code? Open the notebook in Colab and start learning!