get_watersheds {rdwplus}R Documentation

Delineate watersheds for survey sites

Description

This function delineates watersheds around a set of survey sites.

Usage

get_watersheds(sites, flow_dir, out, overwrite = FALSE, lessmem = FALSE)

Arguments

sites

A file path to a shapefile of points.

flow_dir

The name of a flow direction grid in the current GRASS mapset.

out

The names of the output watershed rasters.

overwrite

A logical indicating whether the output should be allowed to overwrite existing files. Defaults to FALSE.

lessmem

A logical indicating whether to use the less memory modified watershed module. Defaults to FALSE. If set to TRUE, the r.wateroutlet.lessmem extension module must be installed. It can be installed using the GRASS GUI.

Value

Nothing. A raster file with the name out may be written to file if you have set the write_file argument accordingly. A raster with the name basename(out) will be imported into the current GRASS mapset.

Examples

# Will only run if GRASS is running
if(check_running()){
# Retrieve paths to data sets
dem <- system.file("extdata", "dem.tif", package = "rdwplus")
lus <- system.file("extdata", "landuse.tif", package = "rdwplus")
sts <- system.file("extdata", "site.shp", package = "rdwplus")
stm <- system.file("extdata", "streams.shp", package = "rdwplus")

# Set environment
set_envir(dem)

# Get other data sets (stream layer, sites, land use, etc.)
raster_to_mapset(lus)
vector_to_mapset(c(stm, sts))

# Reclassify streams
out_stream <- paste0(tempdir(), "/streams.tif")
rasterise_stream("streams", out_stream, TRUE)
reclassify_streams("streams.tif", "streams01.tif", overwrite = TRUE)

# Burn in the streams to the DEM
burn_in("dem.tif", "streams01.tif", "burndem.tif", overwrite = TRUE)

# Fill dem
fill_sinks("burndem.tif", "filldem.tif", "fd1.tif", "sinks.tif", overwrite = TRUE)

# Derive flow direction and accumulation grids
derive_flow("dem.tif", "fd.tif", "fa.tif", overwrite = T)

# Derive a new stream raster from the FA grid
derive_streams("dem.tif", "fa.tif", "new_stm.tif", "new_stm", min_acc = 200, overwrite = T)

# Recode streams
reclassify_streams("new_stm.tif", "null_stm.tif", "none")

# Snap sites to streams and flow accumulation
snap_sites("site", "new_stm.tif", "fa.tif", 2, "snapsite", T)

# Get watersheds
get_watersheds("snapsite", "fd.tif", "wshed.tif", T)
}

[Package rdwplus version 1.0.0 Index]