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 cells have a flow direction.
| 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?
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
Steepest descent
slope = (z0 − zn) / d, d the cell size or √2 times it diagonally100 cells of 30 m= steepest 0.033333Direction
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
- 2026-11-07, changed: The six hydrology tools now hand their work along. Every flow tool tells you to condition the grid first, and the fill tool's answer is exactly what they want, so its page now offers to carry the conditioned grid straight into the flow tools, with the cell size and the no-data value. The tools also point at each other in the order you would use them: fill, flow direction, accumulation, streams, watershed, longest path. A test routes water over a conditioned grid and over the grid as entered, and shows the difference: no cell left stranded in the first, a pit swallowing the bowl in the second. Changelog
- 2026-11-06, added: A second hydrology tool says which way water leaves every cell of an elevation grid. D8 sends each cell's water to whichever of its eight neighbours lies steepest downhill, which is what a watershed or a stream network needs, because it makes the grid something you can walk cell to cell. D-infinity gives the angle instead, which is truer on a hillslope where the water spreads between two neighbours. The pointer grid comes in whichever of the three tables your software reads: the powers of two that ArcGIS uses, the WhiteboxTools table, or TauDEM's 1 to 8. Cells with no lower neighbour get a zero, and the result counts them apart from the ones that simply drain out of the window, with a warning to condition the grid first. Changelog
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
- The extraction of drainage networks from digital elevation data, O'Callaghan, J. F., and Mark, D. M., Computer Vision, Graphics, and Image Processing, Volume 28, issue 3, pages 323-344 (DOI 10.1016/S0734-189X(84)80011-0). The steepest-descent rule that sends each cell's water to one of its eight neighbours, the D8 method.
- A new method for the determination of flow directions and upslope areas in grid digital elevation models, Tarboton, D. G., Water Resources Research, Volume 33, issue 2, pages 309-319 (DOI 10.1029/96WR03137). Equations (1) to (6) and Table 1: the steepest slope over the eight triangular facets of a 3 by 3 window, and the facet factors a_c and a_f that turn a facet's angle into one measured counterclockwise from east.
- D8 flow pointer (direction), Whitebox GAT help, Lindsay, J. B., Guelph Hydrologic Research Group, Whitebox GAT help page, read 2026-11-06. The clockwise base-2 pointer convention, in which a cell that flows to the northwest is assigned 64, and cells with no lower neighbour are assigned zero.
- D8 Flow Directions, TauDEM 5 help, Tarboton, D. G., Utah State University, TauDEM 5 documentation, read 2026-11-06. D8 flow direction coding: 1 east through 8 southeast, counterclockwise from east.
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.