The difference between carving and filling (1)

Image Posted on Updated on

People using TopoToolbox asked me quite frequently about the difference between the two preprocessing options when calculating a flow direction object (FLOWobj): ‘carve’ and ‘fill’.

First and most important: These options do not alter the DEM, they only control how FLOWobj internally preprocesses the DEM to optimize how flow is routed through topographic depressions.

In this first post I’ll describe how the option ‘fill’ works.

Option ‘fill’: The constructor function FLOWobj fills all topographic depressions (function fillsinks). It then identifies all flat sections (function identifyflats) and calculates an euclidean distance transform (function bwdist) within each flat section seeded at their outer rim. Subsequently, the complement of the distance transform is calculated in each flat area. The complement grid is subsequently used as weights in a gray-weighted distance transform (function graydist). This generates an auxiliary surface in each flat area. The surface has the nice property that flow will run through the centerline of flat areas.

D8 flow networks in flat areas derived with different terrain analysis software.

So how does this approach to derive flow directions in flat areas compare to other software. Above figure shows how other software handle flow directions in the flat areas. It seems that only TauDEM uses a similar approach as TopoToolbox 2. Other software seem to handle the problem differently and produce linear, somewhat unelegant flowpaths through flat sections.



Posted on Updated on


this is my first post and I want to quickly provide an overview on what you can expect from my posts. I am geoscientist with a major background in geomorphology, GIS, geostatistics and numerical modeling. In the last couple of months Dirk Scherler (Caltech) and I have developed TopoToolbox, a function library for Digital Elevation Model (DEM) analysis in MATLAB. This toolbox has been applied in research topics such as pedometrics, glaciology, landscape evolution modeling and hydrology by researchers and practitioners around the globe. TopoToolbox is also interesting for those amongst you, who study geomorphology, geomorphometry and hydrology and who seek to develop their own models and experimenting with DEMs.

The key to understanding how TopoToolbox works requires some knowledge about mathematics and image processing. I will try my best to cover these topics in posts that should be understood with only little background in these disciplines. Since my interests also go beyond the technical issues I will cover other topics related to DEM analysis as well.

So, hope you enjoy reading. Please leave comments.


Posted on

Schwanghart, W., Scherler, D. (2014): TopoToolbox 2 – MATLAB-based software for topographic analysis and modeling in Earth surface sciences. Earth Surface Dynamics, 2, 1-7. [DOI: 10.5194/esurf-2-1-2014, Discussion paper: 10.5194/esurfd-1-261-2013]. open access and software available here [DOI: 10.1594/IEDA/100175].

Schwanghart, W., Kuhn, N. J. (2010): TopoToolbox: a set of Matlab functions for topographic analysis. Environmental Modelling & Software, 25, 770-781. [DOI: 10.1016/j.envsoft.2009.12.002]


Posted on Updated on


TopoToolbox is plat-form independent but requires Matlab and the Image Processing Toolbox. The toolbox has been developed using Matlab Versions R2011b and you should use this or a later version.


Download the latest TopoToolbox Version at the Community Surface Dynamics Modeling System (CSDMS) code repository.


Posted on Updated on


TopoToolbox provides a set of Matlab functions that support the analysis of relief and flow pathways in digital elevation models. The major aim of TopoToolbox is to offer stable and efficient analytical GIS utilities in a non-GIS environment in order to support the simultaneous application of GIS-specific and other quantitative methods.

TopoToolbox’ algorithms are largely based on sparse matrix algebra and image processing techniques. Each function is implemented in Matlab-code (*.m-files) and can be easily modified and adapted to specific needs of the user.

TopoToolbox can be regarded as a construction kit and new functions will be added in the future. If you have ideas or comments on how to complement or improve TopoToolbox, if you like to contribute, or if you have any questions or remarks, please contact me:

Wolfgang Schwanghart