Learn R Programming

gwavr (version 0.3.2)

get_basin_interactively: 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,
  ...
)

Value

A sf object that contains watershed polygons the user collected during shiny session.

Arguments

map

a background leaflet or mapview map to be used for editing. If NULL a blank mapview canvas will be provided.

ns

string name for the Shiny namespace to use. The ns is unlikely to require a change.

viewer

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.

title

string to customize the title of the UI window. The default is "Delineate Basin".

dem

A 'SpatRaster' object dem. (optional)

threshold

A threshold for stream initiation. 1000 (default).

...

other arguments to leafletOutput() in module and/or wbt_* functions.

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

  1. Input a well-suited DEM zoom level and threshold. (skip if own DEM is inputted)

  2. Draw bounding box (rectangle or polygon) (skip if own DEM is inputted).

  3. Use marker to place pour point(s).

  4. If necessary, change 'Cell Threshold' to change drainage density.

  5. Repeat steps 1-4 if needed.

  6. 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.

Examples

Run this code

if(interactive()){
basin_data <- get_basin_interactively()
}


Run the code above in your browser using DataLab