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.
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
To view this discussion visit https://groups.google.com/d/msgid/whiteboxtools/2312af22-5a98-4e3d-b20c-d19e6bd35f9fn%40googlegroups.com.