Package 'HydroCode'

Title: Hydrological Codes
Description: Pfafstetter Hydrological Codes as cited in Verdin and Verdin (1999) <doi: 10.1016/S0022-1694(99)00011-6> are decoded for upstream or downstream queries.
Authors: Thorsten Pohlert [aut, cre]
Maintainer: Thorsten Pohlert <[email protected]>
License: GPL-3
Version: 1.0.3
Built: 2024-12-06 06:28:28 UTC
Source: CRAN

Help Index


Number Type

Description

is.odd tests whether a number is odd. is.even returns the opposite

Usage

is.odd(x)

is.even(x)

Arguments

x

numeric object to be tested

Value

a vector of type logical

Note

if x contains NA the function returns NA

Examples

x <- seq(1, 9, 2)
is.odd(x)
y <- seq(2, 8, 2)
is.even(y)
# NA values
x[1] <- NA
is.odd(x)

Comparison of Pfafstetter Coded Basins

Description

One point (river segment or subbasin) with Pfafstetter code a on the water system can be queried for beeing upstream or downstream as compared to one or many points b on the water system.

Usage

is.upstream(a, b)

a %up% b

is.downstream(a, b)

a %down% b

Arguments

a

numeric, Pfafstetter coded point

b

numeric, one or more Pfaffstetter coded points

Details

For the scientific background of the Pfafstetter coding system see the literature reference.

The following option(s) can be set via, e.g. options("hydrocode.X" = XX):

hydrocode.parallel:

logical. Defaults to FALSE. The runtime may or may not decrease for very large vectors (length > 50000) on multi-threading processors.

hydrocode.alloddorzero:

logical. Defaults to FALSE. This refers to the original Pfafstetter coding system and tests, whether all n numbers are odd, [13579]{n}. Hydrocodes that contain the digit 0 are interpreted as closed catchments (endorheic basins). This setting works, e.g. with the Pfafstetter coded table riversegments of CCM River and Catchment Database, v2.1 (European Commission - JRC, 2007; Vogt et al., 2007). For decoding the Pfafstetter coded tables of the HydroBASIN, v1c dataset (Lehner and Grill, 2013), this option should be set to options("hydrocode.alloddorzero" = TRUE). This tests for all n numbers are odd or zero, [013579]{n}.

Value

a vector of type logical

References

A. L. de Jager and J. V. Vogt, 2010, Development and Demonstration of a Structured Hydrological Feature Coding System for Europe, Hydrological Sciences Journal, 55, 661–75, doi:10.1080/02626667.2010.490786.

B. Lehner and G. Grill, 2013, Global river hydrography and network routing: baseline data and new approaches to study the world’s large river systems, Hydrological Processes, 27, 2171–2186, doi:10.1002/hyp.9740.

K. L. Verdin and J. P. Verdin, 1999, A topological system for delineation and codification of the Earth’s river basins, Journal of Hydrology, 218, 1–12, doi:10.1016/S0022-1694(99)00011-6.

J. Vogt, P. Soille, A. de Jager, E. Rimavičiūtė, W. Mehl, S. Foisneau, K. Bódis, et al., 2007, A Pan-European River and Catchment Database, Publications Office: Luxembourg, doi:10.2788/35907.

Wikipedia contributors, 2019, Pfafstetter Coding System, In Wikipedia, The Free Encyclopedia, Retrieved 13:23, November 9, 2019, https://en.wikipedia.org/w/index.php?title=Pfafstetter_Coding_System&oldid=907987995

See Also

options

Examples

## example from Wikipedia
## 8835 is upstream of segments 8833 and 8811,
## but not segments 8832, 8821 or 9135
dwn <- c(8833, 8811, 8832, 8821, 9135)
is.upstream(8835, dwn)

## works with operator
8835 %up% dwn

## this will produce errors
## Not run: 
is.upstream("12h", 123)
is.upstream(12.4, 123)

## End(Not run)

## example from Verdin and Verdin, 1999, p. 10
b <- c(8883, 8881, 8879, 8877, 8875, 8873, 8871, 8859,
       8857, 8855, 8853, 8851, 8839, 8837, 8835, 8833,
       8831, 8819, 8817, 8815, 8813, 8811, 8886, 8887,
       8888, 8889)
a <- 8885
a %down% b

## example from Vogt et al. (2007),
## pollution source at 464.
## Which subcatchments are
## affected? Mixed levels of subdivisions.
a <- 464
b <- c(465, 466, 467, 47, 48, 49,
       463, 461, 41, 43, 45, 452,
       454)
a %up% b

## same hydro codes return TRUE per default
112 %up% 112
112 %down% 112

CCM2 River and Catchment of the Rhine Catchment, Rivers only

Description

This spatial dataset is a subset of the data layer RIVERSEGMENTS of the tile WGS84_W2003 from the CCM River and Catchment Database v2.1 (Vogt et al. 2007). The original data format was PGeo (ESRI Personal GeoDatabase). The subset consists of rivers within the Rhine basin, i.e. WSO_ID = 291110. In order to save disk space, the fields of the attribute table were shortened.

