get_basin_interactively {gwavr} | R Documentation |
Get Watershed Basin Interactively
Description
This function allows the user to delineate watershed basins interactively with a shiny app. It uses the elevatr package to acquire the Digital Elevation Model (DEM) or user inputted DEM and whitebox package to delineate the basin (see details).
Usage
get_basin_interactively(
map = NULL,
ns = "basin-ui",
viewer = shiny::paneViewer(),
title = "Delineate Basin",
dem = NULL,
threshold = 1000,
...
)
Arguments
map |
a background leaflet or mapview map to be used for editing. If NULL a blank mapview canvas will be provided. |
ns |
|
viewer |
|
title |
|
dem |
A 'SpatRaster' object dem. (optional) |
threshold |
A threshold for stream initiation. 1000 (default). |
... |
other arguments to |
Details
This function will throw an error if you don't draw the bounding box (rectangle) first and you didn't include your own DEM. Once the user has drawn the bounding box (or added own DEM) then you can use the marker as a pour point location.
Steps
Input a well-suited DEM zoom level and threshold. (skip if own DEM is inputted)
Draw bounding box (rectangle or polygon) (skip if own DEM is inputted).
Use marker to place pour point(s).
If necessary, change 'Cell Threshold' to change drainage density.
Repeat steps 1-4 if needed.
When finished, press 'done' and basins will be saved as a list in local environment.
In addition, this function uses both whitebox::wbt_feature_preserving_smoothing()
and whitebox::wbt_breach_depressions()
prior to running the flow direction and flow accumulation (both d8) algorithms.
Value
A sf object that contains watershed polygons the user collected during shiny session.
Note
The marker will only work for the most current stream raster. You can have multiple areas but you need to make sure that you are on the most current raster when selecting basins or the app will crash. If you add your own DEM then you don't need to draw a bounding box.
Examples
if(interactive()){
basin_data <- get_basin_interactively()
}