R geospatial pipeline for hydrological river catchment mapping — Mecufi District, Cabo Delgado, Mozambique. Combines terrain analysis, D8 flow modelling, watershed delineation, and tmap v4 cartographic composition.
# River Catchment Map — Mecufi District, Cabo Delgado, Mozambique
An R pipeline that produces publication-quality river catchment maps for Mecufi District, combining hydrological analysis (D8 flow routing, watershed delineation) with cartographic composition in tmap v4. A flood exposure layer overlays population density weighted by drainage proximity, producing two map variants that compare different population datasets.
**Primary outputs** (300 dpi, 250 × 200 mm):
- `output/mecufi_catchment_map_real.png` — flood exposure using Maxar building-footprint counts
- `output/mecufi_catchment_map_estimated.png` — flood exposure using WorldPop 2026 RF model
---
## Quick Start
```r
# From R or RStudio (working directory = repo root)
source("run_analysis.R")
```
```bash
# From the terminal
Rscript run_analysis.R
```
For map styling iterations only (fastest — skips hydrology and DEM steps):
```r
# In run_analysis.R, force_rerun["map"] is TRUE by default.
# All other flags default to FALSE, so only the map step reruns.
source("run_analysis.R")
```
---
## Requirements
### R packages
```r
install.packages(c(
"sf", "terra", "whitebox", "tidyterra",
"tmap", # >= 4.0 required
"smoothr", "dplyr", "stringr", "scales"
))
```
**tmap v4 is required.** The setup script will error on v3.
### WhiteboxTools
Installed automatically on first run via `whitebox::install_whitebox()`. No manual setup needed.
---
## Input Data
Place source files in `gis/` before running. The pipeline reads archives directly — no manual extraction needed.
| Folder | File | Source |
|--------|------|--------|
| `gis/admin/` | `moz_admin_boundaries.shp.zip` | OCHA — ADM2 district boundaries |
| `gis/raster/elevation/` | `rasters_COP30.tar.gz` | Copernicus GLO-30 DEM tiles |
| `gis/raster/population/` | `MOZ_population_v1_1_gridded.tif` | Maxar — building-footprint constrained counts |
| `gis/raster/population/` | `moz_pop_2026_CN_100m_R2025A_v1.tif` | WorldPop 2026 RF model, 100 m |
| `gis/wate …