My terrain is a highly developed area--which means that

  1. It involves lots of flat area ( gradient=0) because they have been properly paved.
  2. And it involves sudden drop, such as retaining wall, or drain drop.

These two features make me wonder whether the usual flow accumulation algorithms ( like D8) can actually work on such terrain?

I want to do streamline analysis on it, but I am quite unsure whether the usual flow accumulation algorithms ( like D8) can actually work on such terrain? Or, as my previous question frames it, is there any open source flow accumulation algorithm in C++/C# on Windows that handles these features nicely?

Note: I would have to conduct watershed analysis at modelling stage ( because we need to study the waterflow path even before the development begins, to avoid flooding at unwanted area), which means that the DEM is based on my modelling and not something out there on the actual terrain (yet).

  • In my experience flow accumulation over flat area depends on your software, what software do you have? Even though an area seems 'flat' almost nothing is truly flat; if you have very accurate capture you can see very fine changes even in concrete/paved areas. Where did your DEM come from? The trouble with very accurate captured DEM data is that it's full of little 'ponds' which can play havoc with stream accumulation, some software packages can assist in generalizing/cleaning the surface before calculating accumulation. Jun 8, 2018 at 1:36
  • @MichaelStimson, I would say that my watershed analysis has to be conducted at modelling stage, which means that it's not something I can capture from the existing levels out there
    – Graviton
    Jun 8, 2018 at 1:38
  • Esri stops accumulating as soon as a direction=0 occurs, with some effort you can create 'connectors' from the vectorized stream model for continuity. Conversely TNTMips ploughs straight through flat areas when performing a flow accumulation. Jun 8, 2018 at 1:42
  • @MichaelStimson, I am actually looking for open source flow accumulation algorithm in C++ on Windows that can handle this nicely. Is TNTMips available as a command line?
    – Graviton
    Jun 8, 2018 at 1:50
  • TNT Mips is by Microimages, it's not free but not particularly expensive.. there is a trial variant that is limited to a few features or rasters less than a certain size (sorry, I don't know specifics). TNT has its own macro language but also has a C++ API. Have a read of gis.stackexchange.com/questions/113332/… - GDAL is open source and plays nicely with python, C#, VB.net, C++ and even ANSI C (I've heard). Jun 8, 2018 at 2:07

2 Answers 2


Check out SAGA GIS, it's C++ based, and has tons of options for hydrological analysis, including preprocessing your data (e.g. filling sinks and detecting flat areas). It also has the most common flow accumulation algorithms implemented. I would think twice about using the D8 in any case.

EDIT: More about flow accumulation algorithms: D8 is very sensitive to errors in the input digital elevation model. All the accumulated flow is directed to one neighbor, and sometimes the pixel is erroneous, which mean all the flow accumulation can be directed to a wrong pixel. Other algorithms, which distribute flow to more than one neighbor, are more robust. For example consider an area of 10 by 10 m (10 m resolution), quite often the water is not flowing to one direction, but to two or even more. I'd prefer multiple flow direction algorithm (by Quinn, Freeman), or the Tarboton's D infinity. The choice of algorithm also depends on your data. How accurate is it? Does it have noise, or other errors? What resolution is the data?

The SAGA Wetness Index, which uses the neighboring maximum flow accumulation values can also be useful with high-resolution data (< 2 m, in my personal experience,) which can have noise. It gives smoother flow accumulation patterns, so it is not that sensitive to errors. I have tested these algorithms with LiDAR based DEMs and field-quantified data (top-soil moisture), so I am writing from that perspective, although I must say I have not tested these algorithms in urban environments.

For those who can access, this publication has good, short description about the most common flow accumulation algorithms: https://onlinelibrary.wiley.com/doi/pdf/10.1111/j.1654-109X.2010.01083.x

  • Why you are wary towards D8? What are the other methods that you would like to use?
    – Graviton
    Jun 9, 2018 at 0:16

Water falling on an infinite flat surface should accumulate in place. with a single flow algorithm such as G8, there will be no gradient. Multiple flow direction should distribute the water in all directions, so this could help you. This is available in, e.g., GRASS

On the other hand, a simple workaround would be to "artificially" create a gradient from your drain drops based on the distance to the drains. Indeed, adding a few millimeter in height when you move away from the drain will "imitate" what happens when you "empty" a flat surface (e.g. a dam overflow)

  • Would you like to point to me which section in GRASS documentation that has this feature?
    – Graviton
    Jun 8, 2018 at 7:43
  • Also, it's quite unclear to me whether GRASS can be redistributed as a list of DLLs or as a command line-- I would need to package them in my program for my end user to use
    – Graviton
    Jun 8, 2018 at 8:08
  • the links in my answer (r.terraflow) is for an older version, but it is of course also available in the newer version : grass.osgeo.org/grass74/manuals/r.terraflow.html
    – radouxju
    Jun 13, 2018 at 10:08
  • see the grass programmer manual for examples in C. grass.osgeo.org/development/programmer-manual
    – radouxju
    Jun 13, 2018 at 10:11
  • GRASS GIS >= Version 5 is free software, you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the license, or (at your discretion) any later version.
    – radouxju
    Jun 13, 2018 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.