Learn R Programming

openSTARS (version 1.1.0)

derive_streams: Derive stream network from DEM.

Description

Streams are derived from a digital elevation model (DEM) using the GRASS function r.stream.extract. If a stream network is available (see import_data) and burn > 0 it will be first burnt into DEM. Stream topology is derived using the GRASS function r.stream.order.

Usage

derive_streams(burn = 5, accum_threshold = 700, condition = TRUE,
  min_stream_length = 0, dem_name = NULL, clean = TRUE, mem = FALSE)

Arguments

burn

numeric; how many meters should the streams be burned into the DEM? Only applicable if a mapped stream network is provided in import_data.

accum_threshold

integer; accumulation threshold to use (i.e. minimum flow accumulation value in cells that will initiate a new stream). See details below.

condition

logical; should the DEM be conditioned using r.hydrodem'

min_stream_length

integer: minimum stream length in number of DEM raster cells; shorter first order stream segments are deleted; default: 0. See details below.

dem_name

character vector, optional; default: 'dem'; useful if conditioned and / or burnt in DEM raster from previous runs shall be used.

clean

logical; should intermediate raster layer of imported streams ('streams_or') be removed from the GRASS session?

mem

logical; should -m flag in the GRASS function r.watershed be used (for data preparation)?

Value

Nothing. The function produces the following maps:

  • 'streams_r' derived streams (raster)

  • 'streams_v' derived streams with topology (vector)

  • 'dirs' flow directions (raster)

  • 'accums' accumulation values (raster)

  • 'dem_cond' conditioned dem (raster) if condition is TRUE

  • 'dem_[cond]_burn[X]' burnt in DEM (raster) if burn is > 0

The original GRASS map 'dem' is not modified if condition is TRUE and / or burn > 0.

Details

For details on accum_threshold and min_stream_length see the parameters 'threshold' and 'stream_length' at r.stream.extract. It might be useful to not burn in the whole available stream network but only parts of it (e.g., larger streams with higher Strahler stream order only). For this, the stream network needs to be pre-processed (parts could be deleted) before loading it with import_data.

Examples

Run this code
# NOT RUN {
# Initiate GRASS session
if(.Platform$OS.type == "windows"){
  gisbase = "c:/Program Files/GRASS GIS 7.4.0"
  } else {
  gisbase = "/usr/lib/grass74/"
  }
initGRASS(gisBase = gisbase,
    home = tempdir(),
    override = TRUE)

# Load files into GRASS
dem_path <- system.file("extdata", "nc", "elev_ned_30m.tif", package = "openSTARS")
sites_path <- system.file("extdata", "nc", "sites_nc.shp", package = "openSTARS")
setup_grass_environment(dem = dem_path)
import_data(dem = dem_path, sites = sites_path)
gmeta()

# Derive streams from DEM
derive_streams(burn = 0, accum_threshold = 700, condition = TRUE, clean = TRUE)
dem <- readRAST('dem', ignore.stderr = TRUE)
sites <- readVECT('sites_o', ignore.stderr = TRUE)
streams <- readVECT('streams_v', ignore.stderr = TRUE)
plot(dem, col = terrain.colors(20))
lines(streams, col = 'blue', lwd = 2)
points(sites, pch = 4)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab