Skip to contents

Assigns level paths using the stream-leveling approach of NHD and NHDPlus. 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.

Usage

add_levelpaths(
  x,
  name_attribute,
  weight_attribute,
  override_factor = NULL,
  status = FALSE
)

# S3 method for data.frame
add_levelpaths(
  x,
  name_attribute,
  weight_attribute,
  override_factor = NULL,
  status = FALSE
)

# S3 method for hy
add_levelpaths(
  x,
  name_attribute,
  weight_attribute,
  override_factor = NULL,
  status = FALSE
)

Arguments

x

data.frame network compatible with hydroloom_names.

name_attribute

character attribute to be used as name identifiers.

weight_attribute

character attribute to be used as weight.

override_factor

numeric multiplier to use to override name_attribute. See details.

status

boolean if status updates should be printed.

Value

data.frame with id, levelpath_outlet_id, topo_sort, and levelpath columns. See details for more info.

Details

The levelpath algorithm defines upstream mainstem paths through a network. At a given junction with two or more upstream flowpaths, the main path is either 1) the path with the same name, 2) the path with any name, 3) or the path with the larger weight. If the weight_attribute is override_factor times larger on a path, it will be followed regardless of the name_attribute indication.

Examples

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

test_flowline <- add_toids(g)

# use NHDPlus attributes directly
add_levelpaths(test_flowline,
               name_attribute = "GNIS_ID",
               weight_attribute = "ArbolateSu")
#> Simple feature collection with 746 features and 37 fields
#> Geometry type: MULTILINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: 1496152 ymin: 1551203 xmax: 1527383 ymax: 1577303
#> Projected CRS: +proj=aea +lat_0=23 +lon_0=-96 +lat_1=29.5 +lat_2=45.5 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
#> # A tibble: 746 × 38
#>      COMID    toid levelpath_outlet_id Hydroseq LevelPathI
#>  *   <int>   <dbl>               <int>    <int>      <dbl>
#>  1 8897784       0             8897784        1          1
#>  2 8894360 8897784             8897784        2          1
#>  3 8894356 8894360             8897784        3          1
#>  4 8894354 8894356             8897784        4          1
#>  5 8894350 8894354             8894350        5          5
#>  6 8893884 8894350             8894350        6          5
#>  7 8894204 8893884             8894204        7          7
#>  8 8893898 8894204             8894204        8          7
#>  9 8894202 8893884             8894350        9          5
#> 10 8893894 8894202             8894350       10          5
#> # ℹ 736 more rows
#> # ℹ 33 more variables: geom <MULTILINESTRING [m]>, GNIS_ID <chr>,
#> #   GNIS_NAME <chr>, LENGTHKM <dbl>, REACHCODE <chr>, WBAREACOMI <int>,
#> #   FTYPE <chr>, FCODE <int>, StreamLeve <int>, StreamOrde <int>,
#> #   StreamCalc <int>, FromNode <dbl>, ToNode <dbl>, Pathlength <dbl>,
#> #   TerminalPa <dbl>, ArbolateSu <dbl>, Divergence <int>, StartFlag <int>,
#> #   TerminalFl <int>, DnLevel <int>, UpLevelPat <dbl>, UpHydroseq <dbl>, …

# use hy attributes where they can be mapped
add_levelpaths(hy(test_flowline),
               name_attribute = "GNIS_ID",
               weight_attribute = "arbolate_sum")
#> Simple feature collection with 746 features and 37 fields
#> Geometry type: MULTILINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: 1496152 ymin: 1551203 xmax: 1527383 ymax: 1577303
#> Projected CRS: +proj=aea +lat_0=23 +lon_0=-96 +lat_1=29.5 +lat_2=45.5 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
#> # A tibble: 746 × 38
#>         id    toid levelpath_outlet_id topo_sort levelpath
#>      <int>   <dbl>               <int>     <int>     <dbl>
#>  1 8897784       0             8897784         1         1
#>  2 8894360 8897784             8897784         2         1
#>  3 8894356 8894360             8897784         3         1
#>  4 8894354 8894356             8897784         4         1
#>  5 8894350 8894354             8894350         5         5
#>  6 8893884 8894350             8894350         6         5
#>  7 8894204 8893884             8894204         7         7
#>  8 8893898 8894204             8894204         8         7
#>  9 8894202 8893884             8894350         9         5
#> 10 8893894 8894202             8894350        10         5
#> # ℹ 736 more rows
#> # ℹ 33 more variables: geom <MULTILINESTRING [m]>, GNIS_ID <chr>,
#> #   GNIS_NAME <chr>, length_km <dbl>, aggregate_id <chr>, wbid <int>,
#> #   feature_type <chr>, feature_type_code <int>, stream_level <int>,
#> #   stream_order <int>, stream_calculator <int>, fromnode <dbl>, tonode <dbl>,
#> #   pathlength_km <dbl>, terminal_topo_sort <dbl>, arbolate_sum <dbl>,
#> #   divergence <int>, start_flag <int>, terminal_flag <int>, …