Compute Drain area using WhiteBox
Source:R/TNETshape_computeAreaDrain.R
TNETshape_computeAreaDrain.RdThis function will compute drain area of each segment using WhiteBox algorithms. Confluences nodes are mooved upstream with TNETshape_computeNdAreaDrain().
Arguments
- path_DEM
Path to the raster DEM used for drain area calculation.
- path_segments
Path to the shapefile with segments to merge.
- path_node
Path to the shapefile with all segments nodes.
- export_file
Path to the shapefile with results to create.
- ID_special
paste to
TNETshape_computeNdAreaDrain()
Details
Whitebox algorithms use in this function are the following: (in that order)
1 - Prepare the DEM for computations
wbt_fill_depressions(): To fill all depressions in the shapefile
wbt_fill_burn(): To burn the river network in the shapefile
2- Compute flow accumulations for each DEM pixel
wbt_d8_pointer(): To compute the flow direction of each pixel
wbt_d8_flow_accumulation(): To count how many pixels are upstream
This is used to extract total drain area on each segments
3- Snap nodes on rivers
TNETshape_computeNdAreaDrain(): To create one node for each segments.wbt_snap_pour_points(): Snap on the pixel with the most flow accumulation (to be on a river)
4- Compute sub Watershed drain area (area drain only by the studied segment)
wbt_watershed(): Compute all sub watershed area
wbt_raster_area(): convert ID into drain area
wbt_extract_raster_values_at_points(): Extract D8_flow_accumulation and raster_area on every Nodes, to have total drain area and sub-watershed drain area
This is used to extract sub watershed drain area on each segments
Here is a figure on how sub-watershed area drain are calculated:

Examples
## Read test files
shape_name <- system.file("extdata","TestNetwork_Ardiere.shp", package = "TnetRUI")
shapeND_name <- system.file("extdata","TestNetwork_ND_Ardiere.shp", package = "TnetRUI")
DEM_name <- system.file("extdata","DEM_Ardiere.tif", package = "TnetRUI")
#run computation
result_shape <- "test/TestNetwork_areaDrain.shp"
TNETshape_computeAreaDrain(path_DEM = DEM_name,
path_segments = shape_name,
path_node = shapeND_name,
export_file = result_shape)
#> Warning: cannot create dir 'test/tmp_wbt', reason 'No such file or directory'
#> Warning: `/builds/guillaume.hevin/tnet_rui/public/reference' not recognized as a supported file format. (GDAL error 4)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'res': Cannot create a RasterLayer object from this file.
data_result <- st_read(result_shape,quiet = TRUE)
#> Error: Cannot open "test/TestNetwork_areaDrain.shp"; The file doesn't seem to exist.
data_result[1:5,c('gid_new','areaTot','areaSbv')]
#> Error: object 'data_result' not found