Skip to contents

Applies a topological sort and calculates stream level. Algorithm: Terminal level paths are assigned level 1 (see note 1). Paths that terminate at a level 1 are assigned level 2. This pattern is repeated until no paths remain.

If a TRUE/FALSE coastal attribute is included, coastal terminal paths begin at 1 and internal terminal paths begin at 4 as is implemented by the NHD stream leveling rules.

Usage

add_streamlevel(x, coastal = NULL)

# S3 method for data.frame
add_streamlevel(x, coastal = NULL)

# S3 method for hy
add_streamlevel(x, coastal = NULL)

Arguments

x

data.frame network compatible with hydroloom_names.

coastal

character attribute name containing a logical flag indicating if a given terminal catchment flows to the coast of is an inland sink. If no coastal flag is included, all terminal paths are assumed to be coastal.

Value

data,frame containing added stream_level attribute

Examples

x <- sf::read_sf(system.file("extdata/new_hope.gpkg", package = "hydroloom"))

x <- add_toids(x)

y <- add_streamlevel(x)
#> Warning: Outlets don't follow hydroloom convention of 0 or '', not fixing.
#> Warning: no outlet found -- will start from outlets that go no where.

plot(sf::st_geometry(y), lwd = y$streamlevel, col = "blue")
#> Warning: Unknown or uninitialised column: `streamlevel`.
#> Warning: 'x' is NULL so the result will be NULL


x$coastal <- rep(FALSE, nrow(x))

y <- add_streamlevel(x, coastal = "coastal")
#> Warning: Outlets don't follow hydroloom convention of 0 or '', not fixing.
#> Warning: no outlet found -- will start from outlets that go no where.

unique(y$streamlevel)
#> Warning: Unknown or uninitialised column: `streamlevel`.
#> NULL

x$coastal[!x$Hydroseq == min(x$Hydroseq)] <- TRUE

y <- add_streamlevel(x)
#> Warning: Outlets don't follow hydroloom convention of 0 or '', not fixing.
#> Warning: no outlet found -- will start from outlets that go no where.

unique(y$streamlevel)
#> Warning: Unknown or uninitialised column: `streamlevel`.
#> NULL