An introduction to rivnet"

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
suppressPackageStartupMessages(library(rivnet))
suppressPackageStartupMessages(library(traudem))

Overview

rivnet enables a seamless R-based extraction of river networks and watershed data from Digital Elevation Models (DEMs) without the need to install and operate GIS software. It is primarily intended as a riverscape-analyzing tool for subsequent ecological, hydrological and biogeochemical modelling.

Features:

rivnet produces river objects, which are compatible with the OCNet package, and can hence be analyzed and displayed with OCNet functions. As such, river objects can be made compatible with the igraph and SSN packages.

Installing the package

rivnet can be installed from CRAN:

install.packages("rivnet")

The development version can be installed from Github:

devtools::install_github("lucarraro/rivnet")

Among other packages, rivnet depends on the traudem package, and in turn, on the TauDEM library. traudem provides a guide to correct installation of TauDEM and its dependencies for different operating systems, and offers wrapper commands to call TauDEM methods from R. Please read the traudem documentation carefully.

Workflow

Functions and output from packages rivnet and OCNet are interoperable according to the following workflow:

knitr::include_graphics("overview_rivnet.png")

The main function of rivnet is extract_river. This function analyzes a DEM and generates a river object. Necessary inputs are either an user-provided DEM or the extent of a region where DEM data should be downloaded from open-source repositories (via the elevatr package); and the coordinates of the outlet(s) of interest. extract_river can also be used as a wrapper for the TauDEM set of functions extracting D8 flow directions and contributing area:

knitr::include_graphics("TauDEM_workflow.png")

river objects obtained from extract_river can then be processed by aggregate_river (which builds a river network at different aggregation levels) and paths_river (which calculates paths and path distances between network nodes). Refer to the OCNet documentation for details on the definition of aggregation levels and the behavior of these functions.

A minimal example

Extract a river (Wigger, Switzerland) from an user-provided DEM:

fp <- system.file("extdata/wigger.tif", package = "rivnet")
r <- extract_river(outlet = c(637478, 237413), DEM = fp)
r
#> Class         : river 
#> Type          : Real river 
#> No. FD nodes  : 8768 
#> Dimensions    : 195 x 242 
#> Cell size     : 208.23 
#> Has elevation : TRUE 
#> Aggregated    : FALSE 

Outlet coordinates must be expressed in the same coordinate system as the input DEM.

The same river can be extracted starting from DEM data downloaded from open-source servers:

r2 <- extract_river(outlet = c(637478, 237413),
    EPSG = 21781, #CH1903/LV03 coordinate system
    ext = c(6.2e5, 6.6e5, 2e5, 2.5e5),
    z = 10)

plot(r2)
knitr::include_graphics("wigger1.png")

A plot method has been defined for river objects, which calls different drawing functions from the OCNet package. Its default behavior depends on the attributes included in the river object:

r2 <- aggregate_river(r2)
plot(r2)
knitr::include_graphics("wigger2.png")

In the first case, plot calls draw_simple_OCN; in the second case, it calls draw_thematic_OCN.

For computational speed issues, the examples provided are derived from rather coarse DEMs. To increase the resolution of the DEM (and thus of the resulting river), it is possible to increase the z value in extract_river (see elevatr documentation for details).

Other functions



Try the rivnet package in your browser

Any scripts or data that you put into this service are public.

rivnet documentation built on April 4, 2025, 1:25 a.m.