Burning ditch network into DEM

98 views
Skip to first unread message

Sima Mohtashami

unread,
Jan 24, 2025, 9:27:27 AMJan 24
to WhiteboxTools
I want to create an hydrological enforced DEM by burning in a ditch network (in vector format) into a DEM over a study area, and define specific depth of burning along the ditches .
As I learned from earlier published article, there was a specific tool "BurnStream" that had this functionality, to take a vector stream and burn it inot DEM, with desired depth. But this tools is now replaced by other tools like "FillBurn" and "TopologicalBreachBurn", which do not provide the possibility for defining the depth of ditches!
Does any one know how it is possible to modify these tools to work as the old "BurnStream" function, or any other idea to perform the described task with minimum negative impact on the DEM?

Whitebox Geospatial Inc

unread,
Jan 24, 2025, 9:32:57 AMJan 24
to Sima Mohtashami, WhiteboxTools

Hello,

Ā 

You can replicate what you would like to do easily using a Whitebox Workflows for Python script such as the following:

Ā 

import time

from whitebox_workflows import WbEnvironment

Ā 

wbe = WbEnvironment()

start = time.time()

try:

Ā Ā Ā  wbe.verbose = True

Ā Ā Ā  wbe.working_directory = 'path/to/your/data'

Ā 

Ā Ā Ā  decrement_value = 20.0 # Set this to whatever value you wish to lower streams by

Ā 

Ā Ā Ā  # Read in the DEM and streams vector

Ā Ā Ā  dem = wbe.read_raster('your_DEM.tif')

Ā Ā Ā  streams = wbe.read_vector('your_streams.shp')

Ā 

Ā Ā Ā  # Convert the streams vector to a raster

Ā Ā Ā  streams_raster = wbe.rasterize_streams(

Ā Ā Ā Ā Ā Ā Ā  streams=streams,

Ā Ā Ā Ā Ā Ā Ā Ā base_raster=dem,

Ā Ā Ā Ā Ā Ā Ā Ā zero_background=True,

Ā Ā Ā Ā Ā Ā Ā Ā use_feature_id=False

Ā Ā Ā  )

Ā Ā Ā  burned_dem = dem - (streams_raster * decrement_value)

Ā Ā Ā 

Ā Ā Ā Ā # Save the streams burned DEM

Ā Ā Ā  print('Burning streams...')

Ā Ā Ā  wbe.write_raster(burned_dem, 'stream_burned_DEM.tif', compress=True)

Ā 

Ā Ā Ā  print('Done!')

except Exception as e:

Ā Ā Ā  print("The error raised is: ", e)

finally:

Ā Ā Ā  end = time.time()

Ā Ā Ā  print(f'Elapsed time: {end-start}s')

Ā 

I’ll add a ā€œBurnStreamsā€ function to Whitebox Workflows that basically just replicatest his script with user specified input parameters of the decrement value, DEM and stream objects. It won’t be available until I release the next version though.

Ā 

Regards,

Ā 

John

Ā 

--
You received this message because you are subscribed to the Google Groups "WhiteboxTools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to whiteboxtool...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/whiteboxtools/62bda21b-a84a-4f91-8ef2-238ea48b31e0n%40googlegroups.com.

Sima Mohtashami

unread,
Jan 31, 2025, 9:56:24 AMJan 31
to WhiteboxTools
Thank you for the script. Is it possible to add a decay function to this burning approach to ensure that the water routes into the ditches, and at the same time not affect the DEM too much negatively? My ultimate goal is to model DTW before and after ditch burning, and evaluate the changes in the study area, therefore the hydro-enforced DEM needs to catch the channels as correctly as possible.
Regards, SimaĀ 

Whitebox Geospatial Inc

unread,
Jan 31, 2025, 10:05:44 AMJan 31
to Sima Mohtashami, WhiteboxTools

Hi Sima,

Ā 

Yes, the script can be easily modified to add an optional gradient away from rivers. Here’s a sample script. You need to update the working directory, the names of the DEM, streams, and output file, and adjust the decrement_value (the elevation decrement at stream cells) and the gradient_distance (the distance away from streams, measured in grid cells, for which there is some gradient applied).

Ā 

import time

from whitebox_workflows import WbEnvironment

Ā 

