Skip to Content

Getting Started with Spatial Analysis

The spatial workflows run on Python with GeoPandas for vector data and Matplotlib for rendering. This page gets you from a clean environment to a first rendered boundary map.

Create the environment

The notebooks were authored on Python 3.12. Create an isolated environment with the geospatial stack:

conda create -n geo-spatial -c conda-forge python=3.12 \ geopandas matplotlib pyreadstat xlrd openpyxl pandas numpy conda activate geo-spatial

geopandas pulls native libraries (GDAL, PROJ, GEOS). Installing from conda-forge is the reliable path — pip install geopandas often fails to resolve the system GDAL.

Get the source

The notebooks are versioned in the repository; their input layers live on the Hugging Face dataset nhic/rwanda-spatial, not in git. Download and unzip them into the layout the notebooks expect:

pip install -U huggingface_hub cd analysis/spatial-analysis hf download nhic/rwanda-spatial --repo-type dataset --local-dir hf unzip -o hf/rwanda-admin-boundaries.zip -d rwanda unzip -o hf/cells-admin4.zip -d Cell_Shapefile unzip -o hf/villages-admin5.zip -d Village_shapefile unzip -o hf/wetlands.zip -d Wetland unzip -o hf/environmental-layers.zip -d shapefiles cp hf/climate-data.xls "Climate data.xls"

Load a boundary shapefile

Each administrative level is a single shapefile. Reading one returns a GeoDataFrame:

import geopandas as gpd sectors = gpd.read_file("rwanda/rwa_adm3_2006_NISR_WGS1984_20181002.shp") print(sectors.crs) # EPSG:4326 (WGS84) print(len(sectors)) # ~416 sectors

Plot it

import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=(9, 8)) sectors.boundary.plot(ax=ax, linewidth=0.3) ax.set_axis_off() plt.show()

This renders the sector geometries — the base layer every choropleth builds on:

charts/sectors_admin3.png

Where things live

PathContents
analysis/spatial-analysis/*.ipynbThe Climate_maps and Bar-Plots notebooks
analysis/spatial-analysis/rwanda/NISR admin boundaries (admin1admin4)
analysis/spatial-analysis/Village_shapefile/Village boundaries (admin5)
analysis/spatial-analysis/shapefiles/Water, wetland, and land-cover context layers
analysis/spatial-analysis/Climate data.xlsERA5-Land climate variables by health facility

To regenerate the map images, run the generator — it executes both notebooks and writes the PNGs to public/analytics/spatial-analysis/ (git-ignored), then publish them to Hugging Face:

python analysis/spatial-analysis/generate_figures.py bash scripts/upload-spatial-to-hf.sh

The site build itself stays Node-only — Python is only needed to regenerate figures, never to serve the docs.

Next steps

Last updated on