Sunteți pe pagina 1din 7

Atmospheric and Oceanic Science Letters

ISSN: 1674-2834 (Print) 2376-6123 (Online) Journal homepage: https://www.tandfonline.com/loi/taos20

Another Fast and Simple DEM Depression-Filling


Algorithm Based on Priority Queue Structure

Liu Yong-He, Zhang Wan-Chang & Xu Jing-Wen

To cite this article: Liu Yong-He, Zhang Wan-Chang & Xu Jing-Wen (2009) Another Fast and
Simple DEM Depression-Filling Algorithm Based on Priority Queue Structure, Atmospheric and
Oceanic Science Letters, 2:4, 214-219, DOI: 10.1080/16742834.2009.11446800

To link to this article: https://doi.org/10.1080/16742834.2009.11446800

© Institute of Atmospheric Physics, Chinese


Academy of Sciences

Published online: 03 Jul 2015.

Submit your article to this journal

Article views: 549

View related articles

Citing articles: 12 View citing articles

Full Terms & Conditions of access and use can be found at


https://www.tandfonline.com/action/journalInformation?journalCode=taos20
ATMOSPHERIC AND OCEANIC SCIENCE LETTERS, 2009, VOL. 2, NO. 4, 214−219

Another Fast and Simple DEM Depression-Filling Algorithm Based on


Priority Queue Structure
LIU Yong-He1, ZHANG Wan-Chang2, and XU Jing-Wen1
1
Key Laboratory of Regional Climate-Environment Research for Temperate East Asia, Institute of Atmospheric Physics, Chinese
Academy of Sciences, Beijing 100029, China
2
Center for Hydro-Sciences Research, Nanjing University, Nanjing 210093, China
Received 20 April 2009; revised 27 June 2009; accepted 27 June 2009; published 16 July 2009

