Lay of the Land
All methods

Slope, bands, rules and grade

Plan v4, PR 53, items 446 to 449. How the app works slope and facing as numbers, puts slope in bands with acres, shades the ground that meets a rule, and gives the grade along a line; where each method comes from; the distance each is worked over; what each leaves out; and the cases worked outside the engine that the engine is tested against.

The code is in packages/surface/src/slope.ts and packages/surface/src/line-grade.ts. Screens reach it through one module, apps/web/src/lib/terrain/slope-and-grade.ts, which runs slope, bands and rules in the terrain worker. The tests are packages/surface/src/slope.test.ts, packages/surface/src/line-grade.test.ts and apps/web/src/lib/terrain/slope-and-grade.test.ts. Each case below names the test that holds it.

The worker's slope and facing pictures (services/gis-worker/gis_worker/terrain/overlays.py) stay as they are. They are drawn from ground averaged over about 10 m and 30 m, and nothing is measured from them.

0. Ground, distance and direction

Original ground only. Every figure here is worked from the original DEM, never the hydrologically conditioned one, which has had its heights changed so water can run off. computeSlope takes an OriginalDemGrid, whose surface is "original", so passing a conditioned grid doesn't compile; it also checks at run time. Test: "refuses a conditioned surface, at compile time and at run time" (engine), "can't be handed a conditioned surface" (worker grids and readers).

Ground distance. A project's terrain is in NAD83(2011) UTM, one of EPSG:6339 to 6348, in meters: the projects.crs_epsg column is checked to that range (supabase/migrations/20261105190000_projects_and_fields.sql), and the worker builds the DEM in the project's zone (services/gis-worker/gis_worker/terrain/dem.py). Cells are square and their size is in meters, so a rise in meters over a cell spacing in meters is a true slope. A UTM grid meter differs from a meter on the ground by the zone's scale factor, 0.9996 on the central meridian and about 1.0002 at a zone's edge at 49° N, and by height above the ellipsoid, about 0.005% at 300 m. Together that moves a 5% slope by less than 0.005 percentage points, which is far inside every tolerance below. A slope in a geographic system, in degrees, would be wrong, and none is worked.

Direction. Facing is the direction the ground falls, in degrees clockwise from grid north: 0 north, 90 east, 180 south, 270 west. Grid north is the UTM grid's north, which differs from true north by the meridian convergence: nothing on the central meridian, and about 2.3° at a zone's edge at 49° N. A facing condition reads grid north. That is far finer than any facing range a person would set.

1. Slope and facing (item 446)

Method

Horn's weighted differences:

Horn, B. K. P. (1981). "Hill shading and the reflectance map". Proceedings of the IEEE 69(1), 14–47. doi:10.1109/PROC.1981.11918

This is the method GDAL's gdaldem slope and gdaldem aspect use by default ("-alg Horn|ZevenbergenThorne", gdaldem documentation, read 2026-11-30), and the "third-order finite difference" of Esri's planar Slope and Aspect tools, whose formulas are printed in How Slope works and How Aspect works (read 2026-11-30).

With the window's heights named

a b c
d e f
g h i

taken k cells apart on cells of size s meters:

east rise  = ((c + 2f + i) − (a + 2d + g)) / (8 k s)
north rise = ((a + 2b + c) − (g + 2h + i)) / (8 k s)
slope      = 100 × √(east² + north²)              percent
facing     = atan2(−east, −north), in degrees, plus 360 if negative

The facing formula is Esri's atan2(dz/dy, −dz/dx) with its conversion to compass degrees, rewritten for a north rise rather than Esri's southward dz/dy; the two give the same direction, which Esri's own example below confirms.

The distance it's worked over

spacingCells (k) is 1 by default: the usual 3 by 3 window of a cell and its eight neighbors. The result's method says the distance, so a screen can show it:

Field Meaning 1 m cells, k = 1
spacingM How far apart the window's heights are, k s 1 m
acrossM Between the two rows or columns of heights that are differenced, 2ks 2 m
windowM The whole window's side, outer cell edge to outer cell edge, (2k+1)s 3 m

A longer stated distance. A whole number k up to 50 works slope over a longer distance by a stated means: Horn's same eight weighted heights, taken k cells from the center instead of one. On 1 m cells, k = 5 differences heights 10 m apart across an 11 m window, close to the 10 m the worker's slope picture is smoothed over. The means is subsampling, not averaging: only the nine heights named are read. That keeps the method Horn's, exact on a plane, and keeps what is left out simple to state. Its cost is that ground between the nine cells has no say, so a narrow ditch between them doesn't show; a screen that offers a longer distance says so in About this data.

What is left out

A cell is left out, with no slope or facing, and counted:

  • when it has no ground of its own (noGroundCells, cell state SLOPE_NO_GROUND);
  • when any of the nine heights its window reads has no ground, or falls off the grid (windowLeftOutCells, cell state SLOPE_WINDOW_LEFT_OUT).

This is GDAL's rule: "a nodata value in the target dataset will be emitted if at least one pixel set to the nodata value is found in the 3x3 window", giving a one-cell border without a value. Esri's rule is looser: it works a cell with at least seven valid neighbors and reweights the missing ones. The app doesn't fill in a missing height, so a cell near missing ground gets no figure rather than one partly guessed.

