Water over the ground
Pure, deterministic surface-water calculations executed in @tilemapper/surface from a project's stored elevation artifacts. Every depth, water-level, and volume calculation reads only the original ground DEM (surface: "original"), never the hydrologically conditioned surface. Flow paths and watersheds read the D8 flow-direction grid derived from the conditioned surface during terrain build.
All outputs are preliminary estimates for planning and visualization, not construction designs.
1. D8 Flow Direction, Raindrop Path, and Watersheds
Flow-direction encoding
The terrain worker (services/gis-worker/gis_worker/terrain/hydrology.py) uses WhiteboxTools' D8 pointer convention (bit flags, uint8, 0 = no outflow / sink / noData):
| Value | Direction | Row delta | Col delta | Step length |
|---|---|---|---|---|
| 1 | NE | -1 | +1 | sqrt(2) * c |
| 2 | E | 0 | +1 | c |
| 4 | SE | +1 | +1 | sqrt(2) * c |
| 8 | S | +1 | 0 | c |
| 16 | SW | +1 | -1 | sqrt(2) * c |
| 32 | W | 0 | -1 | c |
| 64 | NW | -1 | -1 | sqrt(2) * c |
| 128 | N | -1 | 0 | c |
where c is the DEM cell size in meters.
Raindrop trace
Starting at cell (r0, c0), follow the D8 pointer step-by-step until:
- The path enters ground that fills on the original DEM — a cell whose stored fill depth is at least
0.10 m(LOW_SPOT_MIN_DEPTH_M, the same depth threshold used byfind_low_spotsinservices/gis-worker/gis_worker/terrain/hydrology.py) — (terminus: "low_spot"). - The pointer leads outside the grid or to a noData cell, or stops (
pointer = 0) on a raster or clipped-valid boundary cell (terminus: "edge"). - The path is on a boundary cell and the water leaves the terrain there (
terminus: "edge"; plan v4 item 544). A boundary cell's pointer was chosen only among the neighbors the grid holds, so where the ground falls away past the edge it can only point along the edge, and a path that followed it ran on along the edge (section 7, case 1:61 mfor60). The ground past the edge is taken to go on at the slope it comes in at: the fall out through each missing neighbor is the fall into the cell from the neighbor opposite, over the same distance, read from the original DEM. Where the steepest of those is downhill and steeper than the fall along the pointer, the water leaves at this cell. A cell on the up-slope edge, whose ground past the edge would rise, keeps following its pointer, so a path that starts there, or that runs along an edge where the ground beyond would be higher (the 5 × 5 case below), is unchanged. Without original heights the pointers are followed. - The pointer is
0on an interior cell or hits an already-visited cell (terminus: "low_spot").
Threshold judgment (for engineer review): find_low_spots in the worker filters lidar noise with two thresholds: depth at least 0.10 m (LOW_SPOT_MIN_DEPTH_M) and connected depression area at least 100 m^2 (LOW_SPOT_MIN_AREA_M2). For a raindrop path, stopping at any fill_depth > 0 would trap nearly every path on sub-10 cm lidar noise (on real ground at Moorhead, 39,077 depressions had fill_depth > 0 while only 39 met the low-spot thresholds). Using fill_depth >= 0.10 m per cell without requiring area >= 100 m^2 is the conservative reading: it ignores sub-10 cm lidar speckles while still stopping a raindrop that enters a deep pocket smaller than 100 m^2 rather than claiming water runs off the field. The path stops at the first cell reaching 0.10 m fill depth, with length and fall measured to that cell.
- Path length (m): sum of step lengths (
cfor cardinal steps,sqrt(2) * cfor diagonal steps) from start to stopping cell. - Fall (m):
z_start - z_endread from the original DEM (positive downhill; may be negative if a conditioned breach climbs over a road embankment before reaching a ponding cell — the path reports both start and end original elevations).
Watershed delineation
Given pour-point cell (rp, cp), perform a reverse breadth-first search over all 8 neighbors: neighbor (rn, cn) drains into (r, c) if and only if its D8 pointer steps directly onto (r, c).
- Inside area:
A_in = N_cells * c^2. - Outside run-on entries (
outside_entry): During terrain build, the worker traces land past the terrain's edge on USGS's 1/3 arc-second DEM (10 m grid, 2 km margin) and stores each cell's own incoming area at the terrain cell where external flow enters (outside_entry, in m²), not as a downstream running total. When delineating a watershed, each cell visited by the reverse BFS adds its ownoutside_entryvalue once:A_out = sum(outside_entry[i])overiin the watershed. - Total area:
A_total = A_in + A_out(converted to acres via1 ac = 4046.8564224 m^2). - Invariants:
- On a valid D8 grid with no cycles, the cell count of the watershed delineated from cell
(r, c)equals the D8 flow-accumulation count (inclusive of itself) at(r, c). - One
5,000 m^2outside entry upstream of a clicked point adds exactly5,000 m^2to its watershed regardless of how many cells lie downstream of it. Storing entries rather than running totals also keeps outside accounting valid when a culvert changes the downstream route. - On a terrain built by the worker with a context DEM,
A_in + A_outat any clicked cell equals the worker's ownaccumulation_m2at that cell.
- On a valid D8 grid with no cycles, the cell count of the watershed delineated from cell
- A pour point in a low spot (plan v4 item 544): where the clicked cell's stored fill depth is at least
0.10 m, the same depth at which a raindrop stops in a low spot, the reverse search starts from every cell of that low spot: the 4-connected cells with fill depth above zero, as the rain comparison extracts them (section 4). Water reaching any part of a pond reaches all of it. The flow grid drains a filled low spot to one outlet, so the search from one cell found only the cells whose paths happened to cross it: at the bottom of the round pit of section 7, case 5,301 m^2of1,257. Where the clicked cell fills less than0.10 m, the search starts from that cell alone. The app never works a watershed without the fill-depth grid: the tool waits for it as it waits for the flow directions and outside entries, and the calculation dispatcher (executeTerrainTask) refuses a watershed without it, so one point on one terrain gets one answer whatever order the grids load in. Every terrain that stores outside entries stores fill depth with them (both arrived at pipeline version 6), and an older terrain has neither, so the watershed tool already asks for it to be rebuilt there. - Edge truncation ("at least"): If any cell in the watershed lies on the outer valid boundary of the DEM (a cell with valid data touching the grid border or an adjacent noData cell), the result sets
touchesEdge = trueand labels the total as "At least", even after adding traced outside entries (the coarser 2 km context read can still stop short of the full watershed or miss water that left and re-entered the terrain). The card reports both the inside and outside shares. - Holes: a watershed can enclose land that is not part of it (missing data, or a pocket that drains out diagonally). Boundary loops are sorted into outer rings and holes, and drawn and exported that way.
Hand-worked reference cases
5 × 5 converging grid (c = 10 m): All cells in rows 0–4 drain toward a single outlet at (4, 2):
- Columns 0–1 drain east (
2) to column 2; columns 3–4 drain west (32) to column 2; column 2 rows 0–3 drain south (8) to(4, 2);(4, 2)drains south (8) off the grid. - Raindrop from
(0, 0)with no ground that fills: moves E twice (20 m) then S four times (40 m) -> total length 60.0 m, fall 4.0 m, terminus"edge". - Raindrop from
(0, 0)with fill depth0.25 mat(1, 2)and0.40 mat(2, 2): moves E twice (20 m) then S once (10 m) into(1, 2)and stops -> total length 30.0 m, fall304.0 - 301.5 = 2.5 m, terminus"low_spot". - Watershed of
(4, 2): all 25 cells ->25 * 100 = 2500 m^2 = 0.61776 ac,touchesEdge = true. - Watershed of
(2, 2): rows 0–2 across all 5 columns = 15 cells ->1500 m^2. - Watershed with outside entries: on a 1 × 25 channel (
c = 10 m) flowing east with a single5,000 m^2entry at(0, 0), clicking at columnk(k = 0, 1, 5, 19, 24) always adds exactly5,000 m^2(A_total = (k + 1) * 100 + 5000 m^2).
Worker-built valley fixture (300 × 300 m field at 1 m inside a 3,000 × 3,000 m 10 m context DEM, hydrology.md):
- At the south swale
(290, 150), browser reverse BFS over the worker'sflow_dirandoutside_entryCOGs gives64,800 m^2inside +487,500 m^2outside =552,300 m^2(136.48 ac), matching the worker'saccumulation_m2[290, 150] = 552,300 m^2exactly.
2. Water-Level Flooding (Original DEM Only)
Given target water surface elevation h (m) on the original DEM:
- Unconstrained flooding: Every valid cell with
z_i < his inundated to depthd_i = h - z_i. - Connected flooding (seed point): Starting from a chosen cell
(rs, cs), flood only cells withz_i < hreachable via 8-connected neighbors whose elevations are also belowh. Roads, berms, and levees with crestz >= hblock the flood.- Explicit caveat: Airborne lidar captures the top of road embankments and cannot see culverts beneath them. Connected flooding therefore assumes closed embankments unless a culvert is explicitly modeled (PR 43).
- Totals:
A_flood = N_flood * c^2V_flood = c^2 * sum(h - z_i)over flooded cells- Converted to acre-feet via
1 ac-ft = 1233.48183754752 m^3.
3. Volume of Anything (Original DEM Only)
Given a closed polygon in grid coordinates (x, y):
- Select all valid cells whose center
(xc, yc)lies inside the polygon (even-odd ray-casting test). - Identify boundary cells: included cells that have at least one 4-neighbor outside the polygon or missing.
- Compute the reference elevation
z_ref(x, y)according to the chosen mode:lowest_edge:z_ref = min(z_b)across boundary cells.fixed_elevation: user-entered elevationz_ref(m).edge_plane: ordinary least-squares planez_ref(x, y) = a*(x - x_mean) + b*(y - y_mean) + dfitted to boundary cells(x_b, y_b, z_b). If boundary points are collinear (singular 3 × 3 normal matrix), fall back to the mean boundary elevation.
- Integrate prisms over every included cell:
dz_i = z_i - z_ref(x_i, y_i)V_above = c^2 * sum(dz_i)fordz_i > 0V_below = c^2 * sum(-dz_i)fordz_i < 0V_net = V_above - V_below- Converted to cubic yards via
1 yd^3 = 0.764554857984 m^3.
Vertical accuracy uncertainty range
When the terrain states a quality level and meets the USGS Lidar Base Specification (v2024 rev. A, Table 1; e.g., QL2 non-vegetated vertical accuracy RMSEz = 0.10 m), a systematic elevation offset of +/- RMSEz across the polygon area A shifts volume by:
dV_uncertainty = RMSEz * A
Because lidar vertical bias is spatially correlated at field scale, this conservative bound is reported alongside every volume rather than an optimistic uncorrelated sqrt(N) bound. When a source is marked as not meeting specification (meets_specification = false) or has no stated quality level, no specification range is assumed.
Hand-worked reference cases (synthetic cone and pit)
- Synthetic cone: Radius
R = 20 m, heightH = 4 mabove flat basez0 = 100 m(z(r) = 100 + 4*(1 - r/20)forr <= 20). Analytic volume:V = (1/3) * pi * R^2 * H = (1/3) * pi * 400 * 4 = 1675.516 m^3 = 2191.49 yd^3. Atc = 1 mwithfixed_elevation = 100, grid integration matches within 1.5%. - Synthetic conical pit: Radius
R = 20 m, depthD = 3 mbelow rimz0 = 100 m. Analytic volume:V_below = (1/3) * pi * R^2 * D = 400 * pi = 1256.637 m^3 = 1643.62 yd^3. Matches within 1.5% atc = 1 m.
4. After a Big Rain: Runoff and Ponding
Two runoff choices (user-selected, always stated on screen)
- All rain runs off (default upper bound):
Q = P. Every inch of entered rainfallPreaches the low spot from its contributing watershed. Explicitly stated on screen as the maximum water possible (ignoring infiltration and evapotranspiration). - NRCS Curve Number method: USDA NRCS National Engineering Handbook, Part 630 (Hydrology), Chapter 9 (Hydrologic Soil-Cover Complexes, July 2004, Table 9-1, pp. 9-2 to 9-3; matching TR-55 Tables 2-2b and 2-2c) and Chapter 10 (Estimation of Direct Runoff from Storm Rainfall, July 2004, Eq. 10-11, p. 10-4; Table 10-1, p. 10-6).
Cited Curve Number Table (ARC II, Ia = 0.2 * S)
Source: USDA NRCS NEH Part 630, Chapter 9, Table 9-1, pp. 9-2 to 9-3 (July 2004; and TR-55 Tables 2-2b, 2-2c):
| Land cover & management | Condition | A | B | C | D |
|---|---|---|---|---|---|
| Fallow — bare soil | — | 77 | 86 | 91 | 94 |
| Fallow — crop residue cover | Good | 74 | 83 | 88 | 90 |
| Row crops — straight row | Poor | 72 | 81 | 88 | 91 |
| Row crops — straight row | Good | 67 | 78 | 85 | 89 |
| Row crops — straight row + crop residue | Poor | 71 | 80 | 87 | 90 |
| Row crops — straight row + crop residue | Good | 64 | 75 | 82 | 85 |
| Small grain — straight row | Good | 63 | 75 | 83 | 87 |
| Small grain — straight row + crop residue | Good | 60 | 72 | 80 | 84 |
| Close-seeded legumes / rotation meadow — straight row | Good | 58 | 72 | 81 | 85 |
| Pasture, grassland, or range | Poor | 68 | 79 | 86 | 89 |
| Pasture, grassland, or range | Fair | 49 | 69 | 79 | 84 |
| Pasture, grassland, or range | Good | 39 | 61 | 74 | 80 |
| Meadow — continuous grass (mowed for hay) | Good | 30 | 58 | 71 | 78 |
| Woods | Fair | 36 | 60 | 73 | 79 |
| Woods | Good | 30 | 55 | 70 | 77 |
| Farmsteads (buildings, lanes, driveways) | — | 59 | 74 | 82 | 86 |
Antecedent Runoff Condition (ARC) adjustment
Dry (ARC I) and wet (ARC III) curve numbers are read directly from the published USDA NRCS NEH Part 630, Chapter 10, Table 10-1, p. 10-6 (July 2004) (Ia = 0.2 * S, all 77 rows from CN II = 0 to 100), with linear interpolation only for non-integer intermediate values. For example:
CN II = 75->CN I = 57(dry),CN III = 88(wet)CN II = 85->CN I = 70(dry),CN III = 94(wet)CN II = 60->CN I = 40(dry),CN III = 78(wet)
Direct runoff equation (NEH Part 630, Chapter 10, Eq. 10-11)
For rainfall depth P >= 0 (inches) and curve number CN in (0, 100]:
S = (1000 / CN) - 10
Ia = 0.2 * S
Q = 0 if P <= Ia
Q = (P - Ia)^2 / (P - Ia + S) if P > Ia
= (P - 0.2*S)^2 / (P + 0.8*S)
Invariant: 0 <= Q <= P for all P >= 0 and CN in (0, 100].
Hand-worked NRCS runoff reference cases (NEH Part 630, Chapter 10, July 2004)
All 64 entries in NRCS_CURVE_NUMBERS (Table 9-1, pp. 9-2 to 9-3), all 77 rows of NEH_TABLE_10_1 (Table 10-1, p. 10-6), and the worked examples printed in Chapter 10 (Examples 10-1 through 10-6, pp. 10-9 to 10-18) are verified in packages/surface/src/runoff.test.ts:
- Example 10-1 (p. 10-9):
P = 4.3 in, pasture good on HSG C (CN = 74,S = 3.51 in) ->Q = 1.82 in(engine:1.8198 in). - Example 10-2 (p. 10-10): Same watershed at ARC I (
CN = 55), ARC II (CN = 74), and ARC III (CN = 88) ->Q = 0.65,1.82, and3.01 in(engine:0.6542,1.8198,3.0086 in). - Example 10-3 (p. 10-11, weighted Q):
630 acon HSG B (400 acatCN = 75,230 acatCN = 69),P = 5.1 in->Q = 2.53and2.03 in, weightedQ = 2.35 in(engine:2.3480 in). - Example 10-4 (p. 10-12, weighted CN): Same watershed -> weighted
CN = 72.8(73),Q(73) = 2.36 in,Q(72.8) = 2.34 in(engine:2.3591and2.3430 in). - Example 10-5 (pp. 10-13 to 10-16):
901.3 acacross 4 complexes (CN = 30, 58, 75, 86) forP = 1, 2, 4, 6, 8, 10 in. Exact Eq. 10-11 reproducesP = 1, 2, 6, 8, 10 into the printed precision (0.03, 0.26, 2.62, 4.18, 5.85 inweighted Q). AtP = 4 in, exact Eq. 10-11 gives1.1448 in(weightedCN = 67) and1.2519 in(weighted Q), whereas the handbook prints1.15and1.255(1.26) because Appendix 10A evaluates Eq. 10-11 with Table 10-1's 3-significant-figureS(4.92, 7.24, 3.33, 1.63) and rounds each complex'sQto 2 decimals before weighting. - Example 10-6 / Table 10-2 (pp. 10-17 to 10-18):
CN = 80, 20-hour storm (P = 0.00to5.00 in). Exact Eq. 10-11 reproduces 18 of 21 hourly rows to 2 decimals; the remaining 3 rows (P = 0.62, 1.01, 1.55 in) differ by0.01 inbecause Table 10-2 linearly interpolated Appendix 10A's 0.1-inch table forCN = 80(p. 10A-33). - Additional hand-worked checks:
P = 5.0 in, CN = 75->Q = 2.4493 in;P = 2.0 in, CN = 85->Q = 0.7951 in;P = 0.5 in, CN = 75->P <= Ia = 0.6667 in->Q = 0 in.
What a low spot holds
For each low spot with contributing watershed area A_w (m^2) and depression capacity V_cap (m^3):
- Inflow volume:
V_in = Q_m * A_w, whereQ_m = Q_in * 0.0254 m. - Ponded volume:
V = min(V_in, V_cap). Whatever is overV_capspills downstream out of the depression.
With tile: surface-inlet design ceiling (plan v3 item 372)
Signed as proposed on 2026-11-29 (docs/engineering/plan-v3-signoffs.md, Question 3). Replaces the stopgap withhold of item 433.
The with-tile figure is a design ceiling, never a forecast, computed in @tilemapper/hydraulics (surfaceInletTileCeilings) using the same inletFlow and manningFullFlow capacities used by the drainage engine:
- Eligible intakes: Only non-future surface inlet nodes (
node.kind === "inlet",node.status !== "future") whose(x, y)position falls inside a listed low spot's actualfill_depthcell footprint (never its bounding box) qualify. Each inlet's demand flow isq_inlet = inletAreaM2 * rate(inletRunoffMPerS, or the design drainage coefficient when no inlet-specific rate is entered). If no area or rate is entered, no value is invented. - Active gravity pipes below the inlet: Follow downstream edges to a non-future
outletortie_in. Only non-future gravity pipes (lateral,submain,main) with a computed full-flow capacityQ_fullfrommanningFullFlowcount. Force mains (force_main), outlets (as intakes), and future pipes (status === "future") never count. If an inlet's downstream path is blocked by a force main or future pipe, its gravity ceiling is0 m^3. If a gravity pipe on the path has no size or grade yet, or hits a split or loop, the spot staysNot estimated. - Sharing among low spots on the same main: Processing active gravity edges in topological upstream-to-downstream order, whenever the sum of upstream inlet flows arriving at an edge exceeds
Q_full, every contributing inlet flow on that edge is scaled byQ_full / sum(q). This guarantees no inlet exceeds its entered rate and no pipe or shared main exceeds its full-flow capacity. - Drawdown over the chosen hours: Each served spot's design ceiling over
Hhours isC_tile = (sum of allocated inlet flows in spot) * H * 3600(m^3), removingmin(V_captured, C_tile)from the water captured in that spot. Storm overland spill to downstream spots is unchanged, so any low spot without a surface inlet showsNot estimatedand the exact same water in both views.His what the person types under Hours after rain, a number over 0; a blank, a word, zero or less gives noH, and the views with tile then give no figure and ask for hours over 0 (hoursAfterRain, round 7 of plan v4, 2026-12-02, finding NB7; until then each was taken silently as 0 hr, shown as "Over 0 hr" and "At most 0.00 ac-ft"). - What the ceiling leaves out (stated on screen): Inlet grate/riser opening geometry, trash or silt plugging, subsurface intake through the soil, and outlet tailwater / submergence are not in the design; any of them can make the real drawdown smaller than the design ceiling.
Hand-worked tile ceiling reference cases (signed check cases)
- 40-acre inlet at 0.5 in/day over 24 hours (inlet-limited):
A = 40 ac * 4,046.8564224 m^2/ac = 161,874.257 m^2rate = 0.5 in/day * 0.0254 m/in / 86,400 s/day = 1.4699074e-7 m/sq_inlet = 0.023794016 m^3/s- Over
24 hr = 86,400 sabove a 12-inch main at 0.5% grade (Q_full > 0.0238 m^3/s):C_tile = 161,874.257 * 0.0127 = 2,055.803 m^3(<= 2,056 m^3, rounding to2,056 m^3).
- Two inlets above a shared main carrying 376 m^3/day running full (main-limited):
- Two 40-acre inlets (
2,055.8 m^3/dayeach) on 10-inch submains join a 4-inch (0.1016 m,n = 0.015) shared main graded atS = 0.008688somanningFullFlowgivesQ_full = 0.00435185 m^3/s = 376.000 m^3/day. - Total arriving at the shared main is
4,111.6 m^3/day > 376 m^3/day; proportional sharing scales each inlet to188.000 m^3/day, for376.000 m^3combined over 24 hours (<= 376 m^3).
- Two 40-acre inlets (
- Low spot with no surface inlet: Shows
Not estimated,removed_by_tile = null, and identical volume, depth, acres, and shaded cells in both views.
Routing rain through low spots and water balance (plan v3 item 371)
Signed as proposed on 2026-11-29 (docs/engineering/plan-v3-signoffs.md, Question 2). Replaces the stopgap withhold of item 434.
Every valid terrain cell $i$ carries its own area $c^2$ plus any outside run-on entry $A_{\text{out},i}$ stored in outside_entry. Following D8 pointers on the conditioned flow grid partitions every valid cell once:
- Direct to terrain edge: cells whose D8 path exits the terrain without entering any depression contribute directly to
run_off_terrain. - Direct to depression $k$: cells belonging to or first draining into depression $k$ (across all depressions in
fill_depth, both listed spots and smaller omitted spots) form depression $k$'s own local watershed $A_{\text{own},k}$, generating local runoff $V_{\text{own},k} = A_{\text{own},k} \cdot Q_m$.
Each depression $k$'s spill point is its highest flow-accumulation cell whose D8 pointer steps outside $k$ (matching find_low_spots in hydrology.py), and tracing downstream from that cell identifies the next downstream depression $m$ (or the terrain edge). Depressions are processed in topological order from the top of the watershed down:
$$V_{\text{in},k} = V_{\text{own},k} + \sum_{u \to k} V_{\text{spill},u}$$ $$V_{\text{captured},k} = \min(V_{\text{in},k}, V_{\text{cap},k}), \qquad V_{\text{spill},k} = \max(0, V_{\text{in},k} - V_{\text{cap},k})$$ $$V_{\text{tile},k} = \min(V_{\text{captured},k}, C_{\text{tile},k}), \qquad V_{\text{held},k} = V_{\text{captured},k} - V_{\text{tile},k}$$
where $C_{\text{tile},k} = 0$ without tile or where no surface inlet serves depression $k$.
Depressions are extracted only from cells the flow grid counts as valid, so no cell adds capacity where its rain is not counted. Overflow goes to run_off_terrain only when the spill path really leaves the terrain (a boundary cell, or one beside a cell with no height). Where no path leaves (every cell of $k$ points within $k$, an interior pit with no direction, a spill path that ends in a pointer cycle, or two depressions that spill into each other), the overflow has no way off and stays standing in $k$: $V_{\text{captured},k} = V_{\text{in},k}$ and $V_{\text{spill},k} = 0$, so $V_{\text{held},k}$ can exceed $V_{\text{cap},k}$ while the drawn stage stops at the spill elevation. A conditioned grid from the worker has none of these, and the rule keeps a hand-made grid's water in the right term. The reference cases in section 7 found that the worker could leave an interior pit at a low spot's bottom, so this rule kept overflow that should have spilled. From pipeline version 7 the worker leaves none (section 7, "What the cases found", fault 1), and a terrain built before keeps its old flow grid until it is rebuilt. Rain landing on a cell outside every depression whose own path ends inside the terrain, at an interior pit or on an upland pointer cycle, has no way off either, and no low spot to stand in: its runoff is a seventh term, ends_inside ("Stops inside, no low spot" on the screen, shown only where it isn't zero), at the same runoff depth as the direct-to-edge cells, and is taken out of run_off_terrain. Until round 7 of plan v4 (2026-12-02, finding B2) it was counted as running off the terrain. Worked by hand (runoff.test.ts): nine 1 m² cells with no direction and no fill under 1 in; the eight boundary cells leave by the edge, 8 x 0.0254 = 0.2032 m^3, and the center, an interior pit, keeps 0.0254 m^3 inside, where 0.2286 m^3 was said to leave. A terrain built at pipeline version 7 has no such cell, so the term is 0 and every figure there is as before; an older terrain not yet rebuilt, or a grid made some other way (a hand-made or uploaded one), can have some. Every drop falling on the terrain and its traced outside entries closes the balance to within $0.001\text{ m}^3$:
$$V_{\text{rain_in}} = V_{\text{held_listed}} + V_{\text{held_smaller}} + V_{\text{ends_inside}} + V_{\text{run_off_terrain}} + V_{\text{removed_by_tile}} + V_{\text{not_run_off}}$$
($V_{\text{ends_inside}} = 0$ on a terrain built at pipeline version 7, where the balance is the six terms it always was.)
where $V_{\text{rain_in}} = (A_{\text{inside}} + A_{\text{outside}}) \cdot P_m$ and $V_{\text{not_run_off}}$ sums $(P_m - Q)$ over every partition using that partition's runoff depth $Q$ (which reduces to $(A_{\text{inside}} + A_{\text{outside}})(P_m - Q_m)$ when one runoff depth applies everywhere, and $0$ in all-rain mode).
Basin-by-basin soils in Curve Number mode (plan v3 item 374)
Project SSURGO soil polygons (project_soil_polygons, fetched from NRCS Soil Data Access) are clipped to the project AOI (the merged fields plus a 100 m buffer). In Curve Number mode, those polygons are rasterized onto the terrain grid by cell-center containment so each depression's own direct watershed ($A_{\text{own},k} = A_{\text{own,in},k} + A_{\text{own,out},k}$) can be evaluated on its own Hydrologic Soil Group (HSG) mix rather than one terrain-wide mix. Each SSURGO map unit's rated components contribute their published percent_of_map_unit (taking the undrained second letter of dual groups such as C/D, per NEH Part 630 Chapter 7), while unrated components (such as urban land or open water) and cells outside any soil polygon count as uncovered. A map unit with a rated component that has no published percent can't be split without guessing, so the whole unit is left out of both the soil grid (its cells count as uncovered) and the terrain-wide mix, and the panel says how many map units are left out, or that the soil mix is not worked out when none is left.
- Soil-cover threshold (judgment, for engineer review):
BASIN_SOIL_COVER_MIN_SHARE = 0.90(90% of a depression's own contributing watershed area $A_{\text{own},k} = A_{\text{own,in},k} + A_{\text{own,out},k}$). Requiring 90% tolerates minor boundary aliasing or small unrated inclusions inside a mapped field while preventing a partial soil fragment from speaking for a watershed that extends largely outside the soil map. Where rated soils cover at least 90% of a depression's own watershed, its inside runoff is computed by area-weighted runoff per HSG (areaWeightedRunoffInches, NEH Ch. 10 Example 10-3) from that watershed's own soils; otherwise it falls back to the project's terrain-wide soil mix, and the panel and side-by-side card state which low spots (or how many) fell back. Smaller unlisted depressions follow the same 90% rule. - Land entering from outside (
outside_entry): Outside run-on is traced up to 2 km beyond the terrain on USGS's 10 m DEM, where the project has no SSURGO polygons. Outside-entry area therefore always counts as uncovered in a depression's soil-coverage denominator, and its runoff is always worked from the project's terrain-wide soil mix rather than projecting one local depression's soil onto unmapped land outside the AOI. - Cells draining straight off the terrain edge: Inside cells whose D8 path leaves the terrain without entering any depression follow the same 90% cover rule as one partition: if rated soil polygons cover at least 90% of that inside off-edge area, its runoff is worked from those cells' own soil mix; otherwise it uses the terrain-wide soil mix. Any outside run-on on direct-off-edge cells uses the terrain-wide soil mix.
- All-rain mode: Unchanged; every cell and outside entry sheds $Q = P$ and keeps its upper-bound wording.
Hand-worked routing reference cases
- Two low spots in series under 10 mm of rain on 2 hectares (signed check case): Upper spot drains 1 ha (
10,000 m^2,100 m^3own runoff), lower spot drains the remaining 1 ha (10,000 m^2,100 m^3own runoff) plus spills from upper, totalrain_in = 200 m^3, all rain runs off (not_run_off = 0):- Capacities
150and250 m^3: upper holdsmin(100, 150) = 100 m^3(spills0), lower holdsmin(100 + 0, 250) = 100 m^3(spills0). Total held =200 m^3, run off terrain =0 m^3. - Capacities
60and250 m^3: upper holdsmin(100, 60) = 60 m^3(spills40), lower receives100 + 40 = 140 m^3and holds140 m^3(spills0). Total held =200 m^3, run off terrain =0 m^3. - Capacities
60and120 m^3: upper holds60 m^3(spills40), lower receives140 m^3, holds120 m^3, and spills20 m^3off the terrain edge. Total held =180 m^3, run off terrain =20 m^3.
- Capacities
- Full six-term balance grid (uniform soils):
10 x 10grid atc = 5 m(2,500 m^2inside) with a500 m^2outside entry draining into a small unlisted spot (50 m^2 < 100 m^2, depth0.20 m, capacity10 m^3, own area750 + 500 = 1,250 m^2), a500 m^2north strip draining straight off the edge, and a listed spot (200 m^2, depth0.50 m, capacity100 m^3, own area1,250 m^2, tile ceiling20 m^3) receiving spills from the small spot. UnderP = 2.0 in(0.0508 m) atCN = 85(Q = 0.795131 in = 0.02019634 m):rain_in=3,000 * 0.0508 = 152.400 m^3not_run_off=3,000 * (0.0508 - 0.02019634) = 91.811 m^3run_off_terrain=500 * 0.02019634 = 10.098 m^3held_in_smaller_spots=min(1,250 * 0.02019634, 10) = min(25.245, 10) = 10.000 m^3(spills15.245 m^3)- Listed spot inflow =
1,250 * 0.02019634 + 15.245 = 40.491 m^3(below100 m^3capacity) removed_by_tile=min(40.491, 20) = 20.000 m^3held_in_listed_spots=40.491 - 20.000 = 20.491 m^3- Sum:
20.491 + 10.000 + 10.098 + 20.000 + 91.811 = 152.400 m^3(error< 10^-9 m^3).
- Full six-term balance grid with two low spots on different soils (item 374):
10 x 12grid atc = 10 m(12,000 m^2inside) plus1,000 m^2outside entry on the north strip (13,000 m^2total), underP = 3.0 in(0.0762 m), row crops straight row good (ARC II), terrain-wide fallback mix 50% HSG A / 50% HSG D (Q_terrain = 1.242402 in = 0.03155701 m):- HSG D (
CN = 89):S = 1.235955 in,Ia = 0.247191 in,Q_D = 1.899826 in = 0.04825558 m. - HSG A (
CN = 67):S = 4.925373 in,Ia = 0.985075 in,Q_A = 0.584978 in = 0.01485845 m. - Direct off-edge north strip (
2,000 m^2inside on 100% HSG D +1,000 m^2outside entry on terrain-wide mix):run_off_terrain=2,000 * 0.04825558 + 1,000 * 0.03155701 = 96.511 + 31.557 = 128.068 m^3not_run_off_edge=2,000 * (0.0762 - 0.04825558) + 1,000 * (0.0762 - 0.03155701) = 55.889 + 44.643 = 100.532 m^3
- Upper listed spot (
5,000 m^2own on 100% HSG D, capacity160 m^3, no tile):- Own runoff =
5,000 * 0.04825558 = 241.278 m^3;not_run_off=139.722 m^3 - Holds
160.000 m^3and spills81.278 m^3into the lower spot (under one uniform 50/50 mix, it would receive only157.785 m^3and would not spill).
- Own runoff =
- Lower listed spot (
5,000 m^2own on 100% HSG A, capacity200 m^3, tile ceiling30 m^3):- Own runoff =
5,000 * 0.01485845 = 74.292 m^3;not_run_off=306.708 m^3 - Inflow =
74.292 + 81.278 = 155.570 m^3(below200 m^3, spills0) removed_by_tile=30.000 m^3, holds125.570 m^3.
- Own runoff =
- Six-term balance:
rain_in=13,000 * 0.0762 = 990.600 m^3held_in_listed_spots=160.000 + 125.570 = 285.570 m^3held_in_smaller_spots=0.000 m^3run_off_terrain=128.068 m^3removed_by_tile=30.000 m^3not_run_off=100.532 + 139.722 + 306.708 = 546.962 m^3- Sum:
285.570 + 0.000 + 128.068 + 30.000 + 546.962 = 990.600 m^3(error< 10^-9 m^3).
- HSG D (
Depth, acres, and ponded ground from the original DEM (plan v3 item 370)
Depressions are extracted directly from the stored fill_depth grid (fill_depth > 0 on valid cells of the original DEM, 4-connected, matching find_low_spots in services/gis-worker/gis_worker/terrain/hydrology.py). Depressions meeting area >= 100 m^2 (LOW_SPOT_MIN_AREA_M2) and max_depth >= 0.10 m (LOW_SPOT_MIN_DEPTH_M) are listed; smaller depressions are left out of the low-spot list and counted on screen.
For each listed depression $C$ holding volume $V \in [0, V_{\text{cap}}]$, water surface elevation (stage) $h$ is solved directly from the original DEM (surface: "original"), never from a cone scaling formula:
$$V(h) = c^2 \sum_{i \in C} \operatorname{clamp}(h - z_i, 0, d_{\text{full},i})$$
where $z_i$ is cell $i$'s original ground elevation, $d_{\text{full},i}$ is its stored fill depth, and $c^2$ is the cell area. Because $V(h)$ is continuous and piecewise linear with breakpoints at $z_i$ and $z_i + d_{\text{full},i}$, sweeping the sorted elevations solves $V(h^) = V$ analytically. Each cell's ponded depth is $d_i = \operatorname{clamp}(h^ - z_i, 0, d_{\text{full},i})$, flooded area is $c^2 \cdot |{i \in C : d_i > 0}|$, maximum depth is $\max_{i \in C} d_i$, and the map shades every wet cell directly from $d_i$ rather than drawing a bounding box.
Terrains built before pipeline version 6 have no stored fill_depth or outside_entry grids; the rain comparison tells the user to rebuild terrain and never falls back to cone scaling.
Hand-worked stage-storage reference case (flat basin vs. stepped conical pit)
Two depressions on a 1 m grid (c^2 = 1 m^2) have the same full area (100 m^2) and the same full capacity (100 m^3), each holding V = 25 m^3:
- Flat-bottomed basin:
100cells atz = 100.0 m,d_full = 1.0 m(V_cap = 100 m^3). AtV = 25 m^3, every floor cell is submerged equally:stage = 100.0 + 25 / 100 = 100.25 m,max_depth = 0.25 m,area = 100 m^2(0.02471 ac). - Stepped conical pit:
20bottom cells atz = 100.0 m(d_full = 2.0 m,40 m^3),40middle cells atz = 101.0 m(d_full = 1.0 m,40 m^3), and40outer cells atz = 101.5 m(d_full = 0.5 m,20 m^3), totalV_cap = 100 m^3. Filling from100.0to101.0 mstores20 * 1.0 = 20 m^3in the bottom tier; the remaining5 m^3spreads over20 + 40 = 60active cells fordh = 5 / 60 = 0.08333 m. Thusstage = 101.0833 m,max_depth = 1.0833 m, andarea = 60 m^2(0.01483 ac), while the40outer cells remain dry (depth = 0).
(The former cone approximation d = d_full * f^(1/3), A = A_full * f^(2/3) gave 0.630 m and 39.7 m^2 for the flat basin at f = 0.25, matching neither.)
Routing ponded water through a culvert (plan v3 item 395, finishes item 287)
Signed as proposed on 2026-11-29 (docs/engineering/plan-v3-signoffs.md, Question 6).
Airborne lidar captures the crown of a road or berm rather than the pipe beneath it, so the stored fill_depth grid ponds water behind the road and the stored flow_dir grid routes that depression out along the worker's least-cost breach rather than through the real culvert. When a project has saved culverts, the browser recomputes a routed copy of flow_dir and fill_depth from the stored grids (applyCulvertsToHydrology in @tilemapper/surface, reading only the original DEM for elevations and never mutating the stored grids or terrain):
- Zero-culvert fast path: When no culvert is in force,
applyCulvertsToHydrologyreturns the storedflow_dirandfill_depthreferences directly with no copies, so every water-tool result is bit for bit identical to before. - Storage reduction behind the road: When a culvert's inlet cell $s$ lies inside a 4-connected ponded depression $C$ on the original
fill_depthgrid, the drain elevation is the entered inlet invertinletInvertMwhere one is entered, or the original DEM ground elevation $z(s)$ at the inlet cell where none is entered (stated on the culvert card as a lidar ground reading, not a measured pipe bottom). Priority-Flood (Barnes et al., 2014) runs inside $C$ seeded at $s$ with water surface $w(s) = z_{\text{drain}}$, computing each cell's reachable water level $w(v) = \max(w(\text{parent}), z_v)$ (respecting internal ridges) and reducing its fill depth to $d'v = \min(d{\text{raw},v}, \max(0, w(v) - z_v))$ (never raising storage above the natural rim). Every non-corridor cell in $C$ is re-pointed to its Priority-Flood parent toward the inlet, and the 8-connected Bresenham corridor from inlet to outlet carries flow across the road. - Capacity does not limit routing: All water reaching the culvert inlet is passed to its outlet regardless of barrel diameter, headwater, or HDS-5 capacity. The culvert card states this beside the capacity figure so routing is never read as a claim that the pipe can carry the flow.
- Circle refusal: Before applying a culvert, the outlet's downstream D8 path is traced on the active pointer grid. If the outlet sits inside or flows back into the inlet's ponded area $C$, the inlet cell, or any corridor cell up to the outlet (or closes a loop with another culvert sharing $C$), the culvert is refused with a plain explanation, left out of the routing, and excluded from
culvertsInForce. - Canonical order for multiple culverts: Valid culverts are evaluated in ascending order of drain elevation $z_{\text{drain}}$ (settling downstream / deeper outlets first), breaking ties by inlet row, inlet col, outlet row, outlet col, and finally id — independent of the order they were drawn. Culverts whose inlets fall in the same original depression run a simultaneous multi-source Priority-Flood so neither starves the other and results never depend on drawing order.
- What updates from the new route: Raindrop paths, watersheds (with per-cell
outside_entrysummed once per cell on the new route), listed low spots and their contributing areas (summarizeLowSpots), and the rain comparison on both sides of the road all read the culvert-routedflow_dirandfill_depthgrids. Saved watersheds recordculvertsInForce(item 429) and flag"Made on an earlier routing (culverts have changed)"when active culverts change: a culvert is compared by its inlet, its outlet and, when one is entered, its inlet invert, each to 1 mm (hashCulvertGeometry), since ponded water behind the inlet drains to that level. The invert was left out until round 7 of plan v4 (2026-12-02, finding NB5), so changing it left a saved watershed reading as current; a culvert with no invert has the digest it always had, and a result saved before round 7 on a culvert with an invert is flagged once, since it can't be told whether the invert changed (provenance.test.ts). Subsurface tile calculations, cover checks, fingerprints, and benchmark hashes never read culverts and do not move.
Hand-worked culvert six-term balance reference case
11 x 12 grid at c = 5 m (25 m^2/cell, 132 cells = 3,300 m^2 inside) plus a single 5,000 m^2 outside entry at (5, 0) (8,300 m^2 total), under P = 3.0 in (0.0762 m) and NRCS Curve Number CN = 85 (row crops straight row good on HSG C, ARC II: S = 1.764706 in, Ia = 0.352941 in, Q = 1.588235 in = 0.04034118 m):
- Geometry:
- Outer ridges on rows
0and10(24cells =600 m^2,z = 104 m) drain directly off the north/south edges. - Rows
1..9: cols0..1upland (450 m^2inside +5,000 m^2outside at(5, 0)) drains east into Pond A (cols2..4,27cells =675 m^2, stepped atz = 101.0, 100.5, 100.0 m, trapped behind the road at col5,z = 102.0 m, natural fill depths1.0, 1.5, 2.0 m, natural capacity225 + 337.5 + 450 = 1,012.500 m^3). Raw conditioned pointers breach Pond A north off the edge, bypassing the road. - Downstream of the road: col
5road (225 m^2), cols6..7slope (450 m^2), Pond B (cols8..9,18cells =450 m^2,z = 98.0 m, spill98.5 m, depth0.5 m, capacity225.000 m^3), and cols10..11tailout (450 m^2, draining directly east off the edge).
- Outer ridges on rows
- Common storm totals:
rain_in = 8,300 * 0.0762 = 632.460 m^3;not_run_off = 8,300 * (0.0762 - 0.04034118) = 297.628 m^3; direct off-edge (600 + 450 = 1,050 m^2) =42.358 m^3. - Before culvert: Pond A (
6,125 m^2) holds247.090 m^3(spills0); Pond B (1,125 m^2) holds45.384 m^3(spills0). Six terms:292.474 + 0 + 42.358 + 0 + 297.628 = 632.460 m^3. - With culvert at ground level (
inlet (5, 4)at100.0 m,outlet (5, 6), no entered invert): Pond A drains completely (capacity = 0 m^3, disappears from low spots). Pond B receives all6,125 + 1,125 = 7,250 m^2(292.474 m^3), holds its full225.000 m^3, and spills67.474 m^3east off the edge. Six terms:225.000 + 0 + (42.358 + 67.474 = 109.832) + 0 + 297.628 = 632.460 m^3(error< 10^-9 m^3). Clicking a watershed anywhere downstream at(5, 6)through(5, 11)adds exactly5,000 m^2of outside area. - With culvert at perched invert (
inletInvertM = 100.5 m): Cols2..3drain dry; col4(9cells =225 m^2) retains0.5 mdepth (112.500 m^3, draining900.000 m^3of storage). Residual Pond A holds112.500 m^3and spills134.590 m^3through the culvert into Pond B; Pond B receives45.384 + 134.590 = 179.974 m^3(< 225.000 m^3, spills0). Six terms:(112.500 + 179.974 = 292.474) + 0 + 42.358 + 0 + 297.628 = 632.460 m^3(error< 10^-9 m^3).
5. What These Methods Leave Out
- Unentered culverts, bridges, and culvert capacity: Airborne lidar sees the road crown, not pipes under it. Placed surface culverts drain ponded water behind roads through to their outlets in raindrop paths, watersheds, low spots, and rain comparisons, with all water reaching the inlet passed (barrel capacity does not limit that routing). Unentered culverts and bridges remain invisible to lidar, and connected water-level flooding still assumes closed embankments.
- Flat-ground flow uncertainty: On nearly level ground (average relief grade under 0.15%), small elevation noise can shift D8 flow paths and watershed boundaries.
- Routing between low spots: rain is routed top-down across all depressions (listed and smaller) using conditioned D8 pointers, closing the six-term balance; overland spills occur before tile drawdown so unserved spots never show reduced water from upstream tile.
- Basin soils, uniform land cover, and no timing: in Curve Number mode, each depression whose own watershed has at least 90% rated SSURGO soil cover uses its own watershed's soils; watersheds with under 90% cover and all land entering from outside the project AOI fall back to the terrain-wide soil mix (and the view states which or how many). One chosen land cover and one antecedent soil wetness still apply across the whole terrain, nothing soaks in along the way once runoff leaves a cell, and nothing is timed, so a low spot that would overtop for an hour and one that would fill slowly are treated alike.
- Tile on a pump is not credited: a surface inlet whose pipes reach a lift station and a force main has no gravity pipe to an outlet, and the pump's rate isn't a pipe running full, so its low spot shows no water carried away.
- One water level in each low spot: a low spot's water is laid at one level, the lowest that holds its volume, as a stage-storage curve does. Where a rise inside the low spot stands below its spill level, the real water would lie on whichever side it ran in to, and can stand at two levels until the rise goes under. The volume held is right either way; the depth and the ponded ground can differ from the drawing until the low spot is full.
- Raindrop ponding threshold: stops where standing depth reaches at least
0.10 m(LOW_SPOT_MIN_DEPTH_M) on the original ground, ignoring shallower lidar noise; spills out of a full depression are not traced past that point. - Land outside the terrain: traced out to 2 km on USGS's 10 m DEM and added to clicked watersheds and rain comparisons via per-cell outside entries; clipped watersheds still read "At least" because land beyond 2 km or water that leaves and re-enters the terrain isn't counted.
- What tile carries away after a rain: design ceiling only for listed low spots containing a surface inlet on an active, sized gravity pipe; inlet opening geometry, silt, subsurface soil intake, and outlet tailwater are not modeled and can make actual drawdown smaller. See "With tile: surface-inlet design ceiling" above.
- Dynamic storm routing: The rain view is a volume held in each low spot, not a hydrograph simulation with pipe surcharge or outlet tailwater. Use the SWMM / hydraulic engine for pipe capacity checks.
- Infiltration during ponding and evaporation: Not credited in either mode, keeping the estimate conservative for standing water.
6. Terrain cell size and small-basin refusals (plan v3 item 430)
Every surface-water result states the terrain cell size read from the terrain's record (or from a saved watershed's recorded provenance), or cell size not recorded when absent.
Two judgment thresholds, starting points that are neither cited nor yet measured against results (defined once in packages/surface/src/resolution.ts and proposed in docs/engineering/plan-v3-signoffs.md, Question 4, which no engineer has answered yet) guard small basins and areas:
- Feature width (
MIN_FEATURE_WIDTH_CELLS = 3cells, judgment): A measured-volume polygon narrower than3cells across is refused with"needs finer terrain", withholding its figures and fill shading. - Basin cell count (
MIN_BASIN_CELLS = 9cells, judgment): A delineated watershed, measured-volume polygon, or listed rain-comparison low spot with fewer than9cells is refused with"needs finer terrain". - Rain comparison low spots under 9 cells: On coarse cells (such as
5 mcells,25 m²/cell), depressions of100to200 m²meet the100 m²/0.10 mlisting rule with only4to8cells. Each such listed spot shows"needs finer terrain"in place of its depth and area and is left unshaded on the map, while its stored water still counts inheld_in_listed_spotsso the six-term water balance remains closed within0.001 m³. The view states how many listed low spots are refused. - Where the rule does not apply: Water-level flooding (whole-terrain stage surface) and raindrop tracing (1-cell flow path) show their cell size but are not refused by these two thresholds. When a terrain record has no cell size, nothing is refused on coarseness. See
result-resolution.mdfor the full result table.
7. Reference cases with known answers (plan v4 item 544)
Each case below is a surface whose height has a closed form, so where water goes on it, how much it holds and how much rain fills it can be worked by hand. The working is shown here, with the answer and the tolerance the app must meet and why. The app's own code is then run on each surface:
- The worker's half.
services/gis-worker/gis_worker/water_proof.pybuilds each surface as a grid and runsanalyze_hydrologyon it, as a build with no ground around it does.services/gis-worker/tests/test_water_proof.pychecks the flow grid and fill depths it makes. - The browser's half. Running
python -m gis_worker.water_proof ../../apps/web/src/lib/terrain/fixtures/water-prooffromservices/gis-workerwrites each surface's original heights, flow directions and fill depths with the worker's own COG writers, as a build stores them.apps/web/src/lib/terrain/water-proof.test.tsreads them with the app's own readers (openDem,openFlowDirGrid,openFillDepthGrid) and runs the raindrop, the watershed and the rain comparison throughexecuteTerrainTask, the dispatcher the browser's calculation worker calls. Both run with the ordinary unit test commands (pnpm test, and pytest in the worker's image).
The cases found four faults. Three were mended (pipeline version 7, raindrop and watershed method version 2), and the case that found each is now an ordinary passing test against the same reference answer, never moved. The fourth is what a flow grid of eight directions can deliver, and case 3 holds the app to that, as the method's stated tolerance. "What the cases found" at the end gives each with its numbers, before and after.
Conventions
- Cell
(row, col)has its center atx = col * ceast andy = (row_0 - row) * cnorth of the surface's origin, whererow_0is the row stated for each surface. Every surface here hasc = 1 m. - All the surfaces sit in UTM zone 15N on NAD83(2011) (EPSG:6343), only so the files carry a real system.
- No ground around any surface was read, so no land enters from past its edges (
outside_entry = 0), and the rain comparison runs with every drop running off (Q = P) so the working has no soil in it.
Tolerances that apply to every case
- Heights are stored as float32: about
8 x 10^-6 mnear 100 m, so heights and falls are good to10^-4 m. - Fill depth is stored in whole millimeters (
FILL_DEPTH_SCALE_M = 0.001), so a stored depth or a water level read from it is good to0.5 mm. The tests allow1 mmfor a level and2 mmfor a deepest point, which also need not lie on a cell's center. - Eight directions. The flow grid sends each cell's water to one of its eight neighbors, the steepest drop by
drop / distance. Where the true fall line is one of the eight, a path follows it exactly. Where it lies between two, the path takes the nearer and can be off by up to22.5°(half of the45°between directions). That is a property of the method, not of a cell size, and finer cells don't reduce it. On an even slope every cell makes the same choice, so the error doesn't average out: a path of lengthLends up toL sin 22.5° = 0.38 Lto one side of the fall line,17.9 mover56.6 min case 3. This is the tolerance the app is held to for a path's direction, and "What the cases found", fault 4, says where it matters and what would do better. - Cells along a curved edge. A shore, a rim or a catchment boundary that crosses cells counts each whole cell in or out, so an area can be off by up to about one cell along that boundary. Each case states the boundary's length.
Case 1: a plane falling due east, along one of the eight directions
Surface plane-east, 41 rows by 61 columns, row_0 = 20:
z(x, y) = 100 - 0.02 x
- Direction. The gradient is
(-0.02, 0), so the fall line runs due east, one of the eight. East drops0.02 mover1 m; northeast and southeast drop0.02 mover1.414 m,0.0141a meter. Every cell with ground to its east drains east. - A drop from
(20, 0), atx = 0, runs straight east to the edge cell(20, 60): length60 x 1 = 60.000 m, fall0.02 x 60 = 1.200 m. - Tolerance: length exact, fall
10^-4 m. - Engine: every step is east, and the path ends at the edge cell
(20, 60):60 m, falling1.200 m, "Runs 197 ft and falls 3.9 ft to the terrain's edge." Before fault 2 was mended it went on one more step, south along the edge, for 61 m.
Case 2: a plane falling along a diagonal
Surface plane-northeast, 41 by 41, row_0 = 40:
z(x, y) = 100 - 0.02 (x + y) / sqrt(2)
- Direction. The fall line runs northeast, one of the eight.
- A drop from
(40, 0), the southwest corner, runs 40 diagonal steps to the northeast corner(0, 40): length40 sqrt(2) = 56.569 m, fall0.02 x (40 + 40) / sqrt(2) = 1.1314 m. - Tolerance: length
10^-9 m, fall10^-3 m. - Engine: matches, ending at the corner.
Case 3: a plane whose fall line is none of the eight
Surface plane-oblique, 41 by 61, row_0 = 40, with θ = atan(1/2) = 26.565° north of east:
z(x, y) = 100 - 0.02 (x cos θ + y sin θ)
- The true path. Water runs straight down the fall line. From
(40, 0), at the origin, it leaves by the east edge atx = 60 m,y = 60 tan θ = 30 m, after60 / cos θ = 67.082 m, falling0.02 x 67.082 = 1.342 m. - What eight directions can do. East drops
0.02 cos 26.565° = 0.01789a meter; northeast drops0.02 cos(45° - 26.565°) = 0.02 cos 18.435° = 0.01897a meter. Northeast is steeper, and on a plane it is steeper from every cell, so the path is a straight line18.435°north of the fall line. From(40, 0)it reaches the north edge at(0, 40)after40 sqrt(2) = 56.569 m, falling0.02 x (40 cos θ + 40 sin θ) = 1.0733 m,17.9 mfrom the fall line. - Tolerance. One cell for where the path ends. The
22.5°bound tells how far eight directions can stray; it isn't widened into a tolerance that would pass this. - Engine: every step is northeast, as the method gives, and the path leaves at the north edge,
(0, 40):56.569 m, falling1.073 m,18.4°off the fall line and17.9 mfrom it where it ends, within the method's bound of22.5°and21.6 m(fault 4, the method's tolerance). Before fault 2 was mended it ran a further 20 m along the north edge to the corner(0, 60),76.569 mfalling1.431 m.
Case 4: a cone, standing alone
Surface cone, 41 by 41, row_0 = 20, radius R = 20 m, height H = 4 m, center (x, y) = (20, 0), and no ground past the foot:
r = sqrt((x - 20)^2 + y^2)
z = 100 + 4 (1 - r / 20) where r <= 20, no data elsewhere
- Cells. The 1 m cells whose centers lie within 20 m of a cell center number
1,257, Gauss's count for radius 20 (pi x 20^2 = 1,256.6). - Every drop reaches the foot. Every point on a cone falls straight away from its top, so every path ends at the foot: a cell with ground beside one without. No path climbs.
- A drop from
(20, 21), 1 m east of the top, runs due east (a direction of the eight) to(20, 40): length19 m, fall4 x 19 / 20 = 3.800 m. Exact. - Every other path's length, from radius
r0to its first foot cell, is at least20 - r0 - sqrt(2)m (a foot cell has a neighbor past the circle, so it lies within one diagonal of it) and at most(20 - r0) / cos 22.5° + sqrt(2)m (each step lies within22.5°of straight downhill). Starts within 3 m of the top are left out, where one step turns through more than22.5°of the circle. - Engine: every one of the 1,257 cells ends at the foot without climbing, the drop from
(20, 21)is exact, and every length lies within the bound.
Case 5: a round pit, the cone upside down
Surface pit, 41 by 41, row_0 = 20, radius 20 m, depth 2 m, center (20, 0), and no ground past the rim:
z = 100 - 2 (1 - r / 20) where r <= 20, no data elsewhere
- Every drop reaches the middle, and the land that drains to the middle is the whole pit:
pi x 20^2 = 1,256.6 m^2, or1,257cells of1 m^2. - The pit is a closed low spot. With no lower ground past the rim, it fills to its lowest rim cell, and a conditioned surface drains it out through that cell. So on the flow grid every one of the 1,257 cells must end at one outlet on the rim, and the worker's accumulated area there is
1,257 m^2. - A drop. With fill depths, a drop that lands where water would stand
0.10 mdeep or more starts in the low spot, and one landing on the rim's shallowest ring runs in. Only a drop on the rim's outermost cells (within one diagonal of where the depth is0.10 m, atr = 20 (1 - 0.10 / 2) = 19 m) may run to the outlet instead. - Rain. The low spot's own land is the whole pit less the rim cells that stand at the spill level and drain straight out: between
1,257 - 126and1,257 m^2, where126is the rim's length,2 pi 20, in cells. - What drains to the bottom. The bottom is in the low spot, so what drains there is what drains into the low spot: the whole pit less any rim cells that drain straight out, between
1,257 - 126and1,257 m^2, and "at least", since the pit's rim is the terrain's edge. - Engine: one outlet takes all 1,257 cells and the worker's accumulation there is
1,257 m^2. Over 98% of drops end in the low spot, and the rest start on the rim's outer ring. The low spot's own land is1,252 m^2. Asked what drains to the pit's bottom,(20, 20), the watershed tool gives1,252 m^2,0.309 acres, "at least". Before fault 3 was mended it gave301 m^2.
Case 6: a bowl in a sloping field
Surface bowl, 51 by 61, row_0 = 25: a paraboloid of radius R = 15 m and depth D = 1 m centered at (x0, 0) = (25, 0), cut into a plane falling east at s = 0.01:
z = 100 - s x - D (1 - ((x - x0)^2 + y^2) / R^2) inside the circle, 100 - s x outside
Spill level. Along the bowl's axis (y = 0), downhill of its center, the bowl's wall climbs to the rim at x = x0 + R and the plane falls away beyond it, so the lowest way out is the downhill rim point. The spill level is the plane's height there:
h = 100 - s (x0 + R) = 100 - 0.01 x 40 = 99.600 m
Water at the spill level. With u = x - x0, the water's depth is h - z = s (u - R) + (D / R^2)(R^2 - u^2 - y^2). Completing the square with a = s R^2 / (2D):
h - z = (D / R^2) [ (R - a)^2 - (u - a)^2 - y^2 ]
So the water is itself a paraboloid of the same curvature over a disc of radius rho = R - a, centered a downhill of the bowl's center:
a = 0.01 x 225 / 2 = 1.125 m
rho = 15 - 1.125 = 13.875 m
depth = D rho^2 / R^2 = 192.516 / 225 = 0.8556 m, at x = 26.125 m
area = pi rho^2 = 604.81 m^2
volume = pi D rho^4 / (2 R^2) = pi x 37,061.6 / 450 = 258.743 m^3
bottom = h - depth = 98.744 m
Land that drains into it. The plane's fall line runs due east, so upslope of the bowl every line of cells within R of its axis runs east into it, and every point inside its circle runs to its lowest point. With the grid's west side at x = -0.5 m:
catchment = 2R (x0 + 0.5) + pi R^2 / 2 = 30 x 25.5 + 353.43 = 1,118.43 m^2
Rain that just fills it (every drop running off):
P* = volume / catchment = 258.743 / 1,118.43 = 0.23135 m = 9.108 in
Under 12 in (0.3048 m) the bowl takes 1,118.43 x 0.3048 = 340.90 m^3, holds 258.74 and spills 82.15 m^3, which runs east off the edge. Rain on the whole surface is 3,111 x 0.3048 = 948.23 m^3, so 948.23 - 258.74 = 689.49 m^3 leaves by the edge.
On the grid. Summing each cell's depth below 99.600 m at the cell centers, worked outside the engine (in test_water_proof.py, from the closed form, to the millimeter): 599 cells under water, 258.772 m^3, deepest 0.856 m.
Tolerances, and why:
- Spill level
1 mmand deepest point2 mm: the fill-depth storage above. - Volume
0.5%: on a paraboloid each cell's mean depth isD c^2 / (6 R^2) = 0.0007 mbelow its center's, about0.44 m^3over the 599 wet cells, under0.2%. Storage rounding adds up to0.0005 ma cell, under0.3 m^3. The shore's part cells add or take a little more. - Area
3%: the shore is2 pi 13.875 = 87cells round, and each cell it cuts counts whole. Errors of that kind largely cancel round a circle, and3%is 18 cells. - Catchment
c x (2 x 25.5 + pi R) = 98.1 m^2: one cell along each side of the strip and around the bowl's upper rim, where cells just outside the circle drain diagonally in. - Just-filling rain: the catchment's share and the volume's together,
98.1 / 1,118.43 + 0.5% = 9.3%.
Engine: capacity 258.772 m^3, the grid sum exactly. Full at a stage of 99.600 m, deepest 0.856 m, 599 m^2 under water. Its own land is 1,178 m^2 (+59.6, inside 98.1), so its just-filling rain is 8.649 in (-5.0%, inside 9.3%). Filled by that rain it holds its capacity exactly. Every rain balances to 10^-13 m^3. Under 12 in it holds 258.77 m^3 and spills 100.28 m^3 off the east edge (+18.1 against the reference's 82.15, inside 98.1 x 0.3048 + 0.5% = 31.2): the spill is the catchment's tolerance, since its own land is 59.6 m^2 over. The worker drains the bowl over its downhill rim, within one cell of (25, 40). Before fault 1 was mended the bowl was left with a pit at its bottom (its own land was then 1,191 m^2), and under 12 in it showed 363.02 m^3 held, 104 m^3 more than it can hold, and nothing spilled.
Case 7: two bowls, one spilling into the other
Surface two-bowls, 51 by 101, row_0 = 25: the same plane with the first bowl (D1 = 1 m, x1 = 25) and a second (D2 = 2 m, x2 = 70), both of radius 15 m, on one axis.
The second bowl, by the working of case 6 with a2 = 0.01 x 225 / 4 = 0.5625 m and rho2 = 14.4375 m:
spill = 100 - 0.01 x 85 = 99.150 m
depth = 2 x 208.441 / 225 = 1.8528 m
area = pi x 208.441 = 654.84 m^2
volume = pi x 2 x 43,447.6 / 450 = 606.646 m^3
Where the first bowl's spill goes. It leaves at the first bowl's downhill rim point, (40, 0), and runs due east along the axis into the second bowl's circle at x = 55.
Each bowl's own land. The first bowl's is as in case 6, 1,118.43 m^2. The second's is the strip between the two centers, 2R (x2 - x1) = 30 x 45 = 1,350 m^2: the first bowl's downhill half disc goes to the first, and the second's own downhill half disc makes up the same area. Tolerance c x (2 x 45 + pi R) = 137.1 m^2, as in case 6.
Under 12 in (0.3048 m):
first takes 1,118.43 x 0.3048 = 340.90 m^3
first holds 258.74, spills = 82.15 m^3 into the second
second takes 1,350 x 0.3048 + 82.15 = 411.48 + 82.15 = 493.63 m^3
second holds all of it (capacity 606.65), spills 0
rain in 5,151 x 0.3048 = 1,570.02 m^3
held 258.74 + 493.63 = 752.38 m^3
off the edge 1,570.02 - 752.38 = 817.65 m^3
Under 20 in (0.508 m):
first takes 568.16, holds 258.74, spills 309.42 m^3 into the second
second takes 685.80 + 309.42 = 995.22, holds 606.65, spills 388.57 m^3 off the edge
rain in 2,616.71 m^3 = held 865.39 + off the edge 1,751.32
Every drop accounted for: rain in equals water held plus water off the edge, under any rain.
Tolerances: as in case 6, with a spill's tolerance carrying the catchment's (98.1 m^2 x P) and the volume's.
Engine: both capacities match the grid sums (258.772 and 606.612 m^3), both full stages are within 0.5 mm of 99.600 and 99.150 m, and both depths and areas are within tolerance. Own land is 1,178 and 1,401 m^2 (+59.6 inside 98.1, and +51 inside 137.1). Every rain balances. Under 12 in the first holds 258.77 m^3 and passes 100.28 m^3 to the second, which holds 527.31 m^3 (+33.7 against 493.63, inside the spill's and its own catchment's tolerance, 31.2 + 41.8). Under 20 in both fill: the second takes the first's 339.65 m^3, holds 606.61 and spills 444.75 m^3 off the edge; held 865.38 m^3 against 865.39, and off the edge 1,751.32 m^3 against 1,751.32. Before fault 1 was mended neither bowl's spill was followed: under 12 in the first held 363.02 m^3 and passed nothing on, and the second held only its own 427.63 m^3.
Case 8: ground with no data
Surface plane-gap: case 1's plane with no data in columns 40 to 44, a strip 5 m wide across it.
- What the tools should say. A drop that reaches missing ground stops at the last cell with data, says where it stopped, and gives no length or fall past it. A watershed cut off by missing ground says "At least". The rain comparison counts rain only on ground with data, and says how much ground that is.
- A drop from
(20, 0)runs east to(20, 39), the last cell before the strip:39 m, falling0.02 x 39 = 0.780 m, and its card ends "to a gap in the elevation data." (until 2026-12-01, "to the terrain's edge.", below). - A watershed at
(20, 59), east of the strip, touches the strip's side, so it reads "At least". - The rain comparison counts
41 x 56 = 2,296 m^2, the cells with data. - Engine: the drop never crosses the strip and ends beside it at
(20, 39):39 m, falling0.780 m, "Runs 128 ft and falls 2.6 ft to a gap in the elevation data." The watershed reads "At least", and the rain comparison counts2,296 m^2. Before fault 2 was mended the drop took one more step along the strip's side, on level ground, for 40 m and "Runs 131 ft". - Where a watershed's ground stopped (PR 62,
groundStopsOfinpackages/surface/src/water-outlets.ts). For each cell of the watershed beside a cell with no data, or beside the grid's side, the way to that neighbor is followed across the missing ground. Reaching the grid's side, the ground stops at the terrain's edge on the side it left by; meeting ground with data again first, it stops at a gap in the data. The answer adds it after "At least": "Its ground stops at the terrain's east edge." or "Its ground stops at a gap in the elevation data." The watershed at(20, 59)meets the strip at column 45; west across columns 44 to 40, data comes back at column 39, so it reads "Its ground stops at a gap in the elevation data." Worked by hand on a 10 by 10 grid with a gap inside it, a strip with no data at its east side, and cells on its south side and its northwest corner (water-outlets.test.ts). A saved watershed doesn't keep where its ground stopped, so its card says "At least" alone, as before. - Where a drop's ground stopped: one place, named one way (PR 62, 2026-12-01). The raindrop trace counts a gap inside the terrain and the terrain's outer edge alike as the terrain's edge (
traceRaindrop,packages/surface/src/flow.ts), so a drop beside the strip once said "to the terrain's edge" where a watershed beside the same strip said "a gap in the elevation data". The watershed's walk is the true one: it follows the missing ground to where data comes back or the grid ends. Now the drop is walked the same way (raindropGroundStopsinwater-outlets.ts): from its last cell, along the way it leaves (its pointer, where that steps onto missing ground or off the grid, or else the steepest way off the edge thatleavesAtEdgefound), across the missing ground. Meeting data again, it ran "to a gap in the elevation data"; reaching the grid's side, "to the terrain's edge", as before. Where the way it leaves can't be read, every way off its last cell is walked, and only a stop wholly at gaps is called a gap. Its card's note and its Ends at row say the same ("Follows the terrain to a gap in the elevation data …", "Gap in the elevation data"). Worked by hand on a plane 10 by 7 falling east with no data in columns 5 and 6 of rows 1 to 5 (water-stops.test.ts): a drop from(3, 0)stops at(3, 4), a gap; one from(3, 7)at(3, 9), the east edge; the watershed of(3, 8)at a gap and that of(3, 3)at the west edge. On case 8's plane the drop gives "a gap" and case 1's drop "the east edge" (water-proof.test.ts). The fixture terrains the browser tests use have no cell without a height, so no browser test's drop changes its words. - A low spot that reaches ground with no data (PR 62,
reachesNoDatainextractDepressions,packages/surface/src/runoff.ts). The fill-depth grid treats a hole inside the grid as a wall (fault 1, "Wang and Liu treat a hole inside the grid as a wall"), so a low spot against missing ground has its capacity, depth and stage worked as if the ground went on rising there. Any cell of a low spot with a neighbor, of eight, off the grid, with no height or outside the routed mask flags it. Worked by hand on a 12 by 12 grid with a 3 by 3 floor filling1 m:9 m^3with or without a strip with no height beside it, flagged only with it, and flagged for a diagonal neighbor outside the mask and on the grid's side (runoff.test.ts). See where water goes then counts it among the low spots holding water but leaves its depth out of "at the deepest", and says "One of them runs into ground with no data, so how much it holds isn't known. Draw a larger area to see all of it." That advice holds only where its ground stops at the terrain's outer edge: where it stops at a gap in the data inside the area, which a larger area won't take in, the sentence says so instead ("Its ground stops at a gap in the elevation data inside this area, which a larger area won't fill."), and where some stop at each, which helps ("Some stop at a gap … ; draw a larger area to see the rest."), read from the low spots' owngroundStops(round 7 of plan v4, 2026-12-02, finding NH10; until then it always said to draw a larger area). Its map page adds a row, "1 runs into ground with no data" (water-path-words.test.ts,water-map-page.test.ts). Case 8's plane has no low spot, so none is flagged there. - A low spot whose ground stops: no figure past it (PR 62, 2026-12-01). Every screen that lists low spots now gives a flagged one no depth, area, volume or stage, and says where its ground stopped in the watershed's words (
groundStopsOfCells, the walkgroundStopsOfmakes, over the low spot's cells, reading the original DEM's heights and the routed mask that flagged it): "Runs into ground with no data, so how much it holds isn't known. Its ground stops at a gap in the elevation data." (or "… at the terrain's east edge."). The flag is read from the low spot's full footprint, filled to its spill, which holds its water at any rain, so a low spot that touches missing ground at some rain is flagged at every rain.- Where. The workbench's Low spots list, from the worker's summary (
find_low_spotsinservices/gis-worker/gis_worker/terrain/hydrology.py) or, with culverts in force, the browser's (summarizeLowSpots): the row gives the line in place of its figures, the spot is left out of the two totals, and a line beneath says so ("One of them runs into ground with no data, so how much it holds isn't known. It isn't in these figures."). The rain comparison (compareRainPondingOnGrid): the spot's depth, area and stage are null; it is left out of the deepest water, the acres under water and the water held that the step gives (totalListedVolumeM3,totalAcreFeet), as is any spot refused for coarse terrain (< 9cells, counted once as cut off when a spot is both, matchingsummarizeLowSpots; hand-worked three-spot case inresult-resolution.mdandpackages/surface/src/runoff.test.ts); its row in the table of low spots gives the line, and the step's sentence counts it among those holding water and gives no total ("After 1 in of rain, 3 low spots hold water. One of them runs into ground with no data, so how much it holds isn't known."). Side by side, the two summaries leave it out and say so. - What still counts it. The six-term water balance has to account for every drop, so "Held in listed spots" still includes its water, and a line under the balance says it is worked as if the ground went on there. Its water is still drawn on the map where it stands on cells with data: a picture, not a figure. The picture is drawn whenever any water is (
pondingPictureinapps/web/src/lib/terrain/surface-water.ts, read by the Surface water panel and See where water goes alike), even where that low spot is the only one holding any; until round 7 of plan v4 (2026-12-02, findings NH8 and NB4) the map drew only when a spot of known depth held water, so the sentence said a low spot held water and nothing was drawn, on the screen or the map page. The key's deepest comes only from spots whose depth is known; with none, its ramp runs from "Shallow" to "Deeper" with no figure, and whenever a cut-off spot's water is drawn its note adds "Where a low spot runs into ground with no data, how deep isn't known." On the grid below with floor B alone, at 4 in B's cells stand0.16933 mdeep on the map,maxPondedDepthMis 0 and the key gives no depth (cut-off-ponding.test.ts). - Worked by hand (
packages/surface/src/low-spot-no-data.test.ts,apps/web/src/lib/terrain/low-spot-rows.test.ts). A grid 15 cells wide and 7 high, 1 m cells, at101 m, every cell draining north. Two 3 by 3 floors at100 m, each filling1 m: A at rows 2 to 4, columns 2 to 4, and B at rows 2 to 4, columns 8 to 10. Each gathers its own 9 cells and the 6 below it:15 m^2. At 4 in of rain, all running off, each takes15 x 0.1016 = 1.524 m^3, under its9 m^3, and stands1.524 / 9 = 0.16933 mdeep over9 m^2, its water at100.16933 m. With a strip with no height at column 11, rows 2 to 4, B lies against it: walking east from column 10 across column 11 meets ground with data at column 12, so its ground stops at a gap in the elevation data. The engine gives A exactly the same figures with the strip as without it, to the last digit, and B none; the water held, the deepest and the acres under water are A's alone (1.524 m^3,0.16933 m,9 m^2), and the balance still holds3.048 m^3in listed spots and closes. The low spot summary gives A1 mdeep,9 m^2,9 m^3, B no figure, and totals of9 m^2and9 m^3where they were18without the strip. The same floor moved to columns 12 to 14, on the grid's east side, stops at the terrain's east edge. - What it changes. Nothing for a low spot that doesn't reach missing ground. On the five fields the browser tests build on, no listed low spot reaches it and no cell is without a height, so the with-tile view's pins (
with-tile-pins.test.ts) and the tile benchmarks (benchmarks.test.ts) are untouched. A hand-made grid whose low spots lie on the grid's side, asrunoff.test.ts's two low spots in series do, now has them left out of the totals a screen gives; its balance is unchanged. A terrain built before the worker gave the flag keeps its stored summary, with figures, until it is rebuilt or a culvert is in force.
- Where. The workbench's Low spots list, from the worker's summary (
What the cases found
Four faults, numbered here as the fixes refer to them. The first three were mended on 2026-11-30, and the case that found each is an ordinary passing test against its unchanged reference answer. The fourth is the method's own limit, kept as its stated tolerance.
- Conditioning left some low spots undrained, so their overflow never spilled. Mended in the worker, pipeline version 7.
- What it did. At 1 m cells, WhiteboxTools 2.4.0's
BreachDepressionsLeastCost(searchdist = 100 m / cell, with--fill) left both bowls exactly as they were apart from the bottom cell: neither breached nor filled, with an interior pit at each bottom. The browser's routing then found no way out of the low spot and, by section 4's rule for a hand-made grid, kept its overflow as standing water:363.02 m^3held against a capacity of258.77 m^3under 12 in, nothing passed from the first bowl to the second, and the water balance still closed, so nothing on screen showed it. The browser tests' fixture terrain had 17 interior cells with no direction, each at the bottom of ground that fills2.65to2.67 m, and one of the three real test fields, Brookings (real-brookings-sd.tif, 3 m), had 13. - Why, from the tool's source (
breach_depressions_least_cost.rsat tagv2.4.0). Two separate gaps:- The least-cost search treats a cell past the grid's side as a breach target, since reading it returns no data. When it reaches one first, it counts the pit as solved and walks back along the stored path to cut the channel, but a cell off the grid has no stored step back, so the walk stops at once and nothing is cut. A pit counted as solved never reaches the filling step either. On case 6 a search of 24 cells, which can't reach the grid's north or south side 25 rows away, drained the bowl by filling, and 25 or more didn't, which is what the proof lane measured.
- The filling step floods up from each pit until it finds a neighbor that is lower and has a height. A pit whose only way out is the grid's side or a cell with no height never finds one, and is left. A closed basin wider than the 100-cell search with its lowest exit at the grid's side is such a pit: a prairie pothole whose land rises everywhere to the edge of the terrain.
- The fix (
_conditioninservices/gis-worker/gis_worker/terrain/hydrology.py). After breaching, D8 pointers are worked out and any cell with a height, away from the terrain's edge, with no direction is found (undrained_cells). Where there are none, which is most ground, nothing more runs and the surface is exactly what it was before (Fargo, Mankato and the synthetic 160-acre field came out bit for bit the same). Where there are some, the breached surface is filled withFillDepressionsWangAndLiu --fix_flats, the same filling that measures the low spots' fill depth, which treats the grid's border as where water leaves and gives each filled cell a slope too small to measure toward the spill. That fill is kept only in the connected stretches it raised that hold one of those pits, and everywhere else the breached surface stands. Wang and Liu treat a hole inside the grid as a wall, not an outlet, so a stretch the breach had already drained into a hole is left drained into it (a test holds this). Where a pit is still left, on ground ringed by cells with no height with no path of cells with heights to the grid's side, the worker logs it and the rain comparison keeps its water, as section 4 says. - What stays a low spot. Fill depth, the low spots, their capacity and stage are read from the original DEM and don't change (the fill-depth grid is identical before and after on every surface tried). Only the conditioned surface and the flow grid change, and only inside such a low spot: its cells now drain over its spill point. A raindrop still stops where water would stand
0.10 mdeep, ponding is still drawn from the fill depth, and the rain comparison still fills a low spot before it spills; what changed is that the spill now has a path. The bowls of cases 6 and 7 spill within one cell of(25, 40), the closed form's spill point, and the first bowl's spill runs into the second. - Why not just let the breach reach the edge. Padding the grid with a ring of cells with no height makes the breach work as written, but it then cuts a trench from each bowl to the nearest side: on case 7 the first bowl drained north off the grid instead of over its rim into the second. Filling sends water over the rim, where it really goes.
- What moves. Every terrain built from now on gets the mended flow grid where the fault bit; a terrain built before keeps its stored flow grid until it is rebuilt (pipeline version 7, so a rebuild doesn't reuse the old surface and a saved result says it was made on an earlier terrain). On those terrains the raindrop, watershed, rain comparison (own land, spill and its with-tile water), a ditch's draining area, culvert routing and wetness can change near such a low spot. No tile design result reads the flow grid: cover, grades, pipe sizes and flows come from the network and the original DEM.
- The with-tile view, pinned (PR 62,
apps/web/src/lib/terrain/with-tile-pins.test.ts). The rain comparison's with-tile water is the one figure of the water tools a drainage design shows. On the five fields the browser tests build on (the real fields near Fargo, Mankato and Brookings, the synthetic 160-acre field and the browser tests' fixture terrain), each read with the app's readers and run through the app's calculation dispatcher with one surface inlet at the deepest cell of the largest low spot (4,000 m² at 1/2 in a day, a 6 in pipe at 0.2%), the test pins, at 1 in and 3 in of rain with every drop running off, without the tile and with it: the water held in the listed low spots, the water off the terrain, the acres under water, the deepest water, and the inlet's low spot's water, what the tile takes from it and its stage. A change to any of them fails the test and has to be explained here before the pin moves. - What item 544's mend changed there, measured. The real fields' and the synthetic field's grids were first built after the mend (
12505c0a), so they have no earlier version. The fixture terrain's flow grid was rebuilt by the mend (8900a075). Run on its flow grid from before, the with-tile view differs from the pinned one by: water held in the listed low spots6,265.9768to6,265.8244 m^3at 1 in (-0.1524 m^3,-0.002%) and18,797.9304to18,797.4732 m^3at 3 in (-0.4572 m^3); the water off the terrain up by the same; acres under water4.668562to4.668068at 1 in (-0.0005 ac) and unchanged at 3 in. The deepest water, and the inlet's low spot (what the tile takes,11.8872and35.6616 m^3), are unchanged. Without the tile the same difference shows, so it is the mend's, not the tile's: the rain on6 m^2(0.1524 m^3is1 inon6 m^2) that stood in the undrained cells now runs off.
- What it did. At 1 m cells, WhiteboxTools 2.4.0's
- A path ran on along the terrain's edge. Mended in the raindrop trace, method version 2. An edge cell has no neighbor past the edge, so its pointer could only send water along the edge or nowhere, and the trace followed it: on case 1 the path was
61 mfor60, on case 840 mfor39, and on case 376.6 m,20 mof it along the north edge. The trace now takes the ground past the edge to go on at the slope it comes in at and ends the path where water would fall off the edge more steeply than along its pointer (section 1, "Raindrop trace", rule 3). That reads the original DEM's heights at the edge cell and its neighbors only. Where the ground beyond would rise, the path follows its pointer as before, which keeps section 1's hand-worked 5 × 5 path of60 m,20 mof it along the north edge. The fix is in the trace, not the flow grid, so a watershed is unchanged: one that reaches the terrain's edge still reads "At least", and the worker's accumulated areas still match it cell for cell. The rain comparison still routes by the flow grid, so water reaching an edge cell that points along the edge is still carried along it there; that is left as it is. - The watershed at a closed pit's bottom missed most of the pit. Mended in the watershed, method version 2. This wasn't the missing directions of fault 1: the pit's flow grid had no interior cell without a direction before the fix and after. The worker drains the pit through one channel to one rim cell, so only the cells whose paths happened to pass through the bottom cell counted:
301 m^2of1,257. A pour point where water stands0.10 mdeep or more, where a raindrop would stop, now gets everything that drains into the whole low spot (section 1, "Watershed delineation"):1,252 m^2, "at least", the same land the rain comparison gives the low spot. On the browser tests' fixture terrain the cell the watershed specs click,(120, 318), is in a low spot1.95 mdeep: it now gives1.68 acreswhere it gave1.60, and its neighbor across the channel gives the same1.68where it gave 8 cells. As first mended, the tool used the low spot only when the fill-depth grid happened to be loaded, which the watershed tool alone didn't load, so the same click gave1.68after the rain comparison had been opened and1.60without it. The watershed now always loads and waits for that grid (section 1, "Watershed delineation"), and a unit test works the same point with the grids arriving in every order and gets one answer. A watershed saved before this change records method version 1, and while its terrain is still the current one its card says "Made with an earlier calculation method" (once the terrain is rebuilt it says the earlier terrain instead, which takes precedence). - Eight directions stray up to 22.5°. Not a fault in the code: the limit of a flow grid of eight directions (D8, O'Callaghan and Mark, 1984), kept as the method's tolerance (see "Eight directions" under the tolerances above).
- What it does. Each cell sends all its water to the one neighbor of eight with the steepest drop. Where the ground's fall line lies between two of the eight, every cell makes the same choice, so on an even slope the path runs in a straight line up to
22.5°off the fall line and doesn't come back. On case 3, falling at26.6°north of east, every path runs18.4°off, and after56.6 mit is17.9 mfrom where the water really goes. In general a path of lengthLcan end up to0.38 Lto one side. - Where it matters. Long, even slopes whose fall line lies between the compass points: a smooth field sloping north-northeast, where a person following a drop down it can see it veer. The watershed of a point there has the right area to within the cells along its boundary, since every cell is still counted once, but its shape leans the same way.
- Where it doesn't. Ground with real relief: water gathers in draws and swales within a few cells, and once it is in one the path follows the draw, whatever the angle. The low spots, their fill depth, capacity and stage don't use directions at all, and the rain comparison's routing between low spots follows the draws.
- A proposal for a better raindrop path, for the owner and an engineer to decide. Trace the drop down the conditioned surface's own gradient rather than cell to cell: from the drop's point, step a fixed distance (say half a cell) along the steepest descent worked out from the bilinear surface through the four nearest cell centers, as a streamline, until it enters ground that fills
0.10 mor more, leaves the terrain's edge or reaches a cell with no way out. On case 3 it would follow the fall line to the east edge aty = 30 m,67.08 m. To stay consistent it would need three things. The watershed: the drop must end in the watershed the flow grid gives for where it lands, or the path and the outline disagree; the trace can be kept inside that watershed by stopping it, or snapping it back, where it would cross into another one. The low spots: it stops on the same fill-depth rule, so a drop still ends where water would stand. The with-tile view and culverts: a culvert reroutes the flow grid (applyCulvertsToHydrology), so near a culvert's corridor the trace would have to hand over to the D8 pointers. Its cost: the browser would need the conditioned surface as well as the flow grid (about one float32 grid, 4 bytes a cell, a fetch the app doesn't make today), a tracer of perhaps 150 lines with its own reference cases (the planes of cases 1 to 3, where it must match the closed form to within a cell), and an engineer's review of where it disagrees with the flow grid. A multiple-direction method (D∞, Tarboton 1997, or MFD) would also mend watershed shapes and wetness, but changes the worker's flow grid, the accumulation, outside entries and every routed result, and would be a new pipeline version: a larger decision than the raindrop alone.
- What it does. Each cell sends all its water to the one neighbor of eight with the steepest drop. Where the ground's fall line lies between two of the eight, every cell makes the same choice, so on an even slope the path runs in a straight line up to
8. See where water goes (plan v4 items 538 to 546)
The path See where water goes adds no hydrology. Its Water step runs the tools above: the raindrop (section 1), the watershed (section 1) and the rain comparison (section 4), on the flow, fill-depth and outside-entry grids in force, culverts included (section 4, "Routing ponded water through a culvert"). It adds three things worked from their results, each stated here: where the ground drains out, where a culvert is offered, and how fast a drop's path is drawn. Every figure in the step reads built terrain and its flow grid; until they are read, the step says the detailed ground is on its way and works itself out when it lands.
Where the ground drains out
whereWaterLeaves in @tilemapper/surface (packages/surface/src/water-outlets.ts) follows every valid cell's D8 pointer on the flow grid in force to the cell where its path ends, using the same accumulation as flowAccumulationCells. A path that ends on the terrain's edge (the grid's border, or beside a cell with no height) leaves the terrain there. A path that ends inside it (an interior cell with no direction, or a loop of directions) stays; a terrain built from pipeline version 7 has none (section 7, fault 1). Every share is of all the land with heights, land that stays included, since the sentence and Details say "of the ground" and "most of this ground". Until review H3 (2026-12-02) the shares were of the land that leaves only, so with any land staying each place's share, and the test for most, read high. Details and the map page then say how much ends inside: "Ends inside it, 2% of the ground", or "under 1%" for less than half a percent. Each cell counts its own area, c^2. Land entering from outside the terrain is left out: the sentence is about this ground.
- Where an exit is. First, whether it is at a gap in the data: the way out of the exit cell is followed across the missing ground, as a raindrop's is (section 7, case 8): along its pointer, or, where it has no direction, every way off it to missing ground. Meeting ground with heights again before the grid's side, the water leaves at a gap in the data ("through a gap in the data inside it"), wherever in the terrain the gap lies; a cell with no direction is at a gap only if every way off it is. Otherwise it leaves at the terrain's edge, and the bounding box of the cells with heights is split into thirds each way: an exit cell in a corner third is in that corner's zone ("its northeast corner"), one in the middle third of a side in that side's middle ("the middle of its east side"). Each edge exit also has a side: the side of the box its pointer steps off across, or, where it has no direction, steps onto missing ground or leaves through a corner, the side it is nearest. An edge exit in the middle third both ways, at a notch in the outline open to the grid's side, takes the side its walk reached. Until round 7 of plan v4 (2026-12-02, findings H2 and NH7) only an exit in the middle third both ways was called a gap, so a gap anywhere else was named as a corner or side, against the rule below.
- The rule for "most". A zone that takes more than half of the ground is named: "Most of this ground drains out at its northeast corner". Failing that, a side that takes more than half is named: "Most of this ground drains out along its east side". Failing both, the ground drains several ways, and the sentence says so: "This ground drains out several ways, marked on the map". More than half is what "most" means; it is a judgment of wording, not a hydrologic threshold (
MOST_DRAINS_SHARE = 0.5). The map marks the place named at its exit cell carrying the most land, or, where it drains several ways, each zone taking at least a tenth, up to four. - Following the flow grid. The shares follow the pointers as the rain comparison's routing does, so water reaching an edge cell whose pointer runs along the edge is counted where that run finally leaves (section 7, fault 2 was mended in the raindrop trace, not the grid).
- Low spots on the way. The same sentence goes on to say how many listed low spots hold water at the rain chosen (below): "…, and 3 low spots hold water on the way."
Hand-worked cases (1 m cells, packages/surface/src/water-outlets.test.ts)
Each is matched exactly: the shares are counts of whole cells.
- A plane falling east, 30 × 30, every pointer east. Each row leaves at its east cell, 30 m² a row. Rows 0 to 9 are the northeast corner's zone, 10 to 19 the east side's middle and 20 to 29 the southeast corner's: 300 m² each, a third, so no zone takes more than half. Every exit steps off the east side, which takes all 900 m²: "along its east side".
- A plane falling northeast, 30 × 30, every pointer northeast. The north edge's cell in column
ktakes thek + 1cells of its diagonal, and the east edge's cell in rowjtakes30 - j. The northeast zone holds the north edge's columns 20 to 29 (21 + … + 30 = 255cells) and the east edge's rows 1 to 9 (29 + … + 21 = 225): 480 of 900, 53.3%, more than half: "at its northeast corner", marked at(0, 29). - A ridge down the middle, 30 × 30, columns 0 to 14 west and 15 to 29 east. 450 m² each way: half is not more than half, so it drains several ways.
- The same, 31 wide, columns 0 to 15 west. 480 of 930 m², 51.6%: "along its west side". The two cases are the two sides of the rule.
- A gap in the data, rows and columns 13 to 16 of a 30 × 30 plane falling east: the 13 cells west of the gap in each of its 4 rows end beside it, 52 m², "inside".
- A gap off the middle, one cell with no height at
(5, 5)of a 30 × 30 grid, in its northwest ninth, every other cell pointing straight at it: the 8 cells around it step into it, and walking on across it the next cell has heights, so all 899 m² leaves at a gap, "inside", share 1, and none at the northwest corner. Before round 7 all of it was named "its northwest corner". - Case 8's strip (section 7), 61 × 41 falling east with no heights in columns 40 to 44: each row's first 40 cells end at column 39, and walking east column 45 has heights, so 41 × 40 = 1,640 m² leaves at a gap; columns 45 to 60 leave by the east side, 41 × 16 = 656 m². The gap takes 1,640 of 2,296, 71.4%, "Most of this ground drains out through a gap in the data inside it". Before round 7 the rows in the north and south thirds were named the north and south sides, 560 m² each, and the gap took 520 m².
- A notch in the outline, no heights east of column 24 in rows 0 to 9 of the east plane: those rows end at column 24 and walking east reach the grid's side, so they leave at the terrain's edge, the northeast corner's zone, 250 m².
- An interior cell with no direction at
(15, 20)on the east plane: the 21 cells of row 15 from column 0 to 20 end there and stay; 879 m² leaves, all along the east side: 879 / 900 = 97.7%, said as 98%, more than half, and Details adds "Ends inside it, 2% of the ground". - Most of it ending inside. The east plane, with rows 13 to 28 pointing east up to column 19 and west from column 21 into column 20, which has no direction: 16 × 30 = 480 m² end there. Rows 0 to 12 and row 29 leave east, 14 × 30 = 420 m² (row 29's cell in column 20 is on the edge, so it leaves). The east side takes 420 / 900 = 46.7%, not more than half, so no place is named as taking most. Of the land leaving only, it would have been all of it, and the sentence would have named the east side.
Where the data runs out
Cells with no height are counted nowhere. Water that reaches a gap in the data leaves the terrain there as far as the grid can tell, and the place is named as a gap in the data, never as a corner or side. Land past the terrain's edge is not in the shares.
The rain you choose
- Where it starts. The slider starts at 1 in, a plain round depth to begin from, and the step says so: "Starting at 1 in of rain. Slide to try any depth." It is a starting point, not a design storm for the place, and nothing cites one. It runs from 0.25 to 8 in in steps of 0.25 in. The Surface water section's rain comparison starts from nothing, an empty box (PR 62's Comments).
- What it works out. Each depth runs
compareRainPondingOnGrid(section 4) once, without tile, in the terrain worker (water-pathtask inapps/web/src/lib/terrain/terrain-calc.ts): the same figures as the Surface water section's view without tile, held equal byapps/web/src/lib/terrain/water-path-task.test.tson the surfaces of section 7. Every drop is accounted for by the six-term balance (plan v3 item 371), and More options lists its terms. The sentence says how many listed low spots hold water, how deep the deepest gets and how much runs off the terrain: "After 1 in of rain, 3 low spots hold water, 1.2 ft at the deepest, and 0.84 acre-feet runs off the ground." - What it assumes. By default all the rain runs off, the most water there could be, as the rain comparison's default does, and the step says so beside the slider. Under More options a person can let some soak in: a ground cover from the NEH Part 630 Chapter 9 table (section 4), a soil wetness before the rain, and the soil, from the project's soil map as one mix for the whole ground or, where the project has none, a hydrologic soil group the person chooses. Until a soil is known, all of it runs off and the step says that. The page prints what was assumed in a few words.
- As the slider moves. Each step of a drag works the full figures; the newest depth replaces any still waiting (
TerrainCalcClient's latest-wins). The map draws the water held at a coarse stride while the slider moves (overlayStrides(...).drag), the coarse pass, and at the full stride once it rests. Only the picture is coarse, never a figure.performance.mdhas the timings.
Where a culvert is offered
Lidar sees a road's crown, not the pipe under it, so water ponds behind every road with a culvert under it. culvertOffers in @tilemapper/surface (packages/surface/src/culvert-offer.ts) looks at each listed low spot holding water at the rain chosen, most water first, and offers a culvert where the low spot lies against a long, straight, steep bank with lower ground across it. It never places one: a click on Add a culvert saves it as a surface culvert, the same feature plan v3's item 395 keeps, routed by applyCulvertsToHydrology (section 4), so the water finds its way through, the sentence changes and the culvert is kept with the project. The step says so in that order (culvertAddingWords, round 7 of plan v4, finding H4): "Adding the culvert…" while it saves, "The culvert couldn't be saved. Try again." with the offer back if the save fails, "Culvert kept with the project. Working out where the water goes through it…" once it is saved, and "Culvert added. The water now runs through it, and it's kept with the project." only once the answer on screen was worked after the tap. Until round 7 that last sentence showed at the tap. The thresholds are judgments, not cited values:
- A bank cell. A cell just outside the low spot (8-adjacent to it) where the ground within 3 m (
BANK_REACH_M) of it, outside the low spot, climbs at least 0.3 m (1 ft,BANK_RISE_M) above the lowest ground of the low spot beside it. A natural rim at 5% climbs about 0.22 m in that distance and is not a bank; a road's side slope is. - Long and straight. The bank cells' line is their principal axis. At least 60% of them (
BANK_STRAIGHT_SHARE) must lie within 1.5 cells of it, and those must run at least 20 m (MIN_BANK_LENGTH_M) along it, so a ring of steep sides or a curved hillside is not offered one. - The inlet is the low spot's lowest ground within 3 m of the bank's line. The outlet is found by stepping from the inlet square across the line, away from the low spot's middle, up to 30 m (
MAX_CROSSING_M): the first cell past ground at least 0.3 m above the inlet's whose ground is at least 0.05 m (MIN_OUTLET_DROP_M) below the inlet's, and whose water, followed down the flow grid, doesn't run back into the low spot. Without one, nothing is offered.
Hand-worked case (1 m cells, packages/surface/src/culvert-offer.test.ts)
A valley 81 m across falls south at 4 cm a meter, its sides rising 3 cm a meter from its middle column 40: z = 100 - 0.04 r + 0.03 |c - 40|. A road crosses it on rows 30 to 33, 0.5 m up on its side rows (30, 33) and 1 m on its crown (31, 32). The lowest way across the road is its crown at column 40, row 31: 100 - 1.24 + 1 = 99.76 m; the valley's sides at row 31 stand higher, and its head at row 0 is 100 m, so water ponds behind the road to 99.76 m.
- On row 30 the low spot holds the cells where
99.3 + 0.03 |c - 40| < 99.76,|c - 40| < 15.3, columns 25 to 55; on row 29, where98.84 + 0.03 |c - 40| < 99.76, columns 10 to 70. The cells just outside it against the road are row 31's columns 24 to 56 and row 30's columns 9 to 24 and 56 to 71. Each has the road's crown within 3 m, at least 0.46 m above the low spot beside it: a bank. They lie on two adjacent rows, within 1.5 cells of their line, from column 9 to 71: 63 m. The valley's sides and head climb at most0.05 × 4.4 ≈ 0.22 mwithin reach and are not banks. - The inlet is the lowest ground of the low spot within 3 m of the bank: the valley's middle on row 29, 98.84 m, at
(29, 40). Straight south, row 30 is the low spot, rows 31 and 32 are the crown (99.76 and 99.72 m, above98.84 + 0.3), row 33 is 99.18 m, and row 34 is the first ground below98.84 - 0.05: 98.64 m, at(34, 40), a crossing of 5 m. Its water runs south off the grid. - The engine gives exactly that offer. The same valley without the road, a round bowl with sides at 10 cm a meter, a round pit 12 m across with sides straight down, a road whose far side stays at 100 m (no lower ground within 30 m) and a road whose water would run back north over it are each offered nothing.
Where the data runs out
The walk across the bank stops at a cell with no height, and nothing is offered: a culvert is never offered into ground the terrain doesn't hold.
A drop drawn downhill
A drop's path, from the raindrop trace of section 1, draws itself from its start downhill at about 4 ms a meter (DROP_MS_PER_M), so the eye can follow it: no faster than 0.6 s and no slower than 4 s, so a long path takes a few seconds. A tap on Show the whole path, or another drop, skips it, and anyone whose system asks for less motion (prefers-reduced-motion) sees it whole at once. The drawing changes nothing about the path: its card says how far it runs, how far it falls and where it ends, in a low spot or at the terrain's edge, as section 1 works it, and a path that reaches ground with no data stops at the last cell with heights and says where it stopped: the terrain's edge, or a gap in the elevation data inside it (section 7, case 8).
Eight directions, said where it is wanted
About this data says, beside the water path's line: "A raindrop path moves from cell to cell in one of eight directions, so on a long, even slope it can run up to 22.5° off the true downhill line; on ground with draws and swales it follows them." Section 7, "What the cases found", fault 4, has the working.