Documentation / @interstellar-tools/maps / contourLevels
Function: contourLevels()
ts
function contourLevels(
grid: GridInterface,
interval: number,
base?: number
): number[];Defined in: terrain/contour-levels.ts:57
Find the contour levels at an interval through a grid: every height
Where:
is the intervalandthe base, a height the levels pass throughand are the grid's lowest and highest values, leaving out missing cells
Units
- Inputs:
interval,baseand the grid's values in the same units, m for an elevation grid. - Output: the levels, lowest first.
Notes
- Each level is
, worked out on its own, so rounding doesn't build up along the list. Levels are still floating point: 0.1 × 3 is 0.30000000000000004. Round them for labels. - A level exactly at the lowest or highest value is included, as far as rounding goes. The one at the highest value only outlines the cells at that height.
- A grid with no values, only missing cells, has no levels.
- Mapmakers' index contours, drawn bolder every fifth line, are the levels where
is a multiple of 5: (level - base) / interval % 5 === 0, rounded.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
grid | GridInterface | undefined | The grid, such as heights in m. |
interval | number | undefined | Height between levels, in the grid's units (finite, > 0). |
base? | number | 0 | A height the levels pass through, in the grid's units (finite). Defaults to 0, sea level for heights. |
Returns
number[]
The levels, lowest first.
Throws
- If a size, cell size,
intervalorbaseis not finite, or a value is infinite. - If the grid's parts don't fit together,
intervalis<= 0, or it would give more than 10 000 levels.
Example
ts
// Every 100 m over terrain from 1702 m to 4352 m
contourLevels(grid, 100); // [1800, 1900, …, 4300]
// Every 100 m, offset by 50 m
contourLevels(grid, 100, 50); // [1750, 1850, …, 4350]
const lines = contours(grid, contourLevels(grid, 100)).map(
({ level, segments }) => ({
level,
lines: joinSegments(segments)
})
);