A missing-value tag is matched in its written and its float32 forms, as plan v3's item 431 requires (isValidHeight).

Level ground, with a slope of exactly zero, has no facing (levelCells). GDAL does the same unless -zero_for_flat is given.

Why two programs give different slopes for the same field

They agree on a plane, and differ on real ground, for these reasons:

  1. The distance. A slope from heights 2 m apart sees every lidar ripple; one smoothed over 10 m, like the worker's picture, doesn't. The same field reads steeper at 1 m than at 5 m. This is the largest difference by far.
  2. The cell size. A DEM resampled from 1 m to 3 m averages the ground first, which flattens it before any slope is taken.
  3. The method. Horn weights the middle row and column twice. Zevenbergen and Thorne (GDAL's other choice) uses only the four direct neighbors. Esri's newer Surface Parameters tool fits a curved surface over a window of up to 15 by 15 cells. GDAL's documentation notes that Zevenbergen and Thorne suits smooth ground and Horn rougher ground.
  4. Missing ground and edges. GDAL leaves out any cell whose window touches a gap; Esri reweights up to two missing neighbors; gdaldem -compute_edges interpolates them.
  5. Planar or geodesic. Esri's geodesic method measures against the ellipsoid; planar methods, including this one, measure on the projected grid (section 0).
  6. Units and storage. Degrees or percent, and heights kept as float32, which move a 1 m slope by about 0.002 percentage points (case A2).

Reference case A: a tilted plane

The plane, with x east and y north in meters from the grid's lower left corner:

z = 300 − 0.03 x − 0.04 y

It falls 3 cm per meter eastward and 4 cm per meter northward. Its slope and facing are known exactly:

slope  = √(0.03² + 0.04²) = √(0.0009 + 0.0016) = √0.0025 = 0.05 = 5%
facing : it falls toward (+0.03 east, +0.04 north),
         atan2(0.03, 0.04) = 36.8699°, between north-northeast and northeast

Horn by hand, on a 9 by 9 grid of 2 m cells, at any inner cell. With k = 1, the east column c f i is two cells, 4 m, east of the west column a d g, so each pair differs by −0.03 × 4 = −0.12 m. The north row a b c is 4 m north of the south row g h i, so each pair differs by −0.04 × 4 = −0.16 m:

c − a = f − d = i − g = −0.12
east rise  = (−0.12 + 2(−0.12) + (−0.12)) / (8 × 1 × 2) = −0.48 / 16 = −0.03

a − g = b − h = c − i = −0.16
north rise = (−0.16 + 2(−0.16) + (−0.16)) / 16 = −0.64 / 16 = −0.04
slope      = 100 × √(0.03² + 0.04²) = 5.000%
facing     = atan2(−(−0.03), −(−0.04)) = atan2(0.03, 0.04) = 36.87°

The 32 cells of the outer ring are left out (their windows fall off the grid); 49 are worked. With k = 2 the heights are 4 m apart, east = −0.96 / 32 = −0.03 again, and only the inner 5 by 5, 25 cells, are worked.

Tolerance. With heights in float64 the engine matches to 1e-4 percentage points and 1e-3° (the test's limits; the true error is rounding, about 1e-13). Test: "comes out exactly right on a tilted plane, with the edge cells left out"; "works over a longer stated distance by taking the window's heights farther apart".

Case A2, float32 heights. The DEM is read as float32. Near 312 m a float32 height is within 1.5e-5 m of the true value. Horn's numerator sums 8 weighted heights, so its error is at most about 8 × 1.5e-5 = 1.2e-4 m, divided by 8 s = 8 m on 1 m cells: 1.5e-5, or 0.0015 percentage points. On the plane z = 312.345 + 0.01 x − 0.007 y, slope √(1 + 0.49) = 1.2207% and facing atan2(−0.01, 0.007) + 360 = 304.99°, the tolerance is 0.01 percentage points and 0.1°: the facing's error is the slope's error over the slope, 1.5e-5 / 0.012 = 0.0013 rad = 0.07° at worst. Test: "stays within 0.01 percentage points and 0.1 degrees with heights stored as float32".

Reference case A3: Esri's published examples

Esri's documentation works two cells by hand, and the engine is held to Esri's printed figures:

  • Slope: a b c = 50 45 50, d f = 30 30, g h i = 8 10 10, 5 m cells. Esri: dz/dx = 0.05, dz/dy = −3.8, rise over run 3.80032. The engine gives 380.032%, matched to 0.005 percentage points. Test: "matches Esri's published slope example".
  • Aspect: a b c = 101 92 85, d f = 101 85, g h i = 101 91 84. Esri: dz/dx = −8.125, dz/dy = −0.375, aspect 92.64°. The engine gives 92.64°, matched to 0.005°. Test: "matches Esri's published aspect example".

GDAL. gdaldem isn't installed on the machine this was written on, so it wasn't run on these grids. It uses the same formula and the same rule for missing ground, so it is expected to give the same figures; running it is a check for PR 59's proof with real programs.

Run-out case: missing ground

Case A's plane with the center cell (row 4, column 4) given no ground: that cell is SLOPE_NO_GROUND, its eight neighbors' windows read it and are left out, and the inner cells beyond them are worked. Worked 49 − 9 = 40; left out for the window 32 + 8 = 40; no ground 1. Test: "leaves out a cell with no ground and the eight whose window reaches it".

2. Bands (item 447)

Method

A band runs from its lower edge, included, to the next edge, not included; the first starts at 0% and the last has no top. Each cell in the area with a slope goes in its band. Cells with no slope go on a line of their own, split into no ground and window left out. Each line gives cells, square meters (cells × cell area), acres (square meters ÷ 4,046.8564224) and its share of the whole area, including the ground with no data, so the shares add to one.

Edges can be typed or dragged in any order: they are sorted, repeats dropped, and edges at or below 0% dropped (normalizeBandEdges).

Speed. Bands read a slope grid already worked and kept by the worker. Moving an edge costs one pass over the cells with a binary search over the edges; slope isn't worked again. Test: "reads the same slope grid for every new value, without working slope again" (engine) and "keeps one slope grid per terrain and spacing, and an area per outline" (worker).

Starting bands

Starting bands come from the spread of the ground itself: the slopes below which a fifth, two fifths, three fifths and four fifths of the area's worked cells lie (nearest rank), each rounded to a readable percent, with repeats and zeros dropped (startingSlopeBands).

Why fifths. Each band starts with about a fifth of the ground, so every color shows on the map, on Red River Valley flats where all of a field is under 1% and on hill ground alike. Fixed bands, like the worker's picture's (under 0.5%, 0.5 to 1, 1 to 2, 2 to 5, over 5%), suit one landscape and leave most bands empty on another. Five matches the number of slope classes the worker's picture already draws in DESIGN.md's orange slope ramp. Ground that barely varies gives fewer bands, not empty ones.

Readable percents. Tenths under 1%, halves under 10%, whole percents under 30%, fives above (roundToReadablePercent). Lidar can't resolve finer than about 0.1% over 10 m (the worker's own note in overlays.py), so tenths are the finest worth reading, and the steps grow with the slope so an edge reads as a number a person would type.

Worked case. 100 cells with slopes 0.1%, 0.2%, ... 10.0%. The fifths fall at the 20th, 40th, 60th and 80th values, 2.0, 4.0, 6.0 and 8.0%, already readable. The bands then hold 19 (0.1 to 1.9), 20, 20, 20 and 21 (8.0 to 10.0) cells. Test: "starts the bands at the fifths of the ground's own spread". Uniform and empty ground: "gives fewer starting bands where the ground barely varies, and none with no slope".

A plateau on an edge. Where much of the ground has one slope and an edge falls exactly on it, float32 heights put those cells a hair either side of the edge, and the band split between them is rounding. Case A in float32 with a starting edge at 5% splits its 49 cells 14 and 35. The total is right; a screen offering starting bands on uniform ground should expect it. Test: "reads starting bands and typed edges from the slope grid it already has".

Reference case B: bands on the plane

Case A, 9 by 9 cells of 2 m (4 m² each, 324 m² in all), edges 2, 5 and 8%. Every worked cell is 5%, in the band from 5 to 8%:

Line Cells m² Acres Share
0 to 2% 0 0 0 0
2 to 5% 0 0 0 0
5 to 8% 49 196 196 ÷ 4,046.856 = 0.04843 49/81 = 0.605
8% and steeper 0 0 0 0
No data 32 128 0.03163 32/81 = 0.395

Areas and shares are exact (whole cells times cell area); the test compares acres to 1e-6. Test: "puts every worked cell of the 5% plane in the band from 5 to 8".

Reference case C: bands on a surface of two planes

A 12 by 8 grid of 1 m cells. West of a line 6 m from the west edge, the ground rises east at 2%; east of it, at 10%. With cell centers at x = col + 0.5:

z(col) = 100 + 0.02 (col + 0.5)              col 0 to 5
z(col) = 100.12 + 0.10 (col + 0.5 − 6)       col 6 to 11

Every row is the same, so Horn's weights cancel and east rise = (z(col+1) − z(col−1)) / 2:

Column z east − z west Slope
1 to 4 0.04 2%
5 z6 − z4 = 100.17 − 100.09 = 0.08 4%
6 z7 − z5 = 100.27 − 100.11 = 0.16 8%
7 to 10 0.20 10%

Columns 0 and 11 and rows 0 and 7 are left out: 36 of 96 cells. All worked cells face west, 270°. With edges at 3 and 9%, each worked column has six rows:

Line Cells Share
0 to 3% 4 × 6 = 24 24/96 = 0.25
3 to 9% 2 × 6 = 12 0.125
9% and steeper 4 × 6 = 24 0.25
No data 36 0.375

0.25 + 0.125 + 0.25 + 0.375 = 1. Exact. Test: "gives the two-plane surface's areas as worked by hand, the shares summing to one".

Cut to an outline, with one cell (row 3, column 8) given no ground: an outline from 6 to 11 m east and 1 to 7 m south of the top holds the centers of columns 6 to 10, rows 1 to 6, 30 cells. The missing cell and the eight whose windows read it (rows 2 to 4, columns 7 to 9) have no slope: 9 cells, 1 no ground and 8 window. Column 6's six cells are 8%, under the edge at 9%. Columns 7 to 10 hold 24 − 9 = 15 cells at 10%. 6 + 15 + 9 = 30. Test: "cuts to an area's outline, counting a missing cell inside it on the no-data line".

3. A rule (item 448)

Method

A rule is slope between two values, both included, with up to three further conditions: facing between two directions, read clockwise from the first to the second and so through north when the first is larger (315 to 45 is northwest through north to northeast); elevation between two values, read from the original DEM; and height above ground between two values. A missing end of a range is open. Level ground faces no direction and doesn't meet a facing condition.

Height above ground is the first-return surface less the ground, clamped at zero, as plan v2's computeHeightsAboveGround works it, from the first-return surface plan v3's item 383 builds and item 384 reads. The worker gets the surface in its firstReturn slot and checks it sits on the ground's cells (same size and cell size, origin within a quarter cell, as the lidar panel checks). A cell with no first-return height is unknown, never zero. Without a surface, or with one that doesn't match, the result says so (firstReturn: "none" or "does_not_match", heightsAboveGroundAvailable: false). A height range with neither end allows any height, so it is no condition and needs no surface (hasHeightCondition; round 7, NF1): before that, a range typed and then cleared left every cell undecided. When the heights weren't read, the rule's answer says it isn't worked out and why, and what to do (ruleAnswerWords in apps/web/src/lib/terrain/slope-words.ts, read by the project's screen and its shared link alike), never that no ground meets it, and gives no line on missing data.

