Applies a topological sort and calculates strahler stream order. Algorithm: If more than one upstream flowpath has an order equal to the maximum upstream order then the downstream flowpath is assigned the maximum upstream order plus one. Otherwise it is assigned the max upstream order.

get_streamorder(x, status = TRUE)

Arguments

x

data.frame with dendritic ID and toID columns.

status

logical show progress update messages?

Value

numeric stream order in same order as input

Examples

source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))

test_flowline <- prepare_nhdplus(walker_flowline, 0, 0, FALSE)
#> Warning: removing geometry
#> Warning: Removed 0 flowlines that don't apply.
#>  Includes: Coastlines, non-dendritic paths,
#> and networks with drainage area less than 0 sqkm, and drainage basins smaller than FALSE

test_flowline <- data.frame(
ID = test_flowline$COMID, toID = test_flowline$toCOMID)

(order <- get_streamorder(test_flowline))
#>  [1] 4 4 4 4 4 3 3 3 3 2 2 2 2 2 2 1 3 3 3 3 2 2 1 1 2 2 1 1 1 2 1 2 1 1 1 1 1 2
#> [39] 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2

walker_flowline$order <- order plot(sf::st_geometry(walker_flowline), lwd = walker_flowline$order, col = "blue")