Abstract Some depression cells with heights lower than 1998; Wolock and McCabe, 2000; Yang, 2005). Before
their surrounding cells may often be found in Grid-based using these models, water drainage networks derived from
digital elevation models (DEM) dataset due to sampling digital elevation models (DEM) must be prepared so that
errors. The depression-filling algorithm presented by runoffs can be calculated for each cell. Information about
Planchon and Darboux works very quickly compared to drainage networks is derived from the DEM data, includ-
other published methods. Despite its simplicity and deli- ing the flow direction from cell to cell, the water drainage
cacy, this algorithm remains difficult to understand due to networks, and the associated sub-watersheds (Paz and
its three complex subroutines and its recursive execution. Collischonn, 2007; Turcotte et al., 2001).
Another fast algorithm is presented in this article. The Many studies focused on extracting drainage networks
main idea of this new algorithm is as follows: first, the have been published recently (Ahamed et al., 2002; Co-
DEM dataset is viewed as an island and the outer space as lombo et al., 2007; Jana et al., 2007; Jenson and Domingue,
an ocean; when the ocean level increases, the DEM cells 1988; Planchon and Darboux, 2002; Turcotte et al., 2001;
on the island’s boundary will be inundated; when a cell is Wang and Yin, 1998). Commonly used DEM data for
inundated for the first time, its elevation is increased to extracting drainage networks are squared regular grid
the ocean level at that moment; after the ocean has inun- based (Turcotte et al., 2001), while triangulated irregular
dated the entire DEM, all of the depressions are filled. networks (TIN) are also used in some applications
The depression-removing processing is performed using a (Tucker et al., 2001). Below, the DEM data are referred to
priority queue. Theoretically, this new algorithm is a fast as regular squared grid based DEM.
algorithm despite the fact that it runs more slowly than When extracting drainage networks from any kind of
Planchon and Darboux’s method. Its time-complexity in DEM data, there is a common problem of existing de-
both the worst case and in an average case is O(8nlog2 pressed cells with elevations lower than any surrounding
(m)), which is close to O(n). The running speed of this cells that have no flow direction linking them to the main
algorithm depends mainly on the insertion operation of river channel. This is because errors or noise exist in
the priority queue. As shown by the tests, the depres- DEM data and the actual detailed topographic structure is
sion-filling effects of this algorithm are correct and valid, generalized at a lower resolution by a DEM cell. There-
and the overall time consumption of this algorithm is less fore, before determining flow directions, these depres-
than twice the time consumed by Planchon & Darboux’s sions (known as pits in other publications) must be re-
method for handling a DEM smaller than 2500×2500 moved by modifying the cells' elevations. This paper dis-
cells. More importantly, this new algorithm is simpler and cusses a depression-filling method that prepares valid
easier to understand than Planchon and Darboux’s method. DEM data for the approach of using an eight flow direc-
This advantage allows the correct program code to be tion matrix (D8) because the D8 approach is a common
written quickly. method for deriving drainage networks from raster DEM
Keywords: digital elevation models, depression remov- data (Jenson and Domingue, 1988; McMaster, 2002;
ing, priority queue, quick algorithm Tribe, 1992; Turcotte et al., 2001). Similar methods for
Citation: Liu, Y.-H., W.-C. Zhang, and J.-W. Xu, 2009: other direction-calculating methods and other kinds of
Another fast and simple DEM depression-filling algo- DEM data can be obtained by extending the method used
rithm based on priority queue structure, Atmos. Oceanic for the D8 approach.
Sci. Lett., 2, 214−219. Some efforts have been made to resolve this depres-
sion-removing problem. Ocallaghan does this by smooth-
1 Introduction ing the DEM data; however, only tiny and shallow de-
pressions can be removed, while larger and deeper de-
Numerical hydrological models are powerful tools for pressions remain (Ocallaghan and Mark, 1984). The de-
researching the hydrological characteristics of watersheds, pression-filling method in a real sense was first used to
especially watersheds with large areas (Dodov and Fou- study the roughness of soil, such as calculating a soil’s
foula-Georgiou, 2006; Gumbo et al., 2002; Wang and Yin, depression storage capacity using DEM data (Moore and
Larson, 1979; Onstad, 1984; Planchon and Darboux, 2002;
Corresponding author: ZHANG Wan-Chang, zhangwc@tea.ac.cn Ullah and Dickinson, 1979). The idea of filling these de-
NO. 4 LIU ET AL.: A FAST ALGORITHM FOR DEPRESSION FILLING IN DEM DATA 215

pressions by increasing the cell’s elevation to the minimal element from the PQ that has the highest priority and re-
elevation of the cells that are found on the boundary of turn it. A good PQ should support quick element insertion
the depression is recommended by Jenson and Domingue and removal. Currently, most modern programming lan-
(1988) and Marks et al. (1984). Based on this idea, Jenson guages (Planchon and Darboux, 2002) have their own
and Domingue presented their traditional algorithm. For built-in PQ structures based on a self-balancing binary
applications with small DEM data, this algorithm can search tree. A insertion operation for such a PQ takes
produce satisfying results. However, for applications with O(log(n)) time and the removal operation takes O(1)
a larger DEM dataset, small depressions are often em- time .
bedded in larger ones, and time-consuming scans per- Using a priority queue, every cell neighboring an ocean
formed over the entire DEM dataset must be done more cell (the boundary cell of the island) should be inserted
than once in order to find the embedded or adjacent de- into the PQ and its elevation value should be taken as the
pressions. The time complexity of these scans is O(n2). A priority value associated with it. Each time a cell is re-
common DEM file of about 1 000 000 cells requires sev- moved from the PQ, it is used as a seed for exploring
eral hours to accomplish this task. Moreover, this kind of other island-boundary cells, and its corresponding priority
algorithm is very complex and difficult to implement. is taken as the current ocean level. From this seed, all
In 2002, Planchon and Darboux published their fast cells on the island boundary are explored recursively
algorithm. This algorithm involved two stages; the first without regard to whether their elevations are lower or
stage inundates all DEM with a thick layer of water, and higher than the seed (with a height equal to the sea level).
the second stage drains the excess water. In the second This exploration method, known as the flood-filling ap-
stage, they used two methods, namely scanning the whole proach, is used in image processing and computer graph-
DEM grid and exploring cells via recursion. The former ics. All of the found neighbor cells should be inserted into
method’s time complexity is O(n1.5) and the latter the PQ, and those cells with elevations below the ocean
method’s time complexity is O(n1.2) (Planchon and Dar- level are then set to the ocean level.
boux, 2002). Compared to other algorithms, this algo- Before processing, the imagined ocean surrounds the
rithm is so fast that it can decrease the time consumed entire DEM, so that when the PQ is initialized all cells on
from hours to seconds. Despite its fast speed and delicacy, the boundary of the DEM data set should be inserted into
the algorithm remains difficult to understand to some de- the PQ.
gree because it requires three subroutines and still in- Another data structure that we used is a two-dimen-
volves recursive execution. This forces programmers to sional integer-value or Boolean-value array with the same
spend a great amount of time to grasp the main idea of the size as the DEM. This data structure is used to mark
algorithm and test the program code. ocean cells with 0 and island cells with 1.
The present article describes an additional fast depres- The pseudo-code for this algorithm is presented in Ta-
sion-filling algorithm that is more simple but somewhat ble 1. No more than 25 lines of code are in this algorithm,
slower than Planchon and Darboux’s algorithm. This al- which is only about half of lines of the code used in
gorithm takes advantage of a commonly used data struc- Planchon and Darboux’s method. Moreover, the code is
ture, the priority queue, its time complexity is close to all written in one procedure, so it is very easy to under-
O(n) and it is easy to understand.
Table 1 Pseudo-code of the algorithm.
Procedure FillDepression(DEM)
2 The algorithm new PQ
The idea behind this algorithm is to imagine the DEM For row=0 to DEM.rowCount
//insert first column and last column
as an island surrounded by an ocean. At the start, the PQ.Insert(row, 0)
ocean’s level is below all of the DEM cells, and the PQ.Insert(row, DEM.colCount-1)
ocean’s level then increases gradually. The first inundated End for
cells are those below the ocean’s level and lie on the For col=1 to DEM.colCount-1
//insert first row and last row
boundary of the DEM. When these cells are inundated, PQ.Insert(0, col)
the next to be inundated are the neighboring cells. When a PQ.Insert(DEM.rowCount-1, col)
cell in a depression is inundated for the first time, its ele- End For
vation value should be set to the ocean level at that mo- marks=new double[DEM.rowCount][DEM.colCount](1)
//all elements initialized to 1
ment. When all of the DEM are inundated, all of the de- while PQ.length>0
pressions have been removed. Here, inundating means cell=PQ.remove()
that the ocean’s level is equal to or greater than the cell’s waterlevel=cell.elevation
elevation values. for n in neighboursOf(cell)
if marks[n]=0
Each time, the ocean level should increase to the eleva- continue
tion value of the lowest boundary cells neighboring the If n.Elevation<=waterlevel
ocean cells; there may be more than one such cell with the n.Elevation=waterlevel
same elevation. In order to find these cells quickly, a pri- End if
PQ.Insert(n)
ority queue is used. A priority queue (PQ) is a data struc- End for
ture support that follows two operations: (1) add an ele- End while
ment to the PQ with an associated priority; (2) remove the End procedure
216 ATMOSPHERIC AND OCEANIC SCIENCE LETTERS VOL. 2

stand and implement. When a cell is removed from the der of the cells with the same elevation in the priority
PQ, its neighbors in eight directions are scanned, so the queue is not important because the minimal value of those
time complexity of the main procedure is O(8n) (n is the DEM cells neighboring the ocean is the only value re-
total number of cells in the DEM), while the insertion and quired for the depression-filling algorithm. Thus, a SD
removal operations in the priority queue take O(log2(m)) structure that has a queue structure as its element value
(m is number of cells at the island boundary, so it is very type is a good substitute for a real priority queue with no
small compared to n). Here, the value of m varies over an unique keys. In order to understand the pseudo-code eas-
entire depression-removal process, and it determines the ily, the insertion subroutine of the SD-based priority
time spent by each insertion. Each cell will be inserted queue can be written as Table 2.
into and removed from the priority queue only once, so When a cell is inserted, the program should first check
the overall time complexity both in the worst cases and in whether the SD has a key equal to the cell elevation. If it
average cases is O(8nlog2(m)) and is close to O(n) . does, the cell should be added to the queue with its key
equal to the cell elevation; if not, then a queue object
3 Algorithm implementation using the C# hould be created and push the cell into this new one, then
language add this queue object into the SD with the key equal to the
In popular languages like C++, Java, and Python, there cell elevation. When an element is removed from the SD,
is always a built-in priority queue. Actually, not every all cells with the same elevation are removed. With the
programming language has a built-in priority queue data SD substituting for the priority queue, the algorithm must
structure available, so there is a need to write the code for be modified (Table 3).
a priority queue if none exists. In this section, a C# lan-
guage implementation of the depression filling algorithm Table 2 Insertion method of the SD-based priority queue (pseudo-
is described. In the Microsoft .Net Framework 2.0, there code).
is no built-in priority queue available, but there is a ge- Procedure SD.Insert(cell)
neric structure named SortedDictionary (SD), which is a If SD.Contains(cell.elevation)
binary search tree with log2(n) retrieval, insertion or re- SD[cell.elevation].push(cell)
Else
moval. Its elements are key/value pairs, and every key SD[cell.elevation]=new Queue<Cell>
must be unique. The SD does not allow for multiple ele- SD[cell.elevation].push(cell)
ments with the same key, but its elements can be defined End if
as any collection type, such as a queue structure. The or- End procedure

Table 3 The modified algorithm.


Procedure FillDepression(DEM)
SD=new SortedDictionary<double, Cell>
For row=0 to DEM.rowCount
SD.Insert( new Cell(row, 0) )
SD.Insert( new Cell(row, DEM.colCount-1) )
End for
For col=1 to DEM.colCount-1
SD.Insert( new Cell(0, col) )
SD.Insert( new Cell(DEM.rowCount-1, col) )
End For
marks=new double[DEM.rowCount][DEM.colCount](1) //all elements initialized to 1
while PQ.length>0
waterlevel=SD.FirstKey()
queue=SD[waterlevel] //get the element corresponding to the key of minValue
SD.Remove(waterlevel)
while queue.Count>0
for n in neighboursOf(cell)
if marks[n]=0
continue
else
marks[n]=0
end if
if n.Elevation<=waterlevel
if marks[n]!=2 //marks value with 2 indicate that it is visited
queue.Enqueue(n) // but hasn’t been marked as ocean
marks[n]=2
end if
n.Elevation=waterlevel
else
SD.Insert(n)
End if
End for
End while
End while
End procedure
NO. 4 LIU ET AL.: A FAST ALGORITHM FOR DEPRESSION FILLING IN DEM DATA 217

4 Performance tests extracted by Planchon’s algorithm.


The execution times of the two algorithms with the
The algorithm in this paper can fill the depressions in three datasets are shown in Table 4. The results indicate
DEM correctly (Fig. 1). The algorithm in this paper and that these tests were not performed faster than the tests
the algorithm presented by Planchon and Darboux are performed by Planchon and Darboux in 2001 because
implemented using the C# language within the framework these new tests were executed by managed code under the
of Microsoft .Net 2.0, and they are also tested using three Microsoft .Net Framework 2.0, which is slower than the
differently sized DEM datasets with dimensions of unmanaged C-language program used by Planchon and
977×667, 1201×1201, and 2500×2500 on a laptop with a Darboux. It appears that the execution time of the priority
2.26 GHz Intel P8400 CPU and 768 MHz DDR-II mem- queue-based algorithm is similar to but slower than the
ory. The extracted river nets of the first dataset depres- time taken by Planchon and Darboux’s algorithm. Com-
sion-filled by these two algorithms are shown in Fig. 2. pared to Planchon’s algorithm, the cell numbers handled
This shows that the results produced by the two algo- per millisecond by a priority queue-based algorithm de-
rithms are similar. In comparing the results of these two creased slowly as the size of the datasets increased, so this
algorithms, both show parallel river lines in the flat area, priority queue-based algorithm is not slow. In this case,
but the patterns of these parallel river lines are different. it is important to note that the SD’s element insertion op-
This effect may be related to the processing order of cells
that have the same height in the algorithms. Actually, the
drainage networks in flat areas may behave very randomly,
or can also be affected by human behavior. In this sense,
neither of the extracted results from the two algorithms
was more correct than the other. However, visually it
seemed that the result extracted by the algorithm pre-
sented in this paper was more reasonable because the par-
allel river lines in the flat areas are not as dense as those

Figure 2 River nets extracted from the first dataset (size of 977×667)
depression-filled by the two algorithms. (a) the shadow effects of the
DEM data, (b) depression-filled by Planchon and Darboux’s algorithm,
Figure 1 A example of DEM with (a) depressions and (b) their coun- and (c) depression-filled by algorithm presented in this article. The other
terpart whose depressions were removed using the algorithm presented dataset is not presented here because it is very large and its extracted
in this paper. The highlighted cells are depressed cells. river channel cannot be shown clearly in this paper.
218 ATMOSPHERIC AND OCEANIC SCIENCE LETTERS VOL. 2

Table 4 Execution time of the 2 algorithms.


Planchon and Darboux’s algorithm Priority queue-based Algorithm Execution speed ratio of Planchon’s
Cell number algorithm to the priority queue-based
Execution time (ms) cells per ms Execution time (ms) Cells per ms algorithm
977×667 1937 336 2000 325 1.034
1201×1201 3937 336 4953 291 1.155
2500×2500 16687 374 28656 218 1.71

eration takes the same O(log2(n)) time as the actual prior- queue. If a real priority queue is used instead of using the
ity queue’s insertion operation, but its removal operation structure of a SD combined with a queue object, the algo-
also takes a time of O(log2(n)), which is slower than that rithm may be more efficient. The overall time consump-
of the actual priority queue’s removal. Like the elements tion of the algorithm was no more than twice that con-
operated on by SD, the queue object’s insertion and re- sumed by Planchon & Darboux’s method. The PQ-based
moval takes O(1) time. Thus, this SD-substituted priority algorithm provides an alternative to Planchon & Dar-
queue is slower than an actual priority queue. The slow- boux’s fast algorithm.
ness of this algorithm compared to Planchon’s algorithm The elementary coding used by this new depression-
is mainly explained by the priority queue, which has a filling algorithm requires only 25 lines, which is about
time complexity of O(log(n)) for insertion and removal half the length of the code used by Planchon’s method.
operation of the elements. Furthermore, the main code for this new algorithm can be
written in one procedure, while the code in Planchon’s
5 Discussion and conclusions method requires three or four procedures. The use of a
priority queue structure makes the algorithm easier to
The depression-filling algorithm presented by Plan- understand for users and programmers and will save them
chon and Darboux is quite fast compared to other pub- time. The advantages of this priority queue-based algo-
lished methods (Planchon and Darboux, 2002). Despite its rithm are its simplicity and intelligibility, which make it
simplicity and delicacy, this algorithm is still difficult to very easy to write correct program code quickly.
understand due to the three complex subroutines and the
recursive execution. Acknowledgements. We are very much indebted to Hu Yong-Hong
The additional fast algorithm presented in this article for his help in providing us with DEM datasets for the algorithm
uses a new approach: first, the DEM dataset is regarded as tests. This study was financially supported by the National Basic
Research Program of China (Grant No. 2006CB400502), the Pro-
an island and the outer space as an ocean, and as the motion of 100 Young Talent Scientist Project of the Chinese Acad-
ocean level is increased step by step, DEM cells on the emy of Sciences (8-057493), and the Special Meteorology Project
island boundary are inundated. When a cell is inundated (GYHY(QX)2007-6-1).
for the first time, the elevation of this cell increases to the
ocean level at that time. After the ocean has inundated the References
entire DEM island, all depressions are filled. All of the
Ahamed, T., K. G. Rao, and J. Murthy, 2002: Automatic extraction
boundary cells near the water are pushed into a priority
of tank outlets in a sub-watershed using digital elevation models,
queue, and with each step the cell with the lowest eleva- Agricultural Water Management, 57(1), 1–10.
tion is removed from the priority queue, so that it is inun- Colombo, R., R. V. Vogt, P. Soille, et al., 2007: Deriving river net-
dated first. Theoretically, this new algorithm is also a fast works and catchments at the European scale from medium reso-
algorithm, despite the fact that it runs slower than Plan- lution digital elevation data, Catena, 70(3), 296–305.
chon and Darboux’s method. Its time-complexity is Dodov, B. A., and E. Foufoula-Georgiou, 2006: Floodplain mor-
phometry extraction from a high-resolution digital elevation
O(8nlog2(m)), where n represents the total number of cells
model: A simple algorithm for regional analysis studies, IEEE
and m represents the number of cells at the island bound- Geosci. Remote Sens. Lett., 3(3), 410–413.
ary. Because m is very small compared to n, the time Gumbo, B., N. Munyamba, G. Sithole, et al., 2002: Coupling of
complexity is close to O(n). digital elevation model and rainfall-runoff model in storm
In this paper, a C# language-implemented depres- drainage network design, Phys. Chem. Earth, 27, 755–764.
sion-filling method based on the algorithm presented in Jana, R., T. V. Reshmidevi, P. S. Arun, et al., 2007: An enhanced
this paper is introduced. Because there is no real priority technique in construction of the discrete drainage network from
low-resolution spatial database, Computers & Geosci., 33(6),
queue available in the Microsoft .Net Framework 2.0, the 717–727.
SD structure combined with a queue structure was used to Jenson, S. K., and J. O. Domingue, 1988: Extracting topographic
realize the functions of a priority queue. The program structure from digital elevation data for geographic informa-
code was modified for use in the SD-based algorithm. The tion-system analysis, Photogrammetric Engineering Remote
tests were performed by depression-filling three differ- Sens., 54(11), 1593–1600.
ently sized DEM, and the results showed that the algo- Marks, D., J. Dozier, and J. Frew, 1984: Automated basin delinea-
tion from digital elevation data, Geo-Processing, 2(3), 299–311.
rithm presented in this paper is fast, although slightly McMaster, K. J., 2002: Effects of digital elevation model resolution
slower than Planchon’s method. on derived stream network positions, Water Resour. Res., 38(4),
The running speed of this algorithm is mainly depend- 131–139.
ent on the insertion and removal operations of the priority Moore, I. D., and C. L. Larson, 1979: Estimating micro-relief sur-
NO. 4 LIU ET AL.: A FAST ALGORITHM FOR DEPRESSION FILLING IN DEM DATA 219

face storage from point data, Trans. Asae, 22(5), 1073–1077. morphic modeling using triangulated irregular networks, Com-
Ocallaghan, J. F., and D. M. Mark, 1984: The extraction of drainage puters & Geosci., 27(8), 959–973.
networks from digital elevation data, Computer Vision Graphics Turcotte, R., J. P. Fortin, A. N. Rousseau, et al., 2001: Determina-
Image Processing, 28(3), 323–344. tion of the drainage structure of a watershed using a digital ele-
Onstad, C. A., 1984: Depressional storage on tilled soil surfaces, vation model and a digital river and lake network, J. Hydrol.,
Trans. Asae, 27(3), 729–732. 240, 225–242.
Paz, A. R., and W. Collischonn, 2007: River reach length and slope Ullah, W., and W. T. Dickinson, 1979: Quantitative description of
estimates for large-scale hydrological models based on a rela- depression storage using a digital surface model. 1. Determina-
tively hill high-resolution digital elevation model, J. Hydrol., tion of depression storage, J. Hydrol., 42, 63–75.
343, 127–139. Wang, X. H., and Z. Y. Yin, 1998: A comparison of drainage net-
Planchon, O., and F. Darboux, 2002: A fast, simple and versatile works derived from digital elevation models at two scales, J.
algorithm to fill the depressions of digital elevation models, Ca- Hydrol., 210, 221–241.
tena, 46, 159–176. Wolock, D. M., and G. J. McCabe, 2000: Differences in topographic
Tribe, A., 1992: Automated recognition of valley lines and drainage characteristics computed from 100- and 1000-m resolution digi-
networks from grid digital elevation models—A review and a tal elevation model data, Hydrol. Processes, 14(6), 987–1002.
new method, J. Hydrol., 139, 263–293. Yang, X. J., 2005: Use of LIDAR elevation data to construct a
Tucker, G. E., S. T. Lancaster, N. M. Gasparini, et al., 2001: An high-resolution digital terrain model for an estuarine marsh area,
object-oriented framework for distributed hydrologic and geo- Int. J. Remote Sens., 26(23), 5163–5166

S-ar putea să vă placă și