Calculates level paths using the stream-leveling approach of NHD and NHDPlus. In addition to a levelpath identifier, a topological sort and levelpath outlet identifier is provided in output. If arbolate sum is provided in the weight column, this will match the behavior of NHDPlus. Any numeric value can be included in this column and the largest value will be followed when no nameID is available.

get_levelpaths(x, override_factor = NULL, status = FALSE, cores = NULL)

Arguments

x

data.frame with ID, toID, nameID, and weight columns.

override_factor

numeric factor to use to override nameID. If `weight` is `numeric_factor` times larger on a path, it will be followed regardless of the nameID indication.

status

boolean if status updates should be printed.

cores

numeric number of cores to use in initial path ranking calculations.

Value

data.frame with ID, outletID, topo_sort, and levelpath columns. See details for more info.

Details

  1. levelpath provides an identifier for the collection of flowlines that make up the single mainstem flowpath of a total upstream aggregate catchment.

  2. outletID is the catchment ID (COMID in the case of NHDPlus) for the catchment at the outlet of the levelpath the catchment is part of.

  3. topo_sort is similar to Hydroseq in NHDPlus in that large topo_sort values are upstream of small topo_sort values. Note that there are many valid topological sort orders of a directed graph.

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,
  nameID = walker_flowline$GNIS_ID,
  weight = walker_flowline$ArbolateSu,
  stringsAsFactors = FALSE)

get_levelpaths(test_flowline)
#> # A tibble: 62 × 4
#>         ID outletID topo_sort levelpath
#>      <int>    <int>     <int>     <dbl>
#>  1 5329303  5329303         1         1
#>  2 5329295  5329295         2         2
#>  3 5329293  5329303         3         1
#>  4 5329291  5329291         4         4
#>  5 5329305  5329303         5         1
#>  6 5329299  5329299         6         6
#>  7 5329297  5329299         7         6
#>  8 5329317  5329303         8         1
#>  9 5329333  5329333         9         9
#> 10 5329315  5329303        10         1
#> # … with 52 more rows