Deciding a cell. Three-valued logic: a cell doesn't meet the rule if any condition it can read fails; meets it if every condition holds; and is undecided only when a condition has no value there and none of the others fails. So a cell at the edge with no slope, whose elevation is already above the rule's top, doesn't meet it, rather than being undecided. Undecided cells are counted apart, by the first thing missing: no ground, no slope (window), or no height above ground.

The result is a mask with a code per cell (meets, doesn't, undecided, outside the area) for drawing, and cells, acres and share of the whole area for each of the three, adding to one. A rule shades ground that meets a condition; its sentence says that and no more.

Speed. As bands: one pass over a slope grid already worked.

Reference case C, continued: rules on two planes

  • Slope 5 to 12%, facing 225 to 315°. Meets: columns 6 to 10 (8% and 10%, facing 270°), 5 × 6 = 30 cells. Doesn't: columns 1 to 5, 30 cells. Undecided: the 36 cells with no slope. 30 + 30 + 36 = 96. The same slopes facing 45 to 135° meet nowhere. Test: "shades the two-plane surface's steep west-facing ground, with the edge cells undecided".
  • Slope 5 to 12%, elevation at most 100.3 m. Column heights: 6 is 100.17 m, 7 is 100.27 m, 8 is 100.37 m. Meets: columns 6 and 7, rows 1 to 6, 12 cells. Undecided, no slope and not too high: column 0 (100.01 m, 8 cells) and rows 0 and 7 of columns 1 to 7 (14 cells), 22. Doesn't: worked columns 1 to 5 by slope (30), worked columns 8 to 10 by height (18), column 11 by height though it has no slope (100.67 m, 8), rows 0 and 7 of columns 8 to 10 by height (6): 62. 12 + 22 + 62 = 96. Test: "decides a cell whose slope is unknown when its elevation already rules it out".
  • Height above ground at most 1 m, any slope, with heights 0.5 m everywhere except none in column 9 and 5 m in column 10. Meets: worked cells of columns 1 to 8, 48. Doesn't: column 10's six worked cells, and its two edge cells, whose 5 m already fails, 8. Undecided: column 9's six worked cells for no height, and the other 34 edge cells for no slope, 40. Without a first-return surface, no cell meets: the 60 worked cells are undecided for no height and the 36 others for no slope. Test: "treats a missing height above ground as unknown, never as zero". Through the worker, with a surface 3 m above ground on the west three columns of case A: 35 cells meet, and a surface moved by a meter is "does_not_match". Test: "reads heights above ground from the first-return surface, and says when there's none or it doesn't match".

Facing ranges: "reads a facing range clockwise, through north when it wraps". Missing ground: case A with its center cell missing meets 40 cells, with 1 undecided for no ground and 40 for no slope ("counts a cell with no ground apart and never meets it").

4. Grade along a line (item 449)

Method

A profile's samples are distances along the line with a ground height, or none. The profile tool (apps/web/src/lib/terrain/profile.ts) takes one per cell, however long the line, each its cell's height. Until review round 7 (G3) a line over 1,500 cells long was sampled more widely, so a gap one cell wide could fall between two samples and a grade be given across it; now every reader (the profile card, the driveway, the site map page, a kept grade line and the shared links) reads samples no more than a cell apart. A cell the line only clips for less than one cell length, at a corner, can still fall between two samples, as on any line.

  • Parts. A part is a run of samples that all have ground. The space between two neighboring samples is missing when either has none; missing length is the sum of those spaces, so parts and missing add to the whole line.
  • Steepest grade. For each sample in a part, the run ends at the first later sample in the same part at least the run away, and the grade is the rise over that distance. The steepest is the largest, with where it starts and ends and whether it rises or falls in the direction drawn. Among runs equal to within 1e-9 percent, the first is named. A grade is never taken across a sample with no ground.
  • The run starts at ten cells of the terrain (DEFAULT_GRADE_RUN_CELLS), as the Decisions under "Before PR 53" set it: a grade over one cell is noise. It can be changed, down to three cells (MIN_GRADE_RUN_CELLS), the finest feature plan v3's item 430 allows. The result says the run, in cells and meters, and the steepest's own start and end. Samples are never more than a cell apart (above), so the run is the run chosen.
  • Length steeper than a grade entered. The union of every run steeper than the grade entered by more than the same 1e-9 percent, given as stretches along the line for the chart and the map. A run at the grade entered differs from it only by rounding, so it isn't steeper: a constant 3% line sampled every meter, compared with 3%, has none of its length steeper (round 7, F1; test: "marks none of a constant 3% line steeper than 3%" in line-grade-ties.test.ts). Before that, a few runs rounded just above 3% and their overlapping spans covered the whole 100 m.
  • A level line. A steepest grade that reads as 0.0% is said to be level, never rising or falling (round 7, NF5; steepestLead, test grade-words-level.test.ts).
  • Too short. A part shorter than the run gives no grade, and its length is counted (tooShortM). A line with no part as long as the run gives none at all and says why.

Reference case D: a line across the plane

Case A's plane, z = 300 − 0.03 x − 0.04 y. A line along the facing direction, unit vector (0.6 east, 0.8 north):

dz/ds = −0.03 × 0.6 − 0.04 × 0.8 = −0.018 − 0.032 = −0.05     5%, falling

A line due east: dz/ds = −0.03, 3% falling. Sampled every meter, the engine gives 5% and 3% to 1e-9. Sampled cell by cell along a row of the plane's grid, as the profile tool reads it, the line due east still gives 3%, while the slope of each cell on it is 5%: a line's grade is its own direction's, not the ground's steepest. Tests: "gives 5% falling on the plane's steepest line and 3% on a line due east"; "reads the same 3% from a profile sampled cell by cell across the plane's grid".

Reference case E: a line of two grades

Rising 2% for 50 m, then 8% for 50 m, sampled every meter, run 10 m:

z(d) = 100 + 0.02 d             d ≤ 50
z(d) = 101 + 0.08 (d − 50)      d > 50

Steepest: any run wholly past 50 m, 8% rising; the first is 50 to 60 m. Steeper than 5%: a 10 m run from d between 40 and 50 m rises 0.02 (50 − d) + 0.08 (d − 40) = 0.06 d − 2.2 m, a grade of 0.6 d − 22 percent, which passes 5% when d > 45. On 1 m samples the first such run starts at 46 m, so the stretch is 46 to 100 m, 54 m. The continuous answer is 55 m (from just past 45 m); the tolerance is one sample spacing, since a run can only start at a sample. Test: "finds the steepest run and the length steeper than 5% on a line of two grades". Changing the run to 20 cells of 2 m gives a 40 m run: "can change the run, and says the run it used".

Run-out cases: a gap, a short part, a line too short

  • A gap. Case E with no ground from 30 to 34 m, and the ground beyond 5 m higher, so a run across the gap would read 50%. Parts: 0 to 29 m and 35 to 100 m. Missing: the six spaces from 29 to 35 m each touch a sample with no ground, 6 m, 6%. The parts' grades are 2% and 8%, and the stretch steeper than 5% is still 46 to 100 m. The missing length counts each space next to a gap whole, so it overstates the gap by up to one sample spacing, the cautious way. Test: "gives a line with a gap its grades for the parts it has, never across the gap".
  • A short part. No ground from 7 to 11 m: the part 0 to 6 m is shorter than the 10 m run, gives no grade, and its 6 m are counted. Test: "gives no grade from a part shorter than the run, and says how much that is".
  • A line too short, and a line off the terrain. An 8 m line with a 10 m run: no grade, "No part of this line with ground is as long as the run of 10 m (10 cells of 1 m) a grade is worked over. Draw a longer line or shorten the run." A line with no ground at all: missing 100%, "This line has no ground under it." Test: "withholds a grade on a line shorter than the run, and on a line with no ground".

On the profile card

The profile card (apps/web/src/app/projects/[projectId]/profile-panel.tsx, with grade-along-line.tsx) shows the result under its chart. The numbers are in apps/web/src/lib/terrain/grade-line.ts and the words in grade-words.ts.

  • Built ground only. The card reads a BuiltProfile, which only readBuiltProfile makes, from a reader of the original DEM (DemReader<"original">). The conditioned surface can't be passed, and PR 60's quick-look surface, which comes as a type of its own, can't either.
  • The run is a small choice beside the figure, in feet on the ground: 3, 5, 10, 20 or 50 cells (RUN_CHOICES_CELLS), 10 to start. On 1 m ground the sentence reads "Steepest grade 4.2%, rising along the line, over 33 ft", with where the run lies on the next line.
  • The grade to compare with starts empty. A value taken from somewhere, even from the line itself, would read as a figure the app suggests, and the plan offers no grade by name. Once a grade is typed, the card says the length steeper than it and in how many stretches, and marks them hatched on the chart, behind a heavier line, and wider and dashed with a dark edge on the map, so they differ by more than color.
  • A gap is said beside the figure: "No ground under 20 ft of this line (6%), so its grades are for the parts that have ground. None is taken across the gap." Ground in parts shorter than the run is said too. A line with ground but no part as long as the run gives no steepest grade, says why and offers a shorter run or a longer line. A line with no ground at all keeps the card's own message.
  • Read out once through the shared live region, as plan v3's item 413 set out, after the run or the grade typed settles.
  • Kept as GradeLineSettings: the line in longitude and latitude, the run in cells and the grade typed or null. Item 456 keeps that with the terrain, pipeline version and cell size; the figures are read again from the ground.

Tests: apps/web/src/lib/terrain/grade-line.test.ts and grade-words.test.ts, and the browser spec apps/web/e2e/grade-along-line.spec.ts.

5. Coarse cells

Bands and rules over an area follow plan v3's item 430 (result-resolution.md, packages/surface/src/resolution.ts): an area of fewer than nine cells, or narrower than three cells across, gives no figures, with "needs finer terrain", the two numbers and what to do. One rule is added: an area narrower than the slope's window (windowM) gives no figures either, since its slope would be mostly the slope of the ground around it; this only bites when a longer distance is chosen, because the 3 by 3 window is the three cells item 430 already asks. The cell size checked is the terrain's recorded cell size when one is passed, the grid's otherwise, as measureVolume does. The check is in each result's resolution and withheld, so a screen can offer a finer terrain or a shorter slope distance. The mask and the band index are still filled, so the map can show the cells.

Tests: "withholds the figures for an area narrower than three cells or than the slope's window" (a 2 m strip on 1 m cells; a 5 m strip with a 7 m window), "withholds against a recorded cell size coarser than the grid's", and "marks cells outside the area and withholds a rule over too few cells" (4 cells).

Grade along a line has its own form of the rule: a part shorter than the run gives no grade (section 4).

Plan v4's PR 53 asks a coarse result to offer "a smaller area or a finer flight". Plan v3's rule refuses areas too small for their cells, so the useful offers are a larger area or finer terrain; the screens lane should settle the words.

6. Speed

Measured on 2026-11-30 on the synthetic 160-acre field at 1 m (scripts/synthetic-160ac-cog.ts: 805 by 805 cells, 648,025 cells, 160.1 acres, 644,809 worked), in Node 26.5.0 under Vitest, on an Apple M5 with 16 GB, with other work running (load average about 5). Medians of 7 runs (21 for bands and rules):

Step Time How often
Slope and facing, 3 by 3 window 19 to 20 ms Once per terrain and spacing
Slope and facing, k = 5 (10 m across) 19 to 27 ms Once per terrain and spacing
Area cells for a four-sided outline over most of it 11 ms Once per outline
Starting bands (sorting the slopes) 45 to 60 ms Once per slope grid and area
Bands, four edges, with each cell's band for drawing 3.4 ms Each time an edge moves
A rule of slope, facing and elevation 14 to 15 ms Each time a value moves

Dragging an edge or a value costs the last two rows in the worker, well inside a frame's budget on this machine, plus the copy of the result to the page. These are engine figures; the browser measure the plan's "Done when" asks for, with the map drawing the result while an edge is dragged, belongs with the screens. apps/web/src/lib/terrain/slope-and-grade.test.ts ("works slope once and re-reads it for each band edge and rule value") holds loose ceilings of 3 s for slope and 1 s per rule so a slow CI machine doesn't fail it.

A set of bands, a rule and a grade line are kept in project_slope_results (migration 20261130210000_project_slope_results.sql), one of each per project, as the screens hold them: SlopeBandsSettings, SlopeRuleSettings and GradeLineSettings, whether each is drawn, and the ground it was last worked on (terrain, its name, pipeline version, cell size and SLOPE_RESULTS_METHOD_VERSION), as plan v3's item 429 asks. No figure is kept. Opened again, each is worked from the terrain in use; when that differs from the one recorded, the screen says "Made on an earlier terrain. The figures here are read again from the terrain in use now." (apps/web/src/lib/terrain/kept-slope-results.ts, kept-words.ts).

Bands and the rule are kept as they settle, 0.7 s after the last change and not while a handle is dragged. A grade line is kept from the profile card's Keep this line, and its run and grade as they settle after that. A copied project carries them, each pointing at the copy's own terrain.

A shared link never hands out the terrain (shared-terrain.ts signs pictures only), so the shared page works the kept bands and rule on the app's server with the same executeTerrainTask the browser's worker runs, from the project's original DEM, and sends only the pictures (PNG, at most 1,024 pixels on a side), their key lines and a sentence each. The grade line goes as its line, its steep stretches and its sentence. A terrain over 16 million cells isn't worked there, and the page says so (apps/web/src/lib/terrain/shared-slope-results.ts). A link reads no first-return surface, so a kept rule on height above ground isn't shown there: the page says so and why, with no picture (round 7, NF1). Under a rule it shows, the page gives the same line on ground with no data as the project's screen.

Built ground only: each takes an OriginalDemGrid or a DemReader<"original">, and computeSlope and sampleProfile refuse another surface at run time too. Tests: kept-slope-results.test.ts, shared-slope-results.test.ts ("Bands, rules and grade figures read built terrain only"), supabase/tests/database/082_project_slope_results.test.sql and the browser spec apps/web/e2e/kept-slope-results.spec.ts.

7. What these figures don't say

  • Slope here is the slope of a cell of ground over the stated distance, not the running slope of a built path, a road or a pad.
  • A rule shades ground that meets the conditions typed. It isn't a finding that the ground suits anything.
  • Heights above ground are what the first returns struck: trees, buildings, crops, wires. They aren't a building's or a tree's height.
  • Grade along a line reads the profile tool's samples, each its cell's height, so a line's grade can step where it crosses cells at a slant; over the ten-cell run this is small, and case D's cell-by-cell line gives the plane's grade exactly.

8. A building site's lay of the land (items 468, 469 and 474)

Plan v4, PR 55. What Check a building site's Lay of the land step says about the ground as it is: its fall, the way it falls where one can be named, where most of it lies, the slope half of it is under, the ground at or under a slope chosen with its largest single piece, and what stands on it. The code is packages/surface/src/site-ground.ts, run in the terrain worker by apps/web/src/lib/terrain/site-lay.ts, with its words in apps/web/src/lib/terrain/site-words.ts. The tests are packages/surface/src/site-ground.test.ts, apps/web/src/lib/terrain/site-lay.test.ts and apps/web/src/lib/terrain/site-words.test.ts. Everything reads the original DEM, through the same kept slope grid the bands and the rule read (spacing 1, Horn's 3 by 3 window, section 1).

