geoprimsField-grade geospatial math

Flow direction over a DEM

Which way water leaves every cell of an elevation grid, by steepest descent to one of eight neighbors or by the continuous D-infinity angle, in the pointer encoding your software reads.

Experimental: not yet fully verified. How results are checked

90

90 cells have a flow direction.

Direction grid
Elevations
1, 1, 1, 1, 1, 1, 1, 1, 1, 0
1, 1, 1, 1, 1, 1, 1, 1, 1, 0
1, 1, 1, 1, 1, 1, 1, 1, 1, 0
1, 1, 1, 1, 1, 1, 1, 1, 1, 0
1, 1, 1, 1, 1, 1, 1, 1, 1, 0
1, 1, 1, 1, 1, 1, 1, 1, 1, 0
1, 1, 1, 1, 1, 1, 1, 1, 1, 0
1, 1, 1, 1, 1, 1, 1, 1, 1, 0
1, 1, 1, 1, 1, 1, 1, 1, 1, 0
1, 1, 1, 1, 1, 1, 1, 1, 1, 0
Cells draining out of the window
Cells with nowhere to go
Steepest descent
Encoding
Provenance
Computed by
raster.hydrology.flow-direction 1.0.0, core 0.1.0
Model
D8 (O'Callaghan and Mark 1984): the neighbour of steepest descent, slope (z0 − zn) / d with d the cell size, or √2 times it diagonally; ties go to the first neighbour in ESRI's order, east and clockwise. D-infinity (Tarboton 1997, equations 1 to 6 and Table 1): the steepest of the eight triangular facets of the 3 by 3 window, as an angle counterclockwise from east. Codes: ESRI (E 1, SE 2, S 4, SW 8, W 16, NW 32, N 64, NE 128), WhiteboxTools (clockwise base two from NE 1, so E 2 and NW 64), or TauDEM (1 east through 8 south-east, counterclockwise); 0 where a cell has no lower neighbour
Accuracy
Exact in the arithmetic of each published rule: the direction is the steepest of the eight, and the D-infinity angle is the facet angle of Tarboton's equation (6)
Notes
1 shown with the answer
Cites
O'Callaghan, J. F., and Mark, D. M., Computer Vision, Graphics, and Image Processing, The extraction of drainage networks from digital elevation data; Tarboton, D. G., Water Resources Research, A new method for the determination of flow directions and upslope areas in grid digital elevation models; Lindsay, J. B., Guelph Hydrologic Research Group, D8 flow pointer (direction), Whitebox GAT help; Tarboton, D. G., Utah State University, D8 Flow Directions, TauDEM 5 help

Something look off?

Your values

Showing an example. Change anything.
More options 1
Run many at once from a CSV

Loading…

How we got thisFormula, worked example, sources, and proof

Model: D8 (O'Callaghan and Mark 1984): the neighbour of steepest descent, slope (z0 − zn) / d with d the cell size, or √2 times it diagonally; ties go to the first neighbour in ESRI's order, east and clockwise. D-infinity (Tarboton 1997, equations 1 to 6 and Table 1): the steepest of the eight triangular facets of the 3 by 3 window, as an angle counterclockwise from east. Codes: ESRI (E 1, SE 2, S 4, SW 8, W 16, NW 32, N 64, NE 128), WhiteboxTools (clockwise base two from NE 1, so E 2 and NW 64), or TauDEM (1 east through 8 south-east, counterclockwise); 0 where a cell has no lower neighbour

Show your work

  1. Steepest descent

    slope = (z0 − zn) / d, d the cell size or √2 times it diagonally

    100 cells of 30 m = steepest 0.033333

  2. Direction

    the neighbour of steepest descent (D8)

    ESRI: E 1, SE 2, S 4, SW 8, W 16, NW 32, N 64, NE 128; 0 where nothing is lower = 90

The same steps an agent gets from the MCP server with explain: true.

Accuracy: Exact in the arithmetic of each published rule: the direction is the steepest of the eight, and the D-infinity angle is the facet angle of Tarboton's equation (6)

When to use this: Use this after conditioning a DEM to see where water goes from each cell, or to produce the pointer grid another tool or GIS expects. Pick the encoding your software reads: ESRI's powers of two, WhiteboxTools's clockwise table, or TauDEM's 1 to 8. D-infinity gives the continuous angle instead, which spreads flow more faithfully on a hillslope but cannot be followed cell to cell.

Limitations: It is the published rule and nothing more: flats have no steepest descent, so a cell with no lower neighbour gets 0 and the result counts them, which is why a conditioned grid comes first. Cells on the window's edge, and cells beside no data, drain out of the data when nothing inside is lower. The grid is plane: cell area and diagonal distance come from the cell size, so a geographic grid needs its cell size in meters at the latitude. The window holds at most 25,000 cells.

Worked example: A 10 by 10 ramp falling to the east. Source: add-raster-hydrology raster/hydrology, the Ramp scenario: every cell points east, which is 1 in the ESRI table.

You enter

Cell size
30 m
Elevation grid
100, 99, 98, 97, 96, 95, 94, 93, 92, 91 100, 99, 98, 97, 96, 95, 94, 93, 92, 91 100, 99, 98, 97, 96, 95, 94, 93, 92, 91 100, 99, 98, 97, 96, 95, 94, 93, 92, 91 100, 99, 98, 97, 96, 95, 94, 93, 92, 91 100, 99, 98, 97, 96, 95, 94, 93, 92, 91 100, 99, 98, 97, 96, 95, 94, 93, 92, 91 100, 99, 98, 97, 96, 95, 94, 93, 92, 91 100, 99, 98, 97, 96, 95, 94, 93, 92, 91 100, 99, 98, 97, 96, 95, 94, 93, 92, 91
Pointer encoding
esri
Method
d8

You get

Cells with a direction
90
Cells draining out of the window
10
Cells with nowhere to go
0
Steepest descent
0.033333
Encoding
ESRI: E 1, SE 2, S 4, SW 8, W 16, NW 32, N 64, NE 128; 0 where nothing is lower

Review: Not yet independently reviewed by a GIS professional.

Last verified: 2026-11-06, when a maintainer last confirmed this tool's sources at the issuer. See the sources ledger.

Status: version 1.0.0, core 0.1.0. See this tool in the verification report.

Changes

Checked against: 22 golden test vectors (download the test vectors, each with its source and tolerance). See how results are checked and every source.

Sources

Terms

DEM: digital elevation model
A grid of elevations. A surface model includes buildings and canopy; a terrain model is the ground beneath them. Source: Copernicus DEM GLO-30

Experimental means this tool has not yet met the stable bar: at least 20 golden vectors, differential tests, and an independent worked example.