4

I would like to use the source code of "fill sinks (wang and liu)".

I checked through QGIS3 folders, but could not find much related to it.

Anyone know where the code could be?

3 Answers 3

5

Fill Sinks (Wang and Liu) is a QGIS processing algorithm that calls an external (3rd party) tool SAGA.

The code to call SAGA is in SagaAlgorithm.py.

The source for the SAGA command is either:

2
  • How would I go about calling the SAGA command using SagaAlgorithm.py through an IDE?
    – Suspectful
    Commented Aug 2, 2018 at 18:54
  • @Suspectful, processing.run. If you have further questions,ask a new question.
    – user2856
    Commented Aug 2, 2018 at 20:35
5

The Wang and Liu algorithm is also implemented in Whitebox GIS. You can find it listed under Hydrological Tools\DEM Pre-processing\Fill Depressions.

The source code can be very easily accessed using Whitebox's 'View Code' button on the tool. You can also navigate to the text file yourself. Or you can view it online. The code is written in Groovy, a java-based scripting language.

1
  • And this is one of the things I love about WB GIS. It took me a lot of mucking around to figure out where the source for the QGIS/SAGA implementation was... With WB GIS you can access it from the program itself.
    – user2856
    Commented Jul 12, 2018 at 0:08
2

In addition to the Groovy-based implementation that Chris mentioned (a Whitebox GAT plugin), there is also a newer and more efficient Rust-based open-source implementation of the Wang and Lui depression filling method available in WhiteboxTools. The source code for this tool can be found in the WhiteboxTools Github repository. Importantly, WhiteboxTools can be run independent of Whitebox GAT (i.e. the Whitebox GIS user interface) and can be scripted using Python (See here for details).

from WBT.whitebox_tools import WhiteboxTools
wbt = WhiteboxTools()

dem = "/path/to/data/DEM.tif"
output = "/path/to/data/filled_DEM.tif"
wbt.fill_depressions(dem, output)

Additionally, this Rust-based depression filling tool is available from the Whitebox for Processing QGIS plugin:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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