Watersheds

Watersheds provides spatial watershed aggregation and drainage-network analysis for a user-supplied outlet location. It identifies the watershed containing that location, its inlet and outlet nodes, and its upstream tributaries.

Figure 9. The Watersheds.IOR4 case-IV inlet and outlet analysis for the bundled Weser-basin data.

Figure 9. The Watersheds.IOR4 function identifies the inlet and outlet nodes for a watershed with four connected river stretches.

This repository is the active development home for the former CRAN package Watersheds. Version 1.1 (2016) is preserved in the project’s Git history. Development from version 1.2.0 replaces the retired rgeos dependency with sf geometry operations while retaining the package’s sp-based S4 API.

Installation

The development version can be installed with:

pak::pak("ArturoTorres/watersheds-r")

Or clone this repository and run R CMD build . from its parent directory.

Quick start

library(Watersheds)
data(WatershedsData)

station <- sp::SpatialPoints(
  cbind(4328448.74, 3118576.86),
  proj4string = methods::slot(WatershedsData$subbasin, "proj4string")
)

watershed <- new(
  "Watershed",
  station = station,
  subbasin = WatershedsData$subbasin,
  zhyd = WatershedsData$zhyd,
  river = WatershedsData$river,
  c1 = WatershedsData$subbasin,
  node = WatershedsData$node
)

result <- Watershed.Order(watershed)

The bundled Weser-basin dataset is illustrative. The algorithmic logic was developed against the EEA’s 2012 ECRINS topology. For other networks, the spatial data must share a projected coordinate reference system and include analogous network attributes: OBJECTID, ELEV, and Shape_Area.

Status and compatibility

The package keeps the historical sp object interface for compatibility with the original release. Internally, geometry predicates and measurements use sf; no retired maptools or rgeos dependency is required.

Development

Run the package checks from the repository parent directory:

R CMD build Watersheds
R CMD check --as-cran Watersheds_1.2.0.tar.gz

The vignette is at vignettes/Watersheds.Rnw. Please report reproducible issues with a small spatial example and the versions of R, sp, and sf.

License

GPL (>= 2). See DESCRIPTION.