The site is the project's first area, its cells those whose centers fall inside its outline (areaCellsFromPolygon, as bands are cut to an outline).

The site's fall

The highest cell of the site with ground and the lowest, each at its cell's center, and the fall between them, highest minus lowest. Of cells the same height, the first in row order (north to south, west to east), so the answer is the same every time. The acres are the site's cells times the cell's area.

The fall is withheld when any cell of the site has no ground, since it would then be the fall of part of the site: the step says "Ground heights cover 82% of this site. Draw the site inside the built ground, or build a larger area.", rounding the share down so it never reads as whole. It is withheld, with everything but the acres, by the slope bands' own check on coarse cells (checkSlopeAreaResolution: fewer than nine cells, narrower than three cells or than the slope's window).

The way it falls

One plane is fitted to every cell of the site by ordinary least squares, z = a + b·x + c·y, through PlaneSums, which adds one height at a time so a whole site needs no array of points, and takes its coordinates from the first height so the sums stay small however far the grid's origin is from zero. Its slope is √(b² + c²) and the way it falls is atan2(−b, −c), clockwise from grid north, as section 1 faces. A pad's fall across it (earthwork.md, section 9) uses the same fit, planeFall: the pad's lane noted that the two should share one helper, and they now do.

When a direction is named. A plane always has a direction, even on a bowl or a ridge where it means nothing. So a direction is named only where the plane explains at least half of how the site's height varies, and is at least 0.1% steep:

  • How well it fits is the coefficient of determination, R² = 1 − SS_res / SS_tot, the share of the variation in height about the mean that the plane accounts for. For a least-squares plane it equals (b·S_xz + c·S_yz) / S_zz, with the sums taken about the means.
  • The cutoff, 0.5, is a labeled starting point (FALL_NAMED_EXPLAINED_SHARE), not a finding: at half, a plane says more about the site than everything else together. No published value applies.
  • The least slope, 0.1%, is the finest lidar resolves over about 10 m (section 2, "Readable percents"), so a direction on flatter ground would be read from noise.

