Lay of the Land
All methods

Hillshade and relief shading

Relief shading is a visual aid drawn strictly from the original ground DEM (surface: "original"), never the hydrologically conditioned surface. Nothing in drainage design, earthwork, or water calculations reads a shaded image.

Method

Both the GIS worker (services/gis-worker/gis_worker/terrain/overlays.py, hillshade) and the browser (apps/web/src/lib/terrain/relief.ts, shadeHillshade) compute grayscale Lambertian hillshade on the DEM's projected metric grid:

  • Gradient kernel: Horn's 3×3 weighted finite difference over true metric cell spacing Δx (east = ((c - a) + 2(f - d) + (i - g)) / (8 Δx), south = ((g - a) + 2(h - b) + (i - c)) / (8 Δx)), scaled by vertical exaggeration E.
  • Border handling: Edge replication (np.pad(..., mode="edge") in Python; clamped indices in TypeScript).
  • Missing cells: Any cell whose 3×3 window contains NODATA or a non-finite height is masked transparent (alpha = 0), matching _gaps_near in overlays.py.
  • Default lighting (drawing judgment): Sun azimuth 315° clockwise from north, sun altitude 45° above the horizon, and vertical exaggeration 5× (SUN_AZIMUTH_DEGREES, SUN_ALTITUDE_DEGREES, HILLSHADE_EXAGGERATION in overlays.py; DEFAULT_RELIEF in relief.ts). Agricultural tile country is flat enough that 1× relief reads nearly blank; the panel always states the exaggeration in use.
  • Illumination and 8-bit quantization: Surface normal (-east, south, 1) dotted with unit sun vector (sin az · cos alt, cos az · cos alt, sin alt), divided by √(east² + south² + 1), clamped to [0, 1], multiplied by 255, and truncated to uint8 (astype("uint8") in Python, Math.floor in TypeScript).

Default map image vs. live tiled browser shading (plan v3 items 375 and 380)

At default settings (DEFAULT_RELIEF) on a field whose DEM fits inside the worker's 2,048 px pre-rendered PNG (max(width, height) <= 2048), the map shows the worker's pre-rendered PNG (terrain-hillshade / terrain-elevation) rather than downloading DEM bytes on project open (apps/web/src/app/projects/[projectId]/terrain-layers.tsx).

Whenever any relief lighting control or elevation color range moves off defaults—or on a large DEM (max(width, height) > 2048) once the user zooms in finer than the worker's 2,048 px image—the browser draws relief and elevation color tile by tile (apps/web/src/lib/terrain/tiled-relief.ts):

  • Overview selection: openDem (apps/web/src/lib/terrain/dem-reader.ts) inspects the COG's reduced-resolution overview IFDs from the already-read header and picks the coarsest overview whose cell size is still sharp for the viewport's meters per physical pixel (chooseOverviewLevel), stepping down to native level 0 when zoomed in.
  • Windowed COG reads & cancellation: Only the 512 × 512 display tiles intersecting the viewport are read through demReader.readWindow (backed by the per-level COG tile cache, sharing level-0 tiles with hover, profiles, and water tools). Tiles that leave the viewport abort pending reads and drop queued worker tasks.
  • Seamless edges: Each display tile reads a 1-cell border on every side clamped to the overview boundary, shades the padded window in terrain-calc.worker.ts using shadeHillshade, and crops out the interior cells (shadeHillshadeTile). At stride = 1, every pixel—including tile seams and 3 × 3 NoData gap masks—is bit-for-bit identical to shading the entire grid at once.
  • Bounded caching: Both the decoded DEM tile windows and the worker's tile cache use a 64-tile LRU bound, so dragging a slider re-shades only visible tiles from worker memory without re-reading the COG or re-copying elevation arrays.
  • Drawing only: Tiled overview drawing never feeds cover calculations, profiles, earthwork, or water tools, which always read the original full-resolution DEM.
  • Township build caveat: Tiled drawing keeps zoomed-in sections of large DEMs sharp in the browser, but the GIS worker's memory budget and item 379's production worker benchmark remain deferred (lidar-analysis.md section 1), so building a full township on the production workers is not promised on this branch.
  • When tiles start, and what a township shows: at default lighting and stretch, tiles are used only when the DEM's longer side is over 2,048 cells (the worker image's limit) and the view is finer than the worker image's own meters per pixel. A township (23,040 ac, 9,858 m across with its buffer) built at its default 5 m (recommendedCellSizeM, over 10,000 ac) is 1,972 × 1,972 cells, so it never tiles at default settings. That loses nothing the DEM holds, because the worker image keeps every 5 m cell; but zoomed in on one section it shows 5 m detail, where a single field built at 1 m shows 1 m. A township shows a field's detail only if it is built finer: at 2 m it is 4,929 cells across and tiles when zoomed in. Making 2 m the township default is a change to the cell size bands, which wait on item 379's worker benchmark. tiled-relief.test.ts checks, pixel by pixel, that a section of a 2,600-cell DEM drawn by tiles at default lighting equals that section drawn alone as a single field, away from its outer ring of cells.

