title: "Chapter 2 — Watershed Delineation" chapter: 2
Chapter 2 — Watershed Delineation
Every raindrop that falls on land belongs to exactly one drainage basin. The invisible line separating basins — the watershed divide — can be drawn automatically from any DEM using the flow-direction grid we built in Chapter 1.
2.1 — What Is a Watershed?
A watershed (or catchment) is the set of all cells whose water eventually reaches a given pour point — the outlet where flow leaves the area of interest. The contributing area at a pour point satisfies:
Every cell upstream of is part of its watershed; every cell that drains elsewhere is not.
Click any cell to trace its path downstream ("Trace Down"), or to light up every cell that drains through it ("Show Watershed"). Left-click a cell in the watershed mode to relocate the pour point; check "✏️ Edit Terrain" to modify elevations.
Watershed Concept
Click any cell — trace its path or see its full contributing area
Click any cell to trace its flow path to the outlet.
Notice how clicking the outlet corner (3,3) highlights all 16 cells — the entire grid is one watershed when there is a single outlet. Move the pour point inland to select only the contributing sub-area.
2.2 — The Upstream Tracing Algorithm
D8 arrows point downstream. To find a watershed we must follow them backwards — a Breadth-First Search (BFS) upstream.
watershed ← {pour_point}
queue ← [pour_point]
while queue not empty:
(r, c) ← queue.dequeue()
for each neighbour (nr, nc) of (r, c):
if flow[nr][nc] points INTO (r, c): # arrow tip lands on (r,c)
watershed.add(nr, nc)
queue.enqueue(nr, nc)
The key test: does flow[nr][nc] point into (r,c)? In D8 terms, nr + Δr = r and nc + Δc = c.
Click any cell to place the pour point, then press "▶ Delineate" to watch BFS expand step by step. The queue panel on the right shows pending cells (amber = currently examined); the step log records every neighbour check.
BFS Upstream Delineation
Click a cell to set the pour point, then animate the upstream search
BFS Queue
Click a cell to set the pour point
Step Log
Controls
Select a pour point
BFS visits every cell at most once, so delineation runs in — a full continental DEM with 10⁸ cells takes only seconds.
2.3 — Divides, Multiple Catchments & Stream Order
Real landscapes contain many basins separated by divides — ridgelines where adjacent cells flow in opposite directions.
Tab 1 colours the two basins and marks divide cells in orange. Tab 2 animates two raindrops released on either side of the ridge — they flow to opposite outlets. Tab 3 shows the Strahler stream order: order 1 at headwaters, order increases only when two streams of the same order merge.
Catchment Maps & Divides
Ridge terrain — two basins separated by a divide
Left-click a cell to raise elevation · Right-click to lower · Watch basins reflow live.
The ridge terrain splits cleanly into two 8-cell basins. Drag the FA threshold slider in Tab 3 to see how the stream network grows as you lower the minimum contributing area.
2.4 — Explore Full Terrain
Switch between five 8×8 presets — valley, mountain, ridge, slope, basin — and explore how terrain shape controls basin geometry and stream structure.
- ✏️ Edit: raise / lower any cell; watershed and streams update instantly.
- 📍 Pour Point: click any cell to delineate its watershed in one step.
- 🌊 Stream Network: view the channel network without a pour point; adjust FA threshold .
Toggle Strahler Colors to see stream order superimposed on the watershed shading.
Explore Watersheds
Edit terrain · set pour points · discover drainage basins
Left-click to raise · Right-click to lower
Preset Terrain
Interaction Mode
Overlays
Stream Threshold
— Set a pour point (📍 mode) —
Elevation Ramp
2.5 — For Grad Students
Pfafstetter coding (1997) — hierarchical basin numbering 1–9; odd digits = tributary basins, even digits = mainstem inter-basin segments. Up to 9 nesting levels encode every sub-basin globally without overlap:
Hypsometric curve — cumulative fraction of area above elevation :
HI > 0.6 → young, actively dissected landscape; HI < 0.35 → peneplain (monadnock stage).
Flat-area routing — Wang & Liu fill creates artificial flats where D8 is ambiguous. Solutions: (1) Priority-Flood + -gradient (Barnes 2014); (2) least-cost-distance routing (LDD); (3) D∞ on the original unfilled DEM.
Algorithmic complexity:
| Step | Algorithm | Complexity |
|---|---|---|
| Delineation | Upstream BFS | |
| Catchment map | BFS per outlet | |
| Strahler order | Topo-sort + one pass | |
| Pfafstetter | Recursive delineation |
Summary
| Concept | Rule | Key point |
|---|---|---|
| Watershed | All cells draining to a pour point | Found by upstream BFS, not downstream tracing |
| BFS delineation | Check if flow[nr][nc] points into (r,c) | ; each cell visited once |
| Divide | Cells whose neighbours belong to different basins | Ridge cells — one raindrop, two fates |
| Flow accumulation | FA ≥ τ defines the channel network | Larger τ → fewer, longer streams |
| Strahler order | Confluence of equal orders increments order | Quantifies network branching complexity |
Chapter 3 → Rainfall–runoff processes — how precipitation becomes streamflow through Hortonian overland flow, saturation-excess, and infiltration.