# Only proceed if Whitebox executable is installed
library(whitebox)
if (check_whitebox_binary()){
library(raster)
test_raster <- ch_volcano_raster()
dem_raster_file <- tempfile(fileext = c(".tif"))
no_sink_raster_file <- tempfile("no_sinks", fileext = c(".tif"))
# write test raster to file
writeRaster(test_raster, dem_raster_file, format = "GTiff")
# remove sinks
removed_sinks <- ch_wbt_removesinks(dem_raster_file, no_sink_raster_file, method = "fill")
# get flow directions
flow_dir_file <- tempfile("flow_dir", fileext = c(".tif"))
flow_dir <- ch_wbt_flow_direction(no_sink_raster_file, flow_dir_file)
plot(flow_dir)
} else {
message("Examples not run as Whitebox executable not found")
}
Run the code above in your browser using DataLab