Worker vs. browser check (plan v3 item 376)

services/gis-worker/tests/fixtures/hillshade/relief-dem.tif is a 64 × 64 float32 GeoTIFF (1 m cells, EPSG:6343, NODATA = -999999) containing two ridges with slopes up to 55.8%, a winding draw, a 306-cell flat terrace, non-zero border slopes, and 23 missing cells (an interior 3 × 4 block, a single-cell pinhole, and a 2 × 5 notch on the north edge, producing 60 masked cells in the 3 × 3 gap neighborhood).

The worker's hillshade() and _gray() shade it to services/gis-worker/tests/fixtures/hillshade/worker-hillshade.png (kept fresh by services/gis-worker/tests/test_overlays.py), and apps/web/src/lib/terrain/relief.test.ts shades the same DEM with shadeHillshade(grid, DEFAULT_RELIEF) and compares all 4,096 cells:

  • Measured on the 64 × 64 relief fixture: 0 maximum difference, 0.0 mean difference, 0 alpha mismatches across 4,036 opaque and 60 transparent cells (shade range 0 to 254).
  • Measured on the 512 × 512 browser-test DEM (terrain-cog.tif, 262,144 cells): 1 maximum difference, 3.8 × 10⁻⁶ mean difference (1 cell differs by 1 out of 255).
  • Stated tolerance: at most 1 gray level out of 255 on any opaque cell, mean difference ≤ 0.05, and 0 alpha mismatches. Both implementations share the same gradient kernel, border replication, 3 × 3 gap mask, and 8-bit truncation; the only legitimate difference on the DEM grid is float32 arithmetic in overlays.py vs. float64 in relief.ts, which can shift a value straddling an integer boundary by 1 upon truncation.

Served map image (to_map_image): The worker serves its hillshade as to_map_image(hillshade(dem), dem): the shade on the DEM's grid, warped to Web Mercator (EPSG:3857) bilinearly for gray and by nearest neighbor for transparency. The warp is given src_nodata and dst_nodata, so cells with no data are left out of the bilinear weights. Before that fix, masked cells went in as black, and on this fixture the cells beside a gap came out up to 82 gray levels darker than the browser's shade of the same ground; elevation color bled the same way, by up to 148 levels in one band on a test DEM. Slope, aspect, water paths, low spots and conditioning use nearest neighbor, which takes one cell and never mixed a gap in.

services/gis-worker/scripts/render_hillshade_fixture.py writes the served image for the fixture DEM to worker-hillshade-map.png, with its size and corners in worker-hillshade-map.json. Run it inside the worker's image from the repository root:

docker run --rm --user "$(id -u):$(id -g)" -e HOME=/tmp \
  -v "$PWD/services/gis-worker":/gis-worker -w /gis-worker -e PYTHONPATH=/gis-worker \
  tilemapper-gis-worker:test python scripts/render_hillshade_fixture.py