wbe = WbEnvironment()

start = time.time()

try:

Ā Ā Ā  wbe.verbose = True

Ā Ā Ā  wbe.working_directory = '/path/to/data' # update this

Ā 

Ā Ā Ā  decrement_value = 20.0 # Set this to whatever value you wish to lower streams by

Ā Ā Ā  gradient_distance = 5 # In grid cells

Ā 

Ā Ā Ā  # Read in the DEM and streams vector

Ā Ā Ā  dem = wbe.read_raster('DEM.tif') # update this

Ā Ā Ā  grid_res = (dem.configs.resolution_x + dem.configs.resolution_x) / 2.0

Ā Ā Ā  streams = wbe.read_vector('rivers.shp') # update this

Ā 

Ā Ā Ā  # Convert the streams vector to a raster

Ā Ā Ā  streams_raster = wbe.rasterize_streams(

Ā Ā Ā Ā Ā Ā Ā  streams=streams,

Ā Ā Ā Ā Ā Ā Ā Ā base_raster=dem,

Ā Ā Ā Ā Ā Ā Ā Ā zero_background=True,

Ā Ā Ā Ā Ā Ā Ā Ā use_feature_id=False

Ā Ā Ā  )

Ā Ā Ā 

Ā Ā Ā Ā print('Burning streams...')

Ā Ā Ā  if gradient_distance <= 0.0:

Ā Ā Ā Ā Ā Ā Ā Ā # Perform a straightforward elevation decrement on stream cells only

Ā Ā Ā Ā Ā Ā Ā  burned_dem = dem - (streams_raster * decrement_value)

Ā Ā Ā  else:

Ā Ā Ā Ā Ā Ā Ā  # Decrement stream cells byt he decrement_value and then apply a gradient away from the streams

Ā 

Ā Ā Ā Ā Ā Ā Ā  # First calculate the distance away from streams

Ā Ā Ā Ā Ā Ā Ā  dist = wbe.euclidean_distance(streams_raster)

Ā 

Ā Ā Ā Ā Ā Ā Ā  # Now covert that value into a decrement value

Ā Ā Ā Ā Ā Ā Ā  dist_threshold = gradient_distance * grid_res # Put the gradient distance in map units rather than grid cells

Ā 

Ā Ā Ā Ā Ā Ā Ā  # This is where the elevation decrement and gradient are added

Ā Ā Ā Ā Ā Ā Ā  burned_dem = dem + (((dist - dist_threshold) / dist_threshold).min(0.0)) * decrement_value

Ā Ā Ā 

Ā Ā Ā Ā # Save the streams burned DEM; you might want to change the output name.

Ā Ā Ā  wbe.write_raster(burned_dem, 'stream_burned_DEM.tif', compress=True)

Ā 

Ā Ā Ā  print('Done!')

except Exception as e:

Ā Ā Ā  print("The error raised is: ", e)

finally:

Ā Ā Ā  end = time.time()

Ā Ā Ā  print(f'Elapsed time: {end-start}s')

Ā 

Ā 

Here is what the output looks like:

Ā 

Original DEM

Ā 

Stream-burned DEM

Ā 

Cheers,

Ā 

John

Ā 

Ā 

Sima Mohtashami

unread,
Feb 10, 2025, 10:26:50 AMFeb 10
to WhiteboxTools
Hi John,Ā 
The workflow I created for my process looks like this:Ā 
1) Using this script with a decaying function, ditch channels were burned in DEM.Ā 
2) "breach depressions least cost" on DEMĀ 
3) create DTW maps on the enforcedĀ DEM
Ā which has resulted in visually acceptable effects on DTW, compared to DTW without any ditch-burning.

I wonder if it is still recommended to use " Topological breach burn" prior to DTW-modelling, to prune the surroundingĀ  flow channels into the ditches even more, or will it process the DEM in a similar way as step 2?

Richard Lumb

unread,
May 13, 2025, 7:09:04 AMMay 13
to WhiteboxTools
Hello,

I've been looking for a way to burn a profile into the DEM, so this sounds like it could work. Will you be adding it to the python API? My company won't let me use whitebox workflows due to licensing so I'm stuck with the older python API.

Thanks,
Rick
Reply all
Reply to author
Forward
0 new messages