This function allows the user to get stream networks and watersheds 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 stream network and watersheds (see details).
get_stream_network_interactively(
map = NULL,
ns = "streamnetwork-ui",
viewer = shiny::paneViewer(),
title = "Streamnetwork",
dem = NULL,
threshold = 1000,
...
)
A list of sf objects that the user collected during shiny session as well as flow accumulation and direction paths to tif.
Each list will contain two sf objects: watersheds
and streams
. The streams
object will also return these attributes:
tribid
, strahler
, slope
, length
, mainstem
, FID
, STRM_VAL
.
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 "Streamnetwork".
A raster or terra object dem. (optional)
A threshold for stream initiation. 1000 (default).
other arguments to leafletOutput()
in module and/or wbt_* functions.
This function uses the package elevatr
to download the DEM (unless you provide your own).
Once the user has drawn the bounding box or inputed DEM and selected appropriate zoom (resolution) and threshold then
the app will create basins and streams.
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).
Wait for layers to respond.
Repeat steps 1-4 if needed.
when finished, press 'done' and stream network and watersheds will be saved as a list in local environment with the associated flow accumulation and flow direction.
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()){
streamnetwork <- get_stream_network_interactively()
}
Run the code above in your browser using DataLab