services/gis-worker/tests/test_overlays.py checks the committed image against to_map_image (alpha exact, gray within 1 level, for another GDAL build's rounding). apps/web/src/lib/terrain/relief.test.ts samples shadeHillshade(grid, DEFAULT_RELIEF) bilinearly, leaving out masked cells, at the center of each served pixel and compares:

  • Measured: 0 alpha mismatches, 0.91 maximum and 0.25 mean difference over 4,034 opaque and 322 transparent pixels. The worker truncates its warped value to 8 bits, which alone is under 1.
  • Stated tolerance: at most 2 gray levels on any opaque pixel, mean at most 0.5, at most 8 alpha mismatches.
  • What it catches, checked in the test: a sun 15° off in azimuth (44 maximum, 14 mean) or 10° off in altitude (44, 23), and swapped or flipped axes (249 to 254, 61 to 69, 121 alpha mismatches). The served image from the unfixed warp was 82 off.

Slope, facing, elevation color and contours

These are drawn by the worker from the original ground DEM, like the hillshade, and nothing is calculated from them. Every figure here is a constant in services/gis-worker/gis_worker/terrain/overlays.py or contours.py, and each is a drawing judgment, not a published standard. About this data, opened from the map key, says them in plain words and links here.

  • Smoothing first. Slope, facing and contours are worked from a moving average of the heights, a square window of the nearest odd number of cells to the distance below, that leaves empty cells out (averaged). Raw 1 m slopes are mostly lidar noise; the averaging leaves ditches, channels and other real landforms.
  • Slope is Horn's gradient on heights averaged over about 10 m (SLOPE_DISTANCE_M), drawn in five classes: under 0.5%, 0.5 to 1%, 1 to 2%, 2 to 5% and over 5% (SLOPE_CLASSES). Nothing finer is drawn, because over 10 m a 0.1% slope is a 1 cm rise, which lidar can't resolve.
  • Facing (aspect, the way the ground falls) is worked over about 30 m (ASPECT_DISTANCE_M), since on flat land 10 m picks up every small ridge. It is drawn in four directions, north, east, south and west, because more can't stay distinct for colorblind readers. Ground under 0.15% slope (FLAT_SLOPE_PERCENT, a 4.5 cm rise over 30 m) is drawn as too flat to say.
  • Elevation color runs from dark blue at low ground to pale at high ground (ELEVATION_RAMP), stretched from the 2nd to the 98th percentile of the build's heights (ELEVATION_STRETCH_PERCENTILES), so a pile or a deep pit can't flatten the rest. A range set in the Layers panel replaces that stretch.
  • Contours are traced on heights averaged over about 10 m (SMOOTHING_M), the same distance as slope, at every 0.5 ft, and coarser intervals are the same lines filtered. Each line is simplified by 0.5 m (SIMPLIFY_M), far less than the smoothing, so it keeps its shape and loses only surplus points, and a closed loop less than 40 m around (SHORTEST_LOOP_M) is dropped as a speck of noise rather than a landform.

How fine contour lines can usefully go (plan v4 item 450)

The contour interval control in the Layers panel shows the ground's stated accuracy in a sentence beside the finest intervals, such as "1 ft lines are about as fine as this lidar can show: on open ground, 95% of its heights are within 0.6 ft of the true height." Nothing is marked as too fine, and nothing goes on the map key, a map page or a download. The words and the rule for when they show are in apps/web/src/lib/terrain/interval-hint.ts.

Where the figure comes from. The stated height error is read from the build's record by verticalRmseFromProvenance (apps/web/src/lib/terrain/provenance.ts): the root-mean-square vertical error the USGS Lidar Base Specification sets for the flight's quality level in open ground (Table 4 of the specification's tables; 10 cm for QL1 and QL2, 5 cm for QL0, 20 cm for QL3). A record with no quality level, or one recorded below the specification, states no accuracy, and the control then says nothing. About this data gives the same figure and this source.

What follows from it. If height errors on open ground are normally distributed, 95% of heights are within 1.96 times the stated error of the true height. That is the vertical accuracy at 95% confidence of the FGDC's National Standard for Spatial Data Accuracy, which the ASPRS positional accuracy standard repeats: ASPRS Positional Accuracy Standards for Digital Geospatial Data, edition 2, version 2 (2024), Appendix B.7, example 6, p. 49, "AccuracyV95% = 1.96 * RMSEV", worked for 10 cm as 19.6 cm; Appendix A.1, p. 34, says the NSSDA assumes normal errors and that the NDEP uses the same multiple in open terrain "because elevation errors in open terrain do tend to follow a normal distribution". For QL2 ground that is 19.6 cm, 0.64 ft, either way.

When the hint shows. Beside an interval no wider than the whole range those 95% of heights fall in, from 1.96 errors below the true height to 1.96 above: 3.92 errors, 39.2 cm or 1.29 ft for QL2. Across an interval that narrow, a line's height and its neighbor's are within the spread of the ground's own heights, so the lines can't be told apart reliably. The sentence takes two forms:

  • an interval narrower than 1.96 errors (0.64 ft for QL2) reads "closer together than this lidar's stated accuracy";
  • an interval from there up to 3.92 errors reads "about as fine as this lidar can show";
  • a wider interval has no hint.

For QL2 that is 0.5 ft (closer together) and 1 ft (about as fine). For QL3, at 20 cm, 0.5 and 1 ft are closer together and 2 ft about as fine. For QL0, at 5 cm, 0.5 ft is about as fine and 1 ft has no hint. These cutoffs are this app's reading of the 95% figure, not a rule from a standard, and the hint says only the figure.

Why no interval is marked. The ASPRS standard was read on 2026-11-30, from the copy named in plan v4's sources. It doesn't tie an interval to an accuracy for digital data. Section 7.3, p. 18: "These Standards do not endorse the use of GSD, map scale, or contour interval to express product accuracy." Appendix A.1, p. 33, says the 1947 National Map Accuracy Standards and the ASPRS 1990 standards tie accuracy to the contour interval of a printed map and are "inappropriate for digital geospatial data where scale and contour interval are changed with a push of a button without altering the underlying horizontal and/or vertical accuracy". Table B.6, p. 44, and examples 2 and 4, pp. 46 to 49, give contour intervals only as equivalents for those legacy classes: a 10 cm error matches a 30 cm interval under the 1990 standard's Class 1 (an error of one third of the interval) and a 32.9 cm interval under the 1947 standard. Those are offered for comparison with old maps, and the hint cites none of them.

Smoothing. Contours are traced on heights averaged over about 10 m (above), which takes out much of the random noise between neighboring cells but not an error shared by a whole flight. The stated error is against surveyed checkpoints, so it includes both, and it is the figure the hint uses.

Tests: apps/web/src/lib/terrain/interval-hint.test.ts.

Fine relief (plan v4 item 500)

Three more ways of drawing the original ground, chosen under Relief style beside Hillshade: Light from several directions, Show small rises and hollows and Open to the sky. Each follows the Relief Visualization Toolbox (RVT, ZRC SAZU and the University of Ljubljana, Faculty of Civil and Geodetic Engineering), a toolbox written for finding faint features in lidar. They are pictures: nothing is measured from them, they read only the original DEM, never the conditioned one, and a cell with no ground is left clear. They are worked in the browser, in the terrain worker, by apps/web/src/lib/terrain/fine-relief.ts, and drawn in place of the hillshade at its opacity.

What was read, on 2026-11-30. The toolbox's pages on the simple local relief model, the sky-view factor and hillshading, which has the section on hillshading from several directions (the page named listofvis_mhs.html in the plan doesn't exist; the request returned "404 Documentation page not found"). The pages describe each method but give no formula and no default, so each method and its defaults were taken from the toolbox's own source code, as its documentation publishes it: rvt.vis (slope_aspect, hillshade, multi_hillshade, mean_filter, slrm, horizon_shift_vector, sky_view_factor_compute, sky_view_factor, byte_scale, integral_image) and rvt.default (DefaultValues). The papers the toolbox cites for these methods were not read: its bibliography lists articles that use it, and the pages name no paper for these three. Nothing below is written from memory; each step names the function it reproduces.

Ground distance. RVT gives its radii in cells. This app works in ground meters, so each radius is RVT's default in cells taken at 1 m, the cell size of the app's usual lidar build, and turned back into whole cells for the terrain's own cell size (radiusCells: the nearest whole number, at least one). On 1 m cells they are RVT's own defaults exactly.

Show small rises and hollows: the simple local relief model

RVT's page: "Simple local relief models use a procedure called trend removal that separates local small-scale features from large-scale landscape forms. … The resulting difference map contains only the local deviations from the overall landscape forms."

  • Method (slrm, mean_filter, integral_image): the trend is the mean of the heights in a square 2r + 1 cells on a side centred on each cell, worked with summed-area tables; cells with no height are left out of the mean, and the grid's edge rows and columns are repeated outward (numpy's edge padding) so a window that runs off the grid counts its edge cell again. The model is each height less its trend, in meters. A cell with no height gets none.
  • Radius: slrm_rad_cell = 20 cells, so 20 m. slrm accepts 10 to 50 cells, so the choices under More options are 10, 20, 30 and 50 m.
  • Drawing: RVT's default 8-bit stretch for this model is a fixed −2 to +2 m (slrm_bytscl), which leaves a farm field's few centimeters of relief a flat gray. The app uses the other stretch RVT offers, a percent cut-off, at the 2% on each end that the toolbox's blending example applies to this model (create_layer(vis_method="Simple local relief model", normalization="perc", minimum=2, maximum=2, …) on Blending visualizations): black at the 2nd percentile of the model's values, white at the 98th, written to 8 bits as byte_scale does, floor((255 + 0.9999)(v − low) / (high − low)), clipped.

