A generalization of the hierarchical-queue and priority-queue methods described by previous authors. The algorithm is described using pictures in Fig. 1. Upon entry, (1) DEM contains the elevations of every cell or the value NoData for cells not part of the DEM. (2) The value NoData is less than the elevation of any cell. At exit, (1) DEM contains the elevations of every cell or the value NoData for cells not part of the DEM. (2) The elevations of DEM are such that there are no digital dams and no undrainable depressions in the landscape, though there may be flats.
Require: DEM
- Let Open be a priority queue
- Let Closed have the same dimensions as DEM
- Let Closed be initialized to false
- for all c on the edges of DEM do
- Push c onto Open with priority DEM (c)
- Closed(c) ← true
- while Open is not empty do
- c ← pop(Open)
- for all neighbors n of c do
- if Closed(n) then repeat loop
- DEM(n) ← max(DEM(n), DEM(c))
- Closed(n) ← true
- Push n onto Open with priority DEM (n)