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).
get_basin_interactively(
map = NULL,
ns = "basin-ui",
viewer = shiny::paneViewer(),
title = "Delineate Basin",
dem = NULL,
threshold = 1000,
...
)
A sf object that contains watershed polygons the user collected during shiny session.
a background leaflet or mapview map to be used for editing. If NULL a blank mapview canvas will be provided.
string
name for the Shiny namespace
to use. The ns
is unlikely to require a change.
function
for the viewer. See Shiny viewer
.
NOTE: when using browserViewer(browser = getOption("browser"))
to
open the app in the default browser, the browser window will automatically
close when closing the app (by pressing "done" or "cancel") in most browsers.
Firefox is an exception. See Details for instructions on how to enable this
behaviour in Firefox.
string
to customize the title of the UI window. The default
is "Delineate Basin".
A 'SpatRaster' object dem. (optional)
A threshold for stream initiation. 1000 (default).
other arguments to leafletOutput()
in module and/or wbt_* functions.
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.
if(interactive()){
basin_data <- get_basin_interactively()
}
Run the code above in your browser using DataLab