plot_fun <- function(x, s, n) {
- plot(sf::st_geometry(x), col = "grey")
- plot(sf::st_geometry(x[x$id %in% n, ]), add = TRUE)
- plot(sf::st_geometry(x[x$id %in% s, ]), col = "red", lwd = 3, add = TRUE)
+ plot(sf::st_geometry(x), col = "grey")
+ plot(sf::st_geometry(x[x$id %in% n, ]), add = TRUE)
+ plot(sf::st_geometry(x[x$id %in% s, ]), col = "red", lwd = 3, add = TRUE)
}
-x <- hy(sf::read_sf(system.file("extdata/new_hope.gpkg", package = "hydroloom")))
+x <- hy(sf::read_sf(system.file("extdata/new_hope.gpkg", package = "hydroloom")))
start <- 8891126
dm <- navigate_hydro_network(x, start, "DM")
diff --git a/docs/reference/navigate_network_dfs.html b/docs/reference/navigate_network_dfs.html
index 35e0eec..951abb9 100644
--- a/docs/reference/navigate_network_dfs.html
+++ b/docs/reference/navigate_network_dfs.html
@@ -100,7 +100,7 @@ Value
Examples
-x <- hy(sf::read_sf(system.file("extdata/new_hope.gpkg", package = "hydroloom")))
+x <- hy(sf::read_sf(system.file("extdata/new_hope.gpkg", package = "hydroloom")))
x <- add_toids(x, return_dendritic = FALSE)
diff --git a/docs/reference/rename_geometry.html b/docs/reference/rename_geometry.html
index 263d515..9c5651c 100644
--- a/docs/reference/rename_geometry.html
+++ b/docs/reference/rename_geometry.html
@@ -78,11 +78,17 @@
Examples
-(g <- sf::st_sf(a=3, geo = sf::st_sfc(sf::st_point(1:2))))
+(g <- sf::st_sf(a=3, geo = sf::st_sfc(sf::st_point(1:2))))
#> Simple feature collection with 1 feature and 1 field
#> Geometry type: POINT
#> Dimension: XY
diff --git a/docs/reference/sort_network.html b/docs/reference/sort_network.html
index 2c4bda8..a738cbd 100644
--- a/docs/reference/sort_network.html
+++ b/docs/reference/sort_network.html
@@ -125,7 +125,7 @@ Value
Examples
- x <- sf::read_sf(system.file("extdata/new_hope.gpkg", package = "hydroloom"))
+
Examples
-x <- sf::read_sf(system.file("extdata/new_hope.gpkg", package = "hydroloom"))
+x <- sf::read_sf(system.file("extdata/new_hope.gpkg", package = "hydroloom"))
-one <- dplyr::select(x)
-two <- sf::st_transform(one, 5070)
+one <- dplyr::select(x)
+two <- sf::st_transform(one, 5070)
attr(one, "sf_column") <- "geotest"
names(one)[names(one) == "geom"] <- "geotest"
diff --git a/docs/search.json b/docs/search.json
index b7367a7..81b6a36 100644
--- a/docs/search.json
+++ b/docs/search.json
@@ -1 +1 @@
-[{"path":"https://doi-usgs.github.io/hydroloom/articles/advanced_network.html","id":"terminology","dir":"Articles","previous_headings":"","what":"Terminology","title":"Topological Sort Based Network Attributes","text":"terms used derived concepts graph theory, HY_Features conceptual data model, NHDPlus data model. Many concepts also presented : Mainstems: logical data model implementing mainstem drainage basin feature types based WaterML2 Part 3: HY Features concepts. article formed early draft paper: Generating reference flow network improved connectivity support durable data integration reproducibility coterminous US.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/advanced_network.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Topological Sort Based Network Attributes","text":"NHDPlus data model, attributes described based , includes many ‘value added attributes’ (VAA). vignette discusses core set VAAs hydroloom can create readily available hydrographic inputs. vignette begins background needed understand attributes , demonstrates create based sample input data. attributes documented NHDPlus manual, every effort made faithfully implement meaning. hydroloom package contains functions generate network attributes, (e.g. add_pfafstetter() Pfafstetter codes add_streamorder() stream orders) vignette focuses network attributes NHDPlus data model revolve around topo_sort levelpath. NHDPlus data model, topo_sort referred hydrosequence functionally equivalent topological sort referred topo_sort hydroloom.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/advanced_network.html","id":"topo_sort","dir":"Articles","previous_headings":"Introduction","what":"topo_sort","title":"Topological Sort Based Network Attributes","text":"Smaller ‘topo_sort’ values guaranteed downstream larger values along connected paths. NHDPlus data model includes attribute called hydrosequence functionally topological sort flowline network. provides integer identifier guaranteed decrease downstream direction. flowlines connected single direction navigation (e.g. parallel tributaries) topo_sort significance. However, two flowlines direct navigation, downstream flowline always smaller topo_sort. hydroloom supports creation topo_sort sort_network() function. hard overstate importance topo_sort, function requires understanding upstream-downstream relationships requires sorted version flowline network. NHDPlus data model, dendritic edge-list topology stored form topo_sort ‘topo_sort’ attribute. equivalent available hydroloom, use topo_sort convention, preferring primary identifier (id) accompanying toid store dendritic edge list.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/advanced_network.html","id":"level-path","dir":"Articles","previous_headings":"Introduction","what":"Level Path","title":"Topological Sort Based Network Attributes","text":"Levelpath values constant along mainstem paths derived topo_sort outlet flowline. level path derived “stream level” assigns integer value mainstem rivers outlet network (see NHDPlus documentation ). Rivers terminating ocean given level 1 level extends way headwaters. Rivers terminating level 1 rivers given level 2, . “Stream leveling” process establishing uniquely identified “level paths” stream network. accomplished set rules determine tributary considered dominant every confluence establish “mainstem rivers” “drainage basin” network. hydroloom supports creation stream level add_streamlevel() function, creation level path add_levelpaths(). hydroloom adopts convention used NHDPlus, assign levelpath topo_sort path’s outlet. See Mainstems: logical data model implementing mainstem drainage basin feature types based WaterML2 Part 3: HY Features concepts depth discussion concepts.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/advanced_network.html","id":"other-derived-network-attributes","dir":"Articles","previous_headings":"Introduction","what":"Other Derived Network Attributes","title":"Topological Sort Based Network Attributes","text":"number additional attributes can derived levelpath topo_sort established. include: (note precise attribute names used ) terminal path: identifier (topo_sort primary id) terminal flowline network. topological sort: identifier upstream flowline mainstem topological sort: identifier downstream flowline mainstem level path: identifier next upstream levelpath mainstem level path: identifier next downstream levelpath mainstem path length: distance network outlet downstream along main path. total drainage area: Total accumulated area upstream flowline’s catchment area. arbolate sum: total accumulated length upstream flowlines. terminal flag: simple 0 1 indicating whether flowline terminal path .","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/advanced_network.html","id":"required-base-attributes","dir":"Articles","previous_headings":"Introduction","what":"Required Base Attributes","title":"Topological Sort Based Network Attributes","text":"Creating levelpath topo_sort identifiers requires set base attributes include: fromnode / tonode id / toid: nodes can used generate edge edge flowline topology. length: length required flowline network determine flow distance, using arbolate sum stream leveling. area: local drainage area flowline useful many contexts primarily used calculate total drainage area. weight_attribute: weight metric required stream leveling determine dominant upstream flowline. NHD, arbolate sum used. However, alternative metrics (e.g. total drainage area) can used instead. name_attribute: Many times, preferable follow consistently named path rather strict physical weight stream leveling. cases name_attribute can provided. divergence: order create [many:1] upstream downstream topology, diverted paths must labeled . attribute 0 normal (already [many:1]) connections, 1 main path divergence, 2 diverted path.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/advanced_network.html","id":"a-visual-introduction-to-the-advanced-network-attributes","dir":"Articles","previous_headings":"","what":"A visual introduction to the advanced network attributes","title":"Topological Sort Based Network Attributes","text":"illustrate concepts attributes, ’ll start “New Hope” demo data included hydroloom package add toid attribute based edge-node topology included data.","code":"# Import data x <- hy(sf::read_sf(system.file(\"extdata/new_hope.gpkg\", package = \"hydroloom\"))) # Strip the data back to the required base attributes fpath <- hydroloom::add_toids( dplyr::select(x, id, fromnode, tonode, divergence, feature_type, da_sqkm, length_km, GNIS_ID) ) # Print head(fpath <- select(sf::st_cast(fpath, \"LINESTRING\"), -tonode, -fromnode, -divergence, -feature_type)) #> Simple feature collection with 6 features and 5 fields #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 1517192 ymin: 1555954 xmax: 1518819 ymax: 1557990 #> CRS: unknown #> # A tibble: 6 × 6 #> id toid da_sqkm length_km GNIS_ID geom #> #> 1 8893864 8894334 4.81 3.24 991288 (1518702 1557298, 1518643 1557297, … #> 2 8894490 8894336 0 0.002 991288 (1517194 1556000, 1517192 1555999) #> 3 8894494 8894490 0.009 0.102 991288 (1517288 1556038, 1517252 1556023, … #> 4 8894334 8894492 0.428 0.073 991288 (1517349 1556090, 1517341 1556077, … #> 5 8894492 8894494 0.0018 0.008 991288 (1517295 1556041, 1517288 1556038) #> 6 8893850 8893864 0.406 0.954 991288 (1518668 1557990, 1518699 1557904, …"},{"path":"https://doi-usgs.github.io/hydroloom/articles/advanced_network.html","id":"topo_sort-and-terminal-id","dir":"Articles","previous_headings":"A visual introduction to the advanced network attributes","what":"topo_sort and terminal ID","title":"Topological Sort Based Network Attributes","text":"removing attributes used generate toid attribute, id toid relation representing connectivity network well attributes required generate sorted network sort_network() sort_network() function sorts flowlines headwaters come first terminal flowline last. Additionally, produces terminal_id representing outlet id network. multiple terminal networks provided, terminal_id allow us group data complete sub networks (convenient parallelization scheme). contrast NHDPlus, terminal path identified topo_sort id outlet flowline (meaning outlet level path left user generate), hydroloom uses stable primary id (COMID NHDPlus) identifying outlets allow topo_sort attribute generated discarded needed. can visualize sorting assigning temporary “topo_sort” value sorted network, row wise. , assign first rows sorted set large values last rows small values line topo_sort order convention NHDPlus.","code":"head(fpath <- sort_network(fpath, split = TRUE)) #> Simple feature collection with 6 features and 6 fields #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 1505349 ymin: 1554873 xmax: 1508920 ymax: 1558708 #> CRS: unknown #> # A tibble: 6 × 7 #> id toid da_sqkm length_km GNIS_ID terminal_id geom #> #> 1 8898302 8.90e6 0.152 0.182 \"98382… 8897784 (1505349 1555718, 150545… #> 2 8896658 8.90e6 1.19 1.37 \"98382… 8897784 (1505455 1555570, 150547… #> 3 8896656 8.90e6 3.86 2.64 \"98382… 8897784 (1506375 1554873, 150644… #> 4 8896664 8.90e6 1.38 1.64 \" \" 8897784 (1507786 1554903, 150781… #> 5 8896624 8.90e6 1.34 1.17 \"98382… 8897784 (1508236 1556343, 150825… #> 6 8896572 8.90e6 1.56 1.77 \" \" 8897784 (1508311 1558708, 150835… fpath['topo_sort'] <- seq(nrow(fpath), 1) plot(fpath['topo_sort'], key.pos = NULL)"},{"path":"https://doi-usgs.github.io/hydroloom/articles/advanced_network.html","id":"level-path-and-outlet-id","dir":"Articles","previous_headings":"A visual introduction to the advanced network attributes","what":"Level Path and outlet ID","title":"Topological Sort Based Network Attributes","text":"generate levelpath attribute, “physical” weight needed determine upstream mainstem confluences. example, ’ll follow NHD convention calculate arbolate sum explicitly. add_levelpaths() function add arbolate sum internally weight explicitly defined. name_attribute identifier can also provided override physical weight_attribute “smaller” river name. optional override_factor parameter signifies physical weight override_factor times (e.g. 5) larger unnamed differently named upstream path, physical weight used favor named id. Finally, let’s visualize advanced VAAs! animation, newly added level path shown blue, outlet flowline colored red. Remembering sort_network() sorts flowlines headwaters come first terminal flowlines last invert network level paths fill outlet head waters. clarity, levelpaths 2 flowlines shown.","code":"# Rename and compute weight fpath$arbolatesum <- accumulate_downstream( dplyr::select(fpath, id, toid, length_km), \"length_km\") plot(sf::st_geometry(fpath), lwd = fpath$arbolatesum / 10) # Get levelpaths fpath <- add_levelpaths(fpath, name_attribute = \"GNIS_ID\",weight_attribute = \"arbolatesum\", status = FALSE, override_factor = 5) #> Loading required namespace: future #> Loading required namespace: future.apply # Print head(fpath) #> Simple feature collection with 6 features and 10 fields #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: 1514059 ymin: 1551922 xmax: 1518746 ymax: 1554515 #> CRS: unknown #> # A tibble: 6 × 11 #> id toid levelpath_outlet_id topo_sort levelpath #> #> 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 #> # ℹ 6 more variables: geom , da_sqkm , length_km , #> # GNIS_ID , terminal_id , arbolatesum plot(fpath[\"topo_sort\"], key.pos = NULL, reset = FALSE) plot(fpath[\"levelpath\"], key.pos = NULL) # Invert plotting order fpath <- dplyr::arrange(fpath, topo_sort) # Level Paths with more then 2 flowlines lp <- dplyr::group_by(fpath, levelpath) %>% dplyr::filter(n() > 2) # Unique Level Path ID lp <- unique(lp$levelpath) # Terminal flowline terminal_fpath <- dplyr::filter(fpath, id %in% terminal_id) gif_file <- \"levelpath.gif\" gifski::save_gif({ for(i in 1:length(lp)) { lp_plot <- dplyr::filter(fpath, levelpath == lp[i]) outlet_plot <- dplyr::filter(lp_plot, id %in% terminal_id) plot(sf::st_geometry(fpath), lwd = 0.5, col = \"grey\") plot(sf::st_geometry(terminal_fpath), lwd = 3, col = \"red\", add = TRUE) plot(sf::st_geometry(dplyr::filter(fpath, levelpath %in% lp[1:i])), add = TRUE) plot(sf::st_geometry(lp_plot), col = \"blue\", add = TRUE) plot(sf::st_geometry(outlet_plot), col = \"red\", lwd = 1.5, add = TRUE) } }, gif_file, delay = 0.5) #> [1] \"C:\\\\Users\\\\dblodgett\\\\active_code\\\\hydroloom\\\\vignettes\\\\levelpath.gif\" knitr::include_graphics(gif_file)"},{"path":"https://doi-usgs.github.io/hydroloom/articles/advanced_network.html","id":"summary","dir":"Articles","previous_headings":"","what":"Summary","title":"Topological Sort Based Network Attributes","text":"entire process sorting network building topo_sort, levelpath, derivative variables wrapped nhdplusTools add_plus_network_attributes function provide performance simplicity. supports parallelization print status updates case input network large. add_plus_network_attributes returns NHDPlus attribute names (truncated per shapefile rules done NHDPlus database). attributes described vignette assume diversions network zero flow diversions treated headwaters. See vignette(\"non-dendritic\") information attributes include connected divergences.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/hydroloom.html","id":"hydroloom","dir":"Articles","previous_headings":"","what":"hydroloom","title":"Hydroloom Overview","text":"Hydroloom designed provide general hydrologic network functionality hydrographic hydrologic data. accomplished 1) hy S3 class, 2) collection utility functions, 3) functions work hydrologic network topology graph, 4) functions create add useful network attributes, 5) functions index data network flow network lines waterbody polygons. introduction covers hy S3 class core flow network topology concepts necessary use hydroloom effectively. latest development open issues, please visit package github repository.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/hydroloom.html","id":"hy-s3-class","dir":"Articles","previous_headings":"","what":"hy S3 class","title":"Hydroloom Overview","text":"Hydroloom implements hy S3 class designed simplify integration hydroloom existing data workflows. hy() converts data.frame hy data.frame attributes compatible hydroloom functions. hy_reverse() converts hy data.frame back original attribute names. can teach hydroloom map attributes hydroloom_name_definitions() hydroloom_names() function.8 hydroloom functions work either hy object data.frame containing names registered hydroloom_names(). attributes added data.frame contain names hydroloom must renamed calling environment. Internally, hy S3 class attribute orig_names shown . orig_names attribute used convert original attribute names back original values. Using hydroloom names hy S3 object note required adopting hydroloom_names_definitions() may helpful people aiming consistent, simple, accurate attribute names.","code":"library(hydroloom) hy_net <- sf::read_sf(system.file(\"extdata/new_hope.gpkg\", package = \"hydroloom\")) |> dplyr::select(COMID, REACHCODE, FromNode, ToNode, Hydroseq, TerminalFl, Divergence) hy(hy_net[1:3,]) #> Simple feature collection with 3 features and 7 fields #> Geometry type: MULTILINESTRING #> Dimension: XY #> Bounding box: xmin: 1517192 ymin: 1555954 xmax: 1518702 ymax: 1557298 #> CRS: unknown #> # A tibble: 3 × 8 #> id aggregate_id fromnode tonode topo_sort terminal_flag divergence #> #> 1 8893864 03030002000018 250031721 250031853 250016373 0 0 #> 2 8894490 03030002000018 250031895 250031854 250015665 0 0 #> 3 8894494 03030002000018 250031897 250031895 250015826 0 0 #> # ℹ 1 more variable: geom attr(hy(hy_net), \"orig_names\") #> COMID REACHCODE FromNode ToNode Hydroseq #> \"id\" \"aggregate_id\" \"fromnode\" \"tonode\" \"topo_sort\" #> TerminalFl Divergence geom #> \"terminal_flag\" \"divergence\" \"geom\""},{"path":[]},{"path":"https://doi-usgs.github.io/hydroloom/articles/hydroloom.html","id":"representing-dendritic-network-topology","dir":"Articles","previous_headings":"Network Representation","what":"Representing Dendritic Network Topology","title":"Hydroloom Overview","text":"network flowlines can represented edge--edge (e.g. edge list) edge-node topology. edge list expresses connectivity edges (flowlines context rivers), requiring nodes (confluences context rivers) inferred. edge-node topology, edges directed nodes directed edges. edge--edge toplogy include intervening nodes. “toid” terminal flowline can either NA , convention, 0 ““. Using 0 empty string preferred within hydroloom handled cases. , long 0 set IDs, little practical difference. hydroloom, edge--edge topology referred “id toid” attributes.","code":"#> id toid fromnode tonode #> 1 3 N1 N3 #> 2 3 N2 N3 #> 3 NA N3 N4"},{"path":"https://doi-usgs.github.io/hydroloom/articles/hydroloom.html","id":"representing-dendritic-network-topology-1","dir":"Articles","previous_headings":"Network Representation","what":"Representing Dendritic Network Topology","title":"Hydroloom Overview","text":"discussed vignette(\"hydroloom\") vignette, hydrologic flow network can represented edge edge (e.g. edge list) topology edge-node topology. case dendritic networks, edge list can stored single “toid” attribute feature nodes redundant one one node feature. non-dendritic networks, edge list can include multiple “toid” attributes feature, necessitating one many relationship can difficult interpret. Nevertheless, U.S. National Hydrography Dataset uses edge-list format “flow table” format capable storing non-dendritic feature topology. Using node topology store flow network, feature flows one one node flows one one node. one one relationship features nodes means topology fits table one row per feature common practice spatial feature data. reason, NHDPlus data model converts NHD “flow table” node topology representation non dendritic topology. downside approach requires creation node identifier. node identifiers table deduplication device enables one many relationship (flow table) represented two one one relationships. Given , hydrologic flow networks, node identifiers can created based edge list discarded longer needed. example edge list topology node topology system, feature ‘1’ flows two edges one node. can represent tabular form duplicated row divergence downstream ‘1’ addition node identifiers shown following tables.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/hydroloom.html","id":"network-graph-representation","dir":"Articles","previous_headings":"Network Representation","what":"Network Graph Representation","title":"Hydroloom Overview","text":"make_index_ids() hydroloom function creates adjacency matrix representation flow network well convenient content useful traversing graph. adjacency matrix used heavily hydroloom functions may useful people want write graph traversal algorithms. companion make_index_ids(), make_fromids() reverses graph adjacency matrix directed opposite direction provided graph. used upstream flow network traversals. example ’ll add dendritic toid explore make_index_ids() output. Now ’ll look thing non dendritic set toids. Notice element ind_id now three rows. indicates one connections matrix three downstream neighbors. lengths element indicates many non NA values column matrix element.","code":"y <- add_toids(hy_net, return_dendritic = TRUE) ind_id <- make_index_ids(y) names(ind_id) #> [1] \"to\" \"lengths\" \"to_list\" dim(ind_id$to) #> [1] 1 746 max(lengths(ind_id$lengths)) #> [1] 1 names(ind_id$to_list) #> [1] \"id\" \"indid\" \"toindid\" sapply(ind_id, class) #> $to #> [1] \"matrix\" \"array\" #> #> $lengths #> [1] \"numeric\" #> #> $to_list #> [1] \"data.frame\" y <- add_toids(st_drop_geometry(hy_net), return_dendritic = FALSE) ind_id <- make_index_ids(y) names(ind_id) #> [1] \"to\" \"lengths\" \"to_list\" dim(ind_id$to) #> [1] 3 746 max(ind_id$lengths) #> [1] 3 sum(ind_id$lengths == 2) #> [1] 84 sum(ind_id$lengths == 3) #> [1] 1 names(ind_id$to_list) #> [1] \"id\" \"indid\" \"toindid\" sapply(ind_id, class) #> $to #> [1] \"matrix\" \"array\" #> #> $lengths #> [1] \"numeric\" #> #> $to_list #> [1] \"data.frame\""},{"path":"https://doi-usgs.github.io/hydroloom/articles/non-dendritic.html","id":"introduction","dir":"Articles","previous_headings":"","what":"Introduction","title":"Non-dendritic networks","text":"vignette(\"hydroloom\") vignette(\"advanced_network\") talks basics network topology representation attributes build strictly dendritic network. vignette expands topics describing hydroloom functionality supports non-dendritic networks.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/non-dendritic.html","id":"non-dendritic-topology-attributes-","dir":"Articles","previous_headings":"","what":"Non-dendritic topology attributes.","title":"Non-dendritic networks","text":"Non-dendritic networks represent downstream diverted flow one path primary others thought secondary. following attributes supported hydroloom help track work primary secondary downstream categorization.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/non-dendritic.html","id":"fromnode-and-tonode","dir":"Articles","previous_headings":"Non-dendritic topology attributes.","what":"fromnode and tonode","title":"Non-dendritic networks","text":"attributes fromnode tonode used store flow network edge node topology every network feature one one node upstream one one node downstream. Nodes useful converting flow network graph useful many analysis contexts single identifier confluence divergence.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/non-dendritic.html","id":"divergence","dir":"Articles","previous_headings":"Non-dendritic topology attributes.","what":"divergence","title":"Non-dendritic networks","text":"divergence attribute indicates downstream connection primary (1) secondary (2). 0, connection downstream divergence. attribute useful facilitates following flow network “downstream mainstem” direction every divergence.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/non-dendritic.html","id":"return-divergence","dir":"Articles","previous_headings":"Non-dendritic topology attributes.","what":"return divergence","title":"Non-dendritic networks","text":"return divergence attribute indicates one features upstream given feature originates divergence. 0, upstream features part diversion. 1, one upstream features part diversion.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/non-dendritic.html","id":"stream-calculator","dir":"Articles","previous_headings":"Non-dendritic topology attributes.","what":"stream calculator","title":"Non-dendritic networks","text":"stream calculator attribute part modified Strahler stream order implemented NHDPlus data model. indicates given feature part downstream mainstem dendritic network part diverted path. 0, path part diversion. Otherwise stream calculator equal stream order. generating Strahler stream order, stream calculator 0 given feature, feature considered incrementing downstream stream order.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/non-dendritic.html","id":"summary","dir":"Articles","previous_headings":"Non-dendritic topology attributes.","what":"summary","title":"Non-dendritic networks","text":"system, stream calculator, divergence return divergence support network navigation processing context diverted paths. feature top diversion divergence set 1. features part diversion yet recombined main path, stream calculator set 0. feature just downstream diversion path recombines main path return diversion set 1.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/articles/non-dendritic.html","id":"bringing-it-all-together","dir":"Articles","previous_headings":"Non-dendritic topology attributes.","what":"Bringing it all together","title":"Non-dendritic networks","text":"example shows can recreate non-dendritic attributes use practice. ’ll start small sample watershed ’s included hydroloom select attributes required recreate non-dendritic network. code, removed attributes ID, name feature type recreated dendritic (toid) non-dendritic (fromnode tonode) topology. added divergence attribute, stream_order, stream_calculator, return_divergence attributes.","code":"x <- sf::read_sf(system.file(\"extdata/new_hope.gpkg\", package = \"hydroloom\")) # First we select only an id, a name, and a feature type. flow_net <- x |> select(COMID, GNIS_ID, FTYPE) |> sf::st_transform(5070) # Now we convert the geometric network to an attribute topology # and convert that to a node topology and join our attributes back flow_net <- flow_net |> make_attribute_topology(min_distance = 5) |> make_node_topology(add_div = TRUE) |> left_join(sf::st_drop_geometry(flow_net), by = \"COMID\") #> Loading required namespace: future #> Loading required namespace: future.apply # We only have one outlet so it doesn't matter if it is coastal # or inland but we have to provide it. outlets <- filter(flow_net, !tonode %in% fromnode) # We have these feature types. A larger dataset might include # things like canals which would not be considered \"major\" unique(flow_net$FTYPE) #> [1] \"StreamRiver\" \"Connector\" \"ArtificialPath\" # now we run the add_divergence, add_toids, and add_streamorder flow_net <- add_divergence(flow_net, coastal_outlet_ids = c(), inland_outlet_ids = outlets$COMID, name_attr = \"GNIS_ID\", type_attr = \"FTYPE\", major_types = unique(flow_net$FTYPE)) |> add_toids() |> add_streamorder() |> add_return_divergence() # Make sure we reproduce what came from our source NHDPlus data. sum(flow_net$divergence == 2) #> [1] 84 sum(x$Divergence == 2) #> [1] 84 all(flow_net$divergence == x$Divergence) #> [1] TRUE sum(flow_net$return_divergence == x$RtnDiv) #> [1] 662 names(flow_net) #> [1] \"COMID\" \"toid\" \"fromnode\" #> [4] \"tonode\" \"GNIS_ID\" \"FTYPE\" #> [7] \"divergence\" \"stream_order\" \"stream_calculator\" #> [10] \"return_divergence\""},{"path":"https://doi-usgs.github.io/hydroloom/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"David Blodgett. Author, maintainer.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Blodgett D (2023). hydroloom: Utilities Weave Hydrologic Fabrics. R package version 1.0.0, https://github.com/DOI-USGS/hydroloom.","code":"@Manual{, title = {hydroloom: Utilities to Weave Hydrologic Fabrics}, author = {David Blodgett}, year = {2023}, note = {R package version 1.0.0}, url = {https://github.com/DOI-USGS/hydroloom}, }"},{"path":"https://doi-usgs.github.io/hydroloom/CONTRIBUTING.html","id":"contributing","dir":"","previous_headings":"","what":"Contributing:","title":"NA","text":"First, thanks considering contribution! hope make package community created resource us gain won’t able without help! Contributions thoroughly tested testthat. Code style attempt follow tidyverse style guide. Please attempt describe want prior contributing submitting issue. Please follow typical github fork - pull-request workflow. Make sure use roxygen run Check contributing. front package matures. hydroloom uses tidyselection data masking. Please review list hydroloom global attribute R/00_hydroloom.R contributing. used package variables tidy selection broadly. notes: - consider running lintr prior contributing. - consider running goodpractice::gp() package contributing. - consider running devtools::spell_check() wrote documentation. - package uses pkgdown. Running pkgdown::build_site() refresh .","code":""},{"path":"https://doi-usgs.github.io/hydroloom/DISCLAIMER.html","id":null,"dir":"","previous_headings":"","what":"Disclaimer","title":"Disclaimer","text":"software preliminary provisional subject revision. provided meet need timely best science. software received final approval U.S. Geological Survey (USGS). warranty, expressed implied, made USGS U.S. Government functionality software related material shall fact release constitute warranty. software provided condition neither USGS U.S. Government shall held liable damages resulting authorized unauthorized use software.","code":""},{"path":[]},{"path":"https://doi-usgs.github.io/hydroloom/index.html","id":"hydroloom","dir":"","previous_headings":"","what":"hydroloom:","title":"Utilities to Weave Hydrologic Fabrics","text":"Install: remotes::install_github(“doi-usgs/hydroloom”) hydroloom collection functions work hydrologic geospatial fabrics. Hydroloom designed provide general hydrologic network functionality hydrographic hydrologic data. package intended developers workflows packages require low level network network data manipulation utilities. Learn , visit pkgdown site: https://doi-usgs.github.io/hydroloom/articles/hydroloom.html Hyroloom support attributes can seen : hydroloom supports attribute names map -built definitions. See hydroloom_names() . hydroloom supports dendritic non-dendritic networks start vignette . hydroloom largely created components nhdplusTools: hydroloom support key functionality nhdplusTools. components nhdplusTools deprecated future version package favor hydroloom implementation. general, nhdplusTools continue support web service functionality particulars NHDPlus data model. contrast, hydroloom intended general focused specifically hydro fabric data functionality. hydroloom implements algorithms documented : NHDPlus Attributes: Graph Concepts: Pfafstetter Attributes:","code":"hydroloom::hydroloom_name_definitions Blodgett, D., Johnson, J.M., 2022, nhdplusTools: Tools for Accessing and Working with the NHDPlus, https://doi.org/10.5066/P97AS8JD Moore, R.B., McKay, L.D., Rea, A.H., Bondelid, T.R., Price, C.V., Dewald, T.G., and Johnston, C.M., 2019, User's guide for the national hydrography dataset plus (NHDPlus) high resolution: U.S. Geological Survey Open-File Report 2019–1096, 66 p., https://doi.org/10.3133/ofr20191096. Cormen, T. H., & Leiserson, C. E. (2022). Introduction to Algorithms, fourth edition. MIT Press. Verdin, K. L., & Verdin, J. P. (1999). A topological system for delineation and codification of the Earth's river basins. Journal of Hydrology, 218(1–2), 1–12. https://doi.org/10.1016/S0022-1694(99)00011-6"},{"path":"https://doi-usgs.github.io/hydroloom/index.html","id":"terminology","dir":"","previous_headings":"hydroloom:","what":"Terminology:","title":"Utilities to Weave Hydrologic Fabrics","text":"following definitions used much possible throughout package. Terms rivers:Flowline: flowline linear geometry represents segment flowing body water. flowlines local drainage area never aggregate features.Flowpath: flowpath linear geometry represents connection catchment’s inlet outlet. flowpaths local drainage area may aggregates flowlines.Catchment: physiographic unit zero one inlets one outlet. catchment represented one partial realizations; flowpath, divide, networks flowpaths divides.Catchment Divide: polygon boundary encompasses catchment.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/index.html","id":"design-notes","dir":"","previous_headings":"hydroloom:","what":"Design Notes:","title":"Utilities to Weave Hydrologic Fabrics","text":"Hydroloom uses tibble dplyr verbs data.frame dropping custom hy attributes. data.table package used key joins enhance scalability dplyr preferred clarity. hy class tibble standardizes attribute names code. graph representation facilitated make_index_ids() make_fromids() names plural referring identifiers singular referring numerical attribute.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/index.html","id":"disclaimer","dir":"","previous_headings":"","what":"Disclaimer","title":"Utilities to Weave Hydrologic Fabrics","text":"software preliminary provisional subject revision. provided meet need timely best science. software received final approval U.S. Geological Survey (USGS). warranty, expressed implied, made USGS U.S. Government functionality software related material shall fact release constitute warranty. software provided condition neither USGS U.S. Government shall held liable damages resulting authorized unauthorized use software.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/accumulate_downstream.html","id":null,"dir":"Reference","previous_headings":"","what":"Accumulate Variable Downstream — accumulate_downstream","title":"Accumulate Variable Downstream — accumulate_downstream","text":"given variable, accumulate according network topology.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/accumulate_downstream.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Accumulate Variable Downstream — accumulate_downstream","text":"","code":"accumulate_downstream(x, var) # S3 method for data.frame accumulate_downstream(x, var) # S3 method for hy accumulate_downstream(x, var)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/accumulate_downstream.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Accumulate Variable Downstream — accumulate_downstream","text":"x data.frame network compatible hydroloom_names. var variable accumulate.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/accumulate_downstream.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Accumulate Variable Downstream — accumulate_downstream","text":"","code":"x <- sf::read_sf(system.file(\"extdata/new_hope.gpkg\", package = \"hydroloom\")) x$totDASqKM <- accumulate_downstream(add_toids(x), \"AreaSqKM\") plot(x['totDASqKM'], lwd = x$totDASqKM / 50)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_divergence.html","id":null,"dir":"Reference","previous_headings":"","what":"Add Divergence Attribute — add_divergence","title":"Add Divergence Attribute — add_divergence","text":"Given non-dendritic flow network required attributes, adds divergence attribute according NHDPlus data model methods.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_divergence.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add Divergence Attribute — add_divergence","text":"","code":"add_divergence( x, coastal_outlet_ids, inland_outlet_ids, name_attr, type_attr, major_types ) # S3 method for data.frame add_divergence( x, coastal_outlet_ids, inland_outlet_ids, name_attr, type_attr, major_types ) # S3 method for hy add_divergence( x, coastal_outlet_ids, inland_outlet_ids, name_attr, type_attr, major_types )"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_divergence.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add Divergence Attribute — add_divergence","text":"x data.frame network compatible hydroloom_names. coastal_outlet_ids vector identifiers network outlets terminate coast. inland_outlet_ids vector identifiers network outlets terminate inland. name_attr character attribute name attribute containing feature name name identifier. type_attr character attribute name attribute containing feature type indicator. major_types vector values type_attr interpreted \"major\". e.g. river might major canal might minor.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_divergence.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Add Divergence Attribute — add_divergence","text":"considering downstream connections diversions, three factors considered determine primary. 1a) name 1b) named 2) feature type (type_attr controls ) 3) flows coast (coastal connection preferred) following list describes order precedence tests 1: 1a, 2, 3 2: 1a, 2 3: NHDPlus uses diverted fraction used currently. 4: 1b, 2, 3 5: 2, 3 6: 1b, 3 7: 3, 8: 1b, 2 9: 2 10: 1b checks return primary connection identified, connection smaller id chosen. case two upstream connections, upstream name use chosen 1) one upstream flowline name 2) one upstream flowlines name matches downstream line, 3) one upstream flowlines \"major\" type others , , 4) criteria exist select one, smallest id value otherwise.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_divergence.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Add Divergence Attribute — add_divergence","text":"","code":"f <- system.file(\"extdata/coastal_example.gpkg\", package = \"hydroloom\") g <- sf::read_sf(f) g <- g[g$FTYPE != \"Coastline\", ] outlets <- g$COMID[!g$ToNode %in% g$FromNode] g <- dplyr::select(g, COMID, gnis_id, FTYPE, FromNode, ToNode) add_divergence(g, coastal_outlet_ids = outlets, inland_outlet_ids = c(), name_attr = \"gnis_id\", type_attr = \"FTYPE\", major_types = c(\"StreamRiver\", \"ArtificialPath\", \"Connector\")) #> Loading required namespace: future #> Loading required namespace: future.apply #> Simple feature collection with 535 features and 6 fields #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: -124.3627 ymin: 39.82399 xmax: -123.7742 ymax: 40.41246 #> Geodetic CRS: NAD83 #> # A tibble: 535 × 7 #> COMID gnis_id FTYPE FromNode ToNode geom divergence #> * #> 1 2544239 NA StreamR… 10092685 1.00e7 (-124.2181 40.41246, -12… 0 #> 2 2544241 229695 StreamR… 10004575 1.00e7 (-124.2256 40.39929, -12… 0 #> 3 2544243 NA StreamR… 10092686 1.00e7 (-124.2439 40.40495, -12… 0 #> 4 2544263 229695 StreamR… 10004579 1.00e7 (-124.2273 40.39801, -12… 0 #> 5 2544287 NA StreamR… 10092696 1.00e7 (-124.1699 40.39544, -12… 0 #> 6 2544289 229695 StreamR… 10004588 1.00e7 (-124.1867 40.38665, -12… 0 #> 7 2544301 229695 StreamR… 10092697 1.00e7 (-124.1666 40.38338, -12… 0 #> 8 2544303 229695 StreamR… 10004594 1.00e7 (-124.2376 40.39235, -12… 0 #> 9 2544309 NA StreamR… 10092700 1.00e7 (-124.3126 40.38182, -12… 0 #> 10 2544311 NA StreamR… 10092701 1.00e7 (-124.2285 40.37687, -12… 0 #> # ℹ 525 more rows"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_levelpaths.html","id":null,"dir":"Reference","previous_headings":"","what":"Add Level Paths — add_levelpaths","title":"Add Level Paths — add_levelpaths","text":"Assigns level paths using stream-leveling approach NHD NHDPlus. arbolate sum provided weight column, match behavior NHDPlus. numeric value can included column largest value followed nameid available.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_levelpaths.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add Level Paths — add_levelpaths","text":"","code":"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 )"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_levelpaths.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add Level Paths — add_levelpaths","text":"x data.frame network compatible hydroloom_names. name_attribute character attribute used name identifiers. weight_attribute character attribute used weight. override_factor numeric multiplier use override name_attribute. See details. status boolean status updates printed.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_levelpaths.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add Level Paths — add_levelpaths","text":"data.frame id, levelpath_outlet_id, topo_sort, levelpath columns. See details info.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_levelpaths.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Add Level Paths — add_levelpaths","text":"levelpath algorithm defines upstream mainstem paths network. given junction two upstream flowpaths, main path either 1) path name, 2) path name, 3) path larger weight. weight_attribute override_factor times larger path, followed regardless name_attribute indication.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_levelpaths.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Add Level Paths — add_levelpaths","text":"","code":"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 #> CRS: unknown #> # A tibble: 746 × 38 #> COMID toid levelpath_outlet_id Hydroseq LevelPathI #> * #> 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 , GNIS_ID , #> # GNIS_NAME , LENGTHKM , REACHCODE , WBAREACOMI , #> # FTYPE , FCODE , StreamLeve , StreamOrde , #> # StreamCalc , FromNode , ToNode , Pathlength , #> # TerminalPa , ArbolateSu , Divergence , StartFlag , #> # TerminalFl , DnLevel , UpLevelPat , UpHydroseq , … # 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 #> CRS: unknown #> # A tibble: 746 × 38 #> id toid levelpath_outlet_id topo_sort levelpath #> #> 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 , GNIS_ID , #> # GNIS_NAME , length_km , aggregate_id , wbid , #> # feature_type , feature_type_code , stream_level , #> # stream_order , stream_calculator , fromnode , tonode , #> # pathlength_km , terminal_topo_sort , arbolate_sum , #> # divergence , start_flag , terminal_flag , …"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_pathlength.html","id":null,"dir":"Reference","previous_headings":"","what":"Add Path Length — add_pathlength","title":"Add Path Length — add_pathlength","text":"Generates main path length basin's terminal path.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_pathlength.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add Path Length — add_pathlength","text":"","code":"add_pathlength(x) # S3 method for data.frame add_pathlength(x) # S3 method for hy add_pathlength(x)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_pathlength.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add Path Length — add_pathlength","text":"x data.frame network compatible hydroloom_names.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_pathlength.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add Path Length — add_pathlength","text":"data.frame containing pathlength_km","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_pathlength.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Add Path Length — add_pathlength","text":"","code":"x <- sf::read_sf(system.file(\"extdata/new_hope.gpkg\", package = \"hydroloom\")) x <- add_toids(x) x <- add_pathlength(x) plot(x[\"Pathlength\"])"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_pfafstetter.html","id":null,"dir":"Reference","previous_headings":"","what":"Add Pfafstetter Codes — add_pfafstetter","title":"Add Pfafstetter Codes — add_pfafstetter","text":"Determines Pfafstetter codes dendritic network total drainage area, levelpath, topo_sort attributes. Topo_sort levelpath attributes must self consistent (levelpath values outlet topo_sort value) generated add_levelpaths.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_pfafstetter.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add Pfafstetter Codes — add_pfafstetter","text":"","code":"add_pfafstetter(x, max_level = 2, status = FALSE) # S3 method for data.frame add_pfafstetter(x, max_level = 2, status = FALSE) # S3 method for hy add_pfafstetter(x, max_level = 2, status = FALSE)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_pfafstetter.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add Pfafstetter Codes — add_pfafstetter","text":"x data.frame network compatible hydroloom_names. max_level integer number levels attempt calculate. network resolution support desired level, unexpected behavior may occur. status boolean status updates printed.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_pfafstetter.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add Pfafstetter Codes — add_pfafstetter","text":"data.frame added pfafstetter column","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_pfafstetter.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Add Pfafstetter Codes — add_pfafstetter","text":"","code":"x <- sf::read_sf(system.file(\"extdata/new_hope.gpkg\", package = \"hydroloom\")) x <- add_toids(x) pfaf <- add_pfafstetter(x, max_level = 2) plot(pfaf[\"pf_level_2\"], lwd = 2) if (FALSE) { if(require(nhdplusTools)) { # uses tempdir for example work_dir <- nhdplusTools::nhdplusTools_data_dir(tempdir()) source(system.file(\"extdata/nhdplushr_data.R\", package = \"nhdplusTools\")) x <- hy(hr_data$NHDFlowline) x <- add_toids(x) x <- dplyr::select(x, id, toid, da_sqkm) #' add terminal_id -- add in function? x <- sort_network(x, split = TRUE) x$total_da_sqkm <- accumulate_downstream(x, \"da_sqkm\") x$name <- \"\" x <- add_levelpaths(x, name_attribute = \"name\", weight_attribute = \"total_da_sqkm\") x <- add_pfafstetter(x, max_level = 3) plot(x[\"pf_level_3\"], lwd = 2) pfaf <- add_pfafstetter(x, max_level = 4) hr_catchment <- dplyr::left_join(hr_data$NHDPlusCatchment, sf::st_drop_geometry(pfaf), by = c(\"FEATUREID\" = \"id\")) colors <- data.frame(pf_level_4 = unique(hr_catchment$pf_level_4), color = sample(terrain.colors(length(unique(hr_catchment$pf_level_4))))) hr_catchment <- dplyr::left_join(hr_catchment, colors, by = \"pf_level_4\") plot(hr_catchment[\"color\"], border = NA, reset = FALSE) plot(sf::st_geometry(x), col = \"blue\", add = TRUE) } }"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_return_divergence.html","id":null,"dir":"Reference","previous_headings":"","what":"Add Return Divergence — add_return_divergence","title":"Add Return Divergence — add_return_divergence","text":"Adds return divergence attribute provided network. method implemented matches NHDPlus except rare case diversion includes one secondary path. Requires id, fromnode, tonode divergence attribute. See add_divergence make_node_topology. Algorithm: network connections one downstream feature considered. navigate_network_dfs used find downstream features emanating primary (divergence == 1) outlet diversion question secondary (divergence == 2) outlet(s) starting primary outlet. navigate_network_dfs called reset = FALSE secondary diversion paths terminate combine previously visited feature. diverted paths result one outlet, feature flows marked return divergence. diverted paths result one outlet, one flows upstream feature set features downstream primary outlet diversion marked return divergence.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_return_divergence.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add Return Divergence — add_return_divergence","text":"","code":"add_return_divergence(x, status = TRUE) # S3 method for data.frame add_return_divergence(x, status = TRUE) # S3 method for hy add_return_divergence(x, status = TRUE)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_return_divergence.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add Return Divergence — add_return_divergence","text":"x data.frame network compatible hydroloom_names. status boolean status updates printed.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_return_divergence.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add Return Divergence — add_return_divergence","text":"data.frame containing return_divergence attribute","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_return_divergence.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Add Return Divergence — add_return_divergence","text":"","code":"x <- sf::read_sf(system.file(\"extdata/new_hope.gpkg\", package = \"hydroloom\")) x <- hy(x) x <- add_return_divergence(x) sum(x$return_divergence == x$RtnDiv) #> [1] 745 # see description for documentation of one that does not match"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_streamlevel.html","id":null,"dir":"Reference","previous_headings":"","what":"Add Streamlevel — add_streamlevel","title":"Add Streamlevel — add_streamlevel","text":"Applies topological sort calculates stream level. Algorithm: Terminal level paths assigned level 1 (see note 1). Paths terminate level 1 assigned level 2. pattern repeated paths remain. TRUE/FALSE coastal attribute included, coastal terminal paths begin 1 internal terminal paths begin 4 implemented NHD stream leveling rules.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_streamlevel.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add Streamlevel — add_streamlevel","text":"","code":"add_streamlevel(x, coastal = NULL) # S3 method for data.frame add_streamlevel(x, coastal = NULL) # S3 method for hy add_streamlevel(x, coastal = NULL)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_streamlevel.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add Streamlevel — add_streamlevel","text":"x data.frame network compatible hydroloom_names. coastal character attribute name containing logical flag indicating given terminal catchment flows coast inland sink. coastal flag included, terminal paths assumed coastal.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_streamlevel.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add Streamlevel — add_streamlevel","text":"data,frame containing added stream_level attribute","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_streamlevel.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Add Streamlevel — add_streamlevel","text":"","code":"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"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_streamorder.html","id":null,"dir":"Reference","previous_headings":"","what":"add Streamorder — add_streamorder","title":"add Streamorder — add_streamorder","text":"Adds strahler stream order. Algorithm: one upstream flowpath order equal maximum upstream order downstream flowpath assigned maximum upstream order plus one. Otherwise assigned maximum upstream order. match NHDPlus algorithm, non-dendritic network connectivity divergence attribute must included. secondary paths stream_order upstream primary paths stream_calculator value 0. Secondary paths affect order downstream paths. Requires toid attribute fromnode, tonode, divergence attributes used construct toid attribute.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_streamorder.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"add Streamorder — add_streamorder","text":"","code":"add_streamorder(x, status = TRUE) # S3 method for data.frame add_streamorder(x, status = TRUE) # S3 method for hy add_streamorder(x, status = TRUE)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_streamorder.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"add Streamorder — add_streamorder","text":"x data.frame network compatible hydroloom_names. status boolean status updates printed.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_streamorder.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"add Streamorder — add_streamorder","text":"data.frame containing added stream_order stream_calculator attribute.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_streamorder.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"add Streamorder — add_streamorder","text":"","code":"x <- sf::read_sf(system.file(\"extdata/new_hope.gpkg\", package = \"hydroloom\")) x <- dplyr::select(x, COMID, FromNode, ToNode, Divergence) x <- add_streamorder(x) plot(sf::st_geometry(x), lwd = x$stream_order, col = \"blue\") plot(sf::st_geometry(x), lwd = x$stream_calculator, col = \"blue\")"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_toids.html","id":null,"dir":"Reference","previous_headings":"","what":"Add Downstream IDs — add_toids","title":"Add Downstream IDs — add_toids","text":"Given input fromnode tonode attributes, return input toid attribute result joining tonode fromnode attributes.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_toids.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add Downstream IDs — add_toids","text":"","code":"add_toids(x, return_dendritic = TRUE) # S3 method for data.frame add_toids(x, return_dendritic = TRUE) # S3 method for hy add_toids(x, return_dendritic = TRUE)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_toids.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add Downstream IDs — add_toids","text":"x data.frame network compatible hydroloom_names. return_dendritic logical remove non dendritic paths TRUE. Requires \"divergence\" flag 1 main 2 secondary.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_toids.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add Downstream IDs — add_toids","text":"hy object toid attribute","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_toids.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Add Downstream IDs — add_toids","text":"","code":"g <- sf::read_sf(system.file(\"extdata/new_hope.gpkg\", package = \"hydroloom\")) x <- add_toids(hy(g)) y <- add_toids(g) names(g)[1:4] #> [1] \"COMID\" \"GNIS_ID\" \"GNIS_NAME\" \"LENGTHKM\" names(x)[1:4] #> [1] \"id\" \"toid\" \"GNIS_ID\" \"GNIS_NAME\" names(y)[1:4] #> [1] \"COMID\" \"toid\" \"GNIS_ID\" \"GNIS_NAME\""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_topo_sort.html","id":null,"dir":"Reference","previous_headings":"","what":"Add topo_sort — add_topo_sort","title":"Add topo_sort — add_topo_sort","text":"calls sort_network without support splitting network adds nrow:1 topo_sort attribute.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_topo_sort.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Add topo_sort — add_topo_sort","text":"","code":"add_topo_sort(x, outlets = NULL) # S3 method for data.frame add_topo_sort(x, outlets = NULL) # S3 method for hy add_topo_sort(x, outlets = NULL)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_topo_sort.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Add topo_sort — add_topo_sort","text":"x data.frame network compatible hydroloom_names. outlets id x. specified, network emanating outlets considered returned. NOTE: outlets include outlets given network containing diversions, partial network may returned.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/add_topo_sort.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Add topo_sort — add_topo_sort","text":"data.frame containing topo_sort attribute.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/align_names.html","id":null,"dir":"Reference","previous_headings":"","what":"Align Names to Hydroloom Convention — align_names","title":"Align Names to Hydroloom Convention — align_names","text":"function aligns attribute names x used hydroloom. See hydroloom_names add attribute name mappings attributes data supported. See hydroloom_name_definitions definitions names used hydroloom.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/align_names.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Align Names to Hydroloom Convention — align_names","text":"","code":"align_names(x)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/align_names.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Align Names to Hydroloom Convention — align_names","text":"x data.frame network compatible hydroloom_names.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/align_names.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Align Names to Hydroloom Convention — align_names","text":"data.frame renamed match hydroloom possible.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/align_names.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Align Names to Hydroloom Convention — align_names","text":"","code":"x <- sf::read_sf(system.file(\"extdata/new_hope.gpkg\", package = \"hydroloom\")) names(x) #> [1] \"COMID\" \"GNIS_ID\" \"GNIS_NAME\" \"LENGTHKM\" \"REACHCODE\" #> [6] \"WBAREACOMI\" \"FTYPE\" \"FCODE\" \"StreamLeve\" \"StreamOrde\" #> [11] \"StreamCalc\" \"FromNode\" \"ToNode\" \"Hydroseq\" \"LevelPathI\" #> [16] \"Pathlength\" \"TerminalPa\" \"ArbolateSu\" \"Divergence\" \"StartFlag\" #> [21] \"TerminalFl\" \"DnLevel\" \"UpLevelPat\" \"UpHydroseq\" \"DnLevelPat\" #> [26] \"DnMinorHyd\" \"DnDrainCou\" \"DnHydroseq\" \"FromMeas\" \"ToMeas\" #> [31] \"RtnDiv\" \"VPUIn\" \"VPUOut\" \"AreaSqKM\" \"TotDASqKM\" #> [36] \"geom\" x <- align_names(x) names(x) #> [1] \"id\" \"GNIS_ID\" #> [3] \"GNIS_NAME\" \"length_km\" #> [5] \"aggregate_id\" \"wbid\" #> [7] \"feature_type\" \"feature_type_code\" #> [9] \"stream_level\" \"stream_order\" #> [11] \"stream_calculator\" \"fromnode\" #> [13] \"tonode\" \"topo_sort\" #> [15] \"levelpath\" \"pathlength_km\" #> [17] \"terminal_topo_sort\" \"arbolate_sum\" #> [19] \"divergence\" \"start_flag\" #> [21] \"terminal_flag\" \"dn_stream_level\" #> [23] \"up_levelpath\" \"up_topo_sort\" #> [25] \"dn_levelpath\" \"dn_minor_topo_sort\" #> [27] \"DnDrainCou\" \"dn_topo_sort\" #> [29] \"aggregate_id_from_measure\" \"aggregate_id_to_measure\" #> [31] \"RtnDiv\" \"VPUIn\" #> [33] \"VPUOut\" \"da_sqkm\" #> [35] \"total_da_sqkm\" \"geom\""},{"path":"https://doi-usgs.github.io/hydroloom/reference/check_hy_graph.html","id":null,"dir":"Reference","previous_headings":"","what":"Check hy Graph — check_hy_graph","title":"Check hy Graph — check_hy_graph","text":"check id toid graph contain localized loops.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/check_hy_graph.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Check hy Graph — check_hy_graph","text":"","code":"check_hy_graph(x, loop_check = FALSE)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/check_hy_graph.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Check hy Graph — check_hy_graph","text":"x data.frame network compatible hydroloom_names. loop_check logical TRUE, entire network walked top bottom searching loops. loop detection algorithm visits node network upstream neighbors visited. complete depth first search performed node, searching paths lead already visited (upstream) node. algorithm often referred \"recursive depth first search\".","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/check_hy_graph.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Check hy Graph — check_hy_graph","text":"localized loops found, returns TRUE. localized loops found, problem rows row number added.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/check_hy_graph.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Check hy Graph — check_hy_graph","text":"","code":"# notice that row 4 (id = 4, toid = 9) and row 8 (id = 9, toid = 4) is a loop. test_data <- data.frame(id = c(1, 2, 3, 4, 6, 7, 8, 9), toid = c(2, 3, 4, 9, 7, 8, 9, 4)) check_hy_graph(test_data) #> # A tibble: 2 × 4 #> toid id row toid_check #> #> 1 4 9 8 9 #> 2 9 4 4 4"},{"path":"https://doi-usgs.github.io/hydroloom/reference/disambiguate_indexes.html","id":null,"dir":"Reference","previous_headings":"","what":"Disambiguate Flowline Indexes — disambiguate_indexes","title":"Disambiguate Flowline Indexes — disambiguate_indexes","text":"Given set flowline indexes numeric ascii criteria, return closest match. numeric criteria used, minimum difference numeric attribute used disambiguation. ascii criteria used, adist function used following algorithm: 1 - adist_score / max_string_length. Comparisons ignore case.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/disambiguate_indexes.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Disambiguate Flowline Indexes — disambiguate_indexes","text":"","code":"disambiguate_indexes(indexes, flowpath, hydro_location)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/disambiguate_indexes.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Disambiguate Flowline Indexes — disambiguate_indexes","text":"indexes data.frame output index_points_to_lines one hydrologic location per indexed point. flowpath data.frame two columns. first join id field indexes second numeric ascii metric drainage area Name. Names data.frame used. hydro_location data.frame two columns. first join id field indexes second numeric ascii metric drainage area GNIS Name. Names data.frame used.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/disambiguate_indexes.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Disambiguate Flowline Indexes — disambiguate_indexes","text":"data.frame indexes deduplicated according minimum difference values metric columns. two result \"minimum\" value, duplicates returned.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/disambiguate_indexes.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Disambiguate Flowline Indexes — disambiguate_indexes","text":"","code":"source(system.file(\"extdata\", \"sample_flines.R\", package = \"nhdplusTools\")) hydro_location <- sf::st_sf(id = c(1, 2, 3), geom = sf::st_sfc(list(sf::st_point(c(-76.86934, 39.49328)), sf::st_point(c(-76.91711, 39.40884)), sf::st_point(c(-76.88081, 39.36354))), crs = 4326), totda = c(23.6, 7.3, 427.9), nameid = c(\"Patapsco\", \"\", \"Falls Run River\")) indexes <- index_points_to_lines(sample_flines, hydro_location, search_radius = units::set_units(0.2, \"degrees\"), max_matches = 10) #> Warning: converting to LINESTRING, this may be slow, check results disambiguate_indexes(indexes, dplyr::select(sample_flines, COMID, TotDASqKM), dplyr::select(hydro_location, id, totda)) #> # A tibble: 3 × 5 #> point_id COMID REACHCODE REACHCODE_measure offset #> #> 1 1 11688298 02060003000579 0 0.0000603 #> 2 2 11688808 02060003000519 53.6 0.000564 #> 3 3 11688950 02060003000254 18.5 0.00113 result <- disambiguate_indexes(indexes, dplyr::select(sample_flines, COMID, GNIS_NAME), dplyr::select(hydro_location, id, nameid)) result[result$point_id == 1, ] #> # A tibble: 3 × 5 #> point_id COMID REACHCODE REACHCODE_measure offset #> #> 1 1 11689928 02060003001468 0 0.00203 #> 2 1 11689978 02060003001472 100 0.00203 #> 3 1 11690532 02060003000256 0 0.00451 result[result$point_id == 2, ] #> # A tibble: 10 × 5 #> point_id COMID REACHCODE REACHCODE_measure offset #> #> 1 2 11688808 02060003000519 53.6 0.000564 #> 2 2 11690110 02060003001493 100 0.00742 #> 3 2 11688822 02060003000518 39.5 0.00768 #> 4 2 11688742 02060003000521 0 0.00855 #> 5 2 11688778 02060003000520 0 0.00855 #> 6 2 11690112 02060003001494 100 0.00955 #> 7 2 11690122 02060003001495 100 0.0103 #> 8 2 11688868 02060003000517 27.8 0.0169 #> 9 2 11690124 02060003001496 100 0.0195 #> 10 2 11690128 02060003001498 100 0.0210 result[result$point_id == 3, ] #> # A tibble: 1 × 5 #> point_id COMID REACHCODE REACHCODE_measure offset #> #> 1 3 11688948 02060003000516 0 0.00321"},{"path":"https://doi-usgs.github.io/hydroloom/reference/drop_geometry.html","id":null,"dir":"Reference","previous_headings":"","what":"Drop Geometry — drop_geometry","title":"Drop Geometry — drop_geometry","text":"drops geometry present, nothing otherwise.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/drop_geometry.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Drop Geometry — drop_geometry","text":"","code":"drop_geometry(x)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/drop_geometry.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Drop Geometry — drop_geometry","text":"x data.frame may contain geometry column","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/drop_geometry.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Drop Geometry — drop_geometry","text":"data.frame without geometry column","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/drop_geometry.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Drop Geometry — drop_geometry","text":"","code":"(g <- sf::st_sf(a=3, geo = sf::st_sfc(sf::st_point(1:2)))) #> Simple feature collection with 1 feature and 1 field #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1 ymin: 2 xmax: 1 ymax: 2 #> CRS: NA #> a geo #> 1 3 POINT (1 2) drop_geometry(g) #> a #> 1 3"},{"path":"https://doi-usgs.github.io/hydroloom/reference/fix_flowdir.html","id":null,"dir":"Reference","previous_headings":"","what":"Fix Flow Direction — fix_flowdir","title":"Fix Flow Direction — fix_flowdir","text":"flowlines digitized expected direction, reorder nodes .","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/fix_flowdir.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Fix Flow Direction — fix_flowdir","text":"","code":"fix_flowdir(id, network = NULL, fn_list = NULL)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/fix_flowdir.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Fix Flow Direction — fix_flowdir","text":"id integer id flowline check network data.frame network compatible hydroloom_names. fn_list list containing named elements flowline, network, check_end, flowline flowline checked network feature downstream flowline checked, check_end \"start\" \"end\" depending network input upstream (\"start\") downstream (\"end\") flowline checked. option allows pre-compilation pairs features may useful large numbers flow direction checks.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/fix_flowdir.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Fix Flow Direction — fix_flowdir","text":"geometry feature reversed needed.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/fix_flowdir.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Fix Flow Direction — fix_flowdir","text":"","code":"x <- sf::read_sf(system.file(\"extdata/new_hope.gpkg\", package = \"hydroloom\")) # We add a tocomid with prepare_nhdplus x <- add_toids(hy(x)) # Look at the end node of the 10th line. (n1 <- get_node(x[10, ], position = \"end\")) #> Simple feature collection with 1 feature and 0 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1520118 ymin: 1560497 xmax: 1520118 ymax: 1560497 #> CRS: unknown #> # A tibble: 1 × 1 #> geometry #> * #> 1 (1520118 1560497) # Break the geometry by reversing it. sf::st_geometry(x)[10] <- sf::st_reverse(sf::st_geometry(x)[10]) # Note that the end node is different now. (n2 <- get_node(x[10, ], position = \"end\")) #> Simple feature collection with 1 feature and 0 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1520229 ymin: 1560983 xmax: 1520229 ymax: 1560983 #> CRS: unknown #> # A tibble: 1 × 1 #> geometry #> * #> 1 (1520229 1560983) # Pass the broken geometry to fix_flowdir with the network for toCOMID sf::st_geometry(x)[10] <- fix_flowdir(x$id[10], x) # Note that the geometry is now in the right order. (n3 <- get_node(x[10, ], position = \"end\")) #> Simple feature collection with 1 feature and 0 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 1520118 ymin: 1560497 xmax: 1520118 ymax: 1560497 #> CRS: unknown #> # A tibble: 1 × 1 #> geometry #> * #> 1 (1520118 1560497) plot(sf::st_geometry(x)[10]) plot(n1, add = TRUE) plot(n2, add = TRUE, col = \"blue\") plot(n3, add = TRUE, cex = 2, col = \"red\")"},{"path":"https://doi-usgs.github.io/hydroloom/reference/format_index_ids.html","id":null,"dir":"Reference","previous_headings":"","what":"Format Index ids — format_index_ids","title":"Format Index ids — format_index_ids","text":"Format Index ids","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/format_index_ids.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Format Index ids — format_index_ids","text":"","code":"format_index_ids(g, return_list = FALSE)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/format_index_ids.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Format Index ids — format_index_ids","text":"g data.frame graph id, inid toindid returned make_index_ids long_form=TRUE. return_list logical TRUE, returned list include \"froms_list\" element containing ids list form.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/format_index_ids.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Format Index ids — format_index_ids","text":"list containing adjacency matrix lengths vector indicating number connections node. complete TRUE return also include data.frame indid column toindid list column.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/format_index_ids.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Format Index ids — format_index_ids","text":"","code":"x <- sf::read_sf(system.file(\"extdata/new_hope.gpkg\", package = \"hydroloom\")) y <- add_toids(x) |> make_index_ids(long_form = TRUE) |> format_index_ids()"},{"path":"https://doi-usgs.github.io/hydroloom/reference/get_hydro_location.html","id":null,"dir":"Reference","previous_headings":"","what":"Get Hydro Location — get_hydro_location","title":"Get Hydro Location — get_hydro_location","text":"given flowline index, returns hydrologic location (point) along specific linear element referenced index.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/get_hydro_location.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get Hydro Location — get_hydro_location","text":"","code":"get_hydro_location(indexes, flowpath)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/get_hydro_location.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get Hydro Location — get_hydro_location","text":"indexes data.frame output index_points_to_lines. flowpath data.frame three columns: id, frommeas, tomeas well geometry.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/get_hydro_location.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get Hydro Location — get_hydro_location","text":"","code":"source(system.file(\"extdata\", \"sample_flines.R\", package = \"nhdplusTools\")) indexes <- index_points_to_lines(sample_flines, sf::st_sfc(sf::st_sfc(list(sf::st_point(c(-76.86934, 39.49328)), sf::st_point(c(-76.91711, 39.40884)), sf::st_point(c(-76.88081, 39.36354))), crs = 4326))) #> Warning: converting to LINESTRING, this may be slow, check results get_hydro_location(indexes, sample_flines) #> Geometry set for 3 features #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: -76.91761 ymin: 39.3633 xmax: -76.8694 ymax: 39.49326 #> Geodetic CRS: WGS 84 #> POINT (-76.8694 39.49326) #> POINT (-76.91761 39.40909) #> POINT (-76.881 39.3633)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/get_node.html","id":null,"dir":"Reference","previous_headings":"","what":"Get Line Node — get_node","title":"Get Line Node — get_node","text":"Given one lines, returns particular node line.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/get_node.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get Line Node — get_node","text":"","code":"get_node(x, position = \"end\")"},{"path":"https://doi-usgs.github.io/hydroloom/reference/get_node.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get Line Node — get_node","text":"x sf sf data.frame one LINESTRING features position character either \"start\" \"end\"","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/get_node.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get Line Node — get_node","text":"sf data.frame containing requested nodes","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/get_node.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get Line Node — get_node","text":"","code":"x <- sf::read_sf(system.file(\"extdata/new_hope.gpkg\", package = \"hydroloom\")) start <- get_node(x, \"start\") end <- get_node(x, \"end\") plot(sf::st_zm(sf::st_geometry(x)), lwd = x$StreamOrde, col = \"blue\") plot(sf::st_geometry(start), add = TRUE) plot(sf::st_zm(sf::st_geometry(x)), lwd = x$StreamOrde, col = \"blue\") plot(sf::st_geometry(end), add = TRUE)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/get_partial_length.html","id":null,"dir":"Reference","previous_headings":"","what":"Get Partial Flowpath Length — get_partial_length","title":"Get Partial Flowpath Length — get_partial_length","text":"Finds upstream downstream lengths along given flowpath (flowline NHDPlus terminology). Internally, function rescales aggregate_id_measure id_measure applies rescaled measure length flowpath.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/get_partial_length.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Get Partial Flowpath Length — get_partial_length","text":"","code":"get_partial_length(hydro_location, network = NULL, flowpath = NULL)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/get_partial_length.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Get Partial Flowpath Length — get_partial_length","text":"hydro_location list containing hydrologic locations names aggregate_id (reachcode) aggregate_id_measure (reachcode measure). network data.frame network compatible hydroloom_names. flowpath data.frame containing one flowpath corresponds hydro_location. required x provided. x required flowpath provided.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/get_partial_length.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Get Partial Flowpath Length — get_partial_length","text":"list containing dn elements numeric length km.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/get_partial_length.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Get Partial Flowpath Length — get_partial_length","text":"","code":"x <- sf::read_sf(system.file(\"extdata\", \"walker.gpkg\", package = \"hydroloom\")) hydro_location <- list(comid = 5329339, reachcode = \"18050005000078\", reach_meas = 30) (pl <- get_partial_length(hydro_location, x)) #> $dn #> [1] 1.4358 #> #> $up #> [1] 3.3502 #>"},{"path":"https://doi-usgs.github.io/hydroloom/reference/hy.html","id":null,"dir":"Reference","previous_headings":"","what":"Create a hy Fabric S3 Object — hy","title":"Create a hy Fabric S3 Object — hy","text":"converts compatible dataset fabric s3 class","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/hy.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Create a hy Fabric S3 Object — hy","text":"","code":"hy(x, clean = FALSE)"},{"path":"https://doi-usgs.github.io/hydroloom/reference/hy.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Create a hy Fabric S3 Object — hy","text":"x data.frame network compatible hydroloom_names. clean logical TRUE, geometry non-hydroloom compatible attributes removed.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/hy.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Create a hy Fabric S3 Object — hy","text":"hy object attributes compatible hydroloom package.","code":""},{"path":"https://doi-usgs.github.io/hydroloom/reference/hy.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Create a hy Fabric S3 Object — hy","text":"","code":"x <- sf::read_sf(system.file(\"extdata/new_hope.gpkg\", package = \"hydroloom\")) hy(x) #> Simple feature collection with 746 features and 35 fields #> Geometry type: MULTILINESTRING #> Dimension: XY #> Bounding box: xmin: 1496152 ymin: 1551203 xmax: 1527383 ymax: 1577303 #> CRS: unknown #> # A tibble: 746 × 36 #> id GNIS_ID GNIS_NAME length_km aggregate_id wbid feature_type #> #> 1 8893864 991288 Northeast Creek 3.24 03030002000018 0 StreamRiver #> 2 8894490 991288 Northeast Creek 0.002 03030002000018 0 Connector #> 3 8894494 991288 Northeast Creek 0.102 03030002000018 0 Connector #> 4 8894334 991288 Northeast Creek 0.073 03030002000018 8892958 ArtificialP… #> 5 8894492 991288 Northeast Creek 0.008 03030002000018 8892958 ArtificialP… #> 6 8893850 991288 Northeast Creek 0.954 03030002000019 0 StreamRiver #> 7 8893842 991288 Northeast Creek 0.219 03030002000020 0 StreamRiver #> 8 8894192 991288 Northeast Creek 3.09 03030002000021 0 StreamRiver #> 9 8894310 991288 Northeast Creek 0.045 03030002000021 8892932 ArtificialP… #> 10 8893810 991288 Northeast Creek 0.583 03030002000022 0 StreamRiver #> # ℹ 736 more rows #> # ℹ 29 more variables: feature_type_code , stream_level , #> # stream_order , stream_calculator , fromnode , tonode , #> # topo_sort , levelpath , pathlength_km , #> # terminal_topo_sort