Format

An Object of class SpatialLinesDataFrame with 30343 features. The attribute table comprises 2 fields:

WSO1_ID

int, unique river segment identifier

PFAFSTETTER

num, Pfafstetter code according to CCM2

The PROJ.4 string is +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0.

Source

CCM River and Catchment Database (C) European Commission - JRC, 2007.

References

J. Vogt, P. Soille, A. de Jager, E. Rimavičiūtė, W. Mehl, S. Foisneau, K. Bódis, et al., 2007, A Pan-European River and Catchment Database, Publications Office: Luxembourg, doi:10.2788/35907.

Examples

## Not run: 
## get the flowpath from a head catchment to
## the sea
## Be patient, this might take a while.
system.time(fps <- 973842223 %up% rhineCCM2$PFAFSTETTER)
flowpath <- subset(rhineCCM2, subset = fps)
sp::plot(flowpath)

## does parallel threats increase the speed
## and provide the same results?
op.old <- options()
options("hydrocode.parallel" = TRUE)
system.time(fpp <- 973842223 %up% rhineCCM2$PFAFSTETTER)
all.equal(fps, fpp)

## reset previous settings
options(op.old)

## End(Not run)

HydroBASINS Level 08 Data of the Rhine Catchment

Description

This spatial dataset is a subset of the data layer hybas_eu_lev08_v1c from the HydroBASINS v1.c database (Lehner and Grill, 2013). The original data format was SHP (ESRI Shape File). The subset consists of subbasins within the Rhine basin, i.e. MAIN_BAS = 2080023010.

Format

An Object of class SpatialPolygonsDataFrame with 289 features. The attribute table comprises 13 fields:

HYBAS_ID

factor, unique basin identifier

NEXT_DOWN

factor, Hybas_id of the next downstream polygon

NEXT_SINK

factor, Hybas_id of the next downstream sink

MAIN_BAS

factor, Hybas_id of the most downstream sink, i.e. the outlet of the main river basin

DIST_SINK

numeric, Distance from polygon outlet to the next downstream sink along the river network, in kilometers

DIST_MAIN

numeric, Distance from polygon outlet to the most downstream sink, i.e. the outlet of the main river basin along the river network, in kilometers

SUB_AREA

numeric, Area of the individual polygon (i.e. sub-basin), in square kilometers

UP_AREA

numeric, Total upstream area, in square kilometers, calculated from the headwaters to the polygon location (including the polygon)

PFAF_IF

int, the Pfafstetter code

ENDO

int, Indicator for endorheic (inland) basins without surface flow connection to the ocean: 0 = not part of an endorheic basin; 1 = part of an endorheic basin; 2 = sink (i.e. most downstream polygon) of an endorheic basin.

COAST

int, indicator for lumped coastal basins: 0 = no; 1 = yes

ORDER

int, Indicator of river order (classical ordering system): order 1 represents the main stem river from sink to source; order 2 represents all tributaries that flow into a 1 st order river; order 3 represents all tributaries that flow into a 2 nd order river; etc.; order 0 is used for conglomerates of small coastal watersheds

SORT

int, Indicator showing the record number (sequence) in which the original polygons are stored in the shapefile (i.e. counting upwards from 1 in the original shapefile).

The PROJ.4 string is +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84+towgs84=0,0,0

Source

This product rhineHYBASlev08 incorporates data from the HydroSHEDS database which is (C) World Wildlife Fund, Inc. (2006-2013) and has been used herein under license. WWF has not evaluated the data as altered and incorporated within rhineHYBASlev08, and therefore gives no warranty regarding its accuracy, completeness, currency or suitability for any particular purpose. Portions of the HydroSHEDS database incorporate data which are the intellectual property rights of (C) USGS (2006-2008), NASA (2000-2005), ESRI (1992-1998), CIAT (2004-2006), UNEP-WCMC (1993), WWF (2004), Commonwealth of Australia (2007), and Her Royal Majesty and the British Crown and are used under license. The HydroSHEDS database and more information are available at http://www.hydrosheds.org.

References

B. Lehner and G. Grill, 2013, Global river hydrography and network routing: baseline data and new approaches to study the world’s large river systems, Hydrological Processes, 27, 2171–2186, doi:10.1002/hyp.9740.

Examples

## Not run: 
## Catchment of gauge Mainz / Rhein
## HYBAS uses a modified version of Pfafstetter
op.old <- options()
options("hydrocode.alloddorzero" = TRUE)
ok <- is.downstream(23263070, rhineHYBASlev08$PFAF_ID)
MzBas <- subset(rhineHYBASlev08, subset = ok)
sp::plot(rhineHYBASlev08)
sp::plot(MzBas, add = TRUE, col = "red")

## get catchment size
## AEO : 98206 km2 according to website
sum(MzBas$SUB_AREA)

## reset previous settings
options(op.old)

## End(Not run)