Open to the sky: the sky-view factor

RVT's page: "SVF represents the portion of the sky visible from a certain point. … It ignores any direction below the mathematical horizon."

  • Method (sky_view_factor, sky_view_factor_compute, horizon_shift_vector): heights are divided by the cell size, so a rise over a distance in cells is a slope. In each of n directions, at angles 2πi / n, the cells looked at are those at radii from the least to the greatest in steps of a third of a cell, each rounded to a whole cell along the direction (numpy rounds halves to even, and so does the app's roundHalfEven), repeats dropped. The horizon's slope in that direction is the steepest (h_other − h) / distance over them, skipping cells with no height; the sky-view factor is (1/n) Σ (1 − sin(max(atan(slope), 0))). The grid is mirrored at its edges (numpy's reflect padding), so, as RVT says, edge values are "averaged over half of the hemisphere".
  • Parameters: svf_n_dir = 16 directions; svf_r_max = 10 cells, so 10 m; svf_noise = 0, so the search starts at the next cell (radius_min = 1). Choices under More options: 5, 10 and 20 m.
  • Drawing: RVT's page: "A good general rule is to use a histogram stretch of 0.65 to 1.0 for diverse terrain and 0.9 to 1.0 for very flat terrain." Fields are flat, so 0.9 to 1 is the default, with 0.65 to 1 under More options as Hilly. (RVT's own default, svf_bytscl, is 0.6375 to 1.)

Light from several directions

RVT's page: "Producing multiple hillshading outputs by illuminating a surface from multiple directions enhances the visualization of topography. … A step towards an improved understanding of the results is combining multiple shadings by considering only the mean, the maximum, or the range of values, for each pixel."

  • Method (multi_hillshade, hillshade, slope_aspect): slope and aspect from central differences, dz/dx = (z_west − z_east) / 2Δx and dz/dy = (z_south − z_north) / 2Δx, slope atan √(dz/dx² + dz/dy²) and aspect atan2(dz/dx, dz/dy) (with dz/dy set to 10e-9 where it is 0, as RVT does); a neighbor off the grid or with no height reads as the cell itself (RVT's edge padding and roll_fill_nans). Each direction's shade is cos Z cos S + sin Z sin S cos(A − φ), negatives set to 0, for the sun's zenith Z, slope S, aspect A and the light's direction φ. The app combines them by the mean, the first of the three the page names, so the picture is one gray.
  • Parameters: mhs_nr_dir = 16 directions, from north round in 22.5° steps; mhs_sun_el = 35° above the horizon. RVT's own exaggeration default is none (ve_factor = 1), which reads blank on a farm field; this uses the app's own hillshade exaggeration, 5× (Method), and the style's line says so.
  • Drawing: RVT's own stretch for it is 0 to 1 (mhs_bytscl), which on a farm field leaves one flat gray: the small picture beside the choice showed the mound and the ditch only faintly. So the app uses RVT's percent mode at the same 2% at each end as small rises and hollows: black at the 2nd percentile of the shades, white at the 98th. Where every value is the same, as on a flat plain, black and white are a hundredth either side of it, so the plain is one mid-gray.
  • What the mean does: where no direction's shade is clipped at 0 (any slope under the light's own 55° from overhead, after exaggeration), the cos(A − φ) terms cancel over a full circle, and the mean is cos Z cos S: a picture of steepness, the same on every side of a rise. That is what the key's ends say: Steeper, Level.

The pictures beside each choice

Each style's small picture is that style's own code run on a small made-up piece of ground, 64 by 40 cells of 1 m (sampleSurface): a field falling 0.5% to the east and 0.3% to the south, with a swell 60 m long and 40 cm high, a mound 30 cm high and 6 m across, and a ditch 25 cm deep and 2 m wide. The one for Light from one side is the existing hillshade at its defaults on the same ground. They are drawn when the panel opens, the way the layout patterns' pictures are drawn from their own layouts.

Proofs, worked by hand

apps/web/src/lib/terrain/fine-relief.test.ts checks each.

  • A tilted plane's local relief is zero away from the edges. For z = a + bx + cy, a square window centred on a cell has as many cells at +d as at −d along each axis, so its mean is the centre's height and the model is 0. On a 60 by 50 grid of z = 100 + 0.01x − 0.02y with r = 10, every cell at least 10 cells from an edge is within 10⁻⁴ m of 0 (float32 heights near 100 m hold about 8 µm). Nearer the edges the repeated edge cells pull the mean off the plane, as RVT's do.
  • One small bump is the bump. Add 0.3 m to one cell, r = 5: every window holding it has (2·5 + 1)² = 121 cells, so its mean rises by 0.3 / 121 = 0.00248 m. The bump reads 0.3 − 0.00248 = 0.29752 m, every cell within 5 cells of it −0.00248 m, and every other cell 0, each to 10⁻⁴ m.
  • A flat plain sees the whole sky. Every slope to a neighbor is 0, so max(atan 0, 0) = 0, each direction adds 1 − sin 0 = 1, and the factor is 1, at the edges too, since the mirrored edge is flat as well.
  • The bottom of a cone-shaped pit sees 1 − sin(atan k). Heights rise as k times the ground distance from the bottom, so every cell the search reaches, in every direction, lies at slope exactly k from the bottom, whatever the rounding of its offset: the horizon is atan k all round. For k = 0.5: 1 − 0.5 / √1.25 = 1 − 0.447214 = 0.552786. The test builds it on 2 m cells, 41 by 41, with a 20 m search, and the engine matches to 10⁻⁵.
  • Light from several directions on a flat plain is the same everywhere. Slope 0, so each direction's shade is cos Z = cos 55° = sin 35° = 0.573576, and so is their mean, to 10⁻⁶ in every cell. With one value everywhere, the stretch puts it halfway between black and white, floor(255.9999 × 0.5) = 127, in every cell.
  • No ground stays empty. A cell with no height is NaN in each model and clear in its picture; the local relief model leaves it out of its neighbors' means, and the sky-view factor passes over it when looking for a horizon.

Speed and the stated limit

Timed in Node 26 on an Apple M5 laptop with 16 GB, in vitest, on the synthetic 160-acre field at 1 m (scripts/synthetic-160ac-cog.ts, 805 by 805 cells), on 2026-11-30, with other lanes running and a load average near 30, so slower than an idle machine:

Style Time
Small rises and hollows, 20 m 81 ms
Light from several directions 261 ms
Open to the sky, 10 m, on 1 m cells 1,531 ms
Open to the sky, quick look on 4 m cells 48 ms

The sky-view factor is the heavy one: about 156 height reads a cell at 10 m and 16 directions. It shows a quick look on cells four times wider first (each the mean of its block, coarsenHeightGrid), then the full picture. Its stated limit: a full pass takes at most 160 million height reads (SKY_VIEW_MAX_READS), about two and a half seconds at the speed above; a larger grid or a longer search is worked on cells coarsened by the least whole factor that fits (skyViewFactorFor), and the panel says the cell size it used. A 160-acre field at 1 m with the 10 m search is about 101 million and runs on its own cells. The other two styles take well under a second on the same field and have no quick look.

What the key says

Each style's line in the map key names it, gives what black and white mean (Lower to Higher; Less sky to Open; Steeper to Level) and says once that it highlights small changes in height. That is the risk the plan names: on flat ground a tractor rut and a seam between flight lines show as plainly as a real feature. About this data says they are pictures and nothing is measured from them.

A contour map (plan v4 items 457 to 465)

Get a contour map is a way to start: an area, its contours with their answer in a sentence, and a map page. It draws on what the worker already makes (the section on contours above) and adds two things worked in the browser, in the terrain worker, from the original DEM only, never the conditioned one: the highest and lowest ground in the area, and lines straight from the elevation cells. Both are in apps/web/src/lib/terrain/contour-cells.ts; the words are in contour-map-words.ts. Before the ground is built the contours draw from the quick look's own tiles (plan v4 item 514), and nothing that is measured, printed or downloaded reads them: the high and low points, the map page, the CAD file and the picture wait for built ground and make themselves when it lands.

The interval it starts on

The step starts on the interval the app already picks, and says "Suggested for this map" beside it while it is showing. Built ground's pick is the worker's (draw_contours in contours.py): of 0.5, 1, 2, 5 and 10 ft, the finest whose lines fit a 4 MB file (MAX_BYTES) is the finest offered, and every interval offered is a multiple of it, so changing the interval filters the same lines and needs no new build. Of those, it starts on the finest that puts 20 lines or fewer (MOST_LINES_BY_DEFAULT) across the ground's relief, measured from its 2nd to its 98th percentile height. Before the build lands the quick look picks the same way across the heights in view (defaultContourIntervalFt), and ground built with no contour file is offered every interval and starts on the same rule across the area's fall (pickForRelief in contour-interval.ts). It is a rule for a readable map, not a statement about the ground's accuracy; that is the hint beside the finest intervals, above.

Highest and lowest ground in the area

Method. Every cell whose middle lies inside the area's outline (even-odd across its rings, so a hole is outside) is compared by its stored height; a cell with no height is counted as missing and never compared. The highest and lowest stored heights are the answer, marked at the middle of their cell. Where several cells share the height, the mark is on the first found reading rows from the north and each row from the west, and the key says how many cells share it. A cell inside two overlapping areas is counted once. The fall is the highest less the lowest.

Worked by hand. A 4 by 4 grid of 1 m cells with its north-west corner at (0, 4), rows from the north: 20, 10, 10, 10 / 10, 12, 15, 10 / 10, 9, 11, 10 / 10, 10, 10, 1. The area runs from (1, 1) to (3, 3), so it holds the middles of the four central cells, (1.5, 2.5), (2.5, 2.5), (1.5, 1.5) and (2.5, 1.5), with heights 12, 15, 9 and 11. The highest is 15 m at (2.5, 2.5), the lowest 9 m at (1.5, 1.5), and the 20 and the 1 in the corners are outside it. The engine gives exactly that (contour-cells.test.ts). The fall sentence's case: 300.00 m and 292.87 m are 7.13 m apart, 7.13 / 0.3048 = 23.39 ft, said as "The ground falls 23.4 ft from its highest point to its lowest."

Where the data runs out. An area with no cell middle inside it, or whose cells all have no height, gives no high, no low and no fall: the step says the area has no ground heights in it and to outline ground the flight covers. Where part of the area has no heights, the step says what share, and that its highest or lowest point could lie there. The fall, or that the ground is level, is then said of the ground that has heights, never of the whole area ("Where the area has ground heights, it is level at 900.0 ft."), on the step and under the map page's title alike (fallLine), and the page's table gives the share with none. Ground that falls less than one interval, so that no line crosses it, says so instead of drawing nothing unexplained, and level ground says it is level.

Lines straight from the elevation cells

Method. Marching squares (traceContourLines, packages/surface/src/contour-lines.ts) on the cells' own stored heights, at every multiple of the interval, with nothing smoothed, simplified or dropped. A square with a corner that has no height is skipped, so a line stops at a gap rather than guessing across it. A cell has no height when it is NaN or holds the grid's no-data tag in either its written or its 32-bit form (isValidHeight, plan v3 item 431), so a tag such as -9999.1, stored as -9999.099609375, is never read as ground; the high and low ground test cells the same way (review finding NF11, contour-nodata-tag.test.ts). A crossing on a square's edge is found by straight-line interpolation between the two cells' heights, and the two squares either side of an edge share it, so lines join exactly; a saddle is split by the mean of its four corners. Every fifth line is an index line, as on the map and in the DXF.

What smoothing does, beside it. The worker's lines, "Smoothed for reading" and the default, are traced on heights averaged over about 10 m, each simplified by 0.5 m, with closed loops under 40 m around dropped (the section on contours above). That takes out the lidar's noise between neighboring cells, which on 1 m cells is most of what makes a raw line wiggle, so the lines follow the ground's shape. Lines straight from the cells keep every wiggle the cells have: on 1 m cells they are jagged, and many more close on themselves around single bumps and hollows. They are a choice, and the map key and each download's text file say which is showing.

Worked by hand. A plane rising 1 ft a cell to the east, with column c's middle at (c + 0.5) ft: the k ft line falls halfway between columns k − 1 and k, at x = k m, running from the middle of the top row to the middle of the bottom row. The engine puts every vertex there to a micrometer (the heights are stored as 32-bit floats).

Lines never cross. Traced on the three real test fields' ground (packages/layout/fixtures/real-test-fields, their real 3 m USGS ground) at 0.5, 1 and 2 ft, no segment of any line properly crosses a segment of another line or of itself (contour-cells.test.ts). The fixtures hold no 1 m ground, so the jaggedness at 1 m isn't tested there.

A budget for drawing. Unsmoothed lines carry far more points than smoothed ones. Past 1.5 million points (MOST_CELL_LINE_POINTS) the next coarser interval offered is used and the step says so, and where none fits it says to draw a smaller area or keep the smoothed lines. The budget is about the browser, not the ground. An interval is also refused, and the next coarser one tried, where the area's relief needs more than 2,000 levels (MOST_CONTOUR_LEVELS, the most contourLevels gives): past that the highest lines would be left out with no word, as at 0.5 ft over 400 m of relief, which needs 2,624 (contourLevelCount, contour-levels-cap.test.ts).

What a big area changes

The worker drops the finest intervals whose file would pass 4 MB, so a large or hilly area may be offered nothing finer than 2 ft; the step then says "Showing 2 ft lines for this area. Draw a smaller area for more detail." An area too large for even 10 ft lines in one file has no smoothed lines, and the step says so and offers the lines from the cells. Ground built on cells coarser than its flight's, as a large area is, says the cell size it used and the flight's, and to draw a smaller area for finer cells. The lines from the cells say when the budget above moved them to a coarser interval. Where it did, every exit names the interval drawn, never the one asked for: the step's sentence, the map key and so the picture, the map page and the CAD file's text file all read drawnInterval in contour-map-words.ts, and each says beside it, in one sentence from steppedUpWords, that it was stepped up from the interval asked for because the finer lines are too many to draw for this area.

The map page, the CAD file and the picture

The map page (contour-map-page.ts) draws the contours as vector lines over a picture of the map taken with the contours hidden, index lines heavier and labeled with their height in feet at their middle where at least 60 points long and 48 points from another label, the high and low points marked and labeled, at a stated engineer's scale or one chosen to fit the area (map-scale.ts), with the page builder's north arrow, scale bar, coordinate system and height reference, and its source line and one sentence. Points closer together on paper than 0.3 point are left out of a printed line. The CAD file is the DXF the Downloads section already makes (contoursToDxf), each line at its own height on the CONTOUR_INDEX and CONTOUR_MINOR layers, in the project's UTM meters or a State Plane zone's foot (state-plane.md); a DXF carries no coordinate system, so the step and the text file say which one to tell CAD. The picture is the map as it is on screen with its key and source line under it, shared through the phone's own share sheet where the browser can share a file, and downloaded anywhere else.

Tests: apps/web/src/lib/terrain/contour-cells.test.ts, contour-map.test.ts.