Documentation / @interstellar-tools/maps / flowAccumulation
Function: flowAccumulation()
ts
function flowAccumulation(grid: GridInterface): GridInterface;Defined in: terrain/flow-accumulation.ts:52
Compute the flow accumulation of every cell of an elevation grid: the area that drains through it, its own included.
Where:
is the cell's contributing area and that of each neighbour draining into it (m²) is the cell's own area (m²)
Units
- Input: heights and the cell size in m.
- Output: contributing area in m², at least one cell's area. Divide by
for a number of cells.
Notes
- Flow follows flowDirections: D8, all of a cell's flow to one neighbour. The largest values trace the channels where water, or on Mars perhaps ice and fine material, would gather.
- Flow stops at a cell with nowhere to drain, so the areas of all such cells add up to the whole grid's. A pit cuts off everything upstream of it: fill pits first for connected drainage.
- Only area inside the grid counts: near an edge, more may drain in from outside.
- Missing cells are
NaNand receive no flow.
Parameters
| Parameter | Type | Description |
|---|---|---|
grid | GridInterface | Elevation grid, heights in m. |
Returns
A grid of the same shape, contributing area in m².
Throws
- If a size or cell size is not finite.
- If the grid's parts don't fit together.
Example
ts
// Falling to the east, 10 m cells
const grid = createGrid({
rows: 2,
columns: 3,
values: [3, 2, 1, 3, 2, 1],
cellSize: { x: 10, y: 10 }
});
flowAccumulation(grid).values; // [100, 200, 300, 100, 200, 300] m²See
- flowDirections
- topographicWetnessIndex
- https://doi.org/10.1016/S0734-189X(84)80011-0 O'Callaghan & Mark (1984), The extraction of drainage networks from digital elevation data