Below either, no direction is named, and the Details say why: "It doesn't fall one way overall: a plane fitted to the ground explains less than half of how its height varies." Above both, the step says "Overall it falls to the southeast.", by the nearest of eight directions.

Most of it

The sentence says where most of the site lies, by its slope bands (section 2, the Layers panel's own, so the table under the sentence and the map are one result):

  1. A single band holding more than half of the site's cells with a slope is "most of it". A band holding exactly half isn't.
  2. Failing that, the pair of neighboring bands holding the most, if that is more than half. Of pairs holding the same, the gentler.
  3. Failing that, no band is named, and the sentence says the slope half of the site is at or under, which is always true: "half of it is at or under 1.5 percent".

The share is of the cells with a slope, not of the whole site, so ground with no data doesn't count against a band. A first band reads "under 2 percent", a last one "8 percent or steeper", and the rest "between 1 and 3 percent".

Why the third step matters. The starting bands begin with a fifth of the ground each (section 2), so on uneven ground no pair of them holds more than about two fifths, and the third step is what the sentence usually says until the bands are changed. On ground where the slope is much the same throughout, the starting bands merge and a band or a pair holds most of it.

The slope half the site is under

The median of the site's cells with a slope, by nearest rank as the starting bands read their fifths: the smallest slope with at least half the cells at or below it. It is where the slider starts.

Ground under a slope you choose (item 469)

The slope rule of section 3 with only a top, slope at most the figure chosen, both ends included, so its shading, its acres and its undecided cells are the rule's own. The slider starts at the median and runs to four times it (at least 5%, at most 100%); a figure from 0 to 100 can be typed in its place. No slope is offered by name: a cell's slope isn't the running slope of a built route, and a named limit reads as a ruling. The words say only what was measured.

The largest single piece is the largest set of cells that meet the rule and connect through shared sides (four neighbors). Two cells that touch only at a corner are separate pieces, because a building or a pad can't stand across a corner a cell wide, and because joining them through corners would let a diagonal chain of single cells read as one piece of ground. Of pieces the same size, the first met in row order. Its outline is traced along the cells' edges (maskToOutlineRings, as a watershed's is), with any hole as a ring of its own, and drawn dashed on the map.

What stands on the site (item 474)

Where the project has a first-return surface built for the terrain in use (plan v3 items 383 and 384), heights above ground are that surface less the ground, as section 3 reads them, drawn on the site's cells in the Show heights colors from 1 ft, with the tallest cell marked and its height given. A cell with no first-return height is unknown, never zero. Without a surface, the step says "Trees and buildings aren't mapped here." A surface that doesn't sit on the terrain's cells says so and gives no heights.

Reference cases

Each is worked by hand and held by site-ground.test.ts to 1e-9 m and 1e-3°.

  • S1, a tilted plane: section 1's case A, z = 300 − 0.03x − 0.04y on 9 by 9 cells of 2 m, the whole grid as the site. 81 cells of 4 m², 324 m², 324 ÷ 4,046.856 = 0.08006 acres. The highest cell is the south-west one, at x = y = 1 m: 300 − 0.03 − 0.04 = 299.93 m. The lowest is the north-east one, at x = y = 17 m: 300 − 0.51 − 0.68 = 298.81 m. The fall is 1.12 m. The plane is the ground itself: slope 5%, falling at atan2(0.03, 0.04) = 36.87°, explaining all of it (R² = 1), so the direction is named, northeast. Every worked cell is 5%, so half the site is at or under 5%.
  • S2, a bowl: z = 100 + 0.01((x − 9)² + (y − 9)²) on the same grid. The heights are symmetric about the middle cell, so S_xz = S_yz = 0: the fitted plane is level and explains nothing (R² = 0), and no direction is named, though the fall is 0.01 × (8² + 8²) = 1.28 m from the corners to the middle.
  • S3, a plane that explains 64%, and one that explains 20%: 4 columns by 3 rows of 1 m cells, heights by column only. With the column centers' x − x̄ = −1.5, −0.5, 0.5, 1.5 (each three times; the rows are balanced, so c = 0):
    • heights 0, 0.2, 0.1, 0.3: z − z̄ = −0.15, 0.05, −0.05, 0.15; per row S_xz = 0.225 − 0.025 − 0.025 + 0.225 = 0.4, S_xx = 5, so b = 0.08, an 8% slope falling west (270°). Explained b·S_xz = 0.032 of S_zz = 0.05: R² = 0.64, at least 0.5, so it is named.
    • heights 0, 0.3, 0, 0.3: S_xz = 0.3, b = 0.06, a 6% slope; explained 0.018 of 0.09: R² = 0.2, under 0.5, so no direction is named although the plane is 6% steep.
  • Run-out, a missing cell: S1 with its middle cell given no ground: 80 of 81 cells have ground, 98.8%, and the fall and the plane are withheld with "Ground heights cover 98% of this site. Draw the site inside the built ground, or build a larger area." The acres are still given.
  • Run-out, coarse cells: a site of 2 by 2 cells is under nine cells, and gives its acres and nothing else, with the slope check's "needs finer terrain" sentence.
  • Most of it: bands of 60, 30 and 10 cells: the first holds 60%, most of it. Bands of 30, 30, 25 and 15: no band holds more than half; the first pair holds 60%, the second 55%, so 0 to 3%. Bands of 50, 25 and 25: the first holds exactly half, which isn't most; the first pair, 75%, is. Bands of 51, 24 and 25: the first, 51%, is. Five bands of 20: no pair holds more than 40%, so none is named and the sentence gives the median. Bands of 0, 30, 30, 30 and 10: the second and third pairs each hold 60%, and the gentler, 1 to 3%, is named.
  • Pieces: on a 4 by 4 grid with the cells (0,0) (0,1) (1,0), (1,3) (2,2) (2,3) (3,3) and (3,1) meeting a rule, sides join three pieces of 3, 4 and 1 cells; the largest is the 4. Through corners, (2,2) and (3,1) would join into 5, which is the case the side rule refuses.

Through the worker, site-lay.test.ts holds that the shading is the rule's own (S1 at or under 6% meets its 49 worked cells, all one piece, and leaves its 32 edge cells undecided), that the largest piece's outline closes, and that heights read from a surface 3 m above the west columns give a tallest of 3 m there, and none without a surface.

What these figures don't say

  • The fall is between the highest and lowest cells of ground as flown, not between corners of a lot, and not the fall of a built surface.
  • "Most of it" and the median describe the ground's cells, and a band says nothing about whether a building, a road or a yard suits it.
  • The direction is the fitted plane's; on ground that rolls, parts of the site fall other ways, which the slope bands and the water paths show.