given a tree with an id and and toid in the first and second columns, returns a sorted and potentially split set of output.
Can also be used as a very fast implementation of upstream with tributaries navigation. The full network from each outlet is returned in sorted order.
get_sorted(x, split = FALSE, outlets = NULL)
data.frame with an identifier and to identifier in the first and second columns.
logical if TRUE, the result will be split into independent networks identified by the id of their outlet. The outlet id of each independent network is added as a "terminalID" attribute.
same as id in x; if specified only the network emanating from these outlets will be considered and returned.
data.frame containing a topologically sorted version of the requested network and optionally a terminal id.
source(system.file("extdata/new_hope_data.R", package = "nhdplusTools"))
fpath <- get_tocomid(
dplyr::select(new_hope_flowline, COMID, FromNode, ToNode, Divergence, FTYPE,
AreaSqKM, LENGTHKM, GNIS_ID)
)
head(fpath <- get_sorted(fpath, split = TRUE))
#> Simple feature collection with 6 features and 10 fields
#> Geometry type: LINESTRING
#> Dimension: XY
#> Bounding box: xmin: 1505349 ymin: 1554873 xmax: 1508920 ymax: 1558708
#> Projected CRS: +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
#> # A tibble: 6 × 11
#> comid tocomid tonode divergence ftype areasqkm lengthkm gnis_id fromnode
#> <int> <dbl> <dbl> <int> <chr> <dbl> <dbl> <chr> <dbl>
#> 1 8898302 8896658 250032382 0 Artif… 0.152 0.182 "98382… 2.50e8
#> 2 8896658 8896656 250032381 0 Strea… 1.19 1.37 "98382… 2.50e8
#> 3 8896656 8896624 250032375 0 Strea… 3.86 2.64 "98382… 2.50e8
#> 4 8896664 8896624 250032375 0 Strea… 1.38 1.64 " " 2.50e8
#> 5 8896624 8896570 250032361 0 Strea… 1.34 1.17 "98382… 2.50e8
#> 6 8896572 8896570 250032361 0 Strea… 1.56 1.77 " " 2.50e8
#> # ℹ 2 more variables: terminalID <int>, geom <LINESTRING [m]>
fpath['sort_order'] <- 1:nrow(fpath)
plot(fpath['sort_order'])