diff --git a/_pkgdown.yml b/_pkgdown.yml index 8d8eaf29..f52193bb 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -19,6 +19,7 @@ reference: - '`get_elev_along_path`' - '`rpu_boundaries`' - '`vpu_boundaries`' + - '`get_boundaries`' - title: Discovery and Subsetting desc: > Functions for finding and saving the part of the NHDPlus you are @@ -59,6 +60,7 @@ reference: - '`disambiguate_flowline_indexes`' - '`get_partial_length`' - '`get_path_lengths`' + - '`get_path_members`' - title: Network Navigation desc: > Functions to traverse and return network subsets. All except `navigate_nldi()` @@ -100,5 +102,6 @@ reference: - '`get_levelpaths`' - '`get_pathlength`' - '`get_streamorder`' + - '`get_terminal`' - '`add_plus_network_attributes`' - '`get_pfaf`' diff --git a/docs/404.html b/docs/404.html index 1683169a..14abe557 100644 --- a/docs/404.html +++ b/docs/404.html @@ -39,7 +39,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -122,7 +122,7 @@

Page not found (404)

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/DISCLAIMER.html b/docs/DISCLAIMER.html index 8fe9dca9..68f8c360 100644 --- a/docs/DISCLAIMER.html +++ b/docs/DISCLAIMER.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -73,9 +73,9 @@

Disclaimer

-

This information is preliminary or provisional and is subject to revision. It is being provided to meet the need for timely best science. The information has not received final approval by the U.S. Geological Survey (USGS) and is provided on the condition that neither the USGS nor the U.S. Government shall be held liable for any damages resulting from the authorized or unauthorized use of the information.

-

This software is in the public domain because it contains materials that originally came from the U.S. Geological Survey (USGS), an agency of the United States Department of Interior. For more information, see the official USGS copyright policy at https://www.usgs.gov/information-policies-and-instructions/copyrights-and-credits

-

Although this software program has been used by the USGS, no warranty, expressed or implied, is made by the USGS or the U.S. Government as to the accuracy and functioning of the program and related program material nor shall the fact of distribution constitute any such warranty, and no responsibility is assumed by the USGS in connection therewith. This software is provided “AS IS.”

+

This software has been approved for release by the U.S. Geological Survey (USGS). Although the software has been subjected to rigorous review, the USGS reserves the right to update the software as needed pursuant to further analysis and review. No warranty, expressed or implied, is made by the USGS or the U.S. Government as to the functionality of the software and related material nor shall the fact of release constitute any such warranty. Furthermore, the software is released on condition that neither the USGS nor the U.S. Government shall be held liable for any damages resulting from its authorized or unauthorized use.

+

From: https://www2.usgs.gov/fsp/fsp_disclaimers.asp#5

+

This software is in the public domain because it contains materials that originally came from the U.S. Geological Survey, an agency of the United States Department of Interior. For more information, see the official USGS copyright policy

@@ -93,7 +93,7 @@

Disclaimer

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 969cedc7..154607fe 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -204,7 +204,7 @@

License

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/articles/US_data.html b/docs/articles/US_data.html index 9d9335d8..ab4b9dc3 100644 --- a/docs/articles/US_data.html +++ b/docs/articles/US_data.html @@ -40,7 +40,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -116,376 +116,490 @@

TL;DR

Pick an outlet location and download some data.

-# Uncomment to install!
-# install.packages("nhdplusTools")
-
-library(nhdplusTools)
-library(sf)
-
-start_point <- st_sfc(st_point(c(-89.362239, 43.090266)), crs = 4269)
-start_comid <- discover_nhdplus_id(start_point)
-
-flowline <- navigate_nldi(list(featureSource = "comid", 
-                               featureID = start_comid), 
-                          mode = "upstreamTributaries", 
-                          distance_km = 1000)
-
-subset_file <- tempfile(fileext = ".gpkg")
-subset <- subset_nhdplus(comids = as.integer(flowline$UT$nhdplus_comid),
-                         output_file = subset_file,
-                         nhdplus_data = "download", 
-                         flowline_only = FALSE,
-                         return_data = TRUE, overwrite = TRUE)
-#> All intersections performed in latitude/longitude.
-#> Reading NHDFlowline_Network
-#> Writing NHDFlowline_Network
-#> Reading CatchmentSP
-#> Writing CatchmentSP
-
-flowline <- subset$NHDFlowline_Network
-catchment <- subset$CatchmentSP
-waterbody <- subset$NHDWaterbody
-
-## Or using a file:
-
-flowline <- sf::read_sf(subset_file, "NHDFlowline_Network")
-catchment <- sf::read_sf(subset_file, "CatchmentSP")
-waterbody <- sf::read_sf(subset_file, "NHDWaterbody")
-
-plot(sf::st_geometry(flowline), col = "blue")
-plot(start_point, cex = 1.5, lwd = 2, col = "red", add = TRUE)
-plot(sf::st_geometry(catchment), add = TRUE)
-plot(sf::st_geometry(waterbody), col = rgb(0, 0, 1, alpha = 0.5), add = TRUE)
+# Uncomment to install! +# install.packages("nhdplusTools") + +library(nhdplusTools) +library(sf) + +start_point <- st_sfc(st_point(c(-89.362239, 43.090266)), crs = 4269) +start_comid <- discover_nhdplus_id(start_point) + +flowline <- navigate_nldi(list(featureSource = "comid", + featureID = start_comid), + mode = "upstreamTributaries", + distance_km = 1000) + +subset_file <- tempfile(fileext = ".gpkg") +subset <- subset_nhdplus(comids = as.integer(flowline$UT$nhdplus_comid), + output_file = subset_file, + nhdplus_data = "download", + flowline_only = FALSE, + return_data = TRUE, overwrite = TRUE) +#> All intersections performed in latitude/longitude. +#> Reading NHDFlowline_Network +#> Spherical geometry (s2) switched off +#> Spherical geometry (s2) switched on +#> Writing NHDFlowline_Network +#> Reading CatchmentSP +#> Spherical geometry (s2) switched off +#> Spherical geometry (s2) switched on +#> Writing CatchmentSP +#> Spherical geometry (s2) switched off +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar +#> Spherical geometry (s2) switched on + +flowline <- subset$NHDFlowline_Network +catchment <- subset$CatchmentSP +waterbody <- subset$NHDWaterbody + +## Or using a file: + +flowline <- sf::read_sf(subset_file, "NHDFlowline_Network") +catchment <- sf::read_sf(subset_file, "CatchmentSP") +waterbody <- sf::read_sf(subset_file, "NHDWaterbody") + +plot(sf::st_geometry(flowline), col = "blue") +plot(start_point, cex = 1.5, lwd = 2, col = "red", add = TRUE) +plot(sf::st_geometry(catchment), add = TRUE) +plot(sf::st_geometry(waterbody), col = rgb(0, 0, 1, alpha = 0.5), add = TRUE)

-

Or fetch NWIS an site as the starting point and generate a plot. Data is returned and/or stored in a local file for later use.

+

Or fetch NWIS an site as the starting point and generate a plot. Data +is returned and/or stored in a local file for later use.

-# ?plot_nhdplus for more
-plot_data <- plot_nhdplus(
-  outlets = list(featureSource = "nwissite", featureID = "USGS-05428500"), 
-  gpkg = subset_file, overwrite = TRUE)
-#> Zoom: 10
-#> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
-#> Audotdetect projection: assuming Google Mercator (epsg 3857)
+# ?plot_nhdplus for more +plot_data <- plot_nhdplus( + outlets = list(featureSource = "nwissite", featureID = "USGS-05428500"), + gpkg = subset_file, overwrite = TRUE) +#> Spherical geometry (s2) switched off +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar +#> Spherical geometry (s2) switched on +#> Zoom: 10 +#> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL. +#> Audotdetect projection: assuming Google Mercator (epsg 3857)

-

This vignette covers a range of utilities the nhdplusTools package offers for working with data in a U.S. context.

-

The first thing you are going to need to do is go get some data to work with. nhdplusTools provides the ability to download small subsets of the NHDPlus directly from web services. For large subsets, greater than a few thousand square kilometers, you can use download_nhdplusv2().

-

If you are working with the whole National Seamless database, nhdplusTools has some convenience functions you should be aware of. Once you have it downloaded and extracted, you can tell the nhdplusTools package where it is with the nhdplus_path() function.

+

This vignette covers a range of utilities the nhdplusTools package +offers for working with data in a U.S. context.

+

The first thing you are going to need to do is go get some data to +work with. nhdplusTools provides the ability to download +small subsets of the NHDPlus directly from web services. For large +subsets, greater than a few thousand square kilometers, you can use +download_nhdplusv2().

+

If you are working with the whole National Seamless database, +nhdplusTools has some convenience functions you should be +aware of. Once you have it downloaded and extracted, you can tell the +nhdplusTools package where it is with the nhdplus_path() +function.

-nhdplus_path(file.path(work_dir, "natseamless.gpkg"))
-
-basename(nhdplus_path())
-#> [1] "natseamless.gpkg"
-

If you are going to be loading and reloading the flowlines, flowline attributes, or catchments, repeatedly, the stage_national_data() function will speed things up a bit. It creates three staged files that are quicker for R to read at the path you tell it. If you call it and its output files exist, it won’t overwrite and just return the paths to your staged files.

+nhdplus_path(file.path(work_dir, "natseamless.gpkg")) + +basename(nhdplus_path()) +#> [1] "natseamless.gpkg" +

If you are going to be loading and reloading the flowlines, flowline +attributes, or catchments, repeatedly, the +stage_national_data() function will speed things up a bit. +It creates three staged files that are quicker for R to read at the path +you tell it. If you call it and its output files exist, it won’t +overwrite and just return the paths to your staged files.

-staged_data <- stage_national_data(output_path = tempdir())
-
-str(lapply(staged_data, basename))
-#> List of 3
-#>  $ attributes: chr "nhdplus_flowline_attributes.rds"
-#>  $ flowline  : chr "nhdplus_flowline.rds"
-#>  $ catchment : chr "nhdplus_catchment.rds"
-

stage_national_data() assumes you want to stage data in the same folder as the nhdplus_path database and returns a list of .rds files that can be read with readRDS. The flowlines and catchments are sf data.frames and attributes is a plain data.frame with the attributes from flowline. Note that this introduction uses a small subset of the national seamless database as shown in the plot.

+staged_data <- stage_national_data(output_path = tempdir()) + +str(lapply(staged_data, basename)) +#> List of 3 +#> $ attributes: chr "nhdplus_flowline_attributes.rds" +#> $ flowline : chr "nhdplus_flowline.rds" +#> $ catchment : chr "nhdplus_catchment.rds" +

stage_national_data() assumes you want to stage data in +the same folder as the nhdplus_path database and returns a list of .rds +files that can be read with readRDS. The flowlines and catchments are sf +data.frames and attributes is a plain +data.frame with the attributes from flowline. +Note that this introduction uses a small subset of the national seamless +database as shown in the plot.

-flowline <- readRDS(staged_data$flowline)
-names(flowline)[1:10]
-#>  [1] "COMID"      "FDATE"      "RESOLUTION" "GNIS_ID"    "GNIS_NAME" 
-#>  [6] "LENGTHKM"   "REACHCODE"  "FLOWDIR"    "WBAREACOMI" "FTYPE"
-
-library(sf)
-plot(sf::st_geometry(flowline))
+flowline <- readRDS(staged_data$flowline) +names(flowline)[1:10] +#> [1] "COMID" "FDATE" "RESOLUTION" "GNIS_ID" "GNIS_NAME" +#> [6] "LENGTHKM" "REACHCODE" "FLOWDIR" "WBAREACOMI" "FTYPE" + +library(sf) +plot(sf::st_geometry(flowline))

-

If you don’t need or want all the geometry for the flowlines, consider using get_vaa(). It allows you to retrieve specific NHDPlus attributes with very little overhead. It also supports access to an updated set of network attributes that incorporate numerous network updates from national hydrologic modelling projects.

+

If you don’t need or want all the geometry for the flowlines, +consider using get_vaa(). It allows you to retrieve +specific NHDPlus attributes with very little overhead. It also supports +access to an updated set of network attributes that incorporate numerous +network updates from national hydrologic modelling projects.

-vaa <- get_vaa()
-names(vaa)
-#>  [1] "comid"      "streamleve" "streamorde" "streamcalc" "fromnode"  
-#>  [6] "tonode"     "hydroseq"   "levelpathi" "pathlength" "terminalpa"
-#> [11] "arbolatesu" "divergence" "startflag"  "terminalfl" "dnlevel"   
-#> [16] "thinnercod" "uplevelpat" "uphydroseq" "dnlevelpat" "dnminorhyd"
-#> [21] "dndraincou" "dnhydroseq" "frommeas"   "tomeas"     "reachcode" 
-#> [26] "lengthkm"   "fcode"      "vpuin"      "vpuout"     "areasqkm"  
-#> [31] "totdasqkm"  "divdasqkm"  "totma"      "wbareatype" "pathtimema"
-#> [36] "slope"      "slopelenkm" "ftype"      "gnis_name"  "gnis_id"   
-#> [41] "wbareacomi" "hwnodesqkm" "rpuid"      "vpuid"      "roughness"
-nrow(vaa)
-#> [1] 2691339
+vaa <- get_vaa() +names(vaa) +#> [1] "comid" "streamleve" "streamorde" "streamcalc" "fromnode" +#> [6] "tonode" "hydroseq" "levelpathi" "pathlength" "terminalpa" +#> [11] "arbolatesu" "divergence" "startflag" "terminalfl" "dnlevel" +#> [16] "thinnercod" "uplevelpat" "uphydroseq" "dnlevelpat" "dnminorhyd" +#> [21] "dndraincou" "dnhydroseq" "frommeas" "tomeas" "reachcode" +#> [26] "lengthkm" "fcode" "vpuin" "vpuout" "areasqkm" +#> [31] "totdasqkm" "divdasqkm" "totma" "wbareatype" "pathtimema" +#> [36] "slope" "slopelenkm" "ftype" "gnis_name" "gnis_id" +#> [41] "wbareacomi" "hwnodesqkm" "rpuid" "vpuid" "roughness" +nrow(vaa) +#> [1] 2691339

NHDPlus HiRes

-

NHDPlus HiRes is an in-development dataset that introduces much more dense flowlines and catchments. In the long run, nhdplusTools will have complete support for NHDPlus HiRes. So far, nhdplusTools will help download and interface NHDPlus HiRes data with existing nhdplusTools functionality. It’s important to note that nhdplusTools was primarily implemented using NHDPlusV2 and any use of HiRes should be subject to scrutiny.

-

For the demo below, a small sample of HiRes data that has been loaded into nhdplusTools is used. The first line shows how you can download additional data (just change download_files to TRUE).

+

NHDPlus HiRes is an in-development dataset that introduces much more +dense flowlines and catchments. In the long run, +nhdplusTools will have complete support for NHDPlus HiRes. +So far, nhdplusTools will help download and interface +NHDPlus HiRes data with existing nhdplusTools +functionality. It’s important to note that nhdplusTools was +primarily implemented using NHDPlusV2 and any use of HiRes should be +subject to scrutiny.

+

For the demo below, a small sample of HiRes data that has been loaded +into nhdplusTools is used. The first line shows how you can +download additional data (just change download_files to +TRUE).

-download_nhdplushr(nhd_dir = "download_dir", 
-                   hu_list = c("0101"), # can mix hu02 and hu04 codes.
-                   download_files = FALSE) # TRUE will download files.
-#> [1] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0101_HU4_GDB.zip"
-
-out_gpkg <- file.path(work_dir, "nhd_hr.gpkg")
-hr_data <- get_nhdplushr(work_dir, 
-                         out_gpkg = out_gpkg)
-(layers <- st_layers(out_gpkg))
-#> Driver: GPKG 
-#> Available layers:
-#>         layer_name geometry_type features fields             crs_name
-#> 1      NHDFlowline   Line String     2691     57 GRS 1980(IUGG, 1980)
-#> 2 NHDPlusCatchment Multi Polygon     2603      7 GRS 1980(IUGG, 1980)
-#> 3     NHDWaterbody       Polygon     1044     15 GRS 1980(IUGG, 1980)
-#> 4          NHDArea       Polygon       10     14 GRS 1980(IUGG, 1980)
-#> 5          NHDLine   Line String      142     12 GRS 1980(IUGG, 1980)
-#> 6      NHDPlusSink         Point        1     10 GRS 1980(IUGG, 1980)
-#> 7         NHDPoint      3D Point        7     10 GRS 1980(IUGG, 1980)
-names(hr_data)
-#> [1] "NHDFlowline"      "NHDPlusCatchment"
-unlink(out_gpkg)
-
-hr_data <- get_nhdplushr(work_dir, 
-                         out_gpkg = out_gpkg, 
-                         layers = NULL)
-(layers <- st_layers(out_gpkg))
-#> Driver: GPKG 
-#> Available layers:
-#>         layer_name geometry_type features fields             crs_name
-#> 1      NHDFlowline   Line String     2691     57 GRS 1980(IUGG, 1980)
-#> 2 NHDPlusCatchment Multi Polygon     2603      7 GRS 1980(IUGG, 1980)
-#> 3     NHDWaterbody       Polygon     1044     15 GRS 1980(IUGG, 1980)
-#> 4          NHDArea       Polygon       10     14 GRS 1980(IUGG, 1980)
-#> 5          NHDLine   Line String      142     12 GRS 1980(IUGG, 1980)
-#> 6      NHDPlusSink         Point        1     10 GRS 1980(IUGG, 1980)
-#> 7         NHDPoint      3D Point        7     10 GRS 1980(IUGG, 1980)
-names(hr_data)
-#> [1] "NHDFlowline"      "NHDPlusCatchment" "NHDWaterbody"     "NHDArea"         
-#> [5] "NHDLine"          "NHDPlusSink"      "NHDPoint"
+download_nhdplushr(nhd_dir = "download_dir", + hu_list = c("0101"), # can mix hu02 and hu04 codes. + download_files = FALSE) # TRUE will download files. +#> [1] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0101_HU4_GDB.zip" + +out_gpkg <- file.path(work_dir, "nhd_hr.gpkg") +hr_data <- get_nhdplushr(work_dir, + out_gpkg = out_gpkg) +(layers <- st_layers(out_gpkg)) +#> Driver: GPKG +#> Available layers: +#> layer_name geometry_type features fields +#> 1 NHDFlowline Line String 2691 57 +#> 2 NHDPlusCatchment Multi Polygon 2603 7 +#> 3 NHDWaterbody Polygon 1044 15 +#> 4 NHDArea Polygon 10 14 +#> 5 NHDLine Line String 142 12 +#> 6 NHDPlusSink Point 1 10 +#> 7 NHDPoint 3D Point 7 10 +names(hr_data) +#> [1] "NHDFlowline" "NHDPlusCatchment" +unlink(out_gpkg) + +hr_data <- get_nhdplushr(work_dir, + out_gpkg = out_gpkg, + layers = NULL) +(layers <- st_layers(out_gpkg)) +#> Driver: GPKG +#> Available layers: +#> layer_name geometry_type features fields +#> 1 NHDFlowline Line String 2691 57 +#> 2 NHDPlusCatchment Multi Polygon 2603 7 +#> 3 NHDWaterbody Polygon 1044 15 +#> 4 NHDArea Polygon 10 14 +#> 5 NHDLine Line String 142 12 +#> 6 NHDPlusSink Point 1 10 +#> 7 NHDPoint 3D Point 7 10 +names(hr_data) +#> [1] "NHDFlowline" "NHDPlusCatchment" "NHDWaterbody" "NHDArea" +#> [5] "NHDLine" "NHDPlusSink" "NHDPoint"

Discovery and Subsetting

-

One of the primary workflows nhdplusTools is designed to accomplish can be described in three steps:

+

One of the primary workflows nhdplusTools is designed to +accomplish can be described in three steps:

  1. what NHDPlus catchment is at the outlet of a watershed,
  2. -
  3. figure out what catchments are up or downstream of that catchment, and
  4. +
  5. figure out what catchments are up or downstream of that catchment, +and
  6. create a stand alone subset for that collection of catchments.
-

Say we want to get a subset of the NHDPlus upstream of a given location. We can start with discover_nhdplus_id() First, let’s look at a given point location. Then see where it is relative to our flowlines.

+

Say we want to get a subset of the NHDPlus upstream of a given +location. We can start with discover_nhdplus_id() First, +let’s look at a given point location. Then see where it is relative to +our flowlines.

-lon <- -89.36
-lat <- 43.09
-
-start_point <- sf::st_sfc(sf::st_point(c(lon, lat)),
-                          crs = 4269)
-
-plot(sf::st_geometry(flowline))
-plot(start_point, cex = 1.5, lwd = 2, col = "red", add = TRUE)
+lon <- -89.36 +lat <- 43.09 + +start_point <- sf::st_sfc(sf::st_point(c(lon, lat)), + crs = 4269) + +plot(sf::st_geometry(flowline)) +plot(start_point, cex = 1.5, lwd = 2, col = "red", add = TRUE)

-

OK, so we have a point location near a river and we want to figure out what catchment is at its outlet. We can use the discover_nhdplus_id() function which calls out to a web service and returns an NHDPlus catchment identifier, typically called a COMID.

-

If we set raindrop = TRUE, we can also get a elevation derived downslope trace to the nearest flowline and some additional info. See get_raindrop_trace() for more on this functionality.

+

OK, so we have a point location near a river and we want to figure +out what catchment is at its outlet. We can use the +discover_nhdplus_id() function which calls out to a web +service and returns an NHDPlus catchment identifier, typically called a +COMID.

+

If we set raindrop = TRUE, we can also get a elevation +derived downslope trace to the nearest flowline and some additional +info. See get_raindrop_trace() for more on this +functionality.

-start_comid <- discover_nhdplus_id(start_point, raindrop = TRUE)
-start_comid
-#> Simple feature collection with 2 features and 7 fields
-#> Geometry type: LINESTRING
-#> Dimension:     XY
-#> Bounding box:  xmin: -89.37037 ymin: 43.08522 xmax: -89.35393 ymax: 43.09491
-#> Geodetic CRS:  WGS 84
-#> # A tibble: 2 x 8
-#>   id       gnis_name   comid reachcode raindrop_pathDi~ measure intersection_po~
-#>   <chr>    <chr>       <int> <chr>                <dbl>   <dbl> <list>          
-#> 1 nhdFlow~ Yahara R~  1.33e7 07090002~             124.    40.1 <dbl [2]>       
-#> 2 raindro~ NA        NA      NA                     NA     NA   <dbl [0]>       
-#> # ... with 1 more variable: geometry <LINESTRING [°]>m
-
-plot(sf::st_geometry(start_comid))
-plot(sf::st_geometry(flowline), add = TRUE, col = "blue", lwd = 2)
-plot(start_point, cex = 1.5, lwd = 2, col = "red", add = TRUE)
+start_comid <- discover_nhdplus_id(start_point, raindrop = TRUE) +start_comid +#> Simple feature collection with 2 features and 7 fields +#> Geometry type: LINESTRING +#> Dimension: XY +#> Bounding box: xmin: -89.37037 ymin: 43.08522 xmax: -89.35393 ymax: 43.09491 +#> Geodetic CRS: WGS 84 +#> # A tibble: 2 × 8 +#> id gnis_name comid reachcode raindrop_pathDi… measure intersection_po… +#> <chr> <chr> <int> <chr> <dbl> <dbl> <list> +#> 1 nhdFlow… Yahara R… 1.33e7 07090002… 124. 40.1 <dbl [2]> +#> 2 raindro… NA NA NA NA NA <dbl [0]> +#> # … with 1 more variable: geometry <LINESTRING [°]> + +plot(sf::st_geometry(start_comid)) +plot(sf::st_geometry(flowline), add = TRUE, col = "blue", lwd = 2) +plot(start_point, cex = 1.5, lwd = 2, col = "red", add = TRUE)

-

If you have the whole National Seamless database and want to work at regional to national scales, skip down the the Local Data Subsetting section.

+

If you have the whole National Seamless database and want to +work at regional to national scales, skip down the the Local Data +Subsetting section.

Web Service Data Subsetting

-

nhdplusTools supports discovery and data subsetting using web services made available through the Network Linked Data Index (NLDI) and the National Water Census Geoserver. The code below shows how to use the NLDI functions to build a dataset upstream of our start_comid that we found above.

-

The NLDI can be queried with any set of watershed outlet locations that it has in its index. We call these “featureSources”. We can query the NLDI for an identifier of a given feature from any of its “featureSources” and find out what our navigation options are as shown below.

+

nhdplusTools supports discovery and data subsetting +using web services made available through the Network Linked Data +Index (NLDI) and the National Water Census +Geoserver. The code below shows how to use the NLDI functions to +build a dataset upstream of our start_comid that we found +above.

+

The NLDI can be queried with any set of watershed outlet locations +that it has in its index. We call these “featureSources”. We can query +the NLDI for an identifier of a given feature from any of its +“featureSources” and find out what our navigation options are as shown +below.

-dataRetrieval::get_nldi_sources()$source
-#>  [1] "comid"          "ca_gages"       "geoconnex-demo" "gfv11_pois"    
-#>  [5] "huc12pp"        "nmwdi-st"       "nwisgw"         "nwissite"      
-#>  [9] "ref_gage"       "vigil"          "wade"           "WQP"
-
-nldi_feature <- list(featureSource = "comid", 
-                     featureID = as.integer(start_comid$comid)[1])
-
-get_nldi_feature(nldi_feature)
-#> Simple feature collection with 1 feature and 4 fields
-#> Geometry type: LINESTRING
-#> Dimension:     XY
-#> Bounding box:  xmin: -89.37037 ymin: 43.08521 xmax: -89.35393 ymax: 43.09491
-#> Geodetic CRS:  WGS 84
-#> # A tibble: 1 x 5
-#>   sourceName    identifier comid    name                                geometry
-#>   <chr>         <chr>      <chr>    <chr>                       <LINESTRING [°]>m
-#> 1 NHDPlus comid 13293750   13293750 ""    (-89.37037 43.09491, -89.36997 43.094~
-

We can use get_nldi_feature() as a way to make sure the featureID is available for the chosen “featureSource”. Now that we know the NLDI has our comid, we can use the “upstreamTributaries” navigation option to get all the flowlines upstream or all the features from any of the “featureSources” as shown below.

+dataRetrieval::get_nldi_sources()$source +#> [1] "ca_gages" "geoconnex-demo" "gfv11_pois" "huc12pp" +#> [5] "nmwdi-st" "nwisgw" "nwissite" "ref_gage" +#> [9] "vigil" "wade" "WQP" "comid" + +nldi_feature <- list(featureSource = "comid", + featureID = as.integer(start_comid$comid)[1]) + +get_nldi_feature(nldi_feature) +#> Simple feature collection with 1 feature and 3 fields +#> Geometry type: LINESTRING +#> Dimension: XY +#> Bounding box: xmin: -89.37037 ymin: 43.08521 xmax: -89.35393 ymax: 43.09491 +#> Geodetic CRS: WGS 84 +#> # A tibble: 1 × 4 +#> sourceName identifier comid geometry +#> <chr> <chr> <chr> <LINESTRING [°]> +#> 1 NHDPlus comid 13293750 13293750 (-89.37037 43.09491, -89.36997 43.09475, -8…
+

We can use get_nldi_feature() as a way to make sure the +featureID is available for the chosen “featureSource”. Now that we know +the NLDI has our comid, we can use the “upstreamTributaries” navigation +option to get all the flowlines upstream or all the features from any of +the “featureSources” as shown below.

-flowline_nldi <- navigate_nldi(nldi_feature, 
-                               mode = "upstreamTributaries", 
-                               distance_km = 1000)
-
-plot(sf::st_geometry(flowline), lwd = 3, col = "black")
-plot(sf::st_geometry(flowline_nldi$origin), lwd = 3, col = "red", add = TRUE)
-plot(sf::st_geometry(flowline_nldi$UT), lwd = 1, col = "red", add = TRUE)
+flowline_nldi <- navigate_nldi(nldi_feature, + mode = "upstreamTributaries", + distance_km = 1000) + +plot(sf::st_geometry(flowline), lwd = 3, col = "black") +plot(sf::st_geometry(flowline_nldi$origin), lwd = 3, col = "red", add = TRUE) +plot(sf::st_geometry(flowline_nldi$UT), lwd = 1, col = "red", add = TRUE)

-

The NLDI only provides geometry and a comid for each of the flowlines. The subset_nhdplus() function has a “download” option that allows us to download four layers and all attributes as shown below. There is also a navigate_network() function that will replace navigate_nldi() and subset_nhdplus() for many use cases.

+

The NLDI only provides geometry and a comid for each of the +flowlines. The subset_nhdplus() function has a “download” +option that allows us to download four layers and all attributes as +shown below. There is also a navigate_network() function +that will replace navigate_nldi() and +subset_nhdplus() for many use cases.

-output_file_download <- file.path(work_dir, "subset_download.gpkg")
-
-output_file_download <-subset_nhdplus(comids = as.integer(flowline_nldi$UT$nhdplus_comid),
-                                      output_file = output_file_download,
-                                      nhdplus_data = "download", return_data = FALSE,
-                                      overwrite = TRUE)
-#> All intersections performed in latitude/longitude.
-#> Reading NHDFlowline_Network
-#> Writing NHDFlowline_Network
-
-sf::st_layers(output_file_download)
-#> Driver: GPKG 
-#> Available layers:
-#>            layer_name geometry_type features fields crs_name
-#> 1 NHDFlowline_Network   Line String      168    138    NAD83
-
-flowline_download <- sf::read_sf(file.path(work_dir, "subset_download.gpkg"), 
-                                 "NHDFlowline_Network")
-
-plot(sf::st_geometry(dplyr::filter(flowline_download, 
-                                   streamorde > 2)), 
-     lwd = 7, col = "darkgrey")
-plot(sf::st_geometry(flowline_nldi$UT), 
-     lwd = 3, col = "red", add = TRUE)
+output_file_download <- file.path(work_dir, "subset_download.gpkg") + +output_file_download <-subset_nhdplus(comids = as.integer(flowline_nldi$UT$nhdplus_comid), + output_file = output_file_download, + nhdplus_data = "download", return_data = FALSE, + overwrite = TRUE) +#> All intersections performed in latitude/longitude. +#> Reading NHDFlowline_Network +#> Spherical geometry (s2) switched off +#> Spherical geometry (s2) switched on +#> Writing NHDFlowline_Network + +sf::st_layers(output_file_download) +#> Driver: GPKG +#> Available layers: +#> layer_name geometry_type features fields +#> 1 NHDFlowline_Network Line String 168 138 + +flowline_download <- sf::read_sf(file.path(work_dir, "subset_download.gpkg"), + "NHDFlowline_Network") + +plot(sf::st_geometry(dplyr::filter(flowline_download, + streamorde > 2)), + lwd = 7, col = "darkgrey") +plot(sf::st_geometry(flowline_nldi$UT), + lwd = 3, col = "red", add = TRUE)

-

This plot illustrates the kind of thing that’s possible (filtering to specific stream orders) using the attributes that are downloaded.

-

Before moving on, one more demonstration of what can be done using the NLDI. Say we knew the USGS gage ID that we want NHDPlus data upstream of. We can use the NLDI to navigate from the gage the same as we did for our comid. We can also get back all the nwis sites the NLDI knows about upstream of the one we chose!

+

This plot illustrates the kind of thing that’s possible (filtering to +specific stream orders) using the attributes that are downloaded.

+

Before moving on, one more demonstration of what can be done using +the NLDI. Say we knew the USGS gage ID that we want NHDPlus data +upstream of. We can use the NLDI to navigate from the gage the same as +we did for our comid. We can also get back all the nwis sites the NLDI +knows about upstream of the one we chose!

-nldi_feature <- list(featureSource = "nwissite", 
-                     featureID = "USGS-05428500")
-
-flowline_nldi <- navigate_nldi(nldi_feature, 
-                               mode = "upstreamTributaries", 
-                               distance_km = 1000)
-
-output_file_nwis <- file.path(work_dir, "subset_download_nwis.gpkg")
-
-output_file_nwis <-subset_nhdplus(comids = as.integer(flowline_nldi$UT$nhdplus_comid),
-                                  output_file = output_file_nwis,
-                                  nhdplus_data = "download",
-                                  return_data = FALSE, overwrite = TRUE)
-#> All intersections performed in latitude/longitude.
-#> Reading NHDFlowline_Network
-#> Writing NHDFlowline_Network
-
-sf::st_layers(output_file_download)
-#> Driver: GPKG 
-#> Available layers:
-#>            layer_name geometry_type features fields crs_name
-#> 1 NHDFlowline_Network   Line String      168    138    NAD83
-
-flowline_nwis <- sf::read_sf(output_file_nwis, 
-                                 "NHDFlowline_Network")
-
-upstream_nwis <- navigate_nldi(nldi_feature,
-                               mode = "upstreamTributaries",
-                               data_source = "nwissite", 
-                               distance_km = 1000)
-
-plot(sf::st_geometry(flowline_nwis), 
-     lwd = 3, col = "blue")
-plot(sf::st_geometry(upstream_nwis$UT_nwissite), 
-     cex = 1, lwd = 2, col = "red", add = TRUE)
+nldi_feature <- list(featureSource = "nwissite", + featureID = "USGS-05428500") + +flowline_nldi <- navigate_nldi(nldi_feature, + mode = "upstreamTributaries", + distance_km = 1000) + +output_file_nwis <- file.path(work_dir, "subset_download_nwis.gpkg") + +output_file_nwis <-subset_nhdplus(comids = as.integer(flowline_nldi$UT$nhdplus_comid), + output_file = output_file_nwis, + nhdplus_data = "download", + return_data = FALSE, overwrite = TRUE) +#> All intersections performed in latitude/longitude. +#> Reading NHDFlowline_Network +#> Spherical geometry (s2) switched off +#> Spherical geometry (s2) switched on +#> Writing NHDFlowline_Network + +sf::st_layers(output_file_download) +#> Driver: GPKG +#> Available layers: +#> layer_name geometry_type features fields +#> 1 NHDFlowline_Network Line String 168 138 + +flowline_nwis <- sf::read_sf(output_file_nwis, + "NHDFlowline_Network") + +upstream_nwis <- navigate_nldi(nldi_feature, + mode = "upstreamTributaries", + data_source = "nwissite", + distance_km = 1000) + +plot(sf::st_geometry(flowline_nwis), + lwd = 3, col = "blue") +plot(sf::st_geometry(upstream_nwis$UT_nwissite), + cex = 1, lwd = 2, col = "red", add = TRUE)

Local Data Subsetting

-

While web service data access is very convenient, some use cases make working with web services impossible or cumbersome such that working with local data is preferable. nhdplusTools supports such workflows with hybrid, web-service and local, workflows.

-

With the starting COMID we found with discover_nhdplus_id() above, we can use one of the network navigation functions, get_UM(), get_UT(), get_DM(), or get_DD() to retrieve a collection of comids along the upstream mainstem, upstream with tributaries, downstream mainstem, or downstream with diversions network paths. Here we’ll use upstream with tributaries.

+

While web service data access is very convenient, some use cases make +working with web services impossible or cumbersome such that working +with local data is preferable. nhdplusTools supports such workflows with +hybrid, web-service and local, workflows.

+

With the starting COMID we found with +discover_nhdplus_id() above, we can use one of the network +navigation functions, get_UM(), get_UT(), +get_DM(), or get_DD() to retrieve a collection +of comids along the upstream mainstem, upstream with tributaries, +downstream mainstem, or downstream with diversions network paths. Here +we’ll use upstream with tributaries.

-UT_comids <- get_UT(flowline, start_comid$comid[1])
-UT_comids
-#>   [1]  13293750  13293504  13294134  13294128  13294394  13293454  13293430
-#>   [8]  13293424  13294110  13293398  13293392  13293388  13293384  13293380
-#>  [15]  13293576  13294288  13294284  13293506  13294280  13294290  13294298
-#>  [22]  13294304  13294310  13294312  13293696  13293694  13294264  13293676
-#>  [29]  13293620  13293612  13293584  13294166  13293554  13293540  13294282
-#>  [36]  13293520  13293480  13294132  13293588  13293550  13293574  13293508
-#>  [43]  13293530  13293526  13293524  13294138  13293496  13293488  13293484
-#>  [50]  13293474  13294118  13293440  13293426  13293458  13294382  13294274
-#>  [57]  13293422  13293416  13293390  13293382  13293386  13293376  13293396
-#>  [64]  13293394  13293406  13293404  13294268  13294366  13293400  13293432
-#>  [71]  13293452  13293456  13293492  13294158  13294286  13293634  13294368
-#>  [78]  13294124 937090090 937090091  13293464  13293444  13293446  13293434
-#>  [85]  13293542  13294154  13293536  13294292  13294294  13294300  13294308
-#>  [92]  13294314  13294272  13294276  13294384  13294278  13294386  13293494
-#>  [99]  13294130  13294306  13294184  13293690  13293692  13293586  13293614
-#> [106]  13293624  13293678  13293672  13293674  13294176  13294168  13293578
-#> [113]  13293564  13293548  13293478  13293476  13293450  13293442  13293518
-#> [120]  13293472  13293572  13293568  13293556  13293558  13293552  13293514
-#> [127]  13293522  13294144  13293532  13294150  13294148  13294140  13293516
-#> [134]  13293502  13293498  13293460  13294122  13293468  13294112  13293512
-#> [141]  13293486  13293378  13293462  13293428  13293420  13293412  13293438
-#> [148]  13293490  13293436  13294152  13294296  13294270  13302588  13302590
-#> [155]  13293688  13293646  13294174  13294178  13293562  13293600  13293448
-#> [162]  13294116  13294120  13293570  13294114  13293418  13293410  13293590
-

If you are familiar with the NHDPlus, you will recognize that now that we have this list of COMIDs, we could go off and do all sorts of things with the various flowline attributes. For now, let’s just use the COMID list to filter our fline sf data.frame and plot it with our other layers.

+UT_comids <- get_UT(flowline, start_comid$comid[1]) +UT_comids +#> [1] 13293750 13293504 13294134 13294128 13294394 13293454 13293430 +#> [8] 13293424 13294110 13293398 13293392 13293388 13293384 13293380 +#> [15] 13293576 13294288 13294284 13293506 13294280 13294290 13294298 +#> [22] 13294304 13294310 13294312 13293696 13293694 13294264 13293676 +#> [29] 13293620 13293612 13293584 13294166 13293554 13293540 13294282 +#> [36] 13293520 13293480 13294132 13293588 13293550 13293574 13293508 +#> [43] 13293530 13293526 13293524 13294138 13293496 13293488 13293484 +#> [50] 13293474 13294118 13293440 13293426 13293458 13294382 13294274 +#> [57] 13293422 13293416 13293390 13293382 13293386 13293376 13293396 +#> [64] 13293394 13293406 13293404 13294268 13294366 13293400 13293432 +#> [71] 13293452 13293456 13293492 13294158 13294286 13293634 13294368 +#> [78] 13294124 937090090 937090091 13293464 13293444 13293446 13293434 +#> [85] 13293542 13294154 13293536 13294292 13294294 13294300 13294308 +#> [92] 13294314 13294272 13294276 13294384 13294278 13294386 13293494 +#> [99] 13294130 13294306 13294184 13293690 13293692 13293586 13293614 +#> [106] 13293624 13293678 13293672 13293674 13294176 13294168 13293578 +#> [113] 13293564 13293548 13293478 13293476 13293450 13293442 13293518 +#> [120] 13293472 13293572 13293568 13293556 13293558 13293552 13293514 +#> [127] 13293522 13294144 13293532 13294150 13294148 13294140 13293516 +#> [134] 13293502 13293498 13293460 13294122 13293468 13294112 13293512 +#> [141] 13293486 13293378 13293462 13293428 13293420 13293412 13293438 +#> [148] 13293490 13293436 13294152 13294296 13294270 13302588 13302590 +#> [155] 13293688 13293646 13294174 13294178 13293562 13293600 13293448 +#> [162] 13294116 13294120 13293570 13294114 13293418 13293410 13293590
+

If you are familiar with the NHDPlus, you will recognize that now +that we have this list of COMIDs, we could go off and do all sorts of +things with the various flowline attributes. For now, let’s just use the +COMID list to filter our fline sf +data.frame and plot it with our other layers.

-plot(sf::st_geometry(flowline))
-plot(start_point, cex = 1.5, lwd = 2, col = "red", add = TRUE)
-plot(sf::st_geometry(dplyr::filter(flowline, COMID %in% UT_comids)),
-     add=TRUE, col = "red", lwd = 2)
+plot(sf::st_geometry(flowline)) +plot(start_point, cex = 1.5, lwd = 2, col = "red", add = TRUE) +plot(sf::st_geometry(dplyr::filter(flowline, COMID %in% UT_comids)), + add=TRUE, col = "red", lwd = 2)

-

Say you want to save the network subset for later use in R or in some other GIS. The subset_nhdplus() function is your friend. If you have the whole national seamless database downloaded, you can pull out large subsets of it like shown below (this queries for data from the local geodatabase without loading the whole thing into memory). If you don’t have the whole national seamless, look at the second example in this section.

+

Say you want to save the network subset for later use in R or in some +other GIS. The subset_nhdplus() function is your friend. If +you have the whole national seamless database downloaded, you can pull +out large subsets of it like shown below (this queries for data from the +local geodatabase without loading the whole thing into memory). If you +don’t have the whole national seamless, look at the second example in +this section.

-output_file <- file.path(work_dir, "subset.gpkg")
-
-output_file <-subset_nhdplus(comids = UT_comids,
-                             output_file = output_file,
-                             nhdplus_data = nhdplus_path(), 
-                             return_data = FALSE, overwrite = TRUE)
-#> All intersections performed in latitude/longitude.
-#> Reading NHDFlowline_Network
-#> 168 comids of 168
-#> Writing NHDFlowline_Network
-#> Reading CatchmentSP
-#> 168 comids of 168
-#> Writing CatchmentSP
-#> Reading NHDArea
-#> Writing NHDArea
-#> Reading NHDWaterbody
-#> Writing NHDWaterbody
-#> Reading NHDFlowline_NonNetwork
-#> Writing NHDFlowline_NonNetwork
-#> Reading Gage
-#> Writing Gage
-#> Reading Sink
-#> No features to write in Sink
-
-sf::st_layers(output_file)
-#> Driver: GPKG 
-#> Available layers:
-#>               layer_name geometry_type features fields crs_name
-#> 1    NHDFlowline_Network   Line String      168    136    NAD83
-#> 2            CatchmentSP Multi Polygon      167      6    NAD83
-#> 3                NHDArea       Polygon        1     14    NAD83
-#> 4           NHDWaterbody       Polygon       90     21    NAD83
-#> 5 NHDFlowline_NonNetwork   Line String       45     12    NAD83
-#> 6                   Gage         Point       33     19    NAD83
-

Now we have an output geopackage that can be used later. It contains the network subset of catchments and flowlines as well as a spatial subset of other layers as shown in the status output above. To complete the demonstration, here are a couple more layers plotted up.

+output_file <- file.path(work_dir, "subset.gpkg") + +output_file <-subset_nhdplus(comids = UT_comids, + output_file = output_file, + nhdplus_data = nhdplus_path(), + return_data = FALSE, overwrite = TRUE) +#> All intersections performed in latitude/longitude. +#> Reading NHDFlowline_Network +#> 168 comids of 168 +#> Writing NHDFlowline_Network +#> Reading CatchmentSP +#> 168 comids of 168 +#> Writing CatchmentSP +#> Reading NHDArea +#> Writing NHDArea +#> Reading NHDWaterbody +#> Writing NHDWaterbody +#> Reading NHDFlowline_NonNetwork +#> Writing NHDFlowline_NonNetwork +#> Reading Gage +#> Writing Gage +#> Reading Sink +#> No features to write in Sink + +sf::st_layers(output_file) +#> Driver: GPKG +#> Available layers: +#> layer_name geometry_type features fields +#> 1 NHDFlowline_Network Line String 168 136 +#> 2 CatchmentSP Multi Polygon 167 6 +#> 3 NHDArea Polygon 1 14 +#> 4 NHDWaterbody Polygon 90 21 +#> 5 NHDFlowline_NonNetwork Line String 45 12 +#> 6 Gage Point 33 19 +

Now we have an output geopackage that can be used later. It contains +the network subset of catchments and flowlines as well as a spatial +subset of other layers as shown in the status output above. To complete +the demonstration, here are a couple more layers plotted up.

-catchment <- sf::read_sf(output_file, "CatchmentSP")
-waterbody <- sf::read_sf(output_file, "NHDWaterbody")
-
-plot(sf::st_geometry(flowline))
-plot(start_point, cex = 1.5, lwd = 2, col = "red", add = TRUE)
-plot(sf::st_geometry(dplyr::filter(flowline, COMID %in% UT_comids)),
-     add=TRUE, col = "red", lwd = 2)
-plot(sf::st_geometry(catchment), add = TRUE)
-plot(sf::st_geometry(waterbody), col = rgb(0, 0, 1, alpha = 0.5), add = TRUE)
+catchment <- sf::read_sf(output_file, "CatchmentSP") +waterbody <- sf::read_sf(output_file, "NHDWaterbody") + +plot(sf::st_geometry(flowline)) +plot(start_point, cex = 1.5, lwd = 2, col = "red", add = TRUE) +plot(sf::st_geometry(dplyr::filter(flowline, COMID %in% UT_comids)), + add=TRUE, col = "red", lwd = 2) +plot(sf::st_geometry(catchment), add = TRUE) +plot(sf::st_geometry(waterbody), col = rgb(0, 0, 1, alpha = 0.5), add = TRUE)

@@ -493,51 +607,58 @@

Local Data Subsetting

Indexing

-

nhdplusTools supports a number of indexing use cases. See the function index for specifics.

-

Using the data above, we can use the get_flowline_index() function to get the comid, reachcode, and measure of our starting point like this.

+

nhdplusTools supports a number of indexing use cases. See +the function index for specifics.

+

Using the data above, we can use the +get_flowline_index() function to get the comid, reachcode, +and measure of our starting point like this.

-get_flowline_index(flowline, start_point)
-#> Warning in match_crs(flines, points, paste("crs of lines and points don't
-#> match.", : crs of lines and points don't match. attempting st_transform of lines
-#>   id    COMID      REACHCODE REACH_meas       offset
-#> 1  1 13293750 07090002007373    41.8003 0.0009621378
-

get_flowline_index() will work with a list of points too. For demonstration purposes, we can use the gages in our subset from above.

+get_flowline_index(flowline, start_point) +#> Warning in match_crs(flines, points, paste("crs of lines and points don't +#> match.", : crs of lines and points don't match. attempting st_transform of lines +#> id COMID REACHCODE REACH_meas offset +#> 1 1 13293750 07090002007373 41.8003 0.0009621378 +

get_flowline_index() will work with a list of points +too. For demonstration purposes, we can use the gages in our subset from +above.

-gage <- sf::read_sf(output_file, "Gage")
-
-get_flowline_index(flowline, sf::st_geometry(gage), precision = 10)
-#> Warning in match_crs(flines, points, paste("crs of lines and points don't
-#> match.", : crs of lines and points don't match. attempting st_transform of lines
-#>    id    COMID      REACHCODE REACH_meas         offset
-#> 1   1 13293744 07090002007743    29.3045 0.000016031339
-#> 2   2 13294276 07090002008387    14.8355 0.000012319388
-#> 3   3 13294264 07090002007650    56.4439 0.000020924187
-#> 4   4 13293750 07090002007373    42.5089 0.000025343524
-#> 5   5 13294312 07090002008383     1.2211 0.000002976034
-#> 6   6 13294264 07090002007650    41.0519 0.000033122595
-#> 7   7 13294264 07090002007650     2.0872 0.000002256005
-#> 8   9 13294300 07090002008379    85.4441 0.000016082151
-#> 9  10 13293690 07090002007648     0.7642 0.000014026098
-#> 10 11 13294264 07090002007650    71.4042 0.008204867456
-#> 11 13 13294176 07090002007664     6.1174 0.000031905454
-#> 12 15 13294290 07090002008374    88.0213 0.000027985042
-#> 13 16 13294138 07090002007709    73.3717 0.000010977009
-#> 14 18 13293486 07090002007724     8.8530 0.000012426106
-#> 15 19 13293512 07090002007723     5.9868 0.000010481501
-#> 16 20 13294176 07090002007664    16.9958 0.000012406860
-#> 17 22 13293474 07090002007713    72.0814 0.000006053102
-#> 18 23 13293520 07090002007676    18.1942 0.000030263717
-#> 19 24 13293876 07090002007627    60.1357 0.000025453648
-#> 20 25 13293826 07090002007632   100.0000 0.004750241659
-#> 21 26 13293512 07090002007723    68.1716 0.000025778329
-#> 22 27 13294264 07090002007650    97.1673 0.000013950790
-#> 23 28 13294344 07090002007629     6.5788 0.000007648685
-#> 24 29 13293452 07090002007737     0.0000 0.000486895250
-#> 25 30 13294344 07090002007629    27.7300 0.000012934585
-#> 26 31 13293512 07090002007723    67.6223 0.000022459225
-#> 27 32 13294344 07090002007629     6.5788 0.000007648685
-#> 28 33 13294288 07090002008236     4.3379 0.000275389563
-

For more info about get_flowline_index() and other indexing functions, see the article vignette("indexing") about it or the reference page that describes it.

+gage <- sf::read_sf(output_file, "Gage") + +get_flowline_index(flowline, sf::st_geometry(gage), precision = 10) +#> Warning in match_crs(flines, points, paste("crs of lines and points don't +#> match.", : crs of lines and points don't match. attempting st_transform of lines +#> id COMID REACHCODE REACH_meas offset +#> 1 1 13293744 07090002007743 29.3045 0.000016031339 +#> 2 2 13294276 07090002008387 50.4424 0.000012319388 +#> 3 3 13294264 07090002007650 13.4601 0.000020924187 +#> 4 4 13293750 07090002007373 10.6795 0.000025343524 +#> 5 5 13294312 07090002008383 1.3256 0.000002976034 +#> 6 6 13294264 07090002007650 53.7358 0.000033122595 +#> 7 7 13294264 07090002007650 6.9114 0.000002256005 +#> 8 9 13294300 07090002008379 71.0369 0.000016082151 +#> 9 10 13293690 07090002007648 0.7642 0.000014026098 +#> 10 11 13294264 07090002007650 8.4036 0.008204857099 +#> 11 13 13294176 07090002007664 12.0361 0.000031905454 +#> 12 15 13294290 07090002008374 88.0213 0.000027985042 +#> 13 16 13294138 07090002007709 54.6248 0.000010977009 +#> 14 18 13293486 07090002007724 28.9826 0.000012426106 +#> 15 19 13293512 07090002007723 67.1840 0.000010481501 +#> 16 20 13294176 07090002007664 42.3100 0.000012406860 +#> 17 22 13293474 07090002007713 66.1583 0.000006053102 +#> 18 23 13293520 07090002007676 45.5538 0.000030263717 +#> 19 24 13293876 07090002007627 54.6477 0.000025453648 +#> 20 25 13294374 07090002007633 46.8761 0.000002619625 +#> 21 26 13293512 07090002007723 49.3024 0.000025778329 +#> 22 27 13294264 07090002007650 90.8928 0.000013950790 +#> 23 28 13294344 07090002007629 12.2123 0.000007648685 +#> 24 29 13293456 07090002007738 90.8364 0.000036283275 +#> 25 30 13294344 07090002007629 51.4760 0.000012934585 +#> 26 31 13293512 07090002007723 47.7360 0.000022459225 +#> 27 32 13294344 07090002007629 12.2123 0.000007648685 +#> 28 33 13293576 07090002008236 2.7112 0.000009945223 +

For more info about get_flowline_index() and other +indexing functions, see the article vignette("indexing") +about it or the reference page that describes it.

@@ -558,7 +679,7 @@

Indexing

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/articles/US_data_files/figure-html/nldi_nwissite-1.png b/docs/articles/US_data_files/figure-html/nldi_nwissite-1.png index 5baf4ed7..3095a830 100644 Binary files a/docs/articles/US_data_files/figure-html/nldi_nwissite-1.png and b/docs/articles/US_data_files/figure-html/nldi_nwissite-1.png differ diff --git a/docs/articles/US_data_files/figure-html/tldr-1.png b/docs/articles/US_data_files/figure-html/tldr-1.png index 4a93e128..454e81ae 100644 Binary files a/docs/articles/US_data_files/figure-html/tldr-1.png and b/docs/articles/US_data_files/figure-html/tldr-1.png differ diff --git a/docs/articles/advanced_network.html b/docs/articles/advanced_network.html index aefd5bc0..c1a8db25 100644 --- a/docs/articles/advanced_network.html +++ b/docs/articles/advanced_network.html @@ -40,7 +40,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -114,276 +114,429 @@

Terminology

-

The terms used below are derived from concepts of graph theory, the HY_Features data model, and the NHDPlus data model. Many of the concepts here are also presented in: Mainstems: A logical data model implementing mainstem and drainage basin feature types based on WaterML2 Part 3: HY Features concepts.

+

The terms used below are derived from concepts of graph theory, the +HY_Features +data model, and the NHDPlus +data model. Many of the concepts here are also presented in: Mainstems: A +logical data model implementing mainstem and drainage +basin feature types based on WaterML2 Part 3: HY Features +concepts.

Introduction

-

The NHDPlus data model includes many ‘value added attributes’ (VAA). This vignette discusses a core set of VAA’s that nhdplusTools can create from readily available hydrograhic inputs. The vignette begins with a background needed to understand what these attributes are, and then demonstrates how to create them based on some basic input data. These attributes are documented in the NHDPlus manual, and every effort has been made to faithfully implement their meaning.

-

While the nhdplusTools package contains other functions to generate network attributes, (e.g. get_pfaf() for Pfafstetter codes and get_streamorder() for stream orders) this vignette focuses on the advanced network VAAs from the NHDPlus data model that revolve around the hydrosequence and levelpath.

+

The NHDPlus data model includes many ‘value added attributes’ (VAA). +This vignette discusses a core set of VAA’s that +nhdplusTools can create from readily available hydrograhic +inputs. The vignette begins with a background needed to understand what +these attributes are, and then demonstrates how to create them based on +some basic input data. These attributes are documented in the NHDPlus +manual, and every effort has been made to faithfully implement their +meaning.

+

While the nhdplusTools package contains other functions +to generate network attributes, (e.g. get_pfaf() for +Pfafstetter codes and get_streamorder() for stream orders) +this vignette focuses on the advanced network VAAs from the NHDPlus data +model that revolve around the hydrosequence and +levelpath.

Representing Network Topology

-

A network of flowpaths can be represented as an edge-to-edge (e.g. edge list) or edge-node topology. An edge list only expresses the connectivity between edges (flowpaths in the context of rivers), requiring nodes (confluences in the context of rivers) to be inferred.

-

As of 2/2022 nhdplusTools works on edge list representations only. The table and simple graphics below depict both an edge-node and edge-to-edge topology.

-
#>  ID toID fromnode tonode
-#>   1    3       N1     N3
-#>   2    3       N2     N3
-#>   3   NA       N3     N4
+

A network of flowpaths can be represented as an edge-to-edge +(e.g. edge list) or edge-node topology. An edge list only expresses the +connectivity between edges (flowpaths in the context of +rivers), requiring nodes (confluences in the context of rivers) +to be inferred.

+

As of 2/2022 nhdplusTools works on edge list +representations only. The table and simple graphics below depict both an +edge-node and edge-to-edge topology.

+
#>  ID toID fromnode tonode
+#>   1    3       N1     N3
+#>   2    3       N2     N3
+#>   3   NA       N3     N4
In an edge-node topology, edges are directed to nodes which are then directed to other edges. An edge-to-edge toplogy does not have intervening nodes.In an edge-node topology, edges are directed to nodes which are then directed to other edges. An edge-to-edge toplogy does not have intervening nodes.

-In an edge-node topology, edges are directed to nodes which are then directed to other edges. An edge-to-edge toplogy does not have intervening nodes. +In an edge-node topology, edges are directed to nodes which are then +directed to other edges. An edge-to-edge toplogy does not have +intervening nodes.

-

The “toID” of a terminal flowpath can be either NA or, by convention, 0. Using 0 is preferred within nhdplusTools but both are handled in most cases. Further, as long as 0 is not in the set of IDs, there is little practical difference.

-

In nhdplusTools, edge-to-edge topology is referred to with “comid and tocomid” attributes, or a more general, “ID and toID” depending on the function in question.

+

The “toID” of a terminal flowpath can be either NA or, by convention, +0. Using 0 is preferred within nhdplusTools but both are +handled in most cases. Further, as long as 0 is not in the set of IDs, +there is little practical difference.

+

In nhdplusTools, edge-to-edge topology is referred to +with “comid and tocomid” attributes, or a more general, “ID and toID” +depending on the function in question.

Hydrosequence

Smaller 'hydrosequence' values are guaranteed to be downstream of larger values along connected paths.

-Smaller ‘hydrosequence’ values are guaranteed to be downstream of larger values along connected paths. +Smaller ‘hydrosequence’ values are guaranteed to be downstream of larger +values along connected paths.

-

The NHDPlus data model includes an attribute called hydrosequence that is functionally a topological sort of the flowpath network. It provides an integer identifier guaranteed to decrease in the downstream direction. For flowpaths that are not connected by a single direction navigation (e.g. parallel tributaries) the hydrosequence has no significance. However, when two flowpaths have a direct navigation, the downstream flowpath will always have the smaller hydrosequence. nhdplusTools supports creation of hydrosequence with the get_sorted() function.

-

It is hard to overstate the importance of hydrosequence as any function that requires understanding upstream-downstream relationships requires a sorted version of the flowpath network. In the NHDPlus data model, a edge-list topology is stored in the form of a hydrosequence and ‘to hydrosequence’ attribute. The equivalent is available in nhdplusTools, but does not use the to hydrosequence convention, preferring the primary identifier (ID or comid) and an accompanying toID/tocomid.

+

The NHDPlus data model includes an attribute called +hydrosequence that is functionally a topological +sort of the flowpath network. It provides an integer identifier +guaranteed to decrease in the downstream direction. For flowpaths that +are not connected by a single direction navigation (e.g. parallel +tributaries) the hydrosequence has no significance. However, when two +flowpaths have a direct navigation, the downstream flowpath will always +have the smaller hydrosequence. nhdplusTools supports +creation of hydrosequence with the get_sorted() +function.

+

It is hard to overstate the importance of hydrosequence as +any function that requires understanding upstream-downstream +relationships requires a sorted version of the flowpath network. In the +NHDPlus data model, a edge-list topology is stored in the form of a +hydrosequence and ‘to hydrosequence’ attribute. The equivalent is +available in nhdplusTools, but does not use the to +hydrosequence convention, preferring the primary identifier (ID or +comid) and an accompanying toID/tocomid.

Level Path

Levelpath values are constant along mainstem paths and are derived from the hydrosequence of their outlet flowline.

-Levelpath values are constant along mainstem paths and are derived from the hydrosequence of their outlet flowline. +Levelpath values are constant along mainstem paths and are derived from +the hydrosequence of their outlet flowline.

-

A level path is derived from “stream level” which assigns an integer value to mainstem rivers from outlet up the network (see NHDPlus documentation for more). Rivers terminating to the ocean are given level 1 and this level extends all the way to the headwaters. Rivers terminating in level 1 rivers are given level 2, and so on.

-

“Stream leveling”, then, is the process of establishing uniquely identified “level paths” through a stream network. This is accomplished with a set of rules that determine which tributary should be considered dominant at every confluence to establish the “mainstem rivers” for each “drainage basin” in a network. nhdplusTools supports creation of streamlevel with the get_streamlevel() function, and the creation of level path with get_levelpath(). The convention used in NHDPlus is to assign the levelpath as the hydrosequence of the path’s outlet.

-

See Mainstems: A logical data model implementing mainstem and drainage basin feature types based on WaterML2 Part 3: HY Features concepts for an in depth discussion of these concepts.

+

A level path is derived from “stream level” which assigns an integer +value to mainstem rivers from outlet up the network (see NHDPlus +documentation for more). Rivers terminating to the ocean are given level +1 and this level extends all the way to the headwaters. Rivers +terminating in level 1 rivers are given level 2, and so on.

+

“Stream leveling”, then, is the process of establishing uniquely +identified “level paths” through a stream network. This is accomplished +with a set of rules that determine which tributary should be considered +dominant at every confluence to establish the “mainstem rivers” for each +“drainage basin” in a network. nhdplusTools supports +creation of streamlevel with the get_streamlevel() +function, and the creation of level path with +get_levelpath(). The convention used in NHDPlus is to +assign the levelpath as the hydrosequence of the path’s outlet.

+

See Mainstems: A +logical data model implementing mainstem and drainage +basin feature types based on WaterML2 Part 3: HY Features concepts +for an in depth discussion of these concepts.

Other Derived Network Attributes

-

A number of additional attributes can be derived once levelpath and hydrosequence are established. These include:

+

A number of additional attributes can be derived once +levelpath and hydrosequence are established. +These include:

  1. -terminal path (terminalpa): the identifier (hydrosequence or primary id) of the terminal flowpath of network.
  2. +terminal path (terminalpa): the +identifier (hydrosequence or primary id) of the terminal flowpath of +network.
  3. -up hydrosequence (uphydroseq): the identifier of the upstream flowpath on the mainstem
  4. +up hydrosequence (uphydroseq): the +identifier of the upstream flowpath on the mainstem
  5. -down hydrosequence (dnhydroseq): the identifier of the downstream flowpath on the mainstem
  6. +down hydrosequence (dnhydroseq): the +identifier of the downstream flowpath on the mainstem
  7. -up level path (uplevelpat): the identifier of the next upstream levelpath on the mainstem
  8. +up level path (uplevelpat): the +identifier of the next upstream levelpath on the mainstem
  9. -down level path (dnlevelpat): the identifier of the next downstream levelpath on the mainstem
  10. +down level path (dnlevelpat): the +identifier of the next downstream levelpath on the mainstem
  11. -path length (pathlength): The distance to the network outlet downstream along the main path.
  12. +path length (pathlength): The distance +to the network outlet downstream along the main path.
  13. -total drainage area (totdasqkm): Total accumulated area from upstream flowpath’s catchment area.
  14. +total drainage area (totdasqkm): Total +accumulated area from upstream flowpath’s catchment area.
  15. -arbolate sum (arbolatsu): The total accumulated length of upstream flowpaths.
  16. +arbolate sum (arbolatsu): The total +accumulated length of upstream flowpaths.
  17. -terminal flag (terminalfl): A simple 0 or 1 indicating whether a flowpath is a terminal path or not.
  18. +terminal flag (terminalfl): A simple 0 +or 1 indicating whether a flowpath is a terminal path or not.

Required Base Attributes

-

Creating levelpath and hydrosequence identifiers requires a set of base attributes that include:

+

Creating levelpath and hydrosequence identifiers requires a set of +base attributes that include:

    -
  1. fromnode / tonode or ID / toID: from and to nodes can be used to generate an edge to edge flowpath topology. Note that “ID/toID” is “comid/tocomid” in some nhdplusTools functions.

  2. -
  3. length: a length is required for each flowpath in the network to determine a flow distance, and, if using the arbolate sum for stream leveling.

  4. -
  5. area: the local drainage area of each flowpath is useful in many contexts but is primarily used to calculate total drainage area.

  6. -
  7. weight: a weight metric is required for stream leveling to determine the dominant upstream flowpath. In the NHD, the arbolate sum is used however alternative metrics (e.g. total drainage area) can be used instead.

  8. -
  9. nameID: Many times it is preferable to follow a consistently named path (e.g. GNIS) rather a strict physical weight when stream leveling. In these cases a nameID can be provided.

  10. -
  11. divergence: in order to create a [many:1] upstream to downstream topology, diverted paths must be labeled as such. This attribute, is 0 for normal (already [many:1]) connections, 1 for the main path through a divergence, and 2 for any diverted path.

  12. -
  13. feature type (ftype): used to determine whether a feature is a stream, a coastal path, or some other type of connected network feature. This is the ‘ftype’ in the NHD data model.

  14. +
  15. fromnode / tonode or +ID / toID: from and to nodes +can be used to generate an edge to edge flowpath topology. Note that +“ID/toID” is “comid/tocomid” in some nhdplusTools +functions.

  16. +
  17. length: a length is required for +each flowpath in the network to determine a flow distance, and, if using +the arbolate sum for stream leveling.

  18. +
  19. area: the local drainage area of +each flowpath is useful in many contexts but is primarily used to +calculate total drainage area.

  20. +
  21. weight: a weight metric is required +for stream leveling to determine the dominant upstream flowpath. In the +NHD, the arbolate sum is used however alternative metrics (e.g. total +drainage area) can be used instead.

  22. +
  23. nameID: Many times it is preferable +to follow a consistently named path (e.g. GNIS) rather a strict physical +weight when stream leveling. In these cases a nameID can be +provided.

  24. +
  25. divergence: in order to create a +[many:1] upstream to downstream topology, diverted paths must be labeled +as such. This attribute, is 0 for normal (already [many:1]) connections, +1 for the main path through a divergence, and 2 for any diverted +path.

  26. +
  27. feature type (ftype): used to +determine whether a feature is a stream, a coastal path, or some other +type of connected network feature. This is the ‘ftype’ in the NHD data +model.

-

NOTE: The nhdplusTools package does not support creation of all attributes discussed here, however, those that are not directly supported can be created based on basic transformations of attributes that nhdplusTools does support.

+

NOTE: The nhdplusTools package does not +support creation of all attributes discussed here, however, those that +are not directly supported can be created based on basic transformations +of attributes that nhdplusTools does support.

A visual introduction to the advanced network attributes

-

To illustrate the above concepts and attributes, we’ll start with the “New Hope” demo data included in the nhdplusTools package and add a tocomid attribute based on the edge-node topology included in the data.

+

To illustrate the above concepts and attributes, we’ll start with the +“New Hope” demo data included in the nhdplusTools package +and add a tocomid attribute based on the edge-node topology included in +the data.

-# Import data
-source(system.file("extdata/new_hope_data.R", package = "nhdplusTools"))
-
-# Strip the data back to the required base attributes
-fpath <- get_tocomid(
-  dplyr::select(new_hope_flowline, COMID, FromNode, ToNode, Divergence, FTYPE,
-                AreaSqKM, LENGTHKM, GNIS_ID)
-)
-
-# Print
-head(fpath <- select(sf::st_cast(fpath, "LINESTRING"), 
-                     -tonode, -fromnode, -divergence, -ftype))
-#> 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:           +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
-#>     comid tocomid areasqkm lengthkm gnis_id                           geom
-#> 1 8893864 8894334   4.8123    3.245  991288 LINESTRING (1518702 1557298...
-#> 2 8894490 8894336   0.0000    0.002  991288 LINESTRING (1517194 1556000...
-#> 3 8894494 8894490   0.0090    0.102  991288 LINESTRING (1517288 1556038...
-#> 4 8894334 8894492   0.4284    0.073  991288 LINESTRING (1517349 1556090...
-#> 5 8894492 8894494   0.0018    0.008  991288 LINESTRING (1517295 1556041...
-#> 6 8893850 8893864   0.4059    0.954  991288 LINESTRING (1518668 1557990...
+# Import data +source(system.file("extdata/new_hope_data.R", package = "nhdplusTools")) + +# Strip the data back to the required base attributes +fpath <- get_tocomid( + dplyr::select(new_hope_flowline, COMID, FromNode, ToNode, Divergence, FTYPE, + AreaSqKM, LENGTHKM, GNIS_ID) +) + +# Print +head(fpath <- select(sf::st_cast(fpath, "LINESTRING"), + -tonode, -fromnode, -divergence, -ftype)) +#> 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: +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 +#> comid tocomid areasqkm lengthkm gnis_id geom +#> 1 8893864 8894334 4.8123 3.245 991288 LINESTRING (1518702 1557298... +#> 2 8894490 8894336 0.0000 0.002 991288 LINESTRING (1517194 1556000... +#> 3 8894494 8894490 0.0090 0.102 991288 LINESTRING (1517288 1556038... +#> 4 8894334 8894492 0.4284 0.073 991288 LINESTRING (1517349 1556090... +#> 5 8894492 8894494 0.0018 0.008 991288 LINESTRING (1517295 1556041... +#> 6 8893850 8893864 0.4059 0.954 991288 LINESTRING (1518668 1557990...

Hydrosequence and terminal ID

-

After removing attributes used to generate the tocomid attribute, we have a comid and tocomid relation representing the connectivity of the network as well as attributes required to generate a sorted network with get_sorted()

+

After removing attributes used to generate the tocomid +attribute, we have a comid and tocomid +relation representing the connectivity of the network as well as +attributes required to generate a sorted network with +get_sorted()

-head(fpath <- get_sorted(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:           +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
-#>     comid tocomid areasqkm lengthkm gnis_id terminalID
-#> 1 8898302 8896658   0.1521    0.182  983820    8897784
-#> 2 8896658 8896656   1.1871    1.371  983820    8897784
-#> 3 8896656 8896624   3.8565    2.638  983820    8897784
-#> 4 8896664 8896624   1.3770    1.641            8897784
-#> 5 8896624 8896570   1.3392    1.167  983820    8897784
-#> 6 8896572 8896570   1.5561    1.767            8897784
-#>                             geom
-#> 1 LINESTRING (1505349 1555718...
-#> 2 LINESTRING (1505455 1555570...
-#> 3 LINESTRING (1506375 1554873...
-#> 4 LINESTRING (1507786 1554903...
-#> 5 LINESTRING (1508236 1556343...
-#> 6 LINESTRING (1508311 1558708...
-

The get_sorted() function sorts the flowpaths such that headwaters come first and the terminal flowpath last. Additionally, it produces a terminalID representing the outlet ID of the network. If multiple terminal networks had been provided, the terminalID would allow us to group the data by complete sub networks (a convenient parallelization scheme).

-

In contrast to the NHD, where the terminal path is identified by the hydrosequence ID of the outlet flowpath (meaning the outlet of a level path is left to a user to generate), nhdplusTools uses the more stable primary ID for identifying outlets to allow the hydrosequence / topo sort attribute to be generated and discarded as needed.

-

We can visualize this sorting by assigning a temporary “hydrosequence” value to the sorted network row wise. Here, we assign the first rows in the sorted set to large values and the last rows to small values in line with the hydrosequence order convention in NHDPlus.

+head(fpath <- get_sorted(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: +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 +#> comid tocomid areasqkm lengthkm gnis_id terminalID +#> 1 8898302 8896658 0.1521 0.182 983820 8897784 +#> 2 8896658 8896656 1.1871 1.371 983820 8897784 +#> 3 8896656 8896624 3.8565 2.638 983820 8897784 +#> 4 8896664 8896624 1.3770 1.641 8897784 +#> 5 8896624 8896570 1.3392 1.167 983820 8897784 +#> 6 8896572 8896570 1.5561 1.767 8897784 +#> geom +#> 1 LINESTRING (1505349 1555718... +#> 2 LINESTRING (1505455 1555570... +#> 3 LINESTRING (1506375 1554873... +#> 4 LINESTRING (1507786 1554903... +#> 5 LINESTRING (1508236 1556343... +#> 6 LINESTRING (1508311 1558708...
+

The get_sorted() function sorts the flowpaths such that +headwaters come first and the terminal flowpath last. Additionally, it +produces a terminalID representing the outlet ID of the +network. If multiple terminal networks had been provided, the +terminalID would allow us to group the data by complete sub +networks (a convenient parallelization scheme).

+

In contrast to the NHD, where the terminal path is identified by the +hydrosequence ID of the outlet flowpath (meaning the outlet of a level +path is left to a user to generate), nhdplusTools uses the +more stable primary ID for identifying outlets to allow the +hydrosequence / topo sort attribute to be generated and discarded as +needed.

+

We can visualize this sorting by assigning a temporary +“hydrosequence” value to the sorted network row wise. Here, we assign +the first rows in the sorted set to large values and the last rows to +small values in line with the hydrosequence order convention in +NHDPlus.

-fpath['hydrosequence'] <- seq(nrow(fpath), 1)
-plot(fpath['hydrosequence'], key.pos = NULL)
+fpath['hydrosequence'] <- seq(nrow(fpath), 1) +plot(fpath['hydrosequence'], key.pos = NULL)

Level Path and outlet ID

-

To generate a levelpath attribute, a “physical” weight is needed to determine the upstream mainstem at divergences. For this example, we’ll follow the NHD convention and calculate the arbolate sum explicitly. The get_levelpaths() function will add arbolate sum internally if no weight is explicitly defined.

+

To generate a levelpath attribute, a “physical” weight is needed to +determine the upstream mainstem at divergences. For this example, we’ll +follow the NHD convention and calculate the arbolate sum explicitly. The +get_levelpaths() function will add arbolate sum internally +if no weight is explicitly defined.

-# Rename and compute weight
-fpath[["arbolatesum"]] <- calculate_arbolate_sum(
-  dplyr::select(fpath, 
-                ID = comid, toID = tocomid, length = lengthkm))
-
-plot(sf::st_geometry(fpath), lwd = fpath$arbolatesum / 10)
+# Rename and compute weight +fpath[["arbolatesum"]] <- calculate_arbolate_sum( + dplyr::select(fpath, + ID = comid, toID = tocomid, length = lengthkm)) + +plot(sf::st_geometry(fpath), lwd = fpath$arbolatesum / 10)

-

A nameID identifier can also be provided to override the physical weight when a “smaller” river has the same name. There is an optional override_factor parameter that signifies if the physical weight is override_factor times (e.g. 5) larger on an unnamed or differently named upstream path, the physical weight will be used in favor of the named ID.

-

As mentioned above, nhdplusTools favors more general naming of to/from nodes then the NHD, so names are modified accordingly.

+

A nameID identifier can also be provided to override the +physical weight when a “smaller” river has the same name. +There is an optional override_factor parameter that +signifies if the physical weight is override_factor times +(e.g. 5) larger on an unnamed or differently named upstream path, the +physical weight will be used in favor of the named ID.

+

As mentioned above, nhdplusTools favors more general +naming of to/from nodes then the NHD, so names are modified +accordingly.

-# Get levelpaths
-lp <- get_levelpaths(
-  dplyr::select(fpath, 
-                ID = comid, toID = tocomid, 
-                nameID = gnis_id, weight = arbolatesum), 
-  status = FALSE, override_factor = 5)
-
-# Print
-head(fpath <- dplyr::left_join(fpath, lp, by = c("comid" = "ID")))
-#> Simple feature collection with 6 features and 11 fields
-#> Geometry type: LINESTRING
-#> Dimension:     XY
-#> Bounding box:  xmin: 1505349 ymin: 1554873 xmax: 1508920 ymax: 1558708
-#> 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
-#>     comid tocomid areasqkm lengthkm gnis_id terminalID hydrosequence
-#> 1 8898302 8896658   0.1521    0.182  983820    8897784           746
-#> 2 8896658 8896656   1.1871    1.371  983820    8897784           745
-#> 3 8896656 8896624   3.8565    2.638  983820    8897784           744
-#> 4 8896664 8896624   1.3770    1.641            8897784           743
-#> 5 8896624 8896570   1.3392    1.167  983820    8897784           742
-#> 6 8896572 8896570   1.5561    1.767            8897784           741
-#>   arbolatesum outletID topo_sort levelpath                           geom
-#> 1       0.182  8894348       746       725 LINESTRING (1505349 1555718...
-#> 2       1.553  8894348       745       725 LINESTRING (1505455 1555570...
-#> 3       4.191  8894348       744       725 LINESTRING (1506375 1554873...
-#> 4       1.641  8896664       743       743 LINESTRING (1507786 1554903...
-#> 5       6.999  8894348       742       725 LINESTRING (1508236 1556343...
-#> 6       1.767  8896572       741       741 LINESTRING (1508311 1558708...
-
-plot(fpath["topo_sort"], key.pos = NULL, reset = FALSE)
-plot(fpath["levelpath"], key.pos = NULL)
+# Get levelpaths +lp <- get_levelpaths( + dplyr::select(fpath, + ID = comid, toID = tocomid, + nameID = gnis_id, weight = arbolatesum), + status = FALSE, override_factor = 5) + +# Print +head(fpath <- dplyr::left_join(fpath, lp, by = c("comid" = "ID"))) +#> Simple feature collection with 6 features and 11 fields +#> Geometry type: LINESTRING +#> Dimension: XY +#> Bounding box: xmin: 1505349 ymin: 1554873 xmax: 1508920 ymax: 1558708 +#> 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 +#> comid tocomid areasqkm lengthkm gnis_id terminalID hydrosequence +#> 1 8898302 8896658 0.1521 0.182 983820 8897784 746 +#> 2 8896658 8896656 1.1871 1.371 983820 8897784 745 +#> 3 8896656 8896624 3.8565 2.638 983820 8897784 744 +#> 4 8896664 8896624 1.3770 1.641 8897784 743 +#> 5 8896624 8896570 1.3392 1.167 983820 8897784 742 +#> 6 8896572 8896570 1.5561 1.767 8897784 741 +#> arbolatesum outletID topo_sort levelpath geom +#> 1 0.182 8894348 746 725 LINESTRING (1505349 1555718... +#> 2 1.553 8894348 745 725 LINESTRING (1505455 1555570... +#> 3 4.191 8894348 744 725 LINESTRING (1506375 1554873... +#> 4 1.641 8896664 743 743 LINESTRING (1507786 1554903... +#> 5 6.999 8894348 742 725 LINESTRING (1508236 1556343... +#> 6 1.767 8896572 741 741 LINESTRING (1508311 1558708... + +plot(fpath["topo_sort"], key.pos = NULL, reset = FALSE) +plot(fpath["levelpath"], key.pos = NULL)

-

Note that the get_levelpaths adds an outletID signifying the overall network outlet ID (not topo sort / hydrosequence) by primary identifier.

+

Note that the get_levelpaths adds an +outletID signifying the overall network outlet ID (not topo +sort / hydrosequence) by primary identifier.

Finally, let’s visualize these advanced VAAs!

-

In the below animation, each newly added level path is shown in blue, with the outlet flowpath colored in red. Remembering that get_sorted() sorts flowpaths such that headwaters come first and the terminal flowpaths last we invert the network so that level paths fill in from outlet to head waters. For clarity, only levelpaths with more than 2 flowlines are shown.

+

In the below animation, each newly added level path is shown in blue, +with the outlet flowpath colored in red. Remembering that +get_sorted() sorts flowpaths such that headwaters come +first and the terminal flowpaths last we invert the network so that +level paths fill in from outlet to head waters. For clarity, only +levelpaths with more than 2 flowlines are shown.

-# Invert plotting order
-fpath <- dplyr::arrange(fpath, topo_sort) 
-
-# Level Paths with more then 2 flowpaths
-lp <- dplyr::group_by(fpath, levelpath) %>%
-dplyr::filter(n() > 2) 
-
-# Unique Level Path ID
-lp <-  unique(lp$levelpath)
-
-# Terminal Flowpath 
-terminal_fpath <- dplyr::filter(fpath, comid %in% terminalID)
-
-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, comid %in% outletID)
-
-    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\\nhdplusTools\\vignettes\\levelpath.gif"
-
-knitr::include_graphics(gif_file)
+# Invert plotting order +fpath <- dplyr::arrange(fpath, topo_sort) + +# Level Paths with more then 2 flowpaths +lp <- dplyr::group_by(fpath, levelpath) %>% +dplyr::filter(n() > 2) + +# Unique Level Path ID +lp <- unique(lp$levelpath) + +# Terminal Flowpath +terminal_fpath <- dplyr::filter(fpath, comid %in% terminalID) + +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, comid %in% outletID) + + 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\\nhdplusTools\\vignettes\\levelpath.gif" + +knitr::include_graphics(gif_file)

Summary

-

This entire process of sorting the network and building hydrosequence, levelpath, and derivative variables is wrapped in the add_plus_network_attributes() function to provide performance and simplicity. It supports paralellization and will print status updates in the case when the input network is very large. add_plus_network_attributes() returns NHDPlus attribute names (truncated per shapefile rules as is done in the NHDPlus database).

-

The terminalpa, levelpathi, dnlevelpat, and dnhydroseq attributes are hydroseq identifiers as is the convention in NHDPlus, not primary identifiers (comids) as is returned from the base functions demonstrated above.

-

As of 2/2022, this function does not support the up level path (uplevelpat) or up hydrosequence (uphydroseq) noted in “Other Derived Network Attributes”.

+

This entire process of sorting the network and building +hydrosequence, levelpath, and derivative variables is wrapped in the +add_plus_network_attributes() function to provide +performance and simplicity. It supports paralellization and will print +status updates in the case when the input network is very large. +add_plus_network_attributes() returns NHDPlus attribute +names (truncated per shapefile rules as is done in the NHDPlus +database).

+

The terminalpa, levelpathi, +dnlevelpat, and dnhydroseq attributes are +hydroseq identifiers as is the convention in NHDPlus, +not primary identifiers (comids) as is returned +from the base functions demonstrated above.

+

As of 2/2022, this function does not support the up level path +(uplevelpat) or up hydrosequence (uphydroseq) +noted in “Other Derived Network Attributes”.

-head(add_plus_network_attributes(dplyr::select(fpath, comid, tocomid, lengthkm, areasqkm, 
-                                               nameID = gnis_id), status = TRUE))
-#> Simple feature collection with 6 features and 14 fields
-#> Geometry type: LINESTRING
-#> Dimension:     XY
-#> Bounding box:  xmin: 1514059 ymin: 1551922 xmax: 1518746 ymax: 1554515
-#> 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
-#>     comid tocomid lengthkm areasqkm nameID  weight terminalpa hydroseq
-#> 1 8897784       0    1.394   3.5973 991039 577.376          1        1
-#> 2 8894360 8897784    0.045   0.0126        575.982          1        2
-#> 3 8894356 8894360    1.073   0.8622 991037 435.152          1      151
-#> 4 8894354 8894356    0.507   0.2772 991037 426.711          1      159
-#> 5 8894350 8894354    1.463   1.0737 987350  10.910          1      741
-#> 6 8893884 8894350    1.793   2.1402 987350   9.447          1      742
-#>   levelpathi pathlength dnlevelpat dnhydroseq totdasqkm terminalfl
-#> 1          1      0.000          0          0  595.3383          1
-#> 2          1      1.394          1          1  591.7410          0
-#> 3          1      1.439          1          2  437.1840          0
-#> 4          1      2.512          1        151  428.0076          0
-#> 5        741      3.019          1        159   10.9800          0
-#> 6        741      4.482        741        741    9.9063          0
-#>                             geom
-#> 1 LINESTRING (1514515 1553152...
-#> 2 LINESTRING (1514541 1553188...
-#> 3 LINESTRING (1515465 1553664...
-#> 4 LINESTRING (1515773 1554056...
-#> 5 LINESTRING (1517098 1554192...
-#> 6 LINESTRING (1518746 1554515...
+head(add_plus_network_attributes(dplyr::select(fpath, comid, tocomid, lengthkm, areasqkm, + nameID = gnis_id), status = TRUE)) +#> Simple feature collection with 6 features and 14 fields +#> Geometry type: LINESTRING +#> Dimension: XY +#> Bounding box: xmin: 1514059 ymin: 1551922 xmax: 1518746 ymax: 1554515 +#> 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 +#> comid tocomid lengthkm areasqkm nameID weight terminalpa hydroseq +#> 1 8897784 0 1.394 3.5973 991039 577.376 1 1 +#> 2 8894360 8897784 0.045 0.0126 575.982 1 2 +#> 3 8894356 8894360 1.073 0.8622 991037 435.152 1 151 +#> 4 8894354 8894356 0.507 0.2772 991037 426.711 1 159 +#> 5 8894350 8894354 1.463 1.0737 987350 10.910 1 741 +#> 6 8893884 8894350 1.793 2.1402 987350 9.447 1 742 +#> levelpathi pathlength dnlevelpat dnhydroseq totdasqkm terminalfl +#> 1 1 0.000 0 0 595.3383 1 +#> 2 1 1.394 1 1 591.7410 0 +#> 3 1 1.439 1 2 437.1840 0 +#> 4 1 2.512 1 151 428.0076 0 +#> 5 741 3.019 1 159 10.9800 0 +#> 6 741 4.482 741 741 9.9063 0 +#> geom +#> 1 LINESTRING (1514515 1553152... +#> 2 LINESTRING (1514541 1553188... +#> 3 LINESTRING (1515465 1553664... +#> 4 LINESTRING (1515773 1554056... +#> 5 LINESTRING (1517098 1554192... +#> 6 LINESTRING (1518746 1554515...
@@ -404,7 +557,7 @@

Summary

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/articles/index.html b/docs/articles/index.html index 0dbcd199..a2665687 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -97,7 +97,7 @@

All vignettes

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/articles/indexing.html b/docs/articles/indexing.html index b34b357c..85009553 100644 --- a/docs/articles/indexing.html +++ b/docs/articles/indexing.html @@ -40,7 +40,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -114,280 +114,396 @@

Introduction

-

nhdplusTools offers a few indexing functions and some supporting functions that are worth being aware of.

-

The core functions are: get_flowline_index() and get_waterbody_index() – they do the heavy lifting of finding flowlines and waterbodies near point locations.

-

For flowline indexes, there are a number of useful utilities: - disambiguate_flowline_indexes() uses numeric or character attributes to attempt to determine the best flowline match when many near by matches exist. This is especially useful for mainstem / tributary disambiguation. - get_hydro_location() retrieves the point location of an index along a flowline. - rescale_measures() converts 0:100 reachcode measures to 0:100 flowline measures. - get_partial_length() retrieves a partial length (upstream and downstream) of an index location. - get_path_lengths() retrieves the distance between the outlets of pairs of flowlines. Use with get_partial_length() to determine network distance between indexes.

-

For waterbody indexes, the get_wb_outlet() function is helpful too determine which flowline is the outlet of a waterbody.

+

nhdplusTools offers a few indexing functions and some +supporting functions that are worth being aware of.

+

The core functions are: get_flowline_index() and +get_waterbody_index() – they do the heavy lifting of +finding flowlines and waterbodies near point locations.

+

For flowline indexes, there are a number of useful utilities: - +disambiguate_flowline_indexes() uses numeric or character +attributes to attempt to determine the best flowline match when many +near by matches exist. This is especially useful for mainstem / +tributary disambiguation. - get_hydro_location() retrieves +the point location of an index along a flowline. - +rescale_measures() converts 0:100 reachcode measures to +0:100 flowline measures. - get_partial_length() retrieves a +partial length (upstream and downstream) of an index location. - +get_path_lengths() retrieves the distance between the +outlets of pairs of flowlines. Use with +get_partial_length() to determine network distance between +indexes.

+

For waterbody indexes, the get_wb_outlet() function is +helpful too determine which flowline is the outlet of a waterbody.

Flowline Indexing

-

First we’ll load up some data. In this case, we use flowlines from the NHDPlus subset that’s included in the package and a set of points to index. We’ll use the NHDPlus Gages layer for this example. The data in this example is big. The R session needs a lot of memory to hold the whole NHDPlus flowline layer and run the calculations.

+

First we’ll load up some data. In this case, we use flowlines from +the NHDPlus subset that’s included in the package and a set of points to +index. We’ll use the NHDPlus Gages layer for this example. The data in +this example is big. The R session needs a lot of memory to hold the +whole NHDPlus flowline layer and run the calculations.

-library(nhdplusTools)
-
-nhdplus_path(file.path(work_dir, "natseamless.gpkg"))
-
-flowlines <- sf::read_sf(nhdplus_path(), "NHDFlowline_Network")
-gages <- sf::read_sf(nhdplus_path(), "Gage")
-

Now we can call get_flowline_index() on the data we just loaded. The get_flowline_index() function has an input, search_radius which should correspond to the units of the points input. Projection and unit conversion is attempted. See the function documentation for details. See the documentation of the nn2 function from the RANN package for more information on how the search works.

-

NOTE: If you have a small area in which you need flowline indexes, get_flowline_index() has an option to download flowlines in the bounding box of your input points.

+library(nhdplusTools) + +nhdplus_path(file.path(work_dir, "natseamless.gpkg")) + +flowlines <- sf::read_sf(nhdplus_path(), "NHDFlowline_Network") +gages <- sf::read_sf(nhdplus_path(), "Gage")
+

Now we can call get_flowline_index() on the data we just +loaded. The get_flowline_index() function has an input, +search_radius which should correspond to the units of the +points input. Projection and unit conversion is attempted. +See the function documentation for details. See the documentation of the +nn2 function from the +RANN package for more information on how the search works.

+

NOTE: If you have a small area in which you need flowline indexes, +get_flowline_index() has an option to download flowlines in +the bounding box of your input points.

-indexes <- get_flowline_index(sf::st_transform(flowlines, 5070), # albers
-                              sf::st_transform(sf::st_geometry(gages), 5070), 
-                              search_radius = units::set_units(200, "meters"), 
-                              max_matches = 1)
-
-indexes <- left_join(sf::st_sf(id = c(1:nrow(gages)), 
-                               geom = sf::st_geometry(gages)), 
-                     indexes, by = "id")
-
-plot(sf::st_geometry(sf::st_zm(flowlines)))
-plot(sf::st_geometry(indexes), add = TRUE)
+indexes <- get_flowline_index(sf::st_transform(flowlines, 5070), # albers + sf::st_transform(sf::st_geometry(gages), 5070), + search_radius = units::set_units(200, "meters"), + max_matches = 1) + +indexes <- left_join(sf::st_sf(id = c(1:nrow(gages)), + geom = sf::st_geometry(gages)), + indexes, by = "id") + +plot(sf::st_geometry(sf::st_zm(flowlines))) +plot(sf::st_geometry(indexes), add = TRUE)

-

Now let’s look at the results and see how the get_flowline_index() did. The below shows the percent of COMIDs and REACHCODEs that match and shows a histogram of the measure differences for the REACHCODEs that were matched.

+

Now let’s look at the results and see how the +get_flowline_index() did. The below shows the percent of +COMIDs and REACHCODEs that match and shows a histogram of the measure +differences for the REACHCODEs that were matched.

-p_match <- 100 * length(which(indexes$COMID %in% gages$FLComID)) / nrow(gages)
-paste0(round(p_match, digits = 1), 
-       "% were found to match the COMID in the NHDPlus gages layer")
-#> [1] "58.7% were found to match the COMID in the NHDPlus gages layer"
-
-p_match <- 100 * length(which(indexes$REACHCODE %in% gages$REACHCODE)) / nrow(gages)
-paste0(round(p_match, digits = 1), 
-       "% were found to match the REACHCODE in the NHDPlus gages layer")
-#> [1] "60.9% were found to match the REACHCODE in the NHDPlus gages layer"
-
-matched <- cbind(indexes, 
-                 dplyr::select(sf::st_drop_geometry(gages), 
-                               REACHCODE_ref = REACHCODE, 
-                               COMID_ref = FLComID, 
-                               REACH_meas_ref = Measure)) %>%
-  dplyr::filter(REACHCODE == REACHCODE_ref) %>%
-  dplyr::mutate(REACH_meas_diff = REACH_meas - REACH_meas_ref)
-
-hist(matched$REACH_meas_diff, breaks = 100, 
-     main = "Difference in measure for gages matched to the same reach.")
+p_match <- 100 * length(which(indexes$COMID %in% gages$FLComID)) / nrow(gages) +paste0(round(p_match, digits = 1), + "% were found to match the COMID in the NHDPlus gages layer") +#> [1] "58.7% were found to match the COMID in the NHDPlus gages layer" + +p_match <- 100 * length(which(indexes$REACHCODE %in% gages$REACHCODE)) / nrow(gages) +paste0(round(p_match, digits = 1), + "% were found to match the REACHCODE in the NHDPlus gages layer") +#> [1] "60.9% were found to match the REACHCODE in the NHDPlus gages layer" + +matched <- cbind(indexes, + dplyr::select(sf::st_drop_geometry(gages), + REACHCODE_ref = REACHCODE, + COMID_ref = FLComID, + REACH_meas_ref = Measure)) %>% + dplyr::filter(REACHCODE == REACHCODE_ref) %>% + dplyr::mutate(REACH_meas_diff = REACH_meas - REACH_meas_ref) + +hist(matched$REACH_meas_diff, breaks = 100, + main = "Difference in measure for gages matched to the same reach.")

-
-round(quantile(matched$REACH_meas_diff, 
-               probs = c(0, 0.1, 0.25, 0.5, 0.75, 0.9, 1)), 
-      digits = 2)
-#>    0%   10%   25%   50%   75%   90%  100% 
-#> -5.54 -1.02 -0.48  0.06  1.02  6.91 19.59
+ +round(quantile(matched$REACH_meas_diff, + probs = c(0, 0.1, 0.25, 0.5, 0.75, 0.9, 1)), + digits = 2) +#> 0% 10% 25% 50% 75% 90% 100% +#> -5.54 -1.02 -0.48 0.06 1.02 6.91 19.59

Flowline Indexing with higher precision

-

The above example used the native nodes of the NHDPlus as the potential measure snap locations. The get_flowline_index() function has the ability to refine these by segmentizing the line to some given resolution. Let’s try the same thing using a resolution of 10m and see if we can do any better.

-

Note that the sf::st_segmentize function takes care of the distance conversion and segmentizes our lon/lat lines to 10m on the fly. Also note, we are working in units of degrees for this sample. (this is probably not a good way to do things, but is being shown here for the sake of demonstration)

+

The above example used the native nodes of the NHDPlus as the +potential measure snap locations. The get_flowline_index() +function has the ability to refine these by segmentizing the line to +some given resolution. Let’s try the same thing using a resolution of +10m and see if we can do any better.

+

Note that the sf::st_segmentize function takes care of +the distance conversion and segmentizes our lon/lat lines to 10m on the +fly. Also note, we are working in units of degrees for this sample. +(this is probably not a good way to do things, but is being shown here +for the sake of demonstration)

-indexes <- get_flowline_index(flowlines, 
-                              sf::st_geometry(gages), 
-                              search_radius = units::set_units(0.1, "degrees"), 
-                              precision = 10)
-
-indexes <- left_join(data.frame(id = seq_len(nrow(gages))), indexes, by = "id")
+indexes <- get_flowline_index(flowlines, + sf::st_geometry(gages), + search_radius = units::set_units(0.1, "degrees"), + precision = 10) +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate +#> st_as_s2(): dropping Z and/or M coordinate + +indexes <- left_join(data.frame(id = seq_len(nrow(gages))), indexes, by = "id")

Now lets look at out comparison again.

-p_match <- 100 * length(which(indexes$COMID %in% gages$FLComID)) / nrow(gages)
-paste0(round(p_match, digits = 1), 
-       "% were found to match the COMID in the NHDPlus gages layer")
-#> [1] "69.6% were found to match the COMID in the NHDPlus gages layer"
-
-p_match <- 100 * length(which(indexes$REACHCODE %in% gages$REACHCODE)) / nrow(gages)
-paste0(round(p_match, digits = 1), 
-       "% were found to match the REACHCODE in the NHDPlus gages layer")
-#> [1] "71.7% were found to match the REACHCODE in the NHDPlus gages layer"
-
-matched <- cbind(indexes, 
-                 dplyr::select(sf::st_set_geometry(gages, NULL), 
-                               REACHCODE_ref = REACHCODE, 
-                               COMID_ref = FLComID, 
-                               REACH_meas_ref = Measure)) %>%
-  dplyr::filter(REACHCODE == REACHCODE_ref) %>%
-  dplyr::mutate(REACH_meas_diff = REACH_meas - REACH_meas_ref)
-
-hist(matched$REACH_meas_diff, breaks = 100, 
-     main = "Difference in measure for gages matched to the same reach.")
+p_match <- 100 * length(which(indexes$COMID %in% gages$FLComID)) / nrow(gages) +paste0(round(p_match, digits = 1), + "% were found to match the COMID in the NHDPlus gages layer") +#> [1] "76.1% were found to match the COMID in the NHDPlus gages layer" + +p_match <- 100 * length(which(indexes$REACHCODE %in% gages$REACHCODE)) / nrow(gages) +paste0(round(p_match, digits = 1), + "% were found to match the REACHCODE in the NHDPlus gages layer") +#> [1] "76.1% were found to match the REACHCODE in the NHDPlus gages layer" + +matched <- cbind(indexes, + dplyr::select(sf::st_set_geometry(gages, NULL), + REACHCODE_ref = REACHCODE, + COMID_ref = FLComID, + REACH_meas_ref = Measure)) %>% + dplyr::filter(REACHCODE == REACHCODE_ref) %>% + dplyr::mutate(REACH_meas_diff = REACH_meas - REACH_meas_ref) + +hist(matched$REACH_meas_diff, breaks = 100, + main = "Difference in measure for gages matched to the same reach.")

-
-round(quantile(matched$REACH_meas_diff, 
-               probs = c(0, 0.1, 0.25, 0.5, 0.75, 0.9, 1)), digits = 2)
-#>    0%   10%   25%   50%   75%   90%  100% 
-#> -1.31 -0.66 -0.33 -0.04  0.22  0.81  1.57
+ +round(quantile(matched$REACH_meas_diff, + probs = c(0, 0.1, 0.25, 0.5, 0.75, 0.9, 1)), digits = 2) +#> 0% 10% 25% 50% 75% 90% 100% +#> -50.36 -1.81 -0.66 -0.18 0.04 0.77 38.44

Finding multiple indexes

-

get_flowline_index() has a parameter max_matches that controls how many indexed flowlines are returned per point. This is useful for points that are near many flowlines and some further disambiguation is needed to determine exactly which flowline the point should be indexed to.

-

For this example, we’ll just look at one point but keep all the sites for disambiguation down below.

+

get_flowline_index() has a parameter +max_matches that controls how many indexed flowlines are +returned per point. This is useful for points that are near many +flowlines and some further disambiguation is needed to determine exactly +which flowline the point should be indexed to.

+

For this example, we’ll just look at one point but keep all the sites +for disambiguation down below.

-all_indexes <- get_flowline_index(flowlines,
-                                  sf::st_geometry(gages), 
-                                  search_radius = units::set_units(0.01, "degrees"), 
-                                  max_matches = 10)
-
-indexes <- left_join(sf::st_sf(id = 42, 
-                               geom = sf::st_geometry(gages)[42]), 
-                     all_indexes[all_indexes$id == 42, ], by = "id")
-
-plot(sf::st_geometry(sf::st_buffer(indexes, 500)), border = NA)
-plot(sf::st_geometry(indexes), add = TRUE)
-plot(sf::st_geometry(sf::st_zm(flowlines)), col = "blue", add = TRUE)
+all_indexes <- get_flowline_index(flowlines, + sf::st_geometry(gages), + search_radius = units::set_units(0.01, "degrees"), + max_matches = 10) + +indexes <- left_join(sf::st_sf(id = 42, + geom = sf::st_geometry(gages)[42]), + all_indexes[all_indexes$id == 42, ], by = "id") + +plot(sf::st_geometry(sf::st_buffer(indexes, 500)), border = NA) +plot(sf::st_geometry(indexes), add = TRUE) +plot(sf::st_geometry(sf::st_zm(flowlines)), col = "blue", add = TRUE)

-indexes
-#> Simple feature collection with 10 features and 5 fields
-#> Geometry type: POINT
-#> Dimension:     XY
-#> Bounding box:  xmin: -89.35278 ymin: 43.20867 xmax: -89.35278 ymax: 43.20867
-#> Geodetic CRS:  GRS 1980(IUGG, 1980)
-#>    id    COMID      REACHCODE REACH_meas       offset
-#> 1  42 13293452 07090002007737     0.0000 0.0004868953
-#> 2  42 13293456 07090002007738   100.0000 0.0004868953
-#> 3  42 13293432 07090002007736   100.0000 0.0004868953
-#> 4  42 13293430 07090002007639     0.0000 0.0008846702
-#> 5  42 13293454 07090002007638   100.0000 0.0008846702
-#> 6  42 13294394 07090002007637   100.0000 0.0049572540
-#> 7  42 13294128 07090002007636   100.0000 0.0052999159
-#> 8  42 13294382 07090002007725     0.0000 0.0052999159
-#> 9  42 13294274 07090002007725     3.6313 0.0065388475
-#> 10 42 13293458 07090002007725    12.5173 0.0099172984
-#>                          geom
-#> 1  POINT (-89.35278 43.20867)
-#> 2  POINT (-89.35278 43.20867)
-#> 3  POINT (-89.35278 43.20867)
-#> 4  POINT (-89.35278 43.20867)
-#> 5  POINT (-89.35278 43.20867)
-#> 6  POINT (-89.35278 43.20867)
-#> 7  POINT (-89.35278 43.20867)
-#> 8  POINT (-89.35278 43.20867)
-#> 9  POINT (-89.35278 43.20867)
-#> 10 POINT (-89.35278 43.20867)
-

Now that we have multiple matches, we can use the function disambiguate_flowline_indexes() to figure out which is the “best” match. “best” is in scare quotes here because there are many potential sources of ambiguity here and we are really just narrowing down based on the information we have at hand. (read below for a case in point)

-

Below, we run disambiguate_flowline_indexes() on all the indexes we found then pull out the one we looked at just above as an example (gage 42 in our list).

+indexes +#> Simple feature collection with 10 features and 5 fields +#> Geometry type: POINT +#> Dimension: XY +#> Bounding box: xmin: -89.35278 ymin: 43.20867 xmax: -89.35278 ymax: 43.20867 +#> Geodetic CRS: GRS 1980(IUGG, 1980) +#> id COMID REACHCODE REACH_meas offset +#> 1 42 13293452 07090002007737 0.0000 0.0004868953 +#> 2 42 13293456 07090002007738 100.0000 0.0004868953 +#> 3 42 13293432 07090002007736 100.0000 0.0004868953 +#> 4 42 13293430 07090002007639 0.0000 0.0008846702 +#> 5 42 13293454 07090002007638 100.0000 0.0008846702 +#> 6 42 13294394 07090002007637 100.0000 0.0049572540 +#> 7 42 13294128 07090002007636 100.0000 0.0052999159 +#> 8 42 13294382 07090002007725 0.0000 0.0052999159 +#> 9 42 13294274 07090002007725 3.6313 0.0065388475 +#> 10 42 13293458 07090002007725 12.5173 0.0099172984 +#> geom +#> 1 POINT (-89.35278 43.20867) +#> 2 POINT (-89.35278 43.20867) +#> 3 POINT (-89.35278 43.20867) +#> 4 POINT (-89.35278 43.20867) +#> 5 POINT (-89.35278 43.20867) +#> 6 POINT (-89.35278 43.20867) +#> 7 POINT (-89.35278 43.20867) +#> 8 POINT (-89.35278 43.20867) +#> 9 POINT (-89.35278 43.20867) +#> 10 POINT (-89.35278 43.20867) +

Now that we have multiple matches, we can use the function +disambiguate_flowline_indexes() to figure out which is the +“best” match. “best” is in scare quotes here because there are many +potential sources of ambiguity here and we are really just narrowing +down based on the information we have at hand. (read below for a case in +point)

+

Below, we run disambiguate_flowline_indexes() on all the +indexes we found then pull out the one we looked at just above as an +example (gage 42 in our list).

-unique_indexes <- disambiguate_flowline_indexes(
-  all_indexes, 
-  flowlines[, c("COMID", "TotDASqKM"), drop = TRUE],
-  data.frame(ID = seq_len(nrow(gages)),
-             area = gages$DASqKm))
-
-unique_index <- left_join(sf::st_sf(id = 42, 
-                                    geom = sf::st_geometry(gages)[42]), 
-                          unique_indexes[unique_indexes$id == 42, ], by = "id")
-
-plot(sf::st_geometry(sf::st_buffer(indexes, 500)), border = NA)
-plot(sf::st_geometry(indexes), add = TRUE)
-plot(sf::st_geometry(sf::st_zm(flowlines[flowlines$COMID %in% indexes$COMID,])), 
-     col = "grey", lwd = 3, add = TRUE)
-plot(sf::st_geometry(sf::st_zm(flowlines[flowlines$COMID %in% unique_index$COMID,])),
-     col = "blue", add = TRUE)
+unique_indexes <- disambiguate_flowline_indexes( + all_indexes, + flowlines[, c("COMID", "TotDASqKM"), drop = TRUE], + data.frame(ID = seq_len(nrow(gages)), + area = gages$DASqKm)) + +unique_index <- left_join(sf::st_sf(id = 42, + geom = sf::st_geometry(gages)[42]), + unique_indexes[unique_indexes$id == 42, ], by = "id") + +plot(sf::st_geometry(sf::st_buffer(indexes, 500)), border = NA) +plot(sf::st_geometry(indexes), add = TRUE) +plot(sf::st_geometry(sf::st_zm(flowlines[flowlines$COMID %in% indexes$COMID,])), + col = "grey", lwd = 3, add = TRUE) +plot(sf::st_geometry(sf::st_zm(flowlines[flowlines$COMID %in% unique_index$COMID,])), + col = "blue", add = TRUE)

-
-unique_index
-#> Simple feature collection with 1 feature and 5 fields
-#> Geometry type: POINT
-#> Dimension:     XY
-#> Bounding box:  xmin: -89.35278 ymin: 43.20867 xmax: -89.35278 ymax: 43.20867
-#> Geodetic CRS:  GRS 1980(IUGG, 1980)
-#>   id    COMID      REACHCODE REACH_meas       offset                       geom
-#> 1 42 13293454 07090002007638        100 0.0008846702 POINT (-89.35278 43.20867)
-

As can be seen in this example, a drainage area disambiguation resulted in an unexpected result. Further inspection of this particular gage and the network data used, shows that the main path through this small diversion is coded counter to the main path in the real world. So in this case, if our interest is in the best match to the hydrographic network data we have, this is the best match, as the closest spatial match is incorrectly modeled by the hydrographic data set. As always, buyer beware!

+ +unique_index +#> Simple feature collection with 1 feature and 5 fields +#> Geometry type: POINT +#> Dimension: XY +#> Bounding box: xmin: -89.35278 ymin: 43.20867 xmax: -89.35278 ymax: 43.20867 +#> Geodetic CRS: GRS 1980(IUGG, 1980) +#> id COMID REACHCODE REACH_meas offset geom +#> 1 42 13293454 07090002007638 100 0.0008846702 POINT (-89.35278 43.20867) +

As can be seen in this example, a drainage area disambiguation +resulted in an unexpected result. Further inspection of this particular +gage and the network data used, shows that the main path through this +small diversion is coded counter to the main path in the real world. So +in this case, if our interest is in the best match to the hydrographic +network data we have, this is the best match, as the +closest spatial match is incorrectly modeled by the hydrographic data +set. As always, buyer beware!

Waterbody Indexing

-

The get_flowline_index() function estimates a hydrographic address as a linear reference to a flowline. For points near bodies of water, these could be an inappropriate kind of index. This is because where flowlines run through a waterbody. they are “artificial paths” and do not represent the waterbody. The get_waterbody_index() function is intended to address points that are in or near the shore of a waterbody.

-

This next block of code loads the NHDPlus Waterbody layer and creates an interactive map. Of interest on gages that are near the short of bodies of water but far away from flowlines. Note that we drop the NHDPlus geometry and use the source LonSite and LatSite attributes for geometry.

+

The get_flowline_index() function estimates a +hydrographic address as a linear reference to a flowline. For points +near bodies of water, these could be an inappropriate kind of index. +This is because where flowlines run through a waterbody. they are +“artificial paths” and do not represent the waterbody. The +get_waterbody_index() function is intended to address +points that are in or near the shore of a waterbody.

+

This next block of code loads the NHDPlus Waterbody layer and creates +an interactive map. Of interest on gages that are near the short of +bodies of water but far away from flowlines. Note that we drop the +NHDPlus geometry and use the source LonSite and +LatSite attributes for geometry.

-waterbody <- sf::read_sf(nhdplus_path(), "NHDWaterbody")
-
-gages <- sf::st_drop_geometry(gages) %>%
-  dplyr::filter(!is.na(LonSite)) %>%
-  sf::st_as_sf(coords = c("LonSite", "LatSite"), crs = 4326)
-
-plot(sf::st_geometry(sf::st_zm(flowlines)))
-plot(sf::st_geometry(waterbody), add = TRUE)
-plot(sf::st_geometry(gages), add = TRUE)
+waterbody <- sf::read_sf(nhdplus_path(), "NHDWaterbody") + +gages <- sf::st_drop_geometry(gages) %>% + dplyr::filter(!is.na(LonSite)) %>% + sf::st_as_sf(coords = c("LonSite", "LatSite"), crs = 4326) + +plot(sf::st_geometry(sf::st_zm(flowlines))) +plot(sf::st_geometry(waterbody), add = TRUE) +plot(sf::st_geometry(gages), add = TRUE)

-

This next block shows how to call get_flowline_index() and get_waterbody_index() and what the output looks like.

+

This next block shows how to call get_flowline_index() +and get_waterbody_index() and what the output looks +like.

-
-flowline_indexes <- left_join(data.frame(id = seq_len(nrow(gages))),
-                              get_flowline_index(
-                                sf::st_transform(flowlines, 5070), 
-                                sf::st_geometry(sf::st_transform(gages, 5070)), 
-                                search_radius = units::set_units(200, "m")), by = "id")
-                              
-indexed_gages <- cbind(dplyr::select(gages, 
-                                      orig_REACHCODE = REACHCODE, 
-                                      orig_Measure = Measure, 
-                                      FLComID, 
-                                      STATION_NM), 
-                        flowline_indexes,
-                        get_waterbody_index(
-                          st_transform(waterbody, 5070), 
-                          st_transform(gages, 5070), 
-                          st_drop_geometry(flowlines), 
-                          search_radius = units::set_units(200, "m")))
-
-plot(sf::st_geometry(sf::st_zm(flowlines)))
-plot(sf::st_geometry(waterbody), add = TRUE)
-plot(sf::st_geometry(indexed_gages), add = TRUE)
+ +flowline_indexes <- left_join(data.frame(id = seq_len(nrow(gages))), + get_flowline_index( + sf::st_transform(flowlines, 5070), + sf::st_geometry(sf::st_transform(gages, 5070)), + search_radius = units::set_units(200, "m")), by = "id") + +indexed_gages <- cbind(dplyr::select(gages, + orig_REACHCODE = REACHCODE, + orig_Measure = Measure, + FLComID, + STATION_NM), + flowline_indexes, + get_waterbody_index( + st_transform(waterbody, 5070), + st_transform(gages, 5070), + st_drop_geometry(flowlines), + search_radius = units::set_units(200, "m"))) + +plot(sf::st_geometry(sf::st_zm(flowlines))) +plot(sf::st_geometry(waterbody), add = TRUE) +plot(sf::st_geometry(indexed_gages), add = TRUE)

-
-dplyr::select(sf::st_drop_geometry(indexed_gages), near_wb_COMID, near_wb_dist, in_wb_COMID, outlet_fline_COMID)
-#>    near_wb_COMID near_wb_dist in_wb_COMID outlet_fline_COMID
-#> 1             NA           NA          NA                 NA
-#> 2       13293226    11.013063          NA           13294384
-#> 3             NA           NA          NA                 NA
-#> 4      167120949    16.862351          NA           13294360
-#> 5             NA           NA          NA                 NA
-#> 6             NA           NA          NA                 NA
-#> 7       13293262    22.640184          NA           13294312
-#> 8             NA           NA          NA                 NA
-#> 9       13296360    50.380329          NA           13297172
-#> 10            NA           NA          NA                 NA
-#> 11            NA           NA          NA                 NA
-#> 12      13293262    64.925912          NA           13294312
-#> 13      13293262   164.160184          NA           13294312
-#> 14     167120949    39.327388          NA           13294360
-#> 15            NA           NA          NA                 NA
-#> 16            NA           NA          NA                 NA
-#> 17            NA           NA          NA                 NA
-#> 18      13293284    57.456159    13293284                 NA
-#> 19      13293262    33.292260          NA           13294312
-#> 20            NA           NA          NA                 NA
-#> 21            NA           NA          NA                 NA
-#> 22            NA           NA          NA                 NA
-#> 23      13293226   181.370856          NA           13294384
-#> 24            NA           NA          NA                 NA
-#> 25      14711422    22.566279          NA                 NA
-#> 26            NA           NA          NA                 NA
-#> 27            NA           NA          NA                 NA
-#> 28            NA           NA          NA                 NA
-#> 29            NA           NA          NA                 NA
-#> 30            NA           NA          NA                 NA
-#> 31            NA           NA          NA                 NA
-#> 32            NA           NA          NA                 NA
-#> 33            NA           NA          NA                 NA
-#> 34            NA           NA          NA                 NA
-#> 35            NA           NA          NA                 NA
-#> 36      13293316    37.633591    13293316           13294374
-#> 37            NA           NA          NA                 NA
-#> 38            NA           NA          NA                 NA
-#> 39      13293322     6.737635          NA           13294344
-#> 40            NA           NA          NA                 NA
-#> 41            NA           NA          NA                 NA
-#> 42      13293322     3.914543          NA           13294344
-#> 43            NA           NA          NA                 NA
-#> 44      13293322     6.737635          NA           13294344
-#> 45      13293262    50.163000          NA           13294312
+ +dplyr::select(sf::st_drop_geometry(indexed_gages), near_wb_COMID, near_wb_dist, in_wb_COMID, outlet_fline_COMID) +#> near_wb_COMID near_wb_dist in_wb_COMID outlet_fline_COMID +#> 1 NA NA NA NA +#> 2 13293226 11.013063 NA 13294384 +#> 3 NA NA NA NA +#> 4 167120949 16.862351 NA 13294360 +#> 5 NA NA NA NA +#> 6 NA NA NA NA +#> 7 13293262 22.640184 NA 13294312 +#> 8 NA NA NA NA +#> 9 13296360 50.380329 NA 13297172 +#> 10 NA NA NA NA +#> 11 NA NA NA NA +#> 12 13293262 64.925912 NA 13294312 +#> 13 13293262 164.160184 NA 13294312 +#> 14 167120949 39.327388 NA 13294360 +#> 15 NA NA NA NA +#> 16 NA NA NA NA +#> 17 NA NA NA NA +#> 18 13293284 57.456159 13293284 NA +#> 19 13293262 33.292260 NA 13294312 +#> 20 NA NA NA NA +#> 21 NA NA NA NA +#> 22 NA NA NA NA +#> 23 13293226 181.370856 NA 13294384 +#> 24 NA NA NA NA +#> 25 14711422 22.566279 NA NA +#> 26 NA NA NA NA +#> 27 NA NA NA NA +#> 28 NA NA NA NA +#> 29 NA NA NA NA +#> 30 NA NA NA NA +#> 31 NA NA NA NA +#> 32 NA NA NA NA +#> 33 NA NA NA NA +#> 34 NA NA NA NA +#> 35 NA NA NA NA +#> 36 13293316 37.633591 13293316 13294374 +#> 37 NA NA NA NA +#> 38 NA NA NA NA +#> 39 13293322 6.737635 NA 13294344 +#> 40 NA NA NA NA +#> 41 NA NA NA NA +#> 42 13293322 3.914543 NA 13294344 +#> 43 NA NA NA NA +#> 44 13293322 6.737635 NA 13294344 +#> 45 13293262 50.163000 NA 13294312 @@ -408,7 +524,7 @@

Waterbody Indexing

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/articles/indexing_files/figure-html/analyze_inde_precise-1.png b/docs/articles/indexing_files/figure-html/analyze_inde_precise-1.png index fea63cd9..5496e9f3 100644 Binary files a/docs/articles/indexing_files/figure-html/analyze_inde_precise-1.png and b/docs/articles/indexing_files/figure-html/analyze_inde_precise-1.png differ diff --git a/docs/articles/indexing_files/figure-html/analyze_index-1.png b/docs/articles/indexing_files/figure-html/analyze_index-1.png index 15e69356..226edb77 100644 Binary files a/docs/articles/indexing_files/figure-html/analyze_index-1.png and b/docs/articles/indexing_files/figure-html/analyze_index-1.png differ diff --git a/docs/articles/levelpath.gif b/docs/articles/levelpath.gif index b055f71d..76456cd1 100644 Binary files a/docs/articles/levelpath.gif and b/docs/articles/levelpath.gif differ diff --git a/docs/articles/nhdplusTools.html b/docs/articles/nhdplusTools.html index fd6e5866..a9461898 100644 --- a/docs/articles/nhdplusTools.html +++ b/docs/articles/nhdplusTools.html @@ -40,7 +40,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -111,27 +111,46 @@

Reference page.

-

For data discovery and access in a U.S. context, start with the US Data vignette vignette("US_data").

-

For globally applicable functions, start with the advanced network attributes vignette vignette("advanced_network").

-

Please consider registering issues and feature suggestions on github.

+

The nhdplusTools package contains a wide range of hydrographic data +utilities. Many are globally-applicable hydrographic data manipulation +and processing tools. Others are specific to a U.S. context, focused on +particular US datasets and sources.

+

Detailed documentation of all the package functions can be found at +the Reference +page.

+

For data discovery and access in a U.S. context, start with the +US Data vignette vignette("US_data").

+

For globally applicable functions, start with the advanced +network attributes vignette +vignette("advanced_network").

+

Please consider registering issues and +feature suggestions on github.

Installation

For the latest CRAN release of nhdplusTools, use:

-# install.packages("nhdplusTools")
-

The easiest way to install the latest nhdplusTools development is with the remotes package like this:

+# install.packages("nhdplusTools") +

The easiest way to install the latest nhdplusTools +development is with the remotes package like this:

-# install.packages("remotes")
-# remotes::install_github("usgs-r/nhdplusTools")
-

The nhdplusTools package is intended to provide a reusable set of tools to subset, relate data to, and rebuild attributes for hydrography data. It implements a data model consistent with both the NHDPlus and HY_Features. The package aims to provide a set of tools with minimal dependencies that can be used to build workflows using NHDPlus data-model data.

-

The package has three types of functionality presented in the following vegnettes:

+# install.packages("remotes") +# remotes::install_github("usgs-r/nhdplusTools") +

The nhdplusTools package is intended to provide a +reusable set of tools to subset, relate data to, and rebuild attributes +for hydrography data. It implements a data model consistent with both +the NHDPlus +and HY_Features. The +package aims to provide a set of tools with minimal dependencies that +can be used to build workflows using NHDPlus data-model data.

+

The package has three types of functionality presented in the +following vegnettes:

    -
  1. Data access in the U.S. context: vignette("US_data") +
  2. Data access in the U.S. context: +vignette("US_data")
  3. Indexing data to hydrography: vignette("indexing")
  4. -
  5. Hydrographic network attributes: vignette("advanced_network") +
  6. Hydrographic network attributes: +vignette("advanced_network")

Two other vignette articles are available for the package.

@@ -141,7 +160,9 @@

vignette("plot_nhdplus") -

Thanks for taking the time to read the package documentation. If you see anything that looks wrong or could be better, please consider opening an issue or a pull request in github!

+

Thanks for taking the time to read the package documentation. If you +see anything that looks wrong or could be better, please consider +opening an issue or a pull request in github!

diff --git a/docs/articles/nhdplushr.html b/docs/articles/nhdplushr.html index 2802253b..6f8ae0ac 100644 --- a/docs/articles/nhdplushr.html +++ b/docs/articles/nhdplushr.html @@ -40,7 +40,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -114,235 +114,298 @@

TL;DR;

-

Most functions in nhdplusTools work with NHDPlus High Res (HR) the same as they do with medium res. The demo below shows how to get a single four-digit hydrologic unit worth of HR data, index a point to it, subset it, and plot the results.

-

Note: For consistency, identifiers from NHDPlusV2 are used with HiRes data. A future release of nhdplusTools may alter this behavior.

+

Most functions in nhdplusTools work with NHDPlus High +Res (HR) the same as they do with medium res. The demo below shows how +to get a single four-digit hydrologic unit worth of HR data, index a +point to it, subset it, and plot the results.

+

Note: For consistency, identifiers from NHDPlusV2 are used with +HiRes data. A future release of nhdplusTools may alter this +behavior.

-library(nhdplusTools)
-library(sf)
-
-work_dir <- file.path(nhdplusTools_data_dir(), "hr_v_cache")
-
-source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
-
-hr_gpkg <- file.path(work_dir, "hr_data.gpkg")
-
-# Make a plot and get some background NHDPlusV2 data.
-plot_data <- plot_nhdplus(list("nwissite", "USGS-05428500"), streamorder = 3,
-                          nhdplus_data = sample_data,
-                          stoponlargerequest = FALSE)
-#> Zoom: 10
-#> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
-#> Audotdetect projection: assuming Google Mercator (epsg 3857)
+library(nhdplusTools) +library(sf) + +work_dir <- file.path(nhdplusTools_data_dir(), "hr_v_cache") + +source(system.file("extdata/sample_data.R", package = "nhdplusTools")) + +hr_gpkg <- file.path(work_dir, "hr_data.gpkg") + +# Make a plot and get some background NHDPlusV2 data. +plot_data <- plot_nhdplus(list("nwissite", "USGS-05428500"), streamorder = 3, + nhdplus_data = sample_data, + stoponlargerequest = FALSE) +#> Zoom: 10 +#> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL. +#> Audotdetect projection: assuming Google Mercator (epsg 3857)

-
-# Find the HU04 we are interested in.
-hu04 <- unique(substr(plot_data$flowline$reachcode, 1, 4))
-
-# Download some NHDPlusHR Data
-hr_data_dir <- download_nhdplushr(work_dir, hu04)
-
-# Projection and simplification for demo purposes.
-hr <- get_nhdplushr(work_dir, out_gpkg = hr_gpkg,
-                    proj = 3857)
-
-(start_index <- get_flowline_index(st_transform(hr$NHDFlowline, 5070),
-                                   st_transform(plot_data$outlets, 5070),
-                                   search_radius = 200)) # meters albers eq area
-#> Warning in check_search_radius(search_radius, points): search_radius units not
-#> set, trying units of points.
-#>   id          COMID      REACHCODE REACH_meas   offset
-#> 1  1 22001000032700 07090002006114    37.6572 87.71874
-
-ids <- get_UT(hr$NHDFlowline, start_index$COMID)
-
-hr_subset <- subset_nhdplus(ids, nhdplus_data = hr_gpkg)
-#> All intersections performed in latitude/longitude.
-#> Reading NHDFlowline
-#> 366 comids of 366
-#> Writing NHDFlowline
-#> Reading NHDPlusCatchment
-#> 366 comids of 366
-#> Found invalid geometry, attempting to fix.
-#> Writing NHDPlusCatchment
-

Now that we have both a four digit hydrologic unit worth of NHDPlusHR data and a subset upstream of a point of interest, we can plot things up and see what it looks like. This plot uses NHDPlusV2 as returned by plot_nhdplus() as a base layer and adds NHDPlusHR data on top of it.

+ +# Find the HU04 we are interested in. +hu04 <- unique(substr(plot_data$flowline$reachcode, 1, 4)) + +# Download some NHDPlusHR Data +hr_data_dir <- download_nhdplushr(work_dir, hu04) + +# Projection and simplification for demo purposes. +hr <- get_nhdplushr(work_dir, out_gpkg = hr_gpkg, + proj = 3857) + +(start_index <- get_flowline_index(st_transform(hr$NHDFlowline, 5070), + st_transform(plot_data$outlets, 5070), + search_radius = 200)) # meters albers eq area +#> Warning in check_search_radius(search_radius, points): search_radius units not +#> set, trying units of points. +#> id COMID REACHCODE REACH_meas offset +#> 1 1 22001000032700 07090002006114 37.6572 87.71874 + +ids <- get_UT(hr$NHDFlowline, start_index$COMID) + +hr_subset <- subset_nhdplus(ids, nhdplus_data = hr_gpkg) +#> All intersections performed in latitude/longitude. +#> Reading NHDFlowline +#> 366 comids of 366 +#> Writing NHDFlowline +#> Reading NHDPlusCatchment +#> 366 comids of 366 +#> Found invalid geometry, attempting to fix. +#> Writing NHDPlusCatchment +

Now that we have both a four digit hydrologic unit worth of NHDPlusHR +data and a subset upstream of a point of interest, we can plot things up +and see what it looks like. This plot uses NHDPlusV2 as returned by +plot_nhdplus() as a base layer and adds NHDPlusHR data on +top of it.

-plot_nhdplus(list("nwissite", "USGS-05428500"), streamorder = 2, 
-             nhdplus_data = sample_data, overwrite = TRUE,
-             plot_config = list(flowline = list(lwd = 2.5),
-                                basin = list(lwd = 3)),
-             stoponlargerequest = FALSE)
-#> Zoom: 10
-#> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
-#> Audotdetect projection: assuming Google Mercator (epsg 3857)
-
-plot(st_geometry(hr$NHDPlusCatchment), lwd = 0.25, add = TRUE)
-plot(st_geometry(hr$NHDFlowline), col = "blue", lwd = 0.5, add = TRUE)
-
-plot(st_geometry(st_transform(hr_subset$NHDFlowline, 3857)),
-     col = "cyan", lwd = 1, add = TRUE)
+plot_nhdplus(list("nwissite", "USGS-05428500"), streamorder = 2, + nhdplus_data = sample_data, overwrite = TRUE, + plot_config = list(flowline = list(lwd = 2.5), + basin = list(lwd = 3)), + stoponlargerequest = FALSE) +#> Zoom: 10 +#> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL. +#> Audotdetect projection: assuming Google Mercator (epsg 3857) + +plot(st_geometry(hr$NHDPlusCatchment), lwd = 0.25, add = TRUE) +plot(st_geometry(hr$NHDFlowline), col = "blue", lwd = 0.5, add = TRUE) + +plot(st_geometry(st_transform(hr_subset$NHDFlowline, 3857)), + col = "cyan", lwd = 1, add = TRUE)

Download

-

NHDPlusHR support in nhdplusTools begins with the function download_nhdplushr(). The NHDPlusHR can be downloaded in four digit hydrologic unit code subsets here. download_nhdplushr() facilitates downloading these subsets for as few or as many as you need. It takes a directory you want to save your output into and a vector of four digit (HU04) or two digit (HU02) hydrologic units. There is also an option to just return the URLs of the data that would be downloaded for you to use in some other process. Since the TL;DR; above already downloaded some data. The code below shows how to just get the URLs for a whole HU02 and what the output looks like on disk.

-

Note: Data for each HU02 are put in their own output folder.

+

NHDPlusHR support in nhdplusTools begins with the function +download_nhdplushr(). The NHDPlusHR can be downloaded in four +digit hydrologic unit code subsets here. +download_nhdplushr() facilitates downloading these subsets +for as few or as many as you need. It takes a directory you want to save +your output into and a vector of four digit (HU04) or two digit (HU02) +hydrologic units. There is also an option to just return the URLs of the +data that would be downloaded for you to use in some other process. +Since the TL;DR; above already downloaded some data. The code below +shows how to just get the URLs for a whole HU02 and what the output +looks like on disk.

+

Note: Data for each HU02 are put in their own output +folder.

-(hr_urls <- download_nhdplushr(work_dir, "06", download_files = FALSE))
-#> [1] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0601_HU4_GDB.zip"
-#> [2] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0602_HU4_GDB.zip"
-#> [3] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0603_HU4_GDB.zip"
-#> [4] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0604_HU4_GDB.zip"
-
-# already downloaded:
-list.files(hr_data_dir)
-#> [1] "NHDPLUS_H_0709_HU4_GDB.gdb" "NHDPLUS_H_0709_HU4_GDB.jpg"
-#> [3] "NHDPLUS_H_0709_HU4_GDB.xml"
+(hr_urls <- download_nhdplushr(work_dir, "06", download_files = FALSE)) +#> [1] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0601_HU4_GDB.zip" +#> [2] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0602_HU4_GDB.zip" +#> [3] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0603_HU4_GDB.zip" +#> [4] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0604_HU4_GDB.zip" + +# already downloaded: +list.files(hr_data_dir) +#> [1] "NHDPLUS_H_0709_HU4_GDB.gdb" "NHDPLUS_H_0709_HU4_GDB.jpg" +#> [3] "NHDPLUS_H_0709_HU4_GDB.xml"

Basic functionality

-

The second part of nhdplusTools support for NHDPlusHR is a bit more involved. The entry point is a function called get_nhdplushr(). At it’s core, it will take a collection of NHDPlusHR subsets, open them up one by one and build a single output table for later use. It also 1. joins flowline attributes to the flowline geometry, 1. can return one or more selected layers, 1. can save the result to a standalone geopackage for later use, and 1. can make some attributes of a subset look like they are part of a standalone network rather than having references to downstream data that aren’t in the subset.

-

Using the data we downloaded in the TL;DR; intro, the code below demonstrates a few behaviors of get_nhdplushr()

-

First, if we just give it a directory containing HR data, it will give us back a list with flowlines and catchments as sf data.frames.

+

The second part of nhdplusTools support for NHDPlusHR is a bit more +involved. The entry point is a function called +get_nhdplushr(). At it’s core, it will take a collection of +NHDPlusHR subsets, open them up one by one and build a single output +table for later use. It also 1. joins flowline attributes to the +flowline geometry, 1. can return one or more selected layers, 1. can +save the result to a standalone geopackage for later use, and 1. can +make some attributes of a subset look like they are part of a standalone +network rather than having references to downstream data that aren’t in +the subset.

+

Using the data we downloaded in the TL;DR; intro, the code below +demonstrates a few behaviors of get_nhdplushr()

+

First, if we just give it a directory containing HR data, it will +give us back a list with flowlines and catchments as sf data.frames.

-hr <- get_nhdplushr(hr_data_dir)
-sapply(hr, class)
-#>      NHDFlowline  NHDPlusCatchment
-#> [1,] "sf"         "sf"            
-#> [2,] "tbl_df"     "tbl_df"        
-#> [3,] "tbl"        "tbl"           
-#> [4,] "data.frame" "data.frame"
-plot(st_geometry(hr$NHDFlowline), lwd = (hr$NHDFlowline$StreamOrde / 6))
+hr <- get_nhdplushr(hr_data_dir) +sapply(hr, class) +#> NHDFlowline NHDPlusCatchment +#> [1,] "sf" "sf" +#> [2,] "tbl_df" "tbl_df" +#> [3,] "tbl" "tbl" +#> [4,] "data.frame" "data.frame" +plot(st_geometry(hr$NHDFlowline), lwd = (hr$NHDFlowline$StreamOrde / 6))

-

If we want more data, we can get any of the layer options listed in the get_nhdplushr() documentation.

+

If we want more data, we can get any of the layer options listed in +the get_nhdplushr() documentation.

-hr <- get_nhdplushr(hr_data_dir, layers = c("NHDFlowline", "NHDWaterbody", "NHDArea"))
-#> Warning in CPL_read_ogr(dsn, layer, query, as.character(options), quiet, :
-#> GDAL Message 1: organizePolygons() received a polygon with more than 100 parts.
-#> The processing may be really slow. You can skip the processing by setting
-#> METHOD=SKIP, or only make it analyze counter-clock wise parts by setting
-#> METHOD=ONLY_CCW if you can assume that the outline of holes is counter-clock
-#> wise defined
-sapply(hr, class)
-#>      NHDFlowline  NHDWaterbody NHDArea     
-#> [1,] "sf"         "sf"         "sf"        
-#> [2,] "tbl_df"     "tbl_df"     "tbl_df"    
-#> [3,] "tbl"        "tbl"        "tbl"       
-#> [4,] "data.frame" "data.frame" "data.frame"
-sapply(hr, nrow)
-#>  NHDFlowline NHDWaterbody      NHDArea 
-#>        34532        11444          499
-plot(st_geometry(hr$NHDFlowline), lwd = (hr$NHDFlowline$StreamOrde / 6), col = "blue")
-
-plot(c(st_geometry(hr$NHDWaterbody), st_geometry(hr$NHDArea)), 
-     col = "cyan", border = "cyan", lwd = 0.25, add = TRUE)
+hr <- get_nhdplushr(hr_data_dir, layers = c("NHDFlowline", "NHDWaterbody", "NHDArea")) +#> Warning in CPL_read_ogr(dsn, layer, query, as.character(options), quiet, : +#> GDAL Message 1: organizePolygons() received a polygon with more than 100 parts. +#> The processing may be really slow. You can skip the processing by setting +#> METHOD=SKIP, or only make it analyze counter-clock wise parts by setting +#> METHOD=ONLY_CCW if you can assume that the outline of holes is counter-clock +#> wise defined +sapply(hr, class) +#> NHDFlowline NHDWaterbody NHDArea +#> [1,] "sf" "sf" "sf" +#> [2,] "tbl_df" "tbl_df" "tbl_df" +#> [3,] "tbl" "tbl" "tbl" +#> [4,] "data.frame" "data.frame" "data.frame" +sapply(hr, nrow) +#> NHDFlowline NHDWaterbody NHDArea +#> 34532 11444 499 +plot(st_geometry(hr$NHDFlowline), lwd = (hr$NHDFlowline$StreamOrde / 6), col = "blue") + +plot(c(st_geometry(hr$NHDWaterbody), st_geometry(hr$NHDArea)), + col = "cyan", border = "cyan", lwd = 0.25, add = TRUE)

-

Since this function can work over large amounts of data and we don’t want to keep running it again and again, there is an option to save the results to a standalone database for later use.

+

Since this function can work over large amounts of data and we don’t +want to keep running it again and again, there is an option to save the +results to a standalone database for later use.

-demo_gpkg <- file.path(work_dir, "demo.gpkg")
-hr <- get_nhdplushr(hr_data_dir, out_gpkg = demo_gpkg)
-st_layers(demo_gpkg)
-#> Driver: GPKG 
-#> Available layers:
-#>         layer_name     geometry_type features fields crs_name
-#> 1      NHDFlowline Multi Line String    34532     57    NAD83
-#> 2 NHDPlusCatchment     Multi Polygon    42300      7    NAD83
+demo_gpkg <- file.path(work_dir, "demo.gpkg") +hr <- get_nhdplushr(hr_data_dir, out_gpkg = demo_gpkg) +st_layers(demo_gpkg) +#> Driver: GPKG +#> Available layers: +#> layer_name geometry_type features fields +#> 1 NHDFlowline Multi Line String 34532 57 +#> 2 NHDPlusCatchment Multi Polygon 42300 7

HR modification and filtering

-

Since NHDPlusHR data can be very large, get_nhdplushr() offers the ability to subset the data using a few filter options. Most of the filters are described in the manual page of the get_hr_data() utility function. 1. min_size_sqkm will remove flowlines under a certain size threshold. 1. sim will simplify all geometry to a given tolerance using sf::st_simplify(). 1. proj will project the output into the desired projection. 1. keep_cols is used to specify which attributes are desired in the output. 1. rename controls whether output is automatically renamed to be compatible with nhdplusTools functions.

-

Note: These options only operate on the flowline network.

+

Since NHDPlusHR data can be very large, get_nhdplushr() +offers the ability to subset the data using a few filter options. Most +of the filters are described in the manual page of the +get_hr_data() utility function. 1. +min_size_sqkm will remove flowlines under a certain size +threshold. 1. sim will simplify all geometry to a given +tolerance using sf::st_simplify(). 1. proj +will project the output into the desired projection. 1. +keep_cols is used to specify which attributes are desired +in the output. 1. rename controls whether output is +automatically renamed to be compatible with nhdplusTools +functions.

+

Note: These options only operate on the flowline +network.

-demo <- get_nhdplushr(hr_data_dir, layers = "NHDFlowline", 
-                               min_size_sqkm = 50)
-plot(st_geometry(demo$NHDFlowline), 
-     lwd = demo$NHDFlowline$StreamOrde/4, col = "blue")
+demo <- get_nhdplushr(hr_data_dir, layers = "NHDFlowline", + min_size_sqkm = 50) +plot(st_geometry(demo$NHDFlowline), + lwd = demo$NHDFlowline$StreamOrde/4, col = "blue")

-demo <- get_nhdplushr(hr_data_dir, layers = "NHDFlowline", 
-                      min_size_sqkm = 100, 
-                      proj = "+init=epsg:5070", simp = 200,
-                      keep_cols = c("COMID", "StreamOrde"))
-#> Warning in CPL_crs_from_input(x): GDAL Message 1: +init=epsg:XXXX syntax is
-#> deprecated. It might return a CRS with a non-EPSG compliant axis order.
-names(demo$NHDFlowline)
-#> [1] "COMID"      "StreamOrde" "Shape"
-plot(st_geometry(demo$NHDFlowline), 
-     lwd = demo$NHDFlowline$StreamOrde/4, col = "blue")
+demo <- get_nhdplushr(hr_data_dir, layers = "NHDFlowline", + min_size_sqkm = 100, + proj = "+init=epsg:5070", simp = 200, + keep_cols = c("COMID", "StreamOrde")) +#> Warning in CPL_crs_from_input(x): GDAL Message 1: +init=epsg:XXXX syntax is +#> deprecated. It might return a CRS with a non-EPSG compliant axis order. +names(demo$NHDFlowline) +#> [1] "COMID" "StreamOrde" "Shape" +plot(st_geometry(demo$NHDFlowline), + lwd = demo$NHDFlowline$StreamOrde/4, col = "blue")

Make Standalone Basins

-

The NHDPlus data model has some shared identifiers that can span very large distances. For example, the “Level Path Identifier” identifies an entire river from headwater to outlet using the “hydrologic sequence identifier” of the outlet. Similarly, the “Terminal Path Identifier” identifies an entire basin using the hydrologic sequence identifier of the terminal flowline (to the ocean or an inland sink). When creating subsets of NHDPlus data, many times, these attributes can identify flowlines that are not included in the subset. For most applications, this is not a problem, but in some cases, it is advantageous to adjust identifiers such that the subset appears to be a complete drainage basin with a true terminal outlet. make_standalone() accomplishes this task.

-

On a one by one basis, this may seam insignificant, but for workflows that need to work with arbitrary subsets and start from basin outlets, this functionality is useful. It has little impact on the data and is applied by default.

-

The example below shows how the outlet is modified. As described in the documentation os make_standalone() all related attributes upstream are also fixed such that the network is intact for further use.

+

The NHDPlus data model has some shared identifiers that can span very +large distances. For example, the “Level Path Identifier” identifies an +entire river from headwater to outlet using the “hydrologic sequence +identifier” of the outlet. Similarly, the “Terminal Path Identifier” +identifies an entire basin using the hydrologic sequence identifier of +the terminal flowline (to the ocean or an inland sink). When creating +subsets of NHDPlus data, many times, these attributes can identify +flowlines that are not included in the subset. For most applications, +this is not a problem, but in some cases, it is advantageous to adjust +identifiers such that the subset appears to be a complete drainage basin +with a true terminal outlet. make_standalone() accomplishes +this task.

+

On a one by one basis, this may seam insignificant, but for workflows +that need to work with arbitrary subsets and start from basin outlets, +this functionality is useful. It has little impact on the data and is +applied by default.

+

The example below shows how the outlet is modified. As described in +the documentation os make_standalone() all related +attributes upstream are also fixed such that the network is intact for +further use.

-demo <- get_nhdplushr(hr_data_dir, layers = "NHDFlowline", 
-                    min_size_sqkm = 100, check_terminals = FALSE)
-
-# Create a standalone basin with the results for comparison.
-standalone_demo <- make_standalone(demo$NHDFlowline)
-
-demo_outlet <- dplyr::filter(demo$NHDFlowline, TotDASqKM == max(TotDASqKM)) 
-
-standalone_demo_outlet <- dplyr::filter(standalone_demo, TotDASqKM == max(TotDASqKM))
-
-broken_outlet <- dplyr::select(st_drop_geometry(demo_outlet), 
-                               Hydroseq, TerminalPa, TerminalFl, LevelPathI)
-fixed_outlet <- dplyr::select(st_drop_geometry(standalone_demo_outlet), 
-                              Hydroseq, TerminalPa, TerminalFl, LevelPathI)
-
-print(data.frame(broken_outlet))
-#>         Hydroseq     TerminalPa TerminalFl     LevelPathI
-#> 1 22001000000414 22000100000212          0 22000300045683
-print(data.frame(fixed_outlet))
-#>         Hydroseq     TerminalPa TerminalFl     LevelPathI
-#> 1 22001000000414 22001000000414          1 22001000000414
-
-(broken <- dplyr::filter(demo$NHDFlowline, TerminalPa == demo_outlet$Hydroseq))
-#> Simple feature collection with 0 features and 57 fields
-#> Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
-#> Geodetic CRS:  NAD83
-#> # A tibble: 0 x 58
-#> # ... with 58 variables: Permanent_Identifier <chr>, FDate <dttm>,
-#> #   Resolution <int>, GNIS_ID <chr>, GNIS_Name <chr>, LENGTHKM <dbl>,
-#> #   REACHCODE <chr>, FlowDir <int>, WBArea_Permanent_Identifier <chr>,
-#> #   FTYPE <int>, FCODE <int>, MainPath <int>, InNetwork <int>,
-#> #   VisibilityFilter <int>, Shape_Length <dbl>, COMID <dbl>, VPUID <chr>,
-#> #   Enabled <int>, Shape <GEOMETRY [°]>, StreamLeve <int>, StreamOrde <int>,m
-#> #   StreamCalc <int>, FromNode <dbl>, ToNode <dbl>, Hydroseq <dbl>, ...
-(standalone <- dplyr::filter(standalone_demo, TerminalPa == standalone_demo_outlet$Hydroseq))
-#> Simple feature collection with 5358 features and 57 fields
-#> Geometry type: MULTILINESTRING
-#> Dimension:     XY
-#> Bounding box:  xmin: -90.68076 ymin: 41.27482 xmax: -88.1999 ymax: 43.74949
-#> Geodetic CRS:  NAD83
-#> # A tibble: 5,358 x 58
-#>    Permanent_Identifi~ FDate               Resolution GNIS_ID GNIS_Name LENGTHKM
-#>  * <chr>               <dttm>                   <int> <chr>   <chr>        <dbl>
-#>  1 156038282           2012-03-19 01:32:25          2 004155~ Pecatoni~    1.34 
-#>  2 155714162           2014-10-28 19:00:00          2 004248~ Fairfiel~    0.417
-#>  3 156035374           2012-03-19 01:35:08          2 015619~ Gordon C~    0.39 
-#>  4 145600320           2012-03-19 01:34:47          2 004168~ Rock Cre~    0.352
-#>  5 155712981           2012-03-19 02:05:43          2 NA      NA           0.034
-#>  6 137417698           2012-03-18 13:07:30          2 015750~ Sugar Ri~    0.798
-#>  7 156037500           2012-03-19 01:33:10          2 NA      NA           0.009
-#>  8 145599800           2012-03-19 01:34:47          2 004145~ North Fo~    0.665
-#>  9 143246785           2012-03-18 12:56:42          2 004168~ Rock Riv~    0.165
-#> 10 155712415           2012-03-19 02:05:51          2 004241~ Willow C~    2.11 
-#> # ... with 5,348 more rows, and 52 more variables: REACHCODE <chr>,
-#> #   FlowDir <int>, WBArea_Permanent_Identifier <chr>, FTYPE <int>, FCODE <int>,
-#> #   MainPath <int>, InNetwork <int>, VisibilityFilter <int>,
-#> #   Shape_Length <dbl>, COMID <dbl>, VPUID <chr>, Enabled <int>,
-#> #   Shape <MULTILINESTRING [°]>, StreamLeve <int>, StreamOrde <int>,m
-#> #   StreamCalc <int>, FromNode <dbl>, ToNode <dbl>, Hydroseq <dbl>,
-#> #   LevelPathI <dbl>, Pathlength <dbl>, TerminalPa <dbl>, ArbolateSu <dbl>, ...
-
-plot(st_geometry(standalone))
+demo <- get_nhdplushr(hr_data_dir, layers = "NHDFlowline", + min_size_sqkm = 100, check_terminals = FALSE) + +# Create a standalone basin with the results for comparison. +standalone_demo <- make_standalone(demo$NHDFlowline) + +demo_outlet <- dplyr::filter(demo$NHDFlowline, TotDASqKM == max(TotDASqKM)) + +standalone_demo_outlet <- dplyr::filter(standalone_demo, TotDASqKM == max(TotDASqKM)) + +broken_outlet <- dplyr::select(st_drop_geometry(demo_outlet), + Hydroseq, TerminalPa, TerminalFl, LevelPathI) +fixed_outlet <- dplyr::select(st_drop_geometry(standalone_demo_outlet), + Hydroseq, TerminalPa, TerminalFl, LevelPathI) + +print(data.frame(broken_outlet)) +#> Hydroseq TerminalPa TerminalFl LevelPathI +#> 1 22001000000414 22000100000212 0 22000300045683 +print(data.frame(fixed_outlet)) +#> Hydroseq TerminalPa TerminalFl LevelPathI +#> 1 22001000000414 22001000000414 1 22001000000414 + +(broken <- dplyr::filter(demo$NHDFlowline, TerminalPa == demo_outlet$Hydroseq)) +#> Simple feature collection with 0 features and 57 fields +#> Bounding box: xmin: NA ymin: NA xmax: NA ymax: NA +#> Geodetic CRS: NAD83 +#> # A tibble: 0 × 58 +#> # … with 58 variables: Permanent_Identifier <chr>, FDate <dttm>, +#> # Resolution <int>, GNIS_ID <chr>, GNIS_Name <chr>, LENGTHKM <dbl>, +#> # REACHCODE <chr>, FlowDir <int>, WBArea_Permanent_Identifier <chr>, +#> # FTYPE <int>, FCODE <int>, MainPath <int>, InNetwork <int>, +#> # VisibilityFilter <int>, Shape_Length <dbl>, COMID <dbl>, VPUID <chr>, +#> # Enabled <int>, Shape <GEOMETRY [°]>, StreamLeve <int>, StreamOrde <int>, +#> # StreamCalc <int>, FromNode <dbl>, ToNode <dbl>, Hydroseq <dbl>, … +(standalone <- dplyr::filter(standalone_demo, TerminalPa == standalone_demo_outlet$Hydroseq)) +#> Simple feature collection with 5358 features and 57 fields +#> Geometry type: MULTILINESTRING +#> Dimension: XY +#> Bounding box: xmin: -90.68076 ymin: 41.27482 xmax: -88.1999 ymax: 43.74949 +#> Geodetic CRS: NAD83 +#> # A tibble: 5,358 × 58 +#> Permanent_Identifi… FDate Resolution GNIS_ID GNIS_Name LENGTHKM +#> * <chr> <dttm> <int> <chr> <chr> <dbl> +#> 1 156038282 2012-03-19 01:32:25 2 004155… Pecatoni… 1.34 +#> 2 155714162 2014-10-28 19:00:00 2 004248… Fairfiel… 0.417 +#> 3 156035374 2012-03-19 01:35:08 2 015619… Gordon C… 0.39 +#> 4 145600320 2012-03-19 01:34:47 2 004168… Rock Cre… 0.352 +#> 5 155712981 2012-03-19 02:05:43 2 NA NA 0.034 +#> 6 137417698 2012-03-18 13:07:30 2 015750… Sugar Ri… 0.798 +#> 7 156037500 2012-03-19 01:33:10 2 NA NA 0.009 +#> 8 145599800 2012-03-19 01:34:47 2 004145… North Fo… 0.665 +#> 9 143246785 2012-03-18 12:56:42 2 004168… Rock Riv… 0.165 +#> 10 155712415 2012-03-19 02:05:51 2 004241… Willow C… 2.11 +#> # … with 5,348 more rows, and 52 more variables: REACHCODE <chr>, +#> # FlowDir <int>, WBArea_Permanent_Identifier <chr>, FTYPE <int>, FCODE <int>, +#> # MainPath <int>, InNetwork <int>, VisibilityFilter <int>, +#> # Shape_Length <dbl>, COMID <dbl>, VPUID <chr>, Enabled <int>, +#> # Shape <MULTILINESTRING [°]>, StreamLeve <int>, StreamOrde <int>, +#> # StreamCalc <int>, FromNode <dbl>, ToNode <dbl>, Hydroseq <dbl>, +#> # LevelPathI <dbl>, Pathlength <dbl>, TerminalPa <dbl>, ArbolateSu <dbl>, … + +plot(st_geometry(standalone))

@@ -364,7 +427,7 @@

Make Standalone Basins

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/articles/plot_nhdplus.html b/docs/articles/plot_nhdplus.html index 7157dc46..e7783293 100644 --- a/docs/articles/plot_nhdplus.html +++ b/docs/articles/plot_nhdplus.html @@ -40,7 +40,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -114,250 +114,314 @@

Plotting with nhdplusTools

-

The goal of this vignette is to demonstrate a simple and lightweight approach to building maps with NHDPlus data.

+

The goal of this vignette is to demonstrate a simple and lightweight +approach to building maps with NHDPlus data.

The plot_nhdplus function

-

plot_nhdplus is a work in progress. Not all inputs in the function have been implemented as of 11/18/2019 and additional functionality will be added later. Please leave feature requests and issues you find in an issue here.

-

plot_nhdplus is a function that makes getting a simple plot of NHDPlus data as easy as possible. It works with other functions from nhdplusTools for identifying and retrieving watershed outlet locations. See the plot_nhdplus documentation for more info.

-

If we pass plot_nhdplus a single NWIS site id, nhdplusTools uses web services to get data and we get a plot like this:

+

plot_nhdplus is a work in progress. Not all +inputs in the function have been implemented as of 11/18/2019 and +additional functionality will be added later. Please leave feature +requests and issues you find in an issue +here.

+

plot_nhdplus is a function that makes getting a simple +plot of NHDPlus data as easy as possible. It works with other functions +from nhdplusTools for identifying and retrieving watershed +outlet locations. See the plot_nhdplus documentation for +more info.

+

If we pass plot_nhdplus a single NWIS site id, +nhdplusTools uses web services to get data and we get a +plot like this:

-plot_nhdplus("05428500")
+plot_nhdplus("05428500")

-

If we want to add other watersheds, we can use any outlet available from the Network Linked Data Index. See “nldi” functions elsewhere in nhdplusTools.

+

If we want to add other watersheds, we can use any outlet available +from the Network Linked Data Index. See “nldi” functions elsewhere in +nhdplusTools.

-plot_nhdplus(list(list("nwissite", "USGS-05428500"),
-                  list("huc12pp", "070900020602")))
+plot_nhdplus(list(list("nwissite", "USGS-05428500"), + list("huc12pp", "070900020602")))

-plot_nhdplus(list(list("nwissite", "USGS-05428500"),
-                  list("huc12pp", "070900020602")))
+plot_nhdplus(list(list("nwissite", "USGS-05428500"), + list("huc12pp", "070900020602")))

-

If we don’t know a site id, we can just pass in one or more latitude / longitude locations.

+

If we don’t know a site id, we can just pass in one or more latitude +/ longitude locations.

-start_point <- sf::st_as_sf(data.frame(x = -89.36, y = 43.09), 
-                            coords = c("x", "y"), crs = 4326)
-
-plot_nhdplus(start_point)
+start_point <- sf::st_as_sf(data.frame(x = -89.36, y = 43.09), + coords = c("x", "y"), crs = 4326) + +plot_nhdplus(start_point)

-

plot_nhdplus also allows modification of streamorder (if you have data available locally) and styles. This plot request shows how to get a subset of data for a plot and the range of options. See documentation for more details.

+

plot_nhdplus also allows modification of streamorder (if +you have data available locally) and styles. This plot request shows how +to get a subset of data for a plot and the range of options. See +documentation for more details.

-
-source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
-
-plot_nhdplus(list(list("comid", "13293970"),
-                  list("nwissite", "USGS-05428500"),
-                  list("huc12pp", "070900020603"),
-                  list("huc12pp", "070900020602")),
-             streamorder = 2,
-             nhdplus_data = sample_data,
-             plot_config = list(basin = list(lwd = 2),
-                                outlets = list(huc12pp = list(cex = 1.5),
-                                               comid = list(col = "green"))),
-             stoponlargerequest = FALSE)
+ +source(system.file("extdata/sample_data.R", package = "nhdplusTools")) + +plot_nhdplus(list(list("comid", "13293970"), + list("nwissite", "USGS-05428500"), + list("huc12pp", "070900020603"), + list("huc12pp", "070900020602")), + streamorder = 2, + nhdplus_data = sample_data, + plot_config = list(basin = list(lwd = 2), + outlets = list(huc12pp = list(cex = 1.5), + comid = list(col = "green"))), + stoponlargerequest = FALSE)

We can also plot NHDPlus data without an outlet at all.

-bbox <- sf::st_bbox(c(xmin = -89.56684, ymin = 42.99816, xmax = -89.24681, ymax = 43.17192),
-                    crs = "+proj=longlat +datum=WGS84 +no_defs")
-plot_nhdplus(bbox = bbox)
+bbox <- sf::st_bbox(c(xmin = -89.56684, ymin = 42.99816, xmax = -89.24681, ymax = 43.17192), + crs = "+proj=longlat +datum=WGS84 +no_defs") +plot_nhdplus(bbox = bbox)

-

The plots above are all in the EPSG:3857 projection to be compatible with background tiles. Any data added to these plots must be projected to this coordinate system to be added to the plot.

+

The plots above are all in the EPSG:3857 projection to be compatible +with background tiles. Any data added to these plots must be projected +to this coordinate system to be added to the plot.

Getting Data

-

What follows shows how to use nhdplusTools to create plots without the plot_nhdplus function. While super convenient, we all know the “easy button” is never quite right, the description below should help get you started.

-

For this example, we’ll start from an outlet NWIS Site. Note that other options are possible with discover_nhdplus_id and dataRetrieval::get_nldi_sources.

+

What follows shows how to use nhdplusTools to create +plots without the plot_nhdplus function. While super +convenient, we all know the “easy button” is never quite right, the +description below should help get you started.

+

For this example, we’ll start from an outlet NWIS Site. Note that +other options are possible with discover_nhdplus_id and +dataRetrieval::get_nldi_sources.

-library(sf)
-library(nhdplusTools)
-nwissite <- list(featureSource = "nwissite", 
-                     featureID = "USGS-05428500")
-
-flowline <- navigate_nldi(nwissite, 
-                          mode = "upstreamTributaries", 
-                          data_source = "flowlines")
-
-nhdplus <- subset_nhdplus(comids = as.integer(flowline$UT$nhdplus_comid),
-                          output_file = file.path(work_dir, "nhdplus.gpkg"),
-                          nhdplus_data = "download",
-                          overwrite = TRUE, return_data = FALSE)
-#> All intersections performed in latitude/longitude.
-#> Reading NHDFlowline_Network
-#> Writing NHDFlowline_Network
-
-flowline <- read_sf(nhdplus, "NHDFlowline_Network")
-
-upstream_nwis <- navigate_nldi(nwissite,
-                               mode = "upstreamTributaries",
-                               data_source = "nwissite")
-
-basin <- get_nldi_basin(nwissite)
-

Now we have a file at the path held in the variable nhdplus and three sf data.frames with contents that look like:

+library(sf) +library(nhdplusTools) +nwissite <- list(featureSource = "nwissite", + featureID = "USGS-05428500") + +flowline <- navigate_nldi(nwissite, + mode = "upstreamTributaries", + data_source = "flowlines") + +nhdplus <- subset_nhdplus(comids = as.integer(flowline$UT$nhdplus_comid), + output_file = file.path(work_dir, "nhdplus.gpkg"), + nhdplus_data = "download", + overwrite = TRUE, return_data = FALSE) +#> All intersections performed in latitude/longitude. +#> Reading NHDFlowline_Network +#> Spherical geometry (s2) switched off +#> Spherical geometry (s2) switched on +#> Writing NHDFlowline_Network + +flowline <- read_sf(nhdplus, "NHDFlowline_Network") + +upstream_nwis <- navigate_nldi(nwissite, + mode = "upstreamTributaries", + data_source = "nwissite") + +basin <- get_nldi_basin(nwissite)
+

Now we have a file at the path held in the variable +nhdplus and three sf data.frames +with contents that look like:

-st_layers(nhdplus)
-#> Driver: GPKG 
-#> Available layers:
-#>            layer_name geometry_type features fields crs_name
-#> 1 NHDFlowline_Network   Line String       10    138    NAD83
-names(flowline)
-#>   [1] "id"           "comid"        "fdate"        "resolution"   "gnis_id"     
-#>   [6] "gnis_name"    "lengthkm"     "reachcode"    "flowdir"      "wbareacomi"  
-#>  [11] "ftype"        "fcode"        "shape_length" "streamleve"   "streamorde"  
-#>  [16] "streamcalc"   "fromnode"     "tonode"       "hydroseq"     "levelpathi"  
-#>  [21] "pathlength"   "terminalpa"   "arbolatesu"   "divergence"   "startflag"   
-#>  [26] "terminalfl"   "dnlevel"      "uplevelpat"   "uphydroseq"   "dnlevelpat"  
-#>  [31] "dnminorhyd"   "dndraincou"   "dnhydroseq"   "frommeas"     "tomeas"      
-#>  [36] "rtndiv"       "vpuin"        "vpuout"       "areasqkm"     "totdasqkm"   
-#>  [41] "divdasqkm"    "tidal"        "totma"        "wbareatype"   "pathtimema"  
-#>  [46] "hwnodesqkm"   "maxelevraw"   "minelevraw"   "maxelevsmo"   "minelevsmo"  
-#>  [51] "slope"        "elevfixed"    "hwtype"       "slopelenkm"   "qa_ma"       
-#>  [56] "va_ma"        "qc_ma"        "vc_ma"        "qe_ma"        "ve_ma"       
-#>  [61] "qa_01"        "va_01"        "qc_01"        "vc_01"        "qe_01"       
-#>  [66] "ve_01"        "qa_02"        "va_02"        "qc_02"        "vc_02"       
-#>  [71] "qe_02"        "ve_02"        "qa_03"        "va_03"        "qc_03"       
-#>  [76] "vc_03"        "qe_03"        "ve_03"        "qa_04"        "va_04"       
-#>  [81] "qc_04"        "vc_04"        "qe_04"        "ve_04"        "qa_05"       
-#>  [86] "va_05"        "qc_05"        "vc_05"        "qe_05"        "ve_05"       
-#>  [91] "qa_06"        "va_06"        "qc_06"        "vc_06"        "qe_06"       
-#>  [96] "ve_06"        "qa_07"        "va_07"        "qc_07"        "vc_07"       
-#> [101] "qe_07"        "ve_07"        "qa_08"        "va_08"        "qc_08"       
-#> [106] "vc_08"        "qe_08"        "ve_08"        "qa_09"        "va_09"       
-#> [111] "qc_09"        "vc_09"        "qe_09"        "ve_09"        "qa_10"       
-#> [116] "va_10"        "qc_10"        "vc_10"        "qe_10"        "ve_10"       
-#> [121] "qa_11"        "va_11"        "qc_11"        "vc_11"        "qe_11"       
-#> [126] "ve_11"        "qa_12"        "va_12"        "qc_12"        "vc_12"       
-#> [131] "qe_12"        "ve_12"        "lakefract"    "surfarea"     "rareahload"  
-#> [136] "rpuid"        "vpuid"        "enabled"      "geom"
-names(upstream_nwis)
-#> [1] "origin"      "UT_nwissite"
-names(basin)
-#> [1] "geometry"
-class(st_geometry(flowline))
-#> [1] "sfc_LINESTRING" "sfc"
-class(st_geometry(upstream_nwis$UT_nwissite))
-#> [1] "sfc_POINT" "sfc"
-class(st_geometry(basin))
-#> [1] "sfc_POLYGON" "sfc"
-

Our file has four layers: network flowlines, simplified catchments, nhd area features, and nhd waterbody features.

-

The flowlines have a large set of attributes from the NHDPlus dataset. And the nwis sites have a few attributes that came from the NLDI. Attributes for NWIS sites can be found using the dataRetrieval package.

-

See the NHDPlus user guide linked here for more on what these layers are and what the flowline attributes entail.

+st_layers(nhdplus) +#> Driver: GPKG +#> Available layers: +#> layer_name geometry_type features fields +#> 1 NHDFlowline_Network Line String 10 138 +names(flowline) +#> [1] "id" "comid" "fdate" "resolution" "gnis_id" +#> [6] "gnis_name" "lengthkm" "reachcode" "flowdir" "wbareacomi" +#> [11] "ftype" "fcode" "shape_length" "streamleve" "streamorde" +#> [16] "streamcalc" "fromnode" "tonode" "hydroseq" "levelpathi" +#> [21] "pathlength" "terminalpa" "arbolatesu" "divergence" "startflag" +#> [26] "terminalfl" "dnlevel" "uplevelpat" "uphydroseq" "dnlevelpat" +#> [31] "dnminorhyd" "dndraincou" "dnhydroseq" "frommeas" "tomeas" +#> [36] "rtndiv" "vpuin" "vpuout" "areasqkm" "totdasqkm" +#> [41] "divdasqkm" "tidal" "totma" "wbareatype" "pathtimema" +#> [46] "hwnodesqkm" "maxelevraw" "minelevraw" "maxelevsmo" "minelevsmo" +#> [51] "slope" "elevfixed" "hwtype" "slopelenkm" "qa_ma" +#> [56] "va_ma" "qc_ma" "vc_ma" "qe_ma" "ve_ma" +#> [61] "qa_01" "va_01" "qc_01" "vc_01" "qe_01" +#> [66] "ve_01" "qa_02" "va_02" "qc_02" "vc_02" +#> [71] "qe_02" "ve_02" "qa_03" "va_03" "qc_03" +#> [76] "vc_03" "qe_03" "ve_03" "qa_04" "va_04" +#> [81] "qc_04" "vc_04" "qe_04" "ve_04" "qa_05" +#> [86] "va_05" "qc_05" "vc_05" "qe_05" "ve_05" +#> [91] "qa_06" "va_06" "qc_06" "vc_06" "qe_06" +#> [96] "ve_06" "qa_07" "va_07" "qc_07" "vc_07" +#> [101] "qe_07" "ve_07" "qa_08" "va_08" "qc_08" +#> [106] "vc_08" "qe_08" "ve_08" "qa_09" "va_09" +#> [111] "qc_09" "vc_09" "qe_09" "ve_09" "qa_10" +#> [116] "va_10" "qc_10" "vc_10" "qe_10" "ve_10" +#> [121] "qa_11" "va_11" "qc_11" "vc_11" "qe_11" +#> [126] "ve_11" "qa_12" "va_12" "qc_12" "vc_12" +#> [131] "qe_12" "ve_12" "lakefract" "surfarea" "rareahload" +#> [136] "rpuid" "vpuid" "enabled" "geom" +names(upstream_nwis) +#> [1] "origin" "UT_nwissite" +names(basin) +#> [1] "geometry" +class(st_geometry(flowline)) +#> [1] "sfc_LINESTRING" "sfc" +class(st_geometry(upstream_nwis$UT_nwissite)) +#> [1] "sfc_POINT" "sfc" +class(st_geometry(basin)) +#> [1] "sfc_POLYGON" "sfc" +

Our file has four layers: network flowlines, simplified catchments, +nhd area features, and nhd waterbody features.

+

The flowlines have a large set of attributes from the NHDPlus +dataset. And the nwis sites have a few attributes that came from the +NLDI. Attributes for NWIS sites can be found using the dataRetrieval +package.

+

See the NHDPlus user guide linked +here for more on what these layers are and what the flowline +attributes entail.

Bounding Boxes

-

First, a side note on bounding boxes. With the ongoing transition from the sp package to the sf package, there are a few stumbling blocks. Bounding boxes are one of them. As shown below, the sf bbox format is a named vector of class “bbox”. The sp bbox format is a matrix with named dimensions. Many packages expect the sp format. the ggmap package expects yet another bbox format, much like sf but with different names.

+

First, a side note on bounding boxes. With the ongoing transition +from the sp package to the sf package, there +are a few stumbling blocks. Bounding boxes are one of them. As shown +below, the sf bbox format is a named vector of class +“bbox”. The sp bbox format is a matrix with named +dimensions. Many packages expect the sp format. the ggmap +package expects yet another bbox format, much like sf but +with different names.

-library(sp)
-
-sf_bbox <- st_bbox(basin)
-sf_bbox
-#>      xmin      ymin      xmax      ymax 
-#> -89.60465  43.03507 -89.20378  43.36607
-class(sf_bbox)
-#> [1] "bbox"
-
-sp_bbox <- sp::bbox(sf::as_Spatial(basin))
-sp_bbox
-#>         min       max
-#> x -89.60465 -89.20378
-#> y  43.03507  43.36607
-class(sp_bbox)
-#> [1] "matrix" "array"
-
-# Or without the sp::bbox
-sp_bbox <- matrix(sf_bbox, 
-                  byrow = FALSE, 
-                  ncol = 2, 
-                  dimnames = list(c("x", "y"), 
-                                  c("min", "max")))
-sp_bbox
-#>         min       max
-#> x -89.60465 -89.20378
-#> y  43.03507  43.36607
-
-ggmap_bbox <- setNames(sf_bbox, c("left", "bottom", "right", "top"))
-ggmap_bbox
-#>      left    bottom     right       top 
-#> -89.60465  43.03507 -89.20378  43.36607
+library(sp) + +sf_bbox <- st_bbox(basin) +sf_bbox +#> xmin ymin xmax ymax +#> -89.60465 43.03507 -89.20378 43.36607 +class(sf_bbox) +#> [1] "bbox" + +sp_bbox <- sp::bbox(sf::as_Spatial(basin)) +sp_bbox +#> min max +#> x -89.60465 -89.20378 +#> y 43.03507 43.36607 +class(sp_bbox) +#> [1] "matrix" "array" + +# Or without the sp::bbox +sp_bbox <- matrix(sf_bbox, + byrow = FALSE, + ncol = 2, + dimnames = list(c("x", "y"), + c("min", "max"))) +sp_bbox +#> min max +#> x -89.60465 -89.20378 +#> y 43.03507 43.36607 + +ggmap_bbox <- setNames(sf_bbox, c("left", "bottom", "right", "top")) +ggmap_bbox +#> left bottom right top +#> -89.60465 43.03507 -89.20378 43.36607

Base R Plotting

-

In order to maximize flexibility and make sure we understand what’s going on with coordinate reference systems, the demonstration below shows how to use base R plotting with the package prettymappr and rosm.

-

In this example, we have to plot just the geometry, extracted with st_geometry and we need to project the geometry into the plotting coordinate reference system, EPSG:3857 also known as “web mercator”. The reason we have to make this transformation is that practically all basemap tiles are in this projection and reprojection of pre-rendered tiles doesn’t look good. We do this with a simple prep_layer function.

-

The prettymapr::prettymap() function isn’t strictly necessary, but it gives us nice margins, a scale bar, and a north arrow. The rosm::osm.plot and base plot commands put data onto the R plotting device so the first to be plotted is on the bottom. A couple hints here. lwd is line width. pch is point style. cex is an expansion factor. Colors shown below are basic R colors. the rgb function is handy for creating colors with transparency if that’s of interest.

+

In order to maximize flexibility and make sure we understand what’s +going on with coordinate reference systems, the demonstration below +shows how to use base R plotting with the package +prettymappr and rosm.

+

In this example, we have to plot just the geometry, extracted with +st_geometry and we need to project the geometry into the +plotting coordinate reference system, EPSG:3857 also known +as “web mercator”. The reason we have to make this transformation is +that practically all basemap tiles are in this projection and +reprojection of pre-rendered tiles doesn’t look good. We do this with a +simple prep_layer function.

+

The prettymapr::prettymap() function isn’t strictly +necessary, but it gives us nice margins, a scale bar, and a north arrow. +The rosm::osm.plot and base plot commands put +data onto the R plotting device so the first to be plotted is on the +bottom. A couple hints here. lwd is line width. +pch is point style. cex is an expansion +factor. Colors shown below are basic R +colors. the rgb function is handy for creating colors +with transparency if that’s of interest.

-prep_layer <- function(x) st_geometry(st_transform(x, 3857))
-
-prettymapr::prettymap({
-  rosm::osm.plot(sp_bbox, type = "cartolight", quiet = TRUE, 
-                 progress = "none", cachedir = work_dir)
-  
-  plot(prep_layer(basin), 
-       lwd = 2, add = TRUE)
-  
-  plot(prep_layer(flowline), 
-       lwd = 1.5, col = "deepskyblue", add = TRUE)
-  
-  plot(prep_layer(dplyr::filter(flowline, streamorde > 2)), 
-       lwd = 3, col = "darkblue", add = TRUE)
-  
-  us_nwis_layer <- prep_layer(upstream_nwis)
-  
-  plot(us_nwis_layer, 
-       pch = 17, cex = 1.5, col = "yellow", add = TRUE)
-  
-  label_pos <- st_coordinates(us_nwis_layer)
-  
-  text(label_pos[,1],label_pos[,2], 
-       upstream_nwis$identifier, 
-       adj = c(-0.2, 0.5), cex = 0.7)
-  
-}, drawarrow = TRUE)
-#> Zoom: 10
-#> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
-#> Error occured while plotting:  Error in UseMethod("st_transform"): no applicable method for 'st_transform' applied to an object of class "list"
+prep_layer <- function(x) st_geometry(st_transform(x, 3857)) + +prettymapr::prettymap({ + rosm::osm.plot(sp_bbox, type = "cartolight", quiet = TRUE, + progress = "none", cachedir = work_dir) + + plot(prep_layer(basin), + lwd = 2, add = TRUE) + + plot(prep_layer(flowline), + lwd = 1.5, col = "deepskyblue", add = TRUE) + + plot(prep_layer(dplyr::filter(flowline, streamorde > 2)), + lwd = 3, col = "darkblue", add = TRUE) + + us_nwis_layer <- prep_layer(upstream_nwis) + + plot(us_nwis_layer, + pch = 17, cex = 1.5, col = "yellow", add = TRUE) + + label_pos <- st_coordinates(us_nwis_layer) + + text(label_pos[,1],label_pos[,2], + upstream_nwis$identifier, + adj = c(-0.2, 0.5), cex = 0.7) + +}, drawarrow = TRUE) +#> Zoom: 10 +#> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL. +#> Error occured while plotting: Error in UseMethod("st_transform"): no applicable method for 'st_transform' applied to an object of class "list"

Plotting with ggplot2

-

Below is a very similar example using ggmap and ggplot2 geom_sf. Note that ggmap takes case of projections for us, which should either make you happy because it just works or very nervous because it just works.

+

Below is a very similar example using ggmap and ggplot2 +geom_sf. Note that ggmap takes case of projections for +us, which should either make you happy because it just works or +very nervous because it just works.

-library(ggmap)
-library(ggplot2)
-
-upstream_nwis <- dplyr::bind_cols(upstream_nwis$UT_nwissite,
-                           dplyr::rename(dplyr::as_tibble(sf::st_coordinates(upstream_nwis$UT_nwissite)), 
-                                         lat = Y, lon = X))
-
-basemap_toner <- get_map(source = "stamen", maptype = "toner", 
-                         location = ggmap_bbox, zoom = 11, messaging = FALSE)
-basemap_terrain <- get_map(source = "stamen", maptype = "terrain-lines", 
-                           location = ggmap_bbox, zoom = 11, messaging = FALSE)
-toner_map <- ggmap(basemap_toner)
-terrain_map <- ggmap(basemap_terrain)
-
-toner_map
+library(ggmap) +library(ggplot2) + +upstream_nwis <- dplyr::bind_cols(upstream_nwis$UT_nwissite, + dplyr::rename(dplyr::as_tibble(sf::st_coordinates(upstream_nwis$UT_nwissite)), + lat = Y, lon = X)) + +basemap_toner <- get_map(source = "stamen", maptype = "toner", + location = ggmap_bbox, zoom = 11, messaging = FALSE) +basemap_terrain <- get_map(source = "stamen", maptype = "terrain-lines", + location = ggmap_bbox, zoom = 11, messaging = FALSE) +toner_map <- ggmap(basemap_toner) +terrain_map <- ggmap(basemap_terrain) + +toner_map

-
-terrain_map + geom_sf(data = basin,
-                        inherit.aes = FALSE,
-                        color = "black", fill = NA) + 
-  geom_sf(data = flowline,
-          inherit.aes = FALSE,
-          color = "deepskyblue") +
-  geom_sf(data = dplyr::filter(flowline, streamorde > 2),
-          inherit.aes = FALSE,
-          color = "darkblue") +
-  geom_sf(data = upstream_nwis, inherit.aes = FALSE, color = "red") + 
-  geom_text(data = upstream_nwis, aes(label = identifier, x = lon, y = lat),
-            hjust = 0, size=2.5, nudge_x = 0.02, col = "black")
+ +terrain_map + geom_sf(data = basin, + inherit.aes = FALSE, + color = "black", fill = NA) + + geom_sf(data = flowline, + inherit.aes = FALSE, + color = "deepskyblue") + + geom_sf(data = dplyr::filter(flowline, streamorde > 2), + inherit.aes = FALSE, + color = "darkblue") + + geom_sf(data = upstream_nwis, inherit.aes = FALSE, color = "red") + + geom_text(data = upstream_nwis, aes(label = identifier, x = lon, y = lat), + hjust = 0, size=2.5, nudge_x = 0.02, col = "black")

-

Hopefully these examples give a good head start to plotting NHDPlus data. Please submit questions via github issues for more!! Pull requests on this vignette are more than welcome if you have additions or suggestions.

+

Hopefully these examples give a good head start to plotting NHDPlus +data. Please submit questions via github issues for more!! Pull requests +on this vignette are more than welcome if you have additions or +suggestions.

@@ -379,7 +443,7 @@

Plotting with ggplot2

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/articles/plot_nhdplus_files/figure-html/ggmap-2.png b/docs/articles/plot_nhdplus_files/figure-html/ggmap-2.png index 13a0161e..d9a34838 100644 Binary files a/docs/articles/plot_nhdplus_files/figure-html/ggmap-2.png and b/docs/articles/plot_nhdplus_files/figure-html/ggmap-2.png differ diff --git a/docs/authors.html b/docs/authors.html index a046ec6c..00396e6f 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -104,10 +104,10 @@

Citation

title = {nhdplusTools: Tools for Accessing and Working with the NHDPlus}, publisher = {U.S. Geological Survey}, address = {Reston, VA}, - version = {0.5.1}, + version = {0.5.6}, institution = {U.S. Geological Survey}, year = {2022}, - url = {https://code.usgs.gov/water/nhdplusTools}, + url = {https://doi.org/10.5066/P97AS8JD}, } @@ -121,7 +121,7 @@

Citation

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/index.html b/docs/index.html index 2af3b4fc..7e903709 100644 --- a/docs/index.html +++ b/docs/index.html @@ -40,7 +40,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -117,10 +117,10 @@

Dev status

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/news/index.html b/docs/news/index.html index 5f663212..f874c9dc 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -73,7 +73,17 @@

Changelog

- + +
+
+ +

Note v0.5.4 was burned in a CRAN release mistake

+

fixes a cran test failure in an example and an issue with precision of get_flowline_index()

+
+
+

v0.5.3 is primarily bug fixes and enhancements.

One notable addition is the addition of the rpu_boundaries and vpu_boundaries datasets which provide simplified polygons around the RPU and VPU subset domains of the nhdplusV2 dataset.

@@ -272,7 +282,7 @@

Add NHDPlus Network Attributes to a provided network.

-
add_plus_network_attributes(
-  net,
-  override = 5,
-  cores = NULL,
-  split_temp = NULL,
-  status = TRUE
-)
+
add_plus_network_attributes(
+  net,
+  override = 5,
+  cores = NULL,
+  split_temp = NULL,
+  status = TRUE
+)
@@ -103,42 +103,53 @@

Arguments

tocomid == 0 is the convention used for outlets. If a "weight" column is provided, it will be used in get_levelpaths otherwise, arbolate sum is calculated for the network and used as the weight.

+ +
override

numeric factor to be passed to get_levelpaths

+ +
cores

integer number of processes to spawn if run in parallel.

+ +
split_temp

character path to optional temporary copy of the network split into independent sub-networks. If it exists, it will be read from disk rather than recreated.

+ +
status

logical should progress be printed?

+

Value

-

data.frame with added attributes

+ + +

data.frame with added attributes

Examples

-

-source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
-
-test_flowline <- prepare_nhdplus(walker_flowline, 0, 0, FALSE)
+    

+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(
-  comid = test_flowline$COMID,
-  tocomid = test_flowline$toCOMID,
-  nameID = walker_flowline$GNIS_ID,
-  lengthkm = test_flowline$LENGTHKM,
-  areasqkm = walker_flowline$AreaSqKM)
-
-add_plus_network_attributes(test_flowline)
-#> # A tibble: 62 x 14
+
+test_flowline <- data.frame(
+  comid = test_flowline$COMID,
+  tocomid = test_flowline$toCOMID,
+  nameID = walker_flowline$GNIS_ID,
+  lengthkm = test_flowline$LENGTHKM,
+  areasqkm = walker_flowline$AreaSqKM)
+
+add_plus_network_attributes(test_flowline)
+#> # A tibble: 62 × 14
 #>     comid tocomid nameID lengthkm areasqkm weight terminalpa hydroseq levelpathi
 #>     <int>   <int> <chr>     <dbl>    <dbl>  <dbl>      <dbl>    <dbl>      <dbl>
 #>  1 5.33e6       0 255208    1.20     0.868  137.           1        1          1
@@ -151,7 +162,7 @@ 

Examples

#> 8 5.33e6 5329343 255208 3.60 6.94 61.9 1 31 1 #> 9 5.33e6 5329357 255208 3.14 5.13 51.1 1 37 1 #> 10 5.33e6 5329365 254577 1.46 1.69 37.8 1 42 1 -#> # ... with 52 more rows, and 5 more variables: pathlength <dbl>, +#> # … with 52 more rows, and 5 more variables: pathlength <dbl>, #> # dnlevelpat <dbl>, dnhydroseq <dbl>, totdasqkm <dbl>, terminalfl <dbl>
@@ -167,7 +178,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/align_nhdplus_names.html b/docs/reference/align_nhdplus_names.html index aca9d03c..cf357285 100644 --- a/docs/reference/align_nhdplus_names.html +++ b/docs/reference/align_nhdplus_names.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -78,24 +78,27 @@

Align NHD Dataset Names

-
align_nhdplus_names(x)
+
align_nhdplus_names(x)

Arguments

x

a sf object of nhdplus flowlines

+

Value

-

data.frame renamed sf object

+ + +

data.frame renamed sf object

Examples

-
source(system.file("extdata/new_hope_data.R", package = "nhdplusTools"))
-
-names(new_hope_flowline)
+    
source(system.file("extdata/new_hope_data.R", package = "nhdplusTools"))
+
+names(new_hope_flowline)
 #>   [1] "COMID"      "FDATE"      "RESOLUTION" "GNIS_ID"    "GNIS_NAME" 
 #>   [6] "LENGTHKM"   "REACHCODE"  "FLOWDIR"    "WBAREACOMI" "FTYPE"     
 #>  [11] "FCODE"      "StreamLeve" "StreamOrde" "StreamCalc" "FromNode"  
@@ -124,12 +127,12 @@ 

Examples

#> [126] "QC_12" "VC_12" "QE_12" "VE_12" "LakeFract" #> [131] "SurfArea" "RAreaHLoad" "RPUID" "VPUID" "Enabled" #> [136] "geom" - -names(new_hope_flowline) <- tolower(names(new_hope_flowline)) - -new_hope_flowline <- align_nhdplus_names(new_hope_flowline) - -names(new_hope_flowline) + +names(new_hope_flowline) <- tolower(names(new_hope_flowline)) + +new_hope_flowline <- align_nhdplus_names(new_hope_flowline) + +names(new_hope_flowline) #> [1] "COMID" "fdate" "resolution" "gnis_id" "gnis_name" #> [6] "LENGTHKM" "REACHCODE" "flowdir" "WBAREACOMI" "FTYPE" #> [11] "FCODE" "streamleve" "StreamOrde" "StreamCalc" "FromNode" @@ -158,7 +161,7 @@

Examples

#> [126] "qc_12" "vc_12" "qe_12" "ve_12" "lakefract" #> [131] "surfarea" "rareahload" "RPUID" "VPUID" "enabled" #> [136] "geom" - +
@@ -173,7 +176,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/calculate_arbolate_sum.html b/docs/reference/calculate_arbolate_sum.html index da8803cb..1403f34a 100644 --- a/docs/reference/calculate_arbolate_sum.html +++ b/docs/reference/calculate_arbolate_sum.html @@ -19,7 +19,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -82,22 +82,25 @@

Calculate Arbolate Sum

-
calculate_arbolate_sum(x)
+
calculate_arbolate_sum(x)

Arguments

x

data.frame with ID, toID, and length columns.

+

Value

-

numeric with arbolate sum.

+ + +

numeric with arbolate sum.

Examples

-
library(dplyr)
+    
library(dplyr)
 #> 
 #> Attaching package: 'dplyr'
 #> The following objects are masked from 'package:stats':
@@ -106,22 +109,22 @@ 

Examples

#> The following objects are masked from 'package:base': #> #> intersect, setdiff, setequal, union -source(system.file("extdata", "walker_data.R", package = "nhdplusTools")) -catchment_length <- select(walker_flowline, COMID, AreaSqKM) %>% - right_join(prepare_nhdplus(walker_flowline, 0, 0, - purge_non_dendritic = FALSE, warn = FALSE), by = "COMID") %>% - select(ID = COMID, toID = toCOMID, length = LENGTHKM) - -arb_sum <- calculate_arbolate_sum(catchment_length) - -catchment_length$arb_sum <- arb_sum -catchment_length$nhd_arb_sum <- walker_flowline$ArbolateSu - -mean(abs(catchment_length$arb_sum - catchment_length$nhd_arb_sum)) +source(system.file("extdata", "walker_data.R", package = "nhdplusTools")) +catchment_length <- select(walker_flowline, COMID, AreaSqKM) %>% + right_join(prepare_nhdplus(walker_flowline, 0, 0, + purge_non_dendritic = FALSE, warn = FALSE), by = "COMID") %>% + select(ID = COMID, toID = toCOMID, length = LENGTHKM) + +arb_sum <- calculate_arbolate_sum(catchment_length) + +catchment_length$arb_sum <- arb_sum +catchment_length$nhd_arb_sum <- walker_flowline$ArbolateSu + +mean(abs(catchment_length$arb_sum - catchment_length$nhd_arb_sum)) #> [1] 1.73338e-15 -max(abs(catchment_length$arb_sum - catchment_length$nhd_arb_sum)) +max(abs(catchment_length$arb_sum - catchment_length$nhd_arb_sum)) #> [1] 2.842171e-14 - +
@@ -136,7 +139,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/calculate_total_drainage_area.html b/docs/reference/calculate_total_drainage_area.html index 78b05ca0..47bd53c3 100644 --- a/docs/reference/calculate_total_drainage_area.html +++ b/docs/reference/calculate_total_drainage_area.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,38 +80,41 @@

Total Drainage Area

-
calculate_total_drainage_area(x)
+
calculate_total_drainage_area(x)

Arguments

x

data.frame with ID, toID, and area columns.

+

Value

-

numeric with total area.

+ + +

numeric with total area.

Examples

-
library(dplyr)
-source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
-catchment_area <- select(walker_flowline, COMID, AreaSqKM) %>%
-  right_join(prepare_nhdplus(walker_flowline, 0, 0,
-                            purge_non_dendritic = FALSE, warn = FALSE), by = "COMID") %>%
-  select(ID = COMID, toID = toCOMID, area = AreaSqKM)
-
-new_da <- calculate_total_drainage_area(catchment_area)
-
-catchment_area$totda <- new_da
-catchment_area$nhdptotda <- walker_flowline$TotDASqKM
-
-mean(abs(catchment_area$totda - catchment_area$nhdptotda))
+    
library(dplyr)
+source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
+catchment_area <- select(walker_flowline, COMID, AreaSqKM) %>%
+  right_join(prepare_nhdplus(walker_flowline, 0, 0,
+                            purge_non_dendritic = FALSE, warn = FALSE), by = "COMID") %>%
+  select(ID = COMID, toID = toCOMID, area = AreaSqKM)
+
+new_da <- calculate_total_drainage_area(catchment_area)
+
+catchment_area$totda <- new_da
+catchment_area$nhdptotda <- walker_flowline$TotDASqKM
+
+mean(abs(catchment_area$totda - catchment_area$nhdptotda))
 #> [1] 2.607233e-15
-max(abs(catchment_area$totda - catchment_area$nhdptotda))
+max(abs(catchment_area$totda - catchment_area$nhdptotda))
 #> [1] 2.842171e-14
-
+
 
@@ -126,7 +129,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/disambiguate_flowline_indexes.html b/docs/reference/disambiguate_flowline_indexes.html index b77bed08..efe9b7fc 100644 --- a/docs/reference/disambiguate_flowline_indexes.html +++ b/docs/reference/disambiguate_flowline_indexes.html @@ -21,7 +21,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -86,7 +86,7 @@

Disambiguate Flowline Indexes

-
disambiguate_flowline_indexes(indexes, flowpath, hydro_location)
+
disambiguate_flowline_indexes(indexes, flowpath, hydro_location)
@@ -94,72 +94,79 @@

Arguments

indexes

data.frame as output from get_flowline_index with more than one hydrologic location per indexed point.

+ +
flowpath

data.frame with two columns. The first should join to the COMID field of the indexes and the second should be the numeric or ascii metric such as drainage area or GNIS Name. Names of this data.frame are not used.

+ +
hydro_location

data.frame with two columns. The first should join to the id field of the indexes and the second should be the numeric or ascii metric such as drainage area or GNIS Name.. Names of this data,frame are not used.

+

Value

-

data.frame indexes deduplicated according to the minimum difference + + +

data.frame indexes deduplicated according to the minimum difference between the values in the metric columns. If two or more result in the same "minimum" value, duplicates will be returned.

Examples

-
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"))
-
-flowpath <- dplyr::select(sample_flines,
-                          comid = COMID,
-                          totda = TotDASqKM,
-                          nameid = GNIS_NAME,
-                          REACHCODE,
-                          ToMeas,
-                          FromMeas)
-
-indexes <- get_flowline_index(flowpath,
-                              hydro_location,
-                              search_radius = 0.2,
-                              max_matches = 10)
+    
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"))
+
+flowpath <- dplyr::select(sample_flines,
+                          comid = COMID,
+                          totda = TotDASqKM,
+                          nameid = GNIS_NAME,
+                          REACHCODE,
+                          ToMeas,
+                          FromMeas)
+
+indexes <- get_flowline_index(flowpath,
+                              hydro_location,
+                              search_radius = 0.2,
+                              max_matches = 10)
 #> Warning: search_radius units not set, trying units of points.
-
-disambiguate_flowline_indexes(indexes,
-                              dplyr::select(flowpath, comid, totda),
-                              dplyr::select(hydro_location, id, totda))
-#> # A tibble: 3 x 5
+
+disambiguate_flowline_indexes(indexes,
+                              dplyr::select(flowpath, comid, totda),
+                              dplyr::select(hydro_location, id, totda))
+#> # A tibble: 3 × 5
 #>      id    COMID REACHCODE      REACH_meas    offset
 #>   <dbl>    <int> <chr>               <dbl>     <dbl>
 #> 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_flowline_indexes(indexes,
-                                        dplyr::select(flowpath, comid, nameid),
-                                        dplyr::select(hydro_location, id, nameid))
-
-result[result$id == 1, ]
-#> # A tibble: 3 x 5
+
+result <- disambiguate_flowline_indexes(indexes,
+                                        dplyr::select(flowpath, comid, nameid),
+                                        dplyr::select(hydro_location, id, nameid))
+
+result[result$id == 1, ]
+#> # A tibble: 3 × 5
 #>      id    COMID REACHCODE      REACH_meas  offset
 #>   <dbl>    <int> <chr>               <dbl>   <dbl>
 #> 1     1 11689928 02060003001468          0 0.00203
 #> 2     1 11689978 02060003001472        100 0.00203
 #> 3     1 11690532 02060003000256          0 0.00451
-
-result[result$id == 2, ]
-#> # A tibble: 10 x 5
+
+result[result$id == 2, ]
+#> # A tibble: 10 × 5
 #>       id    COMID REACHCODE      REACH_meas   offset
 #>    <dbl>    <int> <chr>               <dbl>    <dbl>
 #>  1     2 11688808 02060003000519       53.6 0.000564
@@ -172,13 +179,13 @@ 

Examples

#> 8 2 11688868 02060003000517 27.8 0.0169 #> 9 2 11690124 02060003001496 100 0.0195 #> 10 2 11690128 02060003001498 100 0.0210 - -result[result$id == 3, ] -#> # A tibble: 1 x 5 + +result[result$id == 3, ] +#> # A tibble: 1 × 5 #> id COMID REACHCODE REACH_meas offset #> <dbl> <int> <chr> <dbl> <dbl> #> 1 3 11688948 02060003000516 0 0.00321 - +
@@ -193,7 +200,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/discover_nhdplus_id.html b/docs/reference/discover_nhdplus_id.html index 025ac12e..2fc5d671 100644 --- a/docs/reference/discover_nhdplus_id.html +++ b/docs/reference/discover_nhdplus_id.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -78,7 +78,7 @@

Discover NHDPlus ID

-
discover_nhdplus_id(point = NULL, nldi_feature = NULL, raindrop = FALSE)
+
discover_nhdplus_id(point = NULL, nldi_feature = NULL, raindrop = FALSE)
@@ -86,45 +86,52 @@

Arguments

point

sfc POINT including crs as created by: sf::st_sfc(sf::st_point(.. ,..), crs)

+ +
nldi_feature

list with names `featureSource` and `featureID` where `featureSource` is derived from the "source" column of the response of get_nldi_sources and the `featureSource` is a known identifier from the specified `featureSource`.

+ +
raindrop

logical if TRUE will call a raindrop trace web service and return will be the same as get_raindrop_trace with direction "none".

+

Value

-

integer COMID or list containing COMID and raindrop trace.

+ + +

integer COMID or list containing COMID and raindrop trace.

Examples

-
# \donttest{
-point <- sf::st_sfc(sf::st_point(c(-76.874, 39.482)), crs = 4326)
-discover_nhdplus_id(point)
+    
# \donttest{
+point <- sf::st_sfc(sf::st_point(c(-76.874, 39.482)), crs = 4326)
+discover_nhdplus_id(point)
 #> [1] 11689978
-
-discover_nhdplus_id(point, raindrop = TRUE)
+
+discover_nhdplus_id(point, raindrop = TRUE)
 #> Simple feature collection with 2 features and 7 fields
 #> Geometry type: LINESTRING
 #> Dimension:     XY
 #> Bounding box:  xmin: -76.88292 ymin: 39.47138 xmax: -76.86733 ymax: 39.49148
 #> Geodetic CRS:  WGS 84
-#> # A tibble: 2 x 8
-#>   id       gnis_name   comid reachcode raindrop_pathDi~ measure intersection_po~
+#> # A tibble: 2 × 8
+#>   id       gnis_name   comid reachcode raindrop_pathDi… measure intersection_po…
 #>   <chr>    <chr>       <int> <chr>                <dbl>   <dbl> <list>          
-#> 1 nhdFlow~ North Br~  1.17e7 02060003~             62.6    53.9 <dbl [2]>       
-#> 2 raindro~ NA        NA      NA                    NA      NA   <dbl [0]>       
-#> # ... with 1 more variable: geometry <LINESTRING [°]>
-
-nldi_nwis <- list(featureSource = "nwissite", featureID = "USGS-08279500")
-discover_nhdplus_id(nldi_feature = nldi_nwis)
+#> 1 nhdFlow… North Br…  1.17e7 02060003…             62.6    53.9 <dbl [2]>       
+#> 2 raindro… NA        NA      NA                    NA      NA   <dbl [0]>       
+#> # … with 1 more variable: geometry <LINESTRING [°]>
+
+nldi_nwis <- list(featureSource = "nwissite", featureID = "USGS-08279500")
+discover_nhdplus_id(nldi_feature = nldi_nwis)
 #> [1] 17864756
-# }
-
+# }
+
 
@@ -139,7 +146,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/discover_nldi_characteristics.html b/docs/reference/discover_nldi_characteristics.html index d3a9dfea..3513c4fb 100644 --- a/docs/reference/discover_nldi_characteristics.html +++ b/docs/reference/discover_nldi_characteristics.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -78,25 +78,28 @@

Discover Characteristics Metadata

-
discover_nldi_characteristics(type = "all")
+
discover_nldi_characteristics(type = "all")

Arguments

type

character "all", "local", "total", or "divergence_routed".

+

Value

-

data.frame containing available characteristics

+ + +

data.frame containing available characteristics

Examples

-
chars <- discover_nldi_characteristics()
-names(chars)
+    
chars <- discover_nldi_characteristics()
+names(chars)
 #> [1] "local"             "total"             "divergence_routed"
-head(chars$local, 10)
+head(chars$local, 10)
 #>    characteristic_id
 #> 1  CAT_WILDFIRE_2011
 #> 2        CAT_CONTACT
@@ -199,7 +202,7 @@ 

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/download_nhdplushr.html b/docs/reference/download_nhdplushr.html index b4641ed5..780bf286 100644 --- a/docs/reference/download_nhdplushr.html +++ b/docs/reference/download_nhdplushr.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6
@@ -78,35 +78,45 @@

Download NHDPlus HiRes

-
download_nhdplushr(nhd_dir, hu_list, download_files = TRUE)
+
download_nhdplushr(nhd_dir, hu_list, download_files = TRUE)

Arguments

nhd_dir

character directory to save output into

+ +
hu_list

character vector of hydrologic region(s) to download. Use get_huc8 to find HU codes of interest. Accepts two digit and four digit codes.

+ +
download_files

boolean if FALSE, only URLs to files will be returned can be hu02s and/or hu04s

+

Value

-

character Paths to geodatabases created.

+ + +

character Paths to geodatabases created.

Examples

-
# \donttest{
-hu <- nhdplusTools::get_huc8(sf::st_sfc(sf::st_point(c(-73, 42)), crs = 4326))
-
-(hu <- substr(hu$huc8, 1, 2))
+    
# \donttest{
+hu <- nhdplusTools::get_huc8(sf::st_sfc(sf::st_point(c(-73, 42)), crs = 4326))
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+
+(hu <- substr(hu$huc8, 1, 2))
 #> [1] "01"
-
-download_nhdplushr(tempdir(), c(hu, "0203"), download_files = FALSE)
+
+download_nhdplushr(tempdir(), c(hu, "0203"), download_files = FALSE)
 #>  [1] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0101_HU4_GDB.zip"
 #>  [2] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0102_HU4_GDB.zip"
 #>  [3] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0103_HU4_GDB.zip"
@@ -118,7 +128,7 @@ 

Examples

#> [9] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0109_HU4_GDB.zip" #> [10] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0110_HU4_GDB.zip" #> [11] "https://prd-tnm.s3.amazonaws.com/StagedProducts/Hydrography/NHDPlusHR/Beta/GDB/NHDPLUS_H_0203_HU4_GDB.zip" -# } +# }
@@ -133,7 +143,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/download_nhdplusv2.html b/docs/reference/download_nhdplusv2.html index 253bc2d5..7a14dff0 100644 --- a/docs/reference/download_nhdplusv2.html +++ b/docs/reference/download_nhdplusv2.html @@ -22,7 +22,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -88,38 +88,45 @@

Download seamless National Hydrography Dataset Version 2 (NHDPlusV2)

-
download_nhdplusv2(
-  outdir,
-  url = paste0("https://s3.amazonaws.com/edap-nhdplus/NHDPlusV21/",
-    "Data/NationalData/NHDPlusV21_NationalData_Seamless", "_Geodatabase_Lower48_07.7z"),
-  progress = TRUE
-)
+
download_nhdplusv2(
+  outdir,
+  url = paste0("https://edap-ow-data-commons.s3.amazonaws.com/NHDPlusV21/",
+    "Data/NationalData/NHDPlusV21_NationalData_Seamless", "_Geodatabase_Lower48_07.7z"),
+  progress = TRUE
+)

Arguments

outdir

The folder path where data should be downloaded and extracted

+ +
url

the location of the online resource

+ +
progress

boolean display download progress?

+

Value

-

character path to the local geodatabase

+ + +

character path to the local geodatabase

Examples

-
if (FALSE) {
-  download_nhdplusV2("./data/nhd/")
-
-  download_nhdplusv2(outdir = "./inst/",
-      url = paste0("https://s3.amazonaws.com/edap-nhdplus/NHDPlusV21/",
-                   "Data/NationalData/NHDPlusV21_NationalData_Seamless",
-                   "_Geodatabase_HI_PR_VI_PI_03.7z"))
-}
+    
if (FALSE) {
+  download_nhdplusV2("./data/nhd/")
+
+  download_nhdplusv2(outdir = "./inst/",
+      url = paste0("https://edap-ow-data-commons.s3.amazonaws.com/NHDPlusV21/",
+                   "Data/NationalData/NHDPlusV21_NationalData_Seamless",
+                   "_Geodatabase_HI_PR_VI_PI_03.7z"))
+}
 
@@ -134,7 +141,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/download_rf1.html b/docs/reference/download_rf1.html index 7ee2582a..5953970c 100644 --- a/docs/reference/download_rf1.html +++ b/docs/reference/download_rf1.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,32 +80,39 @@

Download the seamless Reach File (RF1) Database

-
download_rf1(
-  outdir,
-  url = "https://water.usgs.gov/GIS/dsdl/erf1_2.e00.gz",
-  progress = TRUE
-)
+
download_rf1(
+  outdir,
+  url = "https://water.usgs.gov/GIS/dsdl/erf1_2.e00.gz",
+  progress = TRUE
+)

Arguments

outdir

The folder path where data should be downloaded and extracted

+ +
url

the location of the online resource

+ +
progress

boolean display download progress?

+

Value

-

character path to the local e00 file

+ + +

character path to the local e00 file

Examples

-
if (FALSE) {
-  download_wbd("./data/rf1/")
-}
+    
if (FALSE) {
+  download_wbd("./data/rf1/")
+}
 
@@ -120,7 +127,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/download_vaa.html b/docs/reference/download_vaa.html index 5e8c398c..0111c44e 100644 --- a/docs/reference/download_vaa.html +++ b/docs/reference/download_vaa.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -78,11 +78,11 @@

Download nhdplusVAA data from HydroShare

-
download_vaa(
-  path = get_vaa_path(updated_network),
-  force = FALSE,
-  updated_network = FALSE
-)
+
download_vaa(
+  path = get_vaa_path(updated_network),
+  force = FALSE,
+  updated_network = FALSE
+)
@@ -91,16 +91,23 @@

Arguments

character path where the file should be saved. Default is a persistent system data as retrieved by nhdplusTools_data_dir. Also see: get_vaa_path

+ +
force

logical. Force data re-download. Default = FALSE

+ +
updated_network

logical default FALSE. If TRUE, updated network attributes from E2NHD and National Water Model retrieved from here.

+

Value

-

character path to cached data

+ + +

character path to cached data

Details

@@ -126,7 +133,7 @@

Details

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/download_wbd.html b/docs/reference/download_wbd.html index 514953c6..a6ae06aa 100644 --- a/docs/reference/download_wbd.html +++ b/docs/reference/download_wbd.html @@ -20,7 +20,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -84,33 +84,40 @@

Download the seamless Watershed Boundary Dataset (WBD)

-
download_wbd(
-  outdir,
-  url = paste0("https://prd-tnm.s3.amazonaws.com/StagedProducts/",
-    "Hydrography/WBD/National/GDB/WBD_National_GDB.zip"),
-  progress = TRUE
-)
+
download_wbd(
+  outdir,
+  url = paste0("https://prd-tnm.s3.amazonaws.com/StagedProducts/",
+    "Hydrography/WBD/National/GDB/WBD_National_GDB.zip"),
+  progress = TRUE
+)

Arguments

outdir

The folder path where data should be downloaded and extracted

+ +
url

the location of the online resource

+ +
progress

boolean display download progress?

+

Value

-

character path to the local geodatabase

+ + +

character path to the local geodatabase

Examples

-
if (FALSE) {
-  download_wbd("./data/wbd/")
-}
+    
if (FALSE) {
+  download_wbd("./data/wbd/")
+}
 
@@ -125,7 +132,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/fix_flowdir.html b/docs/reference/fix_flowdir.html index 8aed179f..f6248bc6 100644 --- a/docs/reference/fix_flowdir.html +++ b/docs/reference/fix_flowdir.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,85 +80,90 @@

Fix flow direction

-
fix_flowdir(comid, network)
+
fix_flowdir(comid, network)

Arguments

comid

The COMID of the flowline to check

+ +
network

The entire network to check from. Requires a "toCOMID" field.

+

Value

-

a geometry for the feature that has been reversed if needed.

+ + +

a geometry for the feature that has been reversed if needed.

Examples

-

-source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
-
-fline <- sf::read_sf(sample_data, "NHDFlowline_Network")
-
-# We add a tocomid with prepare_nhdplus
-fline <- sf::st_sf(prepare_nhdplus(fline, 0, 0, 0, FALSE),
-                   geom = sf::st_zm(sf::st_geometry(fline)))
+    

+source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
+
+fline <- sf::read_sf(sample_data, "NHDFlowline_Network")
+
+# We add a tocomid with prepare_nhdplus
+fline <- sf::st_sf(prepare_nhdplus(fline, 0, 0, 0, FALSE),
+                   geom = sf::st_zm(sf::st_geometry(fline)))
 #> Warning: removing geometry
 #> Warning: Got NHDPlus data without a Terminal catchment. Attempting to find it.
 #> 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 0
-
-# Look at the end node of the 10th line.
-(n1 <- get_node(fline[10, ], position = "end"))
+
+# Look at the end node of the 10th line.
+(n1 <- get_node(fline[10, ], position = "end"))
 #> Simple feature collection with 1 feature and 0 fields
 #> Geometry type: POINT
 #> Dimension:     XY
 #> Bounding box:  xmin: -89.34813 ymin: 42.99555 xmax: -89.34813 ymax: 42.99555
 #> Geodetic CRS:  GRS 1980(IUGG, 1980)
-#> # A tibble: 1 x 1
+#> # A tibble: 1 × 1
 #>               geometry
 #> *          <POINT [°]>
 #> 1 (-89.34813 42.99555)
-
-# Break the geometry by reversing it.
-sf::st_geometry(fline)[10] <- sf::st_reverse(sf::st_geometry(fline)[10])
-
-# Note that the end node is different now.
-(n2 <- get_node(fline[10, ], position = "end"))
+
+# Break the geometry by reversing it.
+sf::st_geometry(fline)[10] <- sf::st_reverse(sf::st_geometry(fline)[10])
+
+# Note that the end node is different now.
+(n2 <- get_node(fline[10, ], position = "end"))
 #> Simple feature collection with 1 feature and 0 fields
 #> Geometry type: POINT
 #> Dimension:     XY
 #> Bounding box:  xmin: -89.36355 ymin: 43 xmax: -89.36355 ymax: 43
 #> Geodetic CRS:  GRS 1980(IUGG, 1980)
-#> # A tibble: 1 x 1
+#> # A tibble: 1 × 1
 #>         geometry
 #> *    <POINT [°]>
 #> 1 (-89.36355 43)
-
-# Pass the broken geometry to fix_flowdir with the network for toCOMID
-sf::st_geometry(fline)[10] <- fix_flowdir(fline$COMID[10], fline)
-
-# Note that the geometry is now in the right order.
-(n3 <- get_node(fline[10, ], position = "end"))
+
+# Pass the broken geometry to fix_flowdir with the network for toCOMID
+sf::st_geometry(fline)[10] <- fix_flowdir(fline$COMID[10], fline)
+
+# Note that the geometry is now in the right order.
+(n3 <- get_node(fline[10, ], position = "end"))
 #> Simple feature collection with 1 feature and 0 fields
 #> Geometry type: POINT
 #> Dimension:     XY
 #> Bounding box:  xmin: -89.34813 ymin: 42.99555 xmax: -89.34813 ymax: 42.99555
 #> Geodetic CRS:  GRS 1980(IUGG, 1980)
-#> # A tibble: 1 x 1
+#> # A tibble: 1 × 1
 #>               geometry
 #> *          <POINT [°]>
 #> 1 (-89.34813 42.99555)
-
-plot(sf::st_geometry(fline)[10])
-plot(n1, add = TRUE)
-plot(n2, add = TRUE, col = "blue")
-plot(n3, add = TRUE, cex = 2, col = "red")
+
+plot(sf::st_geometry(fline)[10])
+plot(n1, add = TRUE)
+plot(n2, add = TRUE, col = "blue")
+plot(n3, add = TRUE, cex = 2, col = "red")
 
-
+
 
@@ -173,7 +178,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_DD.html b/docs/reference/get_DD.html index 145fabf2..8fe30945 100644 --- a/docs/reference/get_DD.html +++ b/docs/reference/get_DD.html @@ -19,7 +19,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -82,7 +82,7 @@

Navigate Downstream with Diversions

-
get_DD(network, comid, distance = NULL)
+
get_DD(network, comid, distance = NULL)
@@ -90,36 +90,43 @@

Arguments

network

data.frame NHDPlus flowlines including at a minimum: COMID, DnMinorHyd, DnHydroseq, and Hydroseq.

+ +
comid

integer identifier to start navigating from.

+ +
distance

numeric distance in km to limit how many COMIDs are returned. The COMID that exceeds the distance specified is returned. The longest of the diverted paths is used for limiting distance.

+

Value

-

integer vector of all COMIDs downstream of the starting COMID

+ + +

integer vector of all COMIDs downstream of the starting COMID

Examples

-
library(sf)
-#> Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 7.2.1; sf_use_s2() is TRUE
-start_COMID <- 11688818
-
-source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
-
-DD_COMIDs <- get_DD(sample_flines, start_COMID, distance = 4)
-plot(dplyr::filter(sample_flines, COMID %in% DD_COMIDs)$geom,
-     col = "red", lwd = 2)
-
-DM_COMIDs <- get_DM(sample_flines, start_COMID, distance = 4)
-plot(dplyr::filter(sample_flines, COMID %in% DM_COMIDs)$geom,
-     col = "blue", add = TRUE, lwd = 2)
+    
library(sf)
+#> Linking to GEOS 3.9.1, GDAL 3.3.2, PROJ 7.2.1; sf_use_s2() is TRUE
+start_COMID <- 11688818
+
+source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
+
+DD_COMIDs <- get_DD(sample_flines, start_COMID, distance = 4)
+plot(dplyr::filter(sample_flines, COMID %in% DD_COMIDs)$geom,
+     col = "red", lwd = 2)
+
+DM_COMIDs <- get_DM(sample_flines, start_COMID, distance = 4)
+plot(dplyr::filter(sample_flines, COMID %in% DM_COMIDs)$geom,
+     col = "blue", add = TRUE, lwd = 2)
 
-
+
 
@@ -134,7 +141,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_DM.html b/docs/reference/get_DM.html index 99793b1f..8c3f0bff 100644 --- a/docs/reference/get_DM.html +++ b/docs/reference/get_DM.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -78,7 +78,7 @@

Navigate Downstream Mainstem

-
get_DM(network, comid, distance = NULL, sort = FALSE, include = TRUE)
+
get_DM(network, comid, distance = NULL, sort = FALSE, include = TRUE)
@@ -86,40 +86,51 @@

Arguments

network

data.frame NHDPlus flowlines including at a minimum: COMID, LENGTHKM, DnHydroseq, and Hydroseq.

+ +
comid

integer identifier to start navigating from.

+ +
distance

numeric distance in km to limit how many COMIDs are returned. The COMID that exceeds the distance specified is returned.

+ +
sort

if TRUE, the returned COMID vector will be sorted in order of distance from the input COMID (nearest to farthest)

+ +
include

if TRUE, the input COMID will be included in the returned COMID vector

+

Value

-

integer vector of all COMIDs downstream of the starting COMID + + +

integer vector of all COMIDs downstream of the starting COMID along the mainstem

Examples

-
library(sf)
-
-source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
-
-plot(sample_flines$geom)
-start_COMID <- 11690092
-DM_COMIDs <- get_DM(sample_flines, start_COMID)
-plot(dplyr::filter(sample_flines, COMID %in% DM_COMIDs)$geom,
-     col = "red", add = TRUE, lwd = 3)
-
-DM_COMIDs <- get_DM(sample_flines, start_COMID, distance = 40)
-plot(dplyr::filter(sample_flines, COMID %in% DM_COMIDs)$geom,
-     col = "blue", add = TRUE, lwd = 2)
+    
library(sf)
+
+source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
+
+plot(sample_flines$geom)
+start_COMID <- 11690092
+DM_COMIDs <- get_DM(sample_flines, start_COMID)
+plot(dplyr::filter(sample_flines, COMID %in% DM_COMIDs)$geom,
+     col = "red", add = TRUE, lwd = 3)
+
+DM_COMIDs <- get_DM(sample_flines, start_COMID, distance = 40)
+plot(dplyr::filter(sample_flines, COMID %in% DM_COMIDs)$geom,
+     col = "blue", add = TRUE, lwd = 2)
 
-
-
+
+
 
@@ -134,7 +145,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_UM.html b/docs/reference/get_UM.html index 7120d503..8defc539 100644 --- a/docs/reference/get_UM.html +++ b/docs/reference/get_UM.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -78,7 +78,7 @@

Navigate Upstream Mainstem

-
get_UM(network, comid, distance = NULL, sort = FALSE, include = TRUE)
+
get_UM(network, comid, distance = NULL, sort = FALSE, include = TRUE)
@@ -86,39 +86,50 @@

Arguments

network

data.frame NHDPlus flowlines including at a minimum: COMID,Pathlength, LevelPathI, and Hydroseq.

+ +
comid

integer identifier to start navigating from.

+ +
distance

numeric distance in km to limit how many COMIDs are

+ +
sort

if TRUE, the returned COMID vector will be sorted in order of distance from the input COMID (nearest to farthest)

+ +
include

if TRUE, the input COMID will be included in the returned COMID vector returned. The COMID that exceeds the distance specified is returned.

+

Value

-

integer vector of all COMIDs upstream of the starting COMID + + +

integer vector of all COMIDs upstream of the starting COMID along the mainstem

Examples

-
library(sf)
-
-source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
-
-plot(sample_flines$geom)
-start_COMID <- 11690196
-UM_COMIDs <- get_UM(sample_flines, start_COMID)
-plot(dplyr::filter(sample_flines, COMID %in% UM_COMIDs)$geom,
-     col = "red", add = TRUE, lwd = 3)
-
-UM_COMIDs <- get_UM(sample_flines, start_COMID, distance = 50)
-plot(dplyr::filter(sample_flines, COMID %in% UM_COMIDs)$geom,
-     col = "blue", add = TRUE, lwd = 2)
+    
library(sf)
+
+source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
+
+plot(sample_flines$geom)
+start_COMID <- 11690196
+UM_COMIDs <- get_UM(sample_flines, start_COMID)
+plot(dplyr::filter(sample_flines, COMID %in% UM_COMIDs)$geom,
+     col = "red", add = TRUE, lwd = 3)
+
+UM_COMIDs <- get_UM(sample_flines, start_COMID, distance = 50)
+plot(dplyr::filter(sample_flines, COMID %in% UM_COMIDs)$geom,
+     col = "blue", add = TRUE, lwd = 2)
 
-
+
 
@@ -133,7 +144,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_UT.html b/docs/reference/get_UT.html index a612ef50..18ec8a65 100644 --- a/docs/reference/get_UT.html +++ b/docs/reference/get_UT.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -78,7 +78,7 @@

Navigate Upstream with Tributaries

-
get_UT(network, comid, distance = NULL)
+
get_UT(network, comid, distance = NULL)
@@ -86,33 +86,40 @@

Arguments

network

data.frame NHDPlus flowlines including at a minimum: COMID, Pathlength, LENGTHKM, and Hydroseq.

+ +
comid

integer Identifier to start navigating from.

+ +
distance

numeric distance in km to limit how many COMIDs are returned. The COMID that exceeds the distance specified is returned.

+

Value

-

integer vector of all COMIDs upstream with tributaries of the + + +

integer vector of all COMIDs upstream with tributaries of the starting COMID.

Examples

-
library(sf)
-source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
-plot(sample_flines$geom)
-start_COMID <- 11690196
-UT_COMIDs <- get_UT(sample_flines, start_COMID)
-plot(dplyr::filter(sample_flines, COMID %in% UT_COMIDs)$geom,
-     col = "red", add = TRUE)
-
-UT_COMIDs <- get_UT(sample_flines, start_COMID, distance = 50)
-plot(dplyr::filter(sample_flines, COMID %in% UT_COMIDs)$geom,
-     col = "blue", add = TRUE)
+    
library(sf)
+source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
+plot(sample_flines$geom)
+start_COMID <- 11690196
+UT_COMIDs <- get_UT(sample_flines, start_COMID)
+plot(dplyr::filter(sample_flines, COMID %in% UT_COMIDs)$geom,
+     col = "red", add = TRUE)
+
+UT_COMIDs <- get_UT(sample_flines, start_COMID, distance = 50)
+plot(dplyr::filter(sample_flines, COMID %in% UT_COMIDs)$geom,
+     col = "blue", add = TRUE)
 
-
+
 
@@ -127,7 +134,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_boundaries.html b/docs/reference/get_boundaries.html new file mode 100644 index 00000000..11fc13ad --- /dev/null +++ b/docs/reference/get_boundaries.html @@ -0,0 +1,122 @@ + +Return RPU or VPU boundaries — get_boundaries • nhdplusTools + + +
+
+ + + +
+
+ + +
+

Return RPU or VPU boundaries

+
+ +
+
get_boundaries(type = "vpu")
+
+ +
+

Arguments

+
type
+

character. Either "RPU" or "VPU"

+ +
+
+

Value

+ + +

An object of class "sf"

+ + +
+ +
+ +
+ + +
+ +
+

Site built with pkgdown 2.0.5.

+
+ +
+ + + + + + + + diff --git a/docs/reference/get_elev_along_path-1.png b/docs/reference/get_elev_along_path-1.png index a4678591..5f3c20af 100644 Binary files a/docs/reference/get_elev_along_path-1.png and b/docs/reference/get_elev_along_path-1.png differ diff --git a/docs/reference/get_elev_along_path.html b/docs/reference/get_elev_along_path.html index ae26f070..d2c0e06a 100644 --- a/docs/reference/get_elev_along_path.html +++ b/docs/reference/get_elev_along_path.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,24 +80,33 @@

Get Elevation Along Path (experimental)

-
get_elev_along_path(points, num_pts, res = 1, status = TRUE)
+
get_elev_along_path(points, num_pts, res = 1, status = TRUE)

Arguments

points

sf data.frame containing a point column.

+ +
num_pts

numeric number of points to retrieve along the cross section.

+ +
res

integer resolution of 3D Elevation Program data to request. Must be on of: 1, 3, 5, 10, 30, 60.

+ +
status

logical

+

Value

-

sf data.frame containing points retrieved. Names include + + +

sf data.frame containing points retrieved. Names include "id", "distance_m", "elevation_m", "spatial_ref", "geometry", and ".group". .group tracks which input point each set of output points belongs to.

@@ -105,14 +114,14 @@

Value

Examples

-
# \donttest{
-point1 <- sf::st_sfc(sf::st_point(x = c(-105.9667, 36.17602)), crs = 4326)
-point2 <- sf::st_sfc(sf::st_point(x = c(-105.97768, 36.17526)), crs = 4326)
-point3 <- sf::st_sfc(sf::st_point(x = c(-105.98869, 36.17450)), crs = 4326)
-
-points <- sf::st_as_sf(c(point1, point2, point3))
-
-(xs <- get_elev_along_path(points, 100))
+    
# \donttest{
+point1 <- sf::st_sfc(sf::st_point(x = c(-105.9667, 36.17602)), crs = 4326)
+point2 <- sf::st_sfc(sf::st_point(x = c(-105.97768, 36.17526)), crs = 4326)
+point3 <- sf::st_sfc(sf::st_point(x = c(-105.98869, 36.17450)), crs = 4326)
+
+points <- sf::st_as_sf(c(point1, point2, point3))
+
+(xs <- get_elev_along_path(points, 100))
 #> Requestion segment 1 of 2
 #> Requestion segment 2 of 2
 #> Simple feature collection with 202 features and 5 fields
@@ -120,7 +129,7 @@ 

Examples

#> Dimension: XY #> Bounding box: xmin: -105.9886 ymin: 36.17451 xmax: -105.9667 ymax: 36.176 #> Geodetic CRS: WGS 84 -#> # A tibble: 202 x 6 +#> # A tibble: 202 × 6 #> id distance_m elevation_m spatial_ref geometry .group #> * <chr> <dbl> <dbl> <int> <POINT [°]> <int> #> 1 0 0 1779. 0 (-105.9667 36.176) 1 @@ -133,32 +142,46 @@

Examples

#> 8 7 68.2 1775. 0 (-105.9675 36.17595) 1 #> 9 8 77.9 1775. 0 (-105.9676 36.17594) 1 #> 10 9 87.6 1774. 0 (-105.9677 36.17594) 1 -#> # ... with 192 more rows - -bbox <- sf::st_bbox(xs) + c(-0.005, -0.005, 0.005, 0.005) - -nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE) +#> # … with 192 more rows + +if(!is.null(xs)) { +bbox <- sf::st_bbox(xs) + c(-0.005, -0.005, 0.005, 0.005) + +nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE) + +plot(sf::st_transform(sf::st_geometry(xs), 3857), pch = ".", add = TRUE, col = "red") +plot(sf::st_transform(sf::st_sfc(point1, crs = 4326), 3857), add = TRUE) +plot(sf::st_transform(sf::st_sfc(point2, crs = 4326), 3857), add = TRUE) +plot(sf::st_transform(sf::st_sfc(point3, crs = 4326), 3857), add = TRUE) + +plot(xs$distance_m, xs$elevation_m) +} +#> Spherical geometry (s2) switched off #> Found invalid geometry, attempting to fix. +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off #> Warning: No nhdarea features found +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off #> Warning: No waterbodies features found +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off #> Warning: No nonnetwork features found +#> Spherical geometry (s2) switched on #> Warning: Discarded ellps WGS 84 in Proj4 definition: +proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs #> Warning: Discarded datum WGS_1984 in Proj4 definition #> Zoom: 15 #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL. #> Audotdetect projection: assuming Google Mercator (epsg 3857) - -plot(sf::st_transform(sf::st_geometry(xs), 3857), pch = ".", add = TRUE, col = "red") -plot(sf::st_transform(sf::st_sfc(point1, crs = 4326), 3857), add = TRUE) -plot(sf::st_transform(sf::st_sfc(point2, crs = 4326), 3857), add = TRUE) -plot(sf::st_transform(sf::st_sfc(point3, crs = 4326), 3857), add = TRUE) - -plot(xs$distance_m, xs$elevation_m) - -# } - + +# } +
@@ -173,7 +196,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_flowline_index.html b/docs/reference/get_flowline_index.html index a3b9c0b8..65f0a5c8 100644 --- a/docs/reference/get_flowline_index.html +++ b/docs/reference/get_flowline_index.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,13 +80,13 @@

Get Flowline Index

-
get_flowline_index(
-  flines,
-  points,
-  search_radius = NULL,
-  precision = NA,
-  max_matches = 1
-)
+
get_flowline_index(
+  flines,
+  points,
+  search_radius = NULL,
+  precision = NA,
+  max_matches = 1
+)
@@ -96,24 +96,35 @@

Arguments

COMID, REACHCODE, ToMeas, and FromMeas. Can be "download_nhdplusv2" and remote nhdplusv2 data will be downloaded for the bounding box surround the submitted points. NOTE: The download option may not work for large areas, use with caution.

+ +
points

sf or sfc of type POINT in analysis projection. NOTE: flines will be projected to the projection of the points layer.

+ +
search_radius

units distance for the nearest neighbor search to extend in analysis projection. If missing or NULL, and points are in a lon lat projection, a default of 0.01 degree is used, otherwise 200 m is used. Conversion to the linear unit used by the provided crs of points is attempted. See RANN nn2 documentation for more details.

+ +
precision

numeric the resolution of measure precision in the output in meters.

+ +
max_matches

numeric the maximum number of matches to return if multiple are found in search_radius

+

Value

-

data.frame with five columns, id, COMID, REACHCODE, REACH_meas, and offset. id is the + + +

data.frame with five columns, id, COMID, REACHCODE, REACH_meas, and offset. id is the row or list element in the point input.

@@ -134,41 +145,44 @@

Details

Examples

-
# \donttest{
-
-source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
-
-point <- sf::st_sfc(sf::st_point(c(-76.87479, 39.48233)),
-                    crs = 4326)
-
-get_flowline_index(sample_flines, point)
+    
# \donttest{
+
+source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
+
+point <- sf::st_sfc(sf::st_point(c(-76.87479, 39.48233)),
+                    crs = 4326)
+
+get_flowline_index(sample_flines, point)
 #>   id    COMID      REACHCODE REACH_meas       offset
 #> 1  1 11689978 02060003001472     51.502 0.0003010502
-
-point <- sf::st_transform(point, 5070)
-
-get_flowline_index(sample_flines, point,
-                   search_radius = units::set_units(200, "m"))
+
+point <- sf::st_transform(point, 5070)
+
+get_flowline_index(sample_flines, point,
+                   search_radius = units::set_units(200, "m"))
 #> Warning: crs of lines and points don't match. attempting st_transform of lines
 #>   id    COMID      REACHCODE REACH_meas   offset
 #> 1  1 11689978 02060003001472    51.8751 25.88438
-
-get_flowline_index("download_nhdplusv2", point)
+
+get_flowline_index("download_nhdplusv2", point)
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
 #>   id    COMID      REACHCODE REACH_meas   offset
 #> 1  1 11689978 02060003001472    51.8761 25.85641
-
-get_flowline_index(sample_flines, point, precision = 30)
+
+get_flowline_index(sample_flines, point, precision = 30)
 #> Warning: crs of lines and points don't match. attempting st_transform of lines
 #>   id    COMID      REACHCODE REACH_meas   offset
-#> 1  1 11689978 02060003001472    52.7758 4.302007
-
-get_flowline_index(sample_flines,
-                   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),
-                   search_radius = units::set_units(0.2, "degrees"),
-                   max_matches = 10)
+#> 1  1 11689978 02060003001472    52.4083 4.302007
+
+get_flowline_index(sample_flines,
+                   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),
+                   search_radius = units::set_units(0.2, "degrees"),
+                   max_matches = 10)
 #>    id    COMID      REACHCODE REACH_meas       offset
 #> 1   1 11688298 02060003000579     0.0000 6.026811e-05
 #> 2   2 11688808 02060003000519    53.5874 5.641410e-04
@@ -200,8 +214,8 @@ 

Examples

#> 28 2 11690128 02060003001498 100.0000 2.099143e-02 #> 29 3 11689696 02060003000387 0.4731 1.872134e-02 #> 30 3 11689006 02060003000295 0.0000 1.876644e-02 - -# } + +# }
@@ -216,7 +230,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_gagesII.html b/docs/reference/get_gagesII.html index 6f1986e3..36ce3d88 100644 --- a/docs/reference/get_gagesII.html +++ b/docs/reference/get_gagesII.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,7 +80,7 @@

Find GAGESII Features

-
get_gagesII(AOI = NULL, id = NULL, t_srs = NULL, buffer = 0.5, basin = FALSE)
+
get_gagesII(AOI = NULL, id = NULL, t_srs = NULL, buffer = 0.5, basin = FALSE)
@@ -89,22 +89,33 @@

Arguments

sf (MULTI)POINT or (MULTI)POLYGON. An 'area of interest' can be provided as either a location (sf POINT) or area (sf POLYGON) in any Spatial Reference System.

+ +
id

character NWIS Gage ID(s)

+ +
t_srs

character (PROJ string or EPSG code) or numeric (EPSG code). A user specified - target -Spatial Reference System (SRS/CRS) for returned objects. Will default to the CRS of the input AOI if provided, and to 4326 for ID requests.

+ +
buffer

numeric. The amount (in meters) to buffer a POINT AOI by for an extended search. Default = 0.5

+ +
basin

logical should the gagesII basin also be returned? If True, return value will be a list with "site" and "basin" elements.

+

Value

-

a simple features (sf) object

+ + +

a simple features (sf) object

Details

@@ -129,7 +140,7 @@

Details

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_hr_data.html b/docs/reference/get_hr_data.html index beb8b0b6..536df78e 100644 --- a/docs/reference/get_hr_data.html +++ b/docs/reference/get_hr_data.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,35 +80,48 @@

Get NHDPlus HiRes Data

-
get_hr_data(
-  gdb,
-  layer = NULL,
-  min_size_sqkm = NULL,
-  simp = NULL,
-  proj = NULL,
-  rename = TRUE
-)
+
get_hr_data(
+  gdb,
+  layer = NULL,
+  min_size_sqkm = NULL,
+  simp = NULL,
+  proj = NULL,
+  rename = TRUE
+)

Arguments

gdb

character path to geodatabase to get data from.

+ +
layer

character layer name from geodatabase found with st_layers

+ +
min_size_sqkm

numeric minimum basin size to be included in the output

+ +
simp

numeric simplification tolerance in units of projection

+ +
proj

a projection specification compatible with st_crs

+ +
rename

boolean if TRUE, nhdplusTools standard attribute values will be applied.

+

Value

-

sf data.frame containing requested data

+ + +

sf data.frame containing requested data

@@ -123,7 +136,7 @@

Value

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_huc12.html b/docs/reference/get_huc12.html index c6cd9003..127587e4 100644 --- a/docs/reference/get_huc12.html +++ b/docs/reference/get_huc12.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,7 +80,7 @@

Find WBD HUC 12 unit subsets

-
get_huc12(AOI = NULL, id = NULL, t_srs = NULL, buffer = 0.5)
+
get_huc12(AOI = NULL, id = NULL, t_srs = NULL, buffer = 0.5)
@@ -89,19 +89,28 @@

Arguments

sf (MULTI)POINT or (MULTI)POLYGON. An 'area of interest' can be provided as either a location (sf POINT) or area (sf POLYGON) in any Spatial Reference System.

+ +
id

WBD HUC12 ID(s)

+ +
t_srs

character (PROJ string or EPSG code) or numeric (EPSG code). A user specified - target -Spatial Reference System (SRS/CRS) for returned objects. Will default to the CRS of the input AOI if provided, and to 4326 for ID requests.

+ +
buffer

numeric. The amount (in meters) to buffer a POINT AOI by for an extended search. Default = 0.5

+

Value

-

a simple features (sf) object

+ + +

a simple features (sf) object

Details

@@ -126,7 +135,7 @@

Details

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_huc8.html b/docs/reference/get_huc8.html index 8b0b62d4..fbc45855 100644 --- a/docs/reference/get_huc8.html +++ b/docs/reference/get_huc8.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,7 +80,7 @@

Find WBD HUC 08 unit subsets

-
get_huc8(AOI = NULL, id = NULL, t_srs = NULL, buffer = 0.5)
+
get_huc8(AOI = NULL, id = NULL, t_srs = NULL, buffer = 0.5)
@@ -89,19 +89,28 @@

Arguments

sf (MULTI)POINT or (MULTI)POLYGON. An 'area of interest' can be provided as either a location (sf POINT) or area (sf POLYGON) in any Spatial Reference System.

+ +
id

WBD HUC08 ID(s)

+ +
t_srs

character (PROJ string or EPSG code) or numeric (EPSG code). A user specified - target -Spatial Reference System (SRS/CRS) for returned objects. Will default to the CRS of the input AOI if provided, and to 4326 for ID requests.

+ +
buffer

numeric. The amount (in meters) to buffer a POINT AOI by for an extended search. Default = 0.5

+

Value

-

a simple features (sf) object

+ + +

a simple features (sf) object

Details

@@ -126,7 +135,7 @@

Details

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_hydro_location.html b/docs/reference/get_hydro_location.html index 71aa43d2..edf3fd49 100644 --- a/docs/reference/get_hydro_location.html +++ b/docs/reference/get_hydro_location.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,29 +80,32 @@

Get Hydro Location

-
get_hydro_location(indexes, flowpath)
+
get_hydro_location(indexes, flowpath)

Arguments

indexes

data.frame as output from get_flowline_index.

+ +
flowpath

data.frame with three columns: COMID, FromMeas, and ToMeas as well as geometry.

+

Examples

-
source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
-
-indexes <- get_flowline_index(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)))
-
-get_hydro_location(indexes, sample_flines)
+    
source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
+
+indexes <- get_flowline_index(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)))
+
+get_hydro_location(indexes, sample_flines)
 #> Geometry set for 3 features 
 #> Geometry type: POINT
 #> Dimension:     XY
@@ -111,7 +114,7 @@ 

Examples

#> POINT (-76.8694 39.49326) #> POINT (-76.91761 39.40909) #> POINT (-76.881 39.3633) - +
@@ -126,7 +129,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_levelpaths.html b/docs/reference/get_levelpaths.html index e4df4aec..f9d1cb20 100644 --- a/docs/reference/get_levelpaths.html +++ b/docs/reference/get_levelpaths.html @@ -21,7 +21,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -86,25 +86,34 @@

Get Level Paths

-
get_levelpaths(x, override_factor = NULL, status = FALSE, cores = NULL)
+
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. + + +

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

@@ -121,23 +130,23 @@

Details

Examples

-
source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
-
-test_flowline <- prepare_nhdplus(walker_flowline, 0, 0, FALSE)
+    
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 x 4
+
+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
@@ -150,9 +159,9 @@ 

Examples

#> 8 5329317 5329303 8 1 #> 9 5329333 5329333 9 9 #> 10 5329315 5329303 10 1 -#> # ... with 52 more rows - - +#> # … with 52 more rows + +
@@ -167,7 +176,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_nhdarea.html b/docs/reference/get_nhdarea.html index 0fa97212..34c159ec 100644 --- a/docs/reference/get_nhdarea.html +++ b/docs/reference/get_nhdarea.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,7 +80,7 @@

Find NHD Areas

-
get_nhdarea(AOI = NULL, id = NULL, t_srs = NULL, buffer = 0.5)
+
get_nhdarea(AOI = NULL, id = NULL, t_srs = NULL, buffer = 0.5)
@@ -89,19 +89,28 @@

Arguments

sf (MULTI)POINT or (MULTI)POLYGON. An 'area of interest' can be provided as either a location (sf POINT) or area (sf POLYGON) in any Spatial Reference System.

+ +
id

NHD Area COMID(s)

+ +
t_srs

character (PROJ string or EPSG code) or numeric (EPSG code). A user specified - target -Spatial Reference System (SRS/CRS) for returned objects. Will default to the CRS of the input AOI if provided, and to 4326 for ID requests.

+ +
buffer

numeric. The amount (in meters) to buffer a POINT AOI by for an extended search. Default = 0.5

+

Value

-

a simple features (sf) object

+ + +

a simple features (sf) object

Details

@@ -126,7 +135,7 @@

Details

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_nhdplus.html b/docs/reference/get_nhdplus.html index 44f9cc81..999845b9 100644 --- a/docs/reference/get_nhdplus.html +++ b/docs/reference/get_nhdplus.html @@ -19,7 +19,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -82,14 +82,14 @@

Get National Hydrography Dataset V2 Subsets (Multirealization)

-
get_nhdplus(
-  AOI = NULL,
-  comid = NULL,
-  nwis = NULL,
-  realization = "flowline",
-  streamorder = NULL,
-  t_srs = NULL
-)
+
get_nhdplus(
+  AOI = NULL,
+  comid = NULL,
+  nwis = NULL,
+  realization = "flowline",
+  streamorder = NULL,
+  t_srs = NULL
+)
@@ -98,28 +98,41 @@

Arguments

sf (MULTI)POINT or (MULTI)POLYGON. An 'area of interest' can be provided as either a location (sf POINT) or area (sf POLYGON) in any Spatial Reference System.

+ +
comid

numeric or character. Search for NHD features by COMID(s)

+ +
nwis

numeric or character. Search for NHD features by collocated NWIS identifiers

+ +
realization

character. What realization to return. Default is flowline and options include: outlet, flowline, catchment, and all

+ +
streamorder

numeric or character. Only return NHD flowlines with a streamorder greater then or equal to this value for input value and higher. Only usable with AOI and flowline realizations.

+ +
t_srs

character (PROJ string or EPSG code) or numeric (EPSG code). A user specified - target -Spatial Reference System (SRS/CRS) for returned objects. Will default to the CRS of the input AOI if provided, and to 4326 for ID requests.

+

Value

-

sfc a single, or list, of simple feature objects

+ + +

sfc a single, or list, of simple feature objects

Details

@@ -134,48 +147,56 @@

Details

Examples

-
# \donttest{
- point <- sf::st_sfc(sf::st_point(c(-119.845, 34.4146)), crs = 4326)
- get_nhdplus(point)
+    
# \donttest{
+ point <- sf::st_sfc(sf::st_point(c(-119.845, 34.4146)), crs = 4326)
+ get_nhdplus(point)
+#> Spherical geometry (s2) switched off
+#> Spherical geometry (s2) switched on
 #> Simple feature collection with 1 feature and 138 fields
 #> Geometry type: LINESTRING
 #> Dimension:     XY
 #> Bounding box:  xmin: -119.8823 ymin: 34.40438 xmax: -119.8256 ymax: 34.4179
 #> Geodetic CRS:  WGS 84
-#> # A tibble: 1 x 139
+#> # A tibble: 1 × 139
 #>   id             comid fdate               resolution gnis_id gnis_name lengthkm
 #> * <chr>          <int> <dttm>              <chr>      <chr>   <chr>        <dbl>
-#> 1 nhdflowline_~ 9.48e8 2008-03-19 23:00:00 Medium     " "     " "           6.78
-#> # ... with 132 more variables: reachcode <chr>, flowdir <chr>,
-#> #   wbareacomi <int>, ftype <chr>, fcode <int>, shape_length <dbl>,
-#> #   streamleve <int>, streamorde <int>, streamcalc <int>, fromnode <dbl>,
-#> #   tonode <dbl>, hydroseq <dbl>, levelpathi <dbl>, pathlength <int>,
-#> #   terminalpa <dbl>, arbolatesu <int>, divergence <int>, startflag <int>,
-#> #   terminalfl <int>, dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>,
-#> #   dnlevelpat <dbl>, dnminorhyd <int>, dndraincou <int>, dnhydroseq <dbl>, ...
- get_nhdplus(point, realization = "catchment")
+#> 1 nhdflowline_… 9.48e8 2008-03-19 23:00:00 Medium     " "     " "           6.78
+#> # … with 132 more variables: reachcode <chr>, flowdir <chr>, wbareacomi <int>,
+#> #   ftype <chr>, fcode <int>, shape_length <dbl>, streamleve <int>,
+#> #   streamorde <int>, streamcalc <int>, fromnode <dbl>, tonode <dbl>,
+#> #   hydroseq <dbl>, levelpathi <dbl>, pathlength <int>, terminalpa <dbl>,
+#> #   arbolatesu <int>, divergence <int>, startflag <int>, terminalfl <int>,
+#> #   dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>, dnlevelpat <dbl>,
+#> #   dnminorhyd <int>, dndraincou <int>, dnhydroseq <dbl>, frommeas <int>, …
+ get_nhdplus(point, realization = "catchment")
+#> Spherical geometry (s2) switched off
+#> Spherical geometry (s2) switched on
 #> Simple feature collection with 1 feature and 7 fields
 #> Geometry type: POLYGON
 #> Dimension:     XY
 #> Bounding box:  xmin: -119.8822 ymin: 34.40421 xmax: -119.8252 ymax: 34.41778
 #> Geodetic CRS:  WGS 84
-#> # A tibble: 1 x 8
+#> # A tibble: 1 × 8
 #>   id                gridcode featureid sourcefc areasqkm shape_length shape_area
 #> * <chr>                <int>     <int> <chr>       <dbl>        <dbl>      <dbl>
-#> 1 catchmentsp.2609~  1482979 948060316 NHDFlow~     2.58        0.133   0.000253
-#> # ... with 1 more variable: geometry <POLYGON [°]>
- get_nhdplus(point, realization = "all")
+#> 1 catchmentsp.2609…  1482979 948060316 NHDFlow…     2.58        0.133   0.000253
+#> # … with 1 more variable: geometry <POLYGON [°]>
+ get_nhdplus(point, realization = "all")
+#> Spherical geometry (s2) switched off
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> Spherical geometry (s2) switched on
 #> $catchment
 #> Simple feature collection with 1 feature and 7 fields
 #> Geometry type: POLYGON
 #> Dimension:     XY
 #> Bounding box:  xmin: -119.8822 ymin: 34.40421 xmax: -119.8252 ymax: 34.41778
 #> Geodetic CRS:  WGS 84
-#> # A tibble: 1 x 8
+#> # A tibble: 1 × 8
 #>   id                gridcode featureid sourcefc areasqkm shape_length shape_area
 #> * <chr>                <int>     <int> <chr>       <dbl>        <dbl>      <dbl>
-#> 1 catchmentsp.2609~  1482979 948060316 NHDFlow~     2.58        0.133   0.000253
-#> # ... with 1 more variable: geometry <POLYGON [°]>
+#> 1 catchmentsp.2609…  1482979 948060316 NHDFlow…     2.58        0.133   0.000253
+#> # … with 1 more variable: geometry <POLYGON [°]>
 #> 
 #> $flowline
 #> Simple feature collection with 1 feature and 138 fields
@@ -183,17 +204,17 @@ 

Examples

#> Dimension: XY #> Bounding box: xmin: -119.8823 ymin: 34.40438 xmax: -119.8256 ymax: 34.4179 #> Geodetic CRS: WGS 84 -#> # A tibble: 1 x 139 +#> # A tibble: 1 × 139 #> id comid fdate resolution gnis_id gnis_name lengthkm #> * <chr> <int> <dttm> <chr> <chr> <chr> <dbl> -#> 1 nhdflowline_~ 9.48e8 2008-03-19 23:00:00 Medium " " " " 6.78 -#> # ... with 132 more variables: reachcode <chr>, flowdir <chr>, -#> # wbareacomi <int>, ftype <chr>, fcode <int>, shape_length <dbl>, -#> # streamleve <int>, streamorde <int>, streamcalc <int>, fromnode <dbl>, -#> # tonode <dbl>, hydroseq <dbl>, levelpathi <dbl>, pathlength <int>, -#> # terminalpa <dbl>, arbolatesu <int>, divergence <int>, startflag <int>, -#> # terminalfl <int>, dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>, -#> # dnlevelpat <dbl>, dnminorhyd <int>, dndraincou <int>, dnhydroseq <dbl>, ... +#> 1 nhdflowline_… 9.48e8 2008-03-19 23:00:00 Medium " " " " 6.78 +#> # … with 132 more variables: reachcode <chr>, flowdir <chr>, wbareacomi <int>, +#> # ftype <chr>, fcode <int>, shape_length <dbl>, streamleve <int>, +#> # streamorde <int>, streamcalc <int>, fromnode <dbl>, tonode <dbl>, +#> # hydroseq <dbl>, levelpathi <dbl>, pathlength <int>, terminalpa <dbl>, +#> # arbolatesu <int>, divergence <int>, startflag <int>, terminalfl <int>, +#> # dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>, dnlevelpat <dbl>, +#> # dnminorhyd <int>, dndraincou <int>, dnhydroseq <dbl>, frommeas <int>, … #> #> $outlet #> Simple feature collection with 1 feature and 138 fields @@ -201,115 +222,125 @@

Examples

#> Dimension: XY #> Bounding box: xmin: -119.8295 ymin: 34.4179 xmax: -119.8295 ymax: 34.4179 #> Geodetic CRS: WGS 84 -#> # A tibble: 1 x 139 +#> # A tibble: 1 × 139 #> id comid fdate resolution gnis_id gnis_name lengthkm #> * <chr> <int> <dttm> <chr> <chr> <chr> <dbl> -#> 1 nhdflowline_~ 9.48e8 2008-03-19 23:00:00 Medium " " " " 6.78 -#> # ... with 132 more variables: reachcode <chr>, flowdir <chr>, -#> # wbareacomi <int>, ftype <chr>, fcode <int>, shape_length <dbl>, -#> # streamleve <int>, streamorde <int>, streamcalc <int>, fromnode <dbl>, -#> # tonode <dbl>, hydroseq <dbl>, levelpathi <dbl>, pathlength <int>, -#> # terminalpa <dbl>, arbolatesu <int>, divergence <int>, startflag <int>, -#> # terminalfl <int>, dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>, -#> # dnlevelpat <dbl>, dnminorhyd <int>, dndraincou <int>, dnhydroseq <dbl>, ... +#> 1 nhdflowline_… 9.48e8 2008-03-19 23:00:00 Medium " " " " 6.78 +#> # … with 132 more variables: reachcode <chr>, flowdir <chr>, wbareacomi <int>, +#> # ftype <chr>, fcode <int>, shape_length <dbl>, streamleve <int>, +#> # streamorde <int>, streamcalc <int>, fromnode <dbl>, tonode <dbl>, +#> # hydroseq <dbl>, levelpathi <dbl>, pathlength <int>, terminalpa <dbl>, +#> # arbolatesu <int>, divergence <int>, startflag <int>, terminalfl <int>, +#> # dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>, dnlevelpat <dbl>, +#> # dnminorhyd <int>, dndraincou <int>, dnhydroseq <dbl>, frommeas <int>, … #> - get_nhdplus(comid = 101) + get_nhdplus(comid = 101) +#> Spherical geometry (s2) switched off +#> Spherical geometry (s2) switched on #> Simple feature collection with 1 feature and 138 fields #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: -94.64845 ymin: 31.0838 xmax: -94.62997 ymax: 31.09915 #> Geodetic CRS: WGS 84 -#> # A tibble: 1 x 139 +#> # A tibble: 1 × 139 #> id comid fdate resolution gnis_id gnis_name lengthkm #> * <chr> <int> <dttm> <chr> <chr> <chr> <dbl> -#> 1 nhdflowline_n~ 101 2010-11-30 23:00:00 Medium " " " " 3.25 -#> # ... with 132 more variables: reachcode <chr>, flowdir <chr>, -#> # wbareacomi <int>, ftype <chr>, fcode <int>, shape_length <dbl>, -#> # streamleve <int>, streamorde <int>, streamcalc <int>, fromnode <dbl>, -#> # tonode <dbl>, hydroseq <dbl>, levelpathi <dbl>, pathlength <dbl>, -#> # terminalpa <dbl>, arbolatesu <dbl>, divergence <int>, startflag <int>, -#> # terminalfl <int>, dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>, -#> # dnlevelpat <dbl>, dnminorhyd <int>, dndraincou <int>, dnhydroseq <dbl>, ... - get_nhdplus(nwis = c(11120000, 11120500)) +#> 1 nhdflowline_n… 101 2010-11-30 23:00:00 Medium " " " " 3.25 +#> # … with 132 more variables: reachcode <chr>, flowdir <chr>, wbareacomi <int>, +#> # ftype <chr>, fcode <int>, shape_length <dbl>, streamleve <int>, +#> # streamorde <int>, streamcalc <int>, fromnode <dbl>, tonode <dbl>, +#> # hydroseq <dbl>, levelpathi <dbl>, pathlength <dbl>, terminalpa <dbl>, +#> # arbolatesu <dbl>, divergence <int>, startflag <int>, terminalfl <int>, +#> # dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>, dnlevelpat <dbl>, +#> # dnminorhyd <int>, dndraincou <int>, dnhydroseq <dbl>, frommeas <int>, … + get_nhdplus(nwis = c(11120000, 11120500)) +#> Spherical geometry (s2) switched off +#> Spherical geometry (s2) switched on #> Simple feature collection with 2 features and 138 fields #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: -119.8296 ymin: 34.42014 xmax: -119.8057 ymax: 34.47472 #> Geodetic CRS: WGS 84 -#> # A tibble: 2 x 139 +#> # A tibble: 2 × 139 #> id comid fdate resolution gnis_id gnis_name lengthkm #> * <chr> <int> <dttm> <chr> <chr> <chr> <dbl> -#> 1 nhdflowline_~ 1.76e7 1999-11-18 23:00:00 Medium 269609 Atascade~ 1.88 -#> 2 nhdflowline_~ 1.76e7 1999-11-18 23:00:00 Medium 273489 San Jose~ 2.59 -#> # ... with 132 more variables: reachcode <chr>, flowdir <chr>, -#> # wbareacomi <int>, ftype <chr>, fcode <int>, shape_length <dbl>, -#> # streamleve <int>, streamorde <int>, streamcalc <int>, fromnode <dbl>, -#> # tonode <dbl>, hydroseq <dbl>, levelpathi <dbl>, pathlength <dbl>, -#> # terminalpa <dbl>, arbolatesu <dbl>, divergence <int>, startflag <int>, -#> # terminalfl <int>, dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>, -#> # dnlevelpat <dbl>, dnminorhyd <int>, dndraincou <int>, dnhydroseq <dbl>, ... - area <- sf::st_as_sfc(sf::st_bbox(c(xmin = -119.8851, xmax =-119.8361, - ymax = 34.42439, ymin = 34.40473), crs = 4326)) - get_nhdplus(area) +#> 1 nhdflowline_… 1.76e7 1999-11-18 23:00:00 Medium 269609 Atascade… 1.88 +#> 2 nhdflowline_… 1.76e7 1999-11-18 23:00:00 Medium 273489 San Jose… 2.59 +#> # … with 132 more variables: reachcode <chr>, flowdir <chr>, wbareacomi <int>, +#> # ftype <chr>, fcode <int>, shape_length <dbl>, streamleve <int>, +#> # streamorde <int>, streamcalc <int>, fromnode <dbl>, tonode <dbl>, +#> # hydroseq <dbl>, levelpathi <dbl>, pathlength <dbl>, terminalpa <dbl>, +#> # arbolatesu <dbl>, divergence <int>, startflag <int>, terminalfl <int>, +#> # dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>, dnlevelpat <dbl>, +#> # dnminorhyd <int>, dndraincou <int>, dnhydroseq <dbl>, frommeas <int>, … + area <- sf::st_as_sfc(sf::st_bbox(c(xmin = -119.8851, xmax =-119.8361, + ymax = 34.42439, ymin = 34.40473), crs = 4326)) + get_nhdplus(area) +#> Spherical geometry (s2) switched off +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar +#> Spherical geometry (s2) switched on #> Simple feature collection with 19 features and 138 fields #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: -119.9143 ymin: 34.40438 xmax: -119.8256 ymax: 34.45475 #> Geodetic CRS: WGS 84 -#> # A tibble: 19 x 139 +#> # A tibble: 19 × 139 #> id comid fdate resolution gnis_id gnis_name lengthkm #> * <chr> <int> <dttm> <chr> <chr> <chr> <dbl> -#> 1 nhdflowline~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.725 -#> 2 nhdflowline~ 9.48e8 2008-03-19 23:00:00 Medium " " " " 6.78 -#> 3 nhdflowline~ 9.48e8 2008-03-19 23:00:00 Medium " " " " 3.68 -#> 4 nhdflowline~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.221 -#> 5 nhdflowline~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.369 -#> 6 nhdflowline~ 1.76e7 2008-03-19 23:00:00 Medium "27404~ "Tecolot~ 0.867 -#> 7 nhdflowline~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.833 -#> 8 nhdflowline~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.241 -#> 9 nhdflowline~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.91 -#> 10 nhdflowline~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.652 -#> 11 nhdflowline~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.715 -#> 12 nhdflowline~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.478 -#> 13 nhdflowline~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.058 -#> 14 nhdflowline~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.957 -#> 15 nhdflowline~ 1.76e7 2008-06-04 23:00:00 Medium " " " " 1.23 -#> 16 nhdflowline~ 1.76e7 2008-06-04 23:00:00 Medium " " " " 1.05 -#> 17 nhdflowline~ 1.76e7 2008-06-04 23:00:00 Medium " " " " 4.42 -#> 18 nhdflowline~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.672 -#> 19 nhdflowline~ 9.48e8 2010-11-30 23:00:00 Medium " " " " 0.218 -#> # ... with 132 more variables: reachcode <chr>, flowdir <chr>, -#> # wbareacomi <int>, ftype <chr>, fcode <int>, shape_length <dbl>, -#> # streamleve <int>, streamorde <int>, streamcalc <int>, fromnode <dbl>, -#> # tonode <dbl>, hydroseq <dbl>, levelpathi <dbl>, pathlength <dbl>, -#> # terminalpa <dbl>, arbolatesu <dbl>, divergence <int>, startflag <int>, -#> # terminalfl <int>, dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>, -#> # dnlevelpat <dbl>, dnminorhyd <dbl>, dndraincou <int>, dnhydroseq <dbl>, ... - get_nhdplus(area, realization = "flowline", streamorder = 3) +#> 1 nhdflowline… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.725 +#> 2 nhdflowline… 9.48e8 2008-03-19 23:00:00 Medium " " " " 6.78 +#> 3 nhdflowline… 9.48e8 2008-03-19 23:00:00 Medium " " " " 3.68 +#> 4 nhdflowline… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.221 +#> 5 nhdflowline… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.369 +#> 6 nhdflowline… 1.76e7 2008-03-19 23:00:00 Medium "27404… "Tecolot… 0.867 +#> 7 nhdflowline… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.833 +#> 8 nhdflowline… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.241 +#> 9 nhdflowline… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.91 +#> 10 nhdflowline… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.652 +#> 11 nhdflowline… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.715 +#> 12 nhdflowline… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.478 +#> 13 nhdflowline… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.058 +#> 14 nhdflowline… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.957 +#> 15 nhdflowline… 1.76e7 2008-06-04 23:00:00 Medium " " " " 1.23 +#> 16 nhdflowline… 1.76e7 2008-06-04 23:00:00 Medium " " " " 1.05 +#> 17 nhdflowline… 1.76e7 2008-06-04 23:00:00 Medium " " " " 4.42 +#> 18 nhdflowline… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.672 +#> 19 nhdflowline… 9.48e8 2010-11-30 23:00:00 Medium " " " " 0.218 +#> # … with 132 more variables: reachcode <chr>, flowdir <chr>, wbareacomi <int>, +#> # ftype <chr>, fcode <int>, shape_length <dbl>, streamleve <int>, +#> # streamorde <int>, streamcalc <int>, fromnode <dbl>, tonode <dbl>, +#> # hydroseq <dbl>, levelpathi <dbl>, pathlength <dbl>, terminalpa <dbl>, +#> # arbolatesu <dbl>, divergence <int>, startflag <int>, terminalfl <int>, +#> # dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>, dnlevelpat <dbl>, +#> # dnminorhyd <dbl>, dndraincou <int>, dnhydroseq <dbl>, frommeas <dbl>, … + get_nhdplus(area, realization = "flowline", streamorder = 3) +#> Spherical geometry (s2) switched off +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar +#> Spherical geometry (s2) switched on #> Simple feature collection with 8 features and 138 fields #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: -119.8528 ymin: 34.41655 xmax: -119.8295 ymax: 34.42814 #> Geodetic CRS: WGS 84 -#> # A tibble: 8 x 139 +#> # A tibble: 8 × 139 #> id comid fdate resolution gnis_id gnis_name lengthkm #> * <chr> <int> <dttm> <chr> <chr> <chr> <dbl> -#> 1 nhdflowline_~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.725 -#> 2 nhdflowline_~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.221 -#> 3 nhdflowline_~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.369 -#> 4 nhdflowline_~ 1.76e7 2008-03-19 23:00:00 Medium "27404~ "Tecolot~ 0.867 -#> 5 nhdflowline_~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.833 -#> 6 nhdflowline_~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.241 -#> 7 nhdflowline_~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.91 -#> 8 nhdflowline_~ 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.652 -#> # ... with 132 more variables: reachcode <chr>, flowdir <chr>, -#> # wbareacomi <int>, ftype <chr>, fcode <int>, shape_length <dbl>, -#> # streamleve <int>, streamorde <int>, streamcalc <int>, fromnode <dbl>, -#> # tonode <dbl>, hydroseq <dbl>, levelpathi <dbl>, pathlength <dbl>, -#> # terminalpa <dbl>, arbolatesu <dbl>, divergence <int>, startflag <int>, -#> # terminalfl <int>, dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>, -#> # dnlevelpat <dbl>, dnminorhyd <dbl>, dndraincou <int>, dnhydroseq <dbl>, ... - # } +#> 1 nhdflowline_… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.725 +#> 2 nhdflowline_… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.221 +#> 3 nhdflowline_… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.369 +#> 4 nhdflowline_… 1.76e7 2008-03-19 23:00:00 Medium "27404… "Tecolot… 0.867 +#> 5 nhdflowline_… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.833 +#> 6 nhdflowline_… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.241 +#> 7 nhdflowline_… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.91 +#> 8 nhdflowline_… 1.76e7 1999-11-18 23:00:00 Medium " " " " 0.652 +#> # … with 132 more variables: reachcode <chr>, flowdir <chr>, wbareacomi <int>, +#> # ftype <chr>, fcode <int>, shape_length <dbl>, streamleve <int>, +#> # streamorde <int>, streamcalc <int>, fromnode <dbl>, tonode <dbl>, +#> # hydroseq <dbl>, levelpathi <dbl>, pathlength <dbl>, terminalpa <dbl>, +#> # arbolatesu <dbl>, divergence <int>, startflag <int>, terminalfl <int>, +#> # dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>, dnlevelpat <dbl>, +#> # dnminorhyd <dbl>, dndraincou <int>, dnhydroseq <dbl>, frommeas <int>, … + # }
@@ -324,7 +355,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_nhdplushr.html b/docs/reference/get_nhdplushr.html index 3837289f..c5f882e9 100644 --- a/docs/reference/get_nhdplushr.html +++ b/docs/reference/get_nhdplushr.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -78,24 +78,28 @@

Get NHDPlus HiRes

-
get_nhdplushr(
-  hr_dir,
-  out_gpkg = NULL,
-  layers = c("NHDFlowline", "NHDPlusCatchment"),
-  pattern = ".*GDB.gdb$",
-  check_terminals = TRUE,
-  overwrite = FALSE,
-  keep_cols = NULL,
-  ...
-)
+
get_nhdplushr(
+  hr_dir,
+  out_gpkg = NULL,
+  layers = c("NHDFlowline", "NHDPlusCatchment"),
+  pattern = ".*GDB.gdb$",
+  check_terminals = TRUE,
+  overwrite = FALSE,
+  keep_cols = NULL,
+  ...
+)

Arguments

hr_dir

character directory with geodatabases (gdb search is recursive)

+ +
out_gpkg

character path to write output geopackage

+ +
layers

character vector with desired layers to return. c("NHDFlowline", "NHDPlusCatchment") is default. @@ -105,25 +109,38 @@

Arguments

"NHDPlusBurnLineEvent", "HYDRO_NET_Junctions", "WBDHU2", "WBDHU4","WBDHU6", "WBDHU8" "WBDHU10", "WBDHU12", "WBDLine") Set to NULL to get all available.

+ +
pattern

character optional regex to select certain files in hr_dir

+ +
check_terminals

boolean if TRUE, run make_standalone on output.

+ +
overwrite

boolean should the output overwrite? If false and the output layer exists, it will be read and returned so this function will always return data even if called a second time for the same output. This is useful for workflows. Note that this will NOT delete the entire Geopackage. It will overwrite on a per layer basis.

+ +
keep_cols

character vector of column names to keep in the output. If NULL, all will be kept.

+ +
...

parameters passed along to get_hr_data for "NHDFlowline" layers.

+

Value

-

sf data.frames containing output that may also be written + + +

sf data.frames containing output that may also be written to a geopackage for later use.

@@ -136,28 +153,28 @@

Details

Examples

-
if (FALSE) {
-# Note this will download a lot of data to a temp directory.
-# Change 'temp_dir' to your directory of choice.
-temp_dir <- file.path(nhdplusTools_data_dir(), "temp_hr_cache")
-
-download_dir <- download_nhdplushr(temp_dir, c("0302", "0303"))
-
-get_nhdplushr(download_dir, file.path(download_dir, "nhdplus_0302-03.gpkg"))
-
-get_nhdplushr(download_dir,
-              file.path(download_dir, "nhdplus_0302-03.gpkg"),
-              layers = NULL, overwrite = TRUE)
-
-get_nhdplushr(download_dir,
-              file.path(download_dir, "nhdplus_0302-03.gpkg"),
-              layers = "NHDFlowline", overwrite = TRUE,
-              min_size_sqkm = 10, simp = 10, proj = "+init=epsg:5070")
-
-# Cleanup
-unlink(temp_dir, recursive = TRUE)
-
-}
+    
if (FALSE) {
+# Note this will download a lot of data to a temp directory.
+# Change 'temp_dir' to your directory of choice.
+temp_dir <- file.path(nhdplusTools_data_dir(), "temp_hr_cache")
+
+download_dir <- download_nhdplushr(temp_dir, c("0302", "0303"))
+
+get_nhdplushr(download_dir, file.path(download_dir, "nhdplus_0302-03.gpkg"))
+
+get_nhdplushr(download_dir,
+              file.path(download_dir, "nhdplus_0302-03.gpkg"),
+              layers = NULL, overwrite = TRUE)
+
+get_nhdplushr(download_dir,
+              file.path(download_dir, "nhdplus_0302-03.gpkg"),
+              layers = "NHDFlowline", overwrite = TRUE,
+              min_size_sqkm = 10, simp = 10, proj = "+init=epsg:5070")
+
+# Cleanup
+unlink(temp_dir, recursive = TRUE)
+
+}
 
@@ -172,7 +189,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_nldi_basin.html b/docs/reference/get_nldi_basin.html index 49e2a39c..f38675c0 100644 --- a/docs/reference/get_nldi_basin.html +++ b/docs/reference/get_nldi_basin.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -78,7 +78,7 @@

Get NLDI Basin Boundary

-
get_nldi_basin(nldi_feature, simplify = TRUE, split = FALSE)
+
get_nldi_basin(nldi_feature, simplify = TRUE, split = FALSE)
@@ -88,17 +88,24 @@

Arguments

`featureSource` is derived from the "source" column of the response of dataRetrieval::get_nldi_sources() and the `featureID` is a known identifier from the specified `featureSource`.

+ +
simplify

logical should response geometry be simplified for visualization and performance?

+ +
split

logical should response resolve precisely to the location of the `nldi_feature`? Setting `TRUE` calls an aditional service and will be slower and less robust.

+

Value

-

sf data.frame with result basin boundary

+ + +

sf data.frame with result basin boundary

Details

@@ -108,47 +115,47 @@

Details

Examples

-
# \donttest{
-library(sf)
-library(dplyr)
-
-nldi_nwis <- list(featureSource = "nwissite", featureID = "USGS-05428500")
-
-site <- get_nldi_feature(nldi_nwis)
-
-basin <- get_nldi_basin(nldi_feature = nldi_nwis)
-
-plot(st_geometry(basin))
+    
# \donttest{
+library(sf)
+library(dplyr)
+
+nldi_nwis <- list(featureSource = "nwissite", featureID = "USGS-05428500")
+
+site <- get_nldi_feature(nldi_nwis)
+
+basin <- get_nldi_basin(nldi_feature = nldi_nwis)
+
+plot(st_geometry(basin))
 
-
-basin
+
+basin
 #> Simple feature collection with 1 feature and 0 fields
 #> Geometry type: POLYGON
 #> Dimension:     XY
 #> Bounding box:  xmin: -89.60465 ymin: 43.03507 xmax: -89.20378 ymax: 43.36607
 #> Geodetic CRS:  WGS 84
-#> # A tibble: 1 x 1
+#> # A tibble: 1 × 1
 #>                                                                         geometry
 #>                                                                    <POLYGON [°]>
-#> 1 ((-89.35859 43.11776, -89.35423 43.11546, -89.35437 43.11067, -89.34997 43.10~
-
-basin2 <- get_nldi_basin(nldi_feature = nldi_nwis,
-                         simplify = FALSE, split = TRUE)
-
-length(st_coordinates(basin))
+#> 1 ((-89.35859 43.11776, -89.35423 43.11546, -89.35437 43.11067, -89.34997 43.10…
+
+basin2 <- get_nldi_basin(nldi_feature = nldi_nwis,
+                         simplify = FALSE, split = TRUE)
+
+length(st_coordinates(basin))
 #> [1] 1184
-length(st_coordinates(basin2))
+length(st_coordinates(basin2))
 #> [1] 3224
-
-plot(st_geometry(st_buffer(site, units::set_units(3000, "m"))), border = NA)
-
-plot(st_geometry(site), add = TRUE)
-plot(st_geometry(basin2), add = TRUE)
-
-plot(st_geometry(basin), border = "red", add = TRUE)
+
+plot(st_geometry(st_buffer(site, units::set_units(3000, "m"))), border = NA)
+
+plot(st_geometry(site), add = TRUE)
+plot(st_geometry(basin2), add = TRUE)
+
+plot(st_geometry(basin), border = "red", add = TRUE)
 
-
-# }
+
+# }
 
@@ -163,7 +170,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_nldi_characteristics.html b/docs/reference/get_nldi_characteristics.html index e99cf066..0f78361e 100644 --- a/docs/reference/get_nldi_characteristics.html +++ b/docs/reference/get_nldi_characteristics.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,7 +80,7 @@

Get Catchment Characteristics

-
get_nldi_characteristics(nldi_feature, type = "local")
+
get_nldi_characteristics(nldi_feature, type = "local")
@@ -90,21 +90,26 @@

Arguments

`featureSource` is derived from the "source" column of the response of dataRetrieval::get_nldi_sources() and the `featureID` is a known identifier from the specified `featureSource`.

+ +
type

character "all", "local", "total", or "divergence_routed".

+

Value

-

data.frame contianing requested characteristics

+ + +

data.frame contianing requested characteristics

Examples

-
# \donttest{
-chars <- get_nldi_characteristics(list(featureSource = "nwissite", featureID = "USGS-05429700"))
-names(chars)
+    
# \donttest{
+chars <- get_nldi_characteristics(list(featureSource = "nwissite", featureID = "USGS-05429700"))
+names(chars)
 #> [1] "local"
-head(chars$local, 10)
+head(chars$local, 10)
 #>    characteristic_id characteristic_value percent_nodata
 #> 1  CAT_WILDFIRE_2011                    0            100
 #> 2        CAT_CONTACT                47.28              0
@@ -116,7 +121,7 @@ 

Examples

#> 8 CAT_SATOF 2 0 #> 9 CAT_TWI 14.05 0 #> 10 CAT_WB5100_ANN 215.97 0 -# } +# }
@@ -131,7 +136,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_nldi_feature.html b/docs/reference/get_nldi_feature.html index 82af948e..c825a024 100644 --- a/docs/reference/get_nldi_feature.html +++ b/docs/reference/get_nldi_feature.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -78,7 +78,7 @@

Get NLDI Feature

-
get_nldi_feature(nldi_feature)
+
get_nldi_feature(nldi_feature)
@@ -88,27 +88,30 @@

Arguments

`featureSource` is derived from the "source" column of the response of dataRetrieval::get_nldi_sources() and the `featureID` is a known identifier from the specified `featureSource`.

+

Value

-

sf data.frame with one feature

+ + +

sf data.frame with one feature

Examples

-
# \donttest{
-get_nldi_feature(list("featureSource" = "nwissite", featureID = "USGS-05428500"))
+    
# \donttest{
+get_nldi_feature(list("featureSource" = "nwissite", featureID = "USGS-05428500"))
 #> Simple feature collection with 1 feature and 8 fields
 #> Geometry type: POINT
 #> Dimension:     XY
 #> Bounding box:  xmin: -89.36083 ymin: 43.08944 xmax: -89.36083 ymax: 43.08944
 #> Geodetic CRS:  WGS 84
-#> # A tibble: 1 x 9
-#>   sourceName               identifier  comid name  reachcode measure     X     Y
-#>   <chr>                    <chr>       <chr> <chr> <chr>     <chr>   <dbl> <dbl>
-#> 1 NWIS Surface Water Sites USGS-05428~ 1329~ YAHA~ 07090002~ 42.858~ -89.4  43.1
-#> # ... with 1 more variable: geometry <POINT [°]>
-# }
+#> # A tibble: 1 × 9
+#>   sourceName               identifier  comid measure reachcode name      X     Y
+#>   <chr>                    <chr>       <chr>   <dbl> <chr>     <chr> <dbl> <dbl>
+#> 1 NWIS Surface Water Sites USGS-05428… 1329…    42.9 07090002… YAHA… -89.4  43.1
+#> # … with 1 more variable: geometry <POINT [°]>
+# }
 
@@ -123,7 +126,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_nldi_index.html b/docs/reference/get_nldi_index.html index b883b7f0..93f85494 100644 --- a/docs/reference/get_nldi_index.html +++ b/docs/reference/get_nldi_index.html @@ -20,7 +20,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -84,28 +84,43 @@

Get NLDI Index

-
get_nldi_index(location)
+
get_nldi_index(location)

Arguments

location

numeric WGS84 lon/lat pair (X, Y)

+

Examples

-
# \donttest{
-index <- get_nldi_index(c(-89.276, 42.988))
-
-plot_nhdplus(bbox = sf::st_bbox(sf::st_buffer(index[1,], units::set_units(1000, "m"))))
+    
# \donttest{
+index <- get_nldi_index(c(-89.276, 42.988))
+
+plot_nhdplus(bbox = sf::st_bbox(sf::st_buffer(index[1,], units::set_units(1000, "m"))))
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
 #> Warning: No nonnetwork features found
+#> Spherical geometry (s2) switched on
 #> Zoom: 15
 #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
 #> Audotdetect projection: assuming Google Mercator (epsg 3857)
-plot(sf::st_geometry(sf::st_transform(index, 3857)), add = TRUE)
+plot(sf::st_geometry(sf::st_transform(index, 3857)), add = TRUE)
 
-# }
+# }
 
@@ -120,7 +135,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_node.html b/docs/reference/get_node.html index a8652eab..c003a551 100644 --- a/docs/reference/get_node.html +++ b/docs/reference/get_node.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,41 +80,46 @@

Get Flowline Node

-
get_node(x, position = "end")
+
get_node(x, position = "end")

Arguments

x

sf data.frame with one or more flowlines

+ +
position

character either "start" or "end"

+

Value

-

sf data.frame containing requested nodes

+ + +

sf data.frame containing requested nodes

Examples

-

-source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
-
-fline <- sf::read_sf(sample_data, "NHDFlowline_Network")
-
-start <- get_node(fline, "start")
-end <- get_node(fline, "end")
-
-plot(sf::st_zm(fline$geom),
-     lwd = fline$StreamOrde, col = "blue")
-plot(sf::st_geometry(start), add = TRUE)
+    

+source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
+
+fline <- sf::read_sf(sample_data, "NHDFlowline_Network")
+
+start <- get_node(fline, "start")
+end <- get_node(fline, "end")
+
+plot(sf::st_zm(fline$geom),
+     lwd = fline$StreamOrde, col = "blue")
+plot(sf::st_geometry(start), add = TRUE)
 
-
-plot(sf::st_zm(fline$geom),
-     lwd = fline$StreamOrde, col = "blue")
-plot(sf::st_geometry(end), add = TRUE)
+
+plot(sf::st_zm(fline$geom),
+     lwd = fline$StreamOrde, col = "blue")
+plot(sf::st_geometry(end), add = TRUE)
 
-
+
 
@@ -129,7 +134,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_nwis.html b/docs/reference/get_nwis.html index 7b0dadee..9c615b0c 100644 --- a/docs/reference/get_nwis.html +++ b/docs/reference/get_nwis.html @@ -19,7 +19,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -82,7 +82,7 @@

Discover USGS NWIS Stream Gages

-
get_nwis(AOI = NULL, t_srs = NULL, buffer = 20000)
+
get_nwis(AOI = NULL, t_srs = NULL, buffer = 20000)
@@ -91,18 +91,25 @@

Arguments

sf (MULTI)POINT or (MULTI)POLYGON. An 'area of interest' can be provided as either a location (sf POINT) or area (sf POLYGON) in any Spatial Reference System.

+ +
t_srs

character (PROJ string or EPSG code) or numeric (EPSG code). A user specified - target -Spatial Reference System (SRS/CRS) for returned objects. Will default to the CRS of the input AOI if provided, and to 4326 for ID requests.

+ +
buffer

numeric. The amount (in meters) to buffer a POINT AOI by for an extended search. Default = 20,000. Returned results are arrange by distance from POINT AOI

+

Value

-

a simple features (sf) object

+ + +

a simple features (sf) object

Details

@@ -127,7 +134,7 @@

Details

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_partial_length-1.png b/docs/reference/get_partial_length-1.png index f9e9c9fb..c4fb38d3 100644 Binary files a/docs/reference/get_partial_length-1.png and b/docs/reference/get_partial_length-1.png differ diff --git a/docs/reference/get_partial_length.html b/docs/reference/get_partial_length.html index d948746e..501045d5 100644 --- a/docs/reference/get_partial_length.html +++ b/docs/reference/get_partial_length.html @@ -20,7 +20,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -84,7 +84,7 @@

Get Partial Flowline Length

-
get_partial_length(hl, net = NULL, fl = NULL)
+
get_partial_length(hl, net = NULL, fl = NULL)
@@ -92,55 +92,62 @@

Arguments

hl

list containing a hydrologic location with names reachcode and reach_meas.

+ +
net

data.frame containing a flowpath network with reachcode, frommeas, tomeas, and lengthkm attributes. Not required if `fl` is provided.

+ +
fl

data.frame containing one flowline that corresponds to the reachcode and measure of `hl`. Not required if `hl` is provided.

+

Value

-

list containing `up` and `dn` elements with numeric length in + + +

list containing `up` and `dn` elements with numeric length in km.

Examples

-

-source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
-hydro_location <- list(comid = 5329339,
-                       reachcode = "18050005000078",
-                       reach_meas = 30)
-
-(pl <- get_partial_length(hydro_location, walker_flowline))
+    

+source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
+hydro_location <- list(comid = 5329339,
+                       reachcode = "18050005000078",
+                       reach_meas = 30)
+
+(pl <- get_partial_length(hydro_location, walker_flowline))
 #> $dn
 #> [1] 1.4358
 #> 
 #> $up
 #> [1] 3.3502
 #> 
-
-hydro_location <- sf::st_sf(hydro_location,
-                            geom = nhdplusTools::get_hydro_location(data.frame(hydro_location),
-                                                                    walker_flowline))
-
-net <- navigate_network(hydro_location,
-                        mode = "DM", network = walker_flowline,
-                        distance_km = 4, trim_start = TRUE)
+
+hydro_location <- sf::st_sf(hydro_location,
+                            geom = nhdplusTools::get_hydro_location(data.frame(hydro_location),
+                                                                    walker_flowline))
+
+net <- navigate_network(hydro_location,
+                        mode = "DM", network = walker_flowline,
+                        distance_km = 4, trim_start = TRUE)
 #> Loading required namespace: lwgeom
-
-plot(sf::st_geometry(walker_flowline[walker_flowline$COMID == hydro_location$comid,]))
-plot(sf::st_geometry(hydro_location), add = TRUE)
-plot(sf::st_geometry(net), add = TRUE, col = "blue", lwd = 2)
+
+plot(sf::st_geometry(walker_flowline[walker_flowline$COMID == hydro_location$comid,]))
+plot(sf::st_geometry(hydro_location), add = TRUE)
+plot(sf::st_geometry(net), add = TRUE, col = "blue", lwd = 2)
 
-
-sf::st_length(net)
-#> 1437.438 [m]
-pl$dn
+
+sf::st_length(net)
+#> 2384.619 [m]
+pl$dn
 #> [1] 1.4358
-
+
 
@@ -155,7 +162,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_path_lengths.html b/docs/reference/get_path_lengths.html index cec18cee..9b3eadb5 100644 --- a/docs/reference/get_path_lengths.html +++ b/docs/reference/get_path_lengths.html @@ -19,7 +19,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -82,51 +82,60 @@

Get Path Lengths

-
get_path_lengths(outlets, network, cores = 1, status = FALSE)
+
get_path_lengths(outlets, network, cores = 1, status = FALSE)

Arguments

outlets

vector of IDs from data.frame

+ +
network

data.frame with ID, toID, and lengthkm attributes.

+ +
cores

integer number of cores to use for parallel computation.

+ +
status

logical print status and progress bars?

+

Value

-

data.frame containing the distance between pairs of network outlets. + + +

data.frame containing the distance between pairs of network outlets. For a network with one terminal outlet, the data.frame will have `nrow(network)^2` rows.

Examples

-
source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
-fline <- walker_flowline
-
-outlets <- c(5329303, 5329357, 5329317, 5329365, 5329435, 5329817)
-
-# Add toCOMID
-fline <- nhdplusTools::get_tocomid(fline, add = TRUE)
-
-fl <- dplyr::select(fline, ID = comid, toID = tocomid, lengthkm)
-
-path_lengths <- get_path_lengths(outlets, fl)
-
-outlet_geo <- sf::st_sf(
-  dplyr::left_join(data.frame(ID = outlets),
-                   dplyr::select(fline, ID = comid), by = "ID"))
-
-sf::st_geometry(outlet_geo) <- sf::st_geometry(nhdplusTools::get_node(outlet_geo))
-
-plot(sf::st_geometry(fl))
-plot(sf::st_geometry(outlet_geo), add = TRUE)
+    
source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
+fline <- walker_flowline
+
+outlets <- c(5329303, 5329357, 5329317, 5329365, 5329435, 5329817)
+
+# Add toCOMID
+fline <- nhdplusTools::get_tocomid(fline, add = TRUE)
+
+fl <- dplyr::select(fline, ID = comid, toID = tocomid, lengthkm)
+
+path_lengths <- get_path_lengths(outlets, fl)
+
+outlet_geo <- sf::st_sf(
+  dplyr::left_join(data.frame(ID = outlets),
+                   dplyr::select(fline, ID = comid), by = "ID"))
+
+sf::st_geometry(outlet_geo) <- sf::st_geometry(nhdplusTools::get_node(outlet_geo))
+
+plot(sf::st_geometry(fl))
+plot(sf::st_geometry(outlet_geo), add = TRUE)
 
-
+
 
@@ -141,7 +150,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_path_members.html b/docs/reference/get_path_members.html new file mode 100644 index 00000000..25feea29 --- /dev/null +++ b/docs/reference/get_path_members.html @@ -0,0 +1,169 @@ + +Get Path Members — get_path_members • nhdplusTools + + +
+
+ + + +
+
+ + +
+

Given a network and set of IDs, finds paths between all +identified flowpath outlets. This algorithm finds members between outlets +regardless of flow direction.

+
+ +
+
get_path_members(outlets, network, cores = 1, status = FALSE)
+
+ +
+

Arguments

+
outlets
+

vector of IDs from data.frame

+ + +
network
+

data.frame with ID, toID, and lengthkm attributes.

+ + +
cores
+

integer number of cores to use for parallel computation.

+ + +
status
+

logical print status and progress bars?

+ +
+
+

Value

+ + +

list of lists containing flowpath identifiers along path that connect +outlets.

+
+ +
+

Examples

+
source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
+fline <- walker_flowline
+
+outlets <- c(5329303, 5329357, 5329317, 5329365, 5329435, 5329817)
+
+# Add toCOMID
+fline <- nhdplusTools::get_tocomid(fline, add = TRUE)
+
+fl <- dplyr::select(fline, ID = comid, toID = tocomid, lengthkm)
+
+get_path_members(outlets, fl)
+#>    id_1 id_2                                                      path
+#> 1     1    8                                       7, 6, 5, 4, 3, 2, 1
+#> 2     1    4                                                   3, 2, 1
+#> 3     1    9                                    8, 7, 6, 5, 4, 3, 2, 1
+#> 4     1   16 15, 14, 13, 12, 11, 60, 62, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
+#> 5     1   19                                     18, 17, 5, 4, 3, 2, 1
+#> 6     8    4                                                7, 6, 5, 4
+#> 7     8    9                                                         8
+#> 8     8   16                      15, 14, 13, 12, 11, 60, 62, 10, 9, 8
+#> 9     8   19                                              7, 6, 18, 17
+#> 10    4    9                                             8, 7, 6, 5, 4
+#> 11    4   16          15, 14, 13, 12, 11, 60, 62, 10, 9, 8, 7, 6, 5, 4
+#> 12    4   19                                              18, 17, 5, 4
+#> 13    9   16                         15, 14, 13, 12, 11, 60, 62, 10, 9
+#> 14    9   19                                           8, 7, 6, 18, 17
+#> 15   16   19        15, 14, 13, 12, 11, 60, 62, 10, 9, 8, 7, 6, 18, 17
+
+
+
+
+ +
+ + +
+ +
+

Site built with pkgdown 2.0.5.

+
+ +
+ + + + + + + + diff --git a/docs/reference/get_pathlength.html b/docs/reference/get_pathlength.html index 51d66ed7..ba9ff4cc 100644 --- a/docs/reference/get_pathlength.html +++ b/docs/reference/get_pathlength.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,31 +80,34 @@

Get Path Length

-
get_pathlength(x)
+
get_pathlength(x)

Arguments

x

data.frame with ID, toID, length columns.

+

Value

-

data.frame containing levelpaths for each ID

+ + +

data.frame containing levelpaths for each ID

Examples

-
source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
-
-fl <- dplyr::select(prepare_nhdplus(walker_flowline, 0, 0),
-                    ID = COMID, toID = toCOMID, length = LENGTHKM)
+    
source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
+
+fl <- dplyr::select(prepare_nhdplus(walker_flowline, 0, 0),
+                    ID = COMID, toID = toCOMID, length = LENGTHKM)
 #> 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 0
-
-get_pathlength(fl)
+
+get_pathlength(fl)
 #>         ID pathlength
 #> 1  5329303      0.000
 #> 2  5329295      1.195
@@ -168,7 +171,7 @@ 

Examples

#> 60 5329871 38.554 #> 61 5329407 35.306 #> 62 5329435 35.130 - +
@@ -183,7 +186,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_pfaf-2.png b/docs/reference/get_pfaf-2.png index 22901845..561e36b6 100644 Binary files a/docs/reference/get_pfaf-2.png and b/docs/reference/get_pfaf-2.png differ diff --git a/docs/reference/get_pfaf.html b/docs/reference/get_pfaf.html index 2f3a8d58..8a081849 100644 --- a/docs/reference/get_pfaf.html +++ b/docs/reference/get_pfaf.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,7 +80,7 @@

Get Pfafstetter Codes (Experimental)

-
get_pfaf(x, max_level = 2, status = FALSE)
+
get_pfaf(x, max_level = 2, status = FALSE)
@@ -88,78 +88,85 @@

Arguments

x

sf data.frame with ID, toID, totda, outletID, topo_sort, and levelpath attributes.

+ +
max_level

integer number of pfaf levels to attempt to calculate. If the network doesn't have resolution to support the desired level, unexpected behavior may occur.

+ +
status

boolean print status or not

+

Value

-

data.frame with ID and pfaf columns.

+ + +

data.frame with ID and pfaf columns.

Examples

-
# \donttest{
-library(dplyr)
-source(system.file("extdata/nhdplushr_data.R", package = "nhdplusTools"))
-hr_flowline <- align_nhdplus_names(hr_data$NHDFlowline)
-
-fl <-  select(hr_flowline, COMID, AreaSqKM) %>%
-  right_join(prepare_nhdplus(hr_flowline, 0, 0,
-                             purge_non_dendritic = FALSE,
-                             warn = FALSE),
-             by = "COMID") %>%
-  sf::st_sf() %>%
-  select(ID = COMID, toID = toCOMID, area = AreaSqKM)
-
-fl$nameID = ""
-fl$totda <- calculate_total_drainage_area(sf::st_set_geometry(fl, NULL))
-fl <- left_join(fl, get_levelpaths(rename(sf::st_set_geometry(fl, NULL),
-                                   weight = totda)), by = "ID")
-
-pfaf <- get_pfaf(fl, max_level = 3)
-
-fl <- left_join(fl, pfaf, by = "ID")
-
-plot(fl["pf_level_3"], lwd = 2)
+    
# \donttest{
+library(dplyr)
+source(system.file("extdata/nhdplushr_data.R", package = "nhdplusTools"))
+hr_flowline <- align_nhdplus_names(hr_data$NHDFlowline)
+
+fl <-  select(hr_flowline, COMID, AreaSqKM) %>%
+  right_join(prepare_nhdplus(hr_flowline, 0, 0,
+                             purge_non_dendritic = FALSE,
+                             warn = FALSE),
+             by = "COMID") %>%
+  sf::st_sf() %>%
+  select(ID = COMID, toID = toCOMID, area = AreaSqKM)
+
+fl$nameID = ""
+fl$totda <- calculate_total_drainage_area(sf::st_set_geometry(fl, NULL))
+fl <- left_join(fl, get_levelpaths(rename(sf::st_set_geometry(fl, NULL),
+                                   weight = totda)), by = "ID")
+
+pfaf <- get_pfaf(fl, max_level = 3)
+
+fl <- left_join(fl, pfaf, by = "ID")
+
+plot(fl["pf_level_3"], lwd = 2)
 
-
-pfaf <- get_pfaf(fl, max_level = 4)
-
-hr_catchment <- left_join(hr_data$NHDPlusCatchment, 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)))),
-                    stringsAsFactors = FALSE)
-hr_catchment <- left_join(hr_catchment, colors, by = "pf_level_4")
-plot(hr_catchment["color"], border = NA, reset = FALSE)
-plot(sf::st_geometry(hr_flowline), col = "blue", add = TRUE)
+
+pfaf <- get_pfaf(fl, max_level = 4)
+
+hr_catchment <- left_join(hr_data$NHDPlusCatchment, 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)))),
+                    stringsAsFactors = FALSE)
+hr_catchment <- left_join(hr_catchment, colors, by = "pf_level_4")
+plot(hr_catchment["color"], border = NA, reset = FALSE)
+plot(sf::st_geometry(hr_flowline), col = "blue", add = TRUE)
 
-
-source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
-
-fl <- select(walker_flowline, COMID, AreaSqKM) %>%
-  right_join(prepare_nhdplus(walker_flowline, 0, 0,
-                            purge_non_dendritic = FALSE, warn = FALSE),
-            by = "COMID") %>%
-  sf::st_sf() %>%
-  select(ID = COMID, toID = toCOMID, area = AreaSqKM)
-
-fl$nameID = ""
-fl$totda <- calculate_total_drainage_area(sf::st_set_geometry(fl, NULL))
-fl <- left_join(fl, get_levelpaths(rename(sf::st_set_geometry(fl, NULL),
-                                   weight = totda)), by = "ID")
-
-pfaf <- get_pfaf(fl, max_level = 2)
-
-fl <- left_join(fl, pfaf, by = "ID")
-
-plot(fl["pf_level_2"], lwd = 2)
+
+source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
+
+fl <- select(walker_flowline, COMID, AreaSqKM) %>%
+  right_join(prepare_nhdplus(walker_flowline, 0, 0,
+                            purge_non_dendritic = FALSE, warn = FALSE),
+            by = "COMID") %>%
+  sf::st_sf() %>%
+  select(ID = COMID, toID = toCOMID, area = AreaSqKM)
+
+fl$nameID = ""
+fl$totda <- calculate_total_drainage_area(sf::st_set_geometry(fl, NULL))
+fl <- left_join(fl, get_levelpaths(rename(sf::st_set_geometry(fl, NULL),
+                                   weight = totda)), by = "ID")
+
+pfaf <- get_pfaf(fl, max_level = 2)
+
+fl <- left_join(fl, pfaf, by = "ID")
+
+plot(fl["pf_level_2"], lwd = 2)
 
-# }
+# }
 
@@ -174,7 +181,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_raindrop_trace-1.png b/docs/reference/get_raindrop_trace-1.png index 48c435f9..70639f57 100644 Binary files a/docs/reference/get_raindrop_trace-1.png and b/docs/reference/get_raindrop_trace-1.png differ diff --git a/docs/reference/get_raindrop_trace.html b/docs/reference/get_raindrop_trace.html index 1a001fd4..d63e905f 100644 --- a/docs/reference/get_raindrop_trace.html +++ b/docs/reference/get_raindrop_trace.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,7 +80,7 @@

Get Raindrop Trace

-
get_raindrop_trace(point, direction = "down")
+
get_raindrop_trace(point, direction = "down")
@@ -88,49 +88,68 @@

Arguments

point

sfc POINT including crs as created by: sf::st_sfc(sf::st_point(.. ,..), crs)

+ +
direction

character "up", "down", or "none". Controls the portion of the split flowline that is returned along with the raindrop trace line.

+

Value

-

sf data.frame containing raindrop trace and requested + + +

sf data.frame containing raindrop trace and requested portion of flowline.

Examples

-
# \donttest{
-point <- sf::st_sfc(sf::st_point(x = c(-89.2158, 42.9561)), crs = 4326)
-
-(trace <- get_raindrop_trace(point))
+    
# \donttest{
+point <- sf::st_sfc(sf::st_point(x = c(-89.2158, 42.9561)), crs = 4326)
+
+(trace <- get_raindrop_trace(point))
 #> Simple feature collection with 2 features and 7 fields
 #> Geometry type: LINESTRING
 #> Dimension:     XY
 #> Bounding box:  xmin: -89.21572 ymin: 42.94986 xmax: -89.20944 ymax: 42.95699
 #> Geodetic CRS:  WGS 84
-#> # A tibble: 2 x 8
-#>   id       gnis_name   comid reachcode raindrop_pathDi~ measure intersection_po~
+#> # A tibble: 2 × 8
+#>   id       gnis_name   comid reachcode raindrop_pathDi… measure intersection_po…
 #>   <chr>    <chr>       <int> <chr>                <dbl>   <dbl> <list>          
-#> 1 downstr~ Yahara R~  1.33e7 07090002~             273.    29.7 <dbl [2]>       
-#> 2 raindro~ NA        NA      NA                     NA     NA   <dbl [0]>       
-#> # ... with 1 more variable: geometry <LINESTRING [°]>
-
-bbox <- sf::st_bbox(trace) + c(-0.005, -0.005, 0.005, 0.005)
-
-nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE)
+#> 1 downstr… Yahara R…  1.33e7 07090002…             273.    29.7 <dbl [2]>       
+#> 2 raindro… NA        NA      NA                     NA     NA   <dbl [0]>       
+#> # … with 1 more variable: geometry <LINESTRING [°]>
+
+bbox <- sf::st_bbox(trace) + c(-0.005, -0.005, 0.005, 0.005)
+
+nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE)
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
 #> Warning: No waterbodies features found
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
 #> Zoom: 15
 #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
 #> Audotdetect projection: assuming Google Mercator (epsg 3857)
-
-plot(sf::st_transform(sf::st_sfc(point, crs = 4326), 3857), add = TRUE)
-plot(sf::st_transform(sf::st_geometry(trace)[1], 3857), add = TRUE, col = "red")
-plot(sf::st_transform(sf::st_geometry(trace)[2], 3857), add = TRUE, col = "black")
+
+plot(sf::st_transform(sf::st_sfc(point, crs = 4326), 3857), add = TRUE)
+plot(sf::st_transform(sf::st_geometry(trace)[1], 3857), add = TRUE, col = "red")
+plot(sf::st_transform(sf::st_geometry(trace)[2], 3857), add = TRUE, col = "black")
 
-# }
-
+# }
+
 
@@ -145,7 +164,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_sorted.html b/docs/reference/get_sorted.html index a3f5cfc7..261caf85 100644 --- a/docs/reference/get_sorted.html +++ b/docs/reference/get_sorted.html @@ -22,7 +22,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -88,7 +88,7 @@

Get Sorted Network

-
get_sorted(x, split = FALSE, outlets = NULL)
+
get_sorted(x, split = FALSE, outlets = NULL)
@@ -96,31 +96,38 @@

Arguments

x

data.frame with an identifier and to identifier in the first and second columns.

+ +
split

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.

+ +
outlets

same as id in x; if specified only the network emanating from these outlets will be considered and returned.

+

Value

-

data.frame containing a topologically sorted version + + +

data.frame containing a topologically sorted version of the requested network and optionally a terminal id.

Examples

-
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))
+    
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: MULTILINESTRING
 #> Dimension:     XY
@@ -140,12 +147,12 @@ 

Examples

#> 4 1.641 8897784 MULTILINESTRING ((1507786 1... #> 5 1.167 983820 8897784 MULTILINESTRING ((1508236 1... #> 6 1.767 8897784 MULTILINESTRING ((1508311 1... - -fpath['sort_order'] <- 1:nrow(fpath) - -plot(fpath['sort_order']) + +fpath['sort_order'] <- 1:nrow(fpath) + +plot(fpath['sort_order']) - +
@@ -160,7 +167,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_split_catchment-1.png b/docs/reference/get_split_catchment-1.png index 62e4832d..938d6830 100644 Binary files a/docs/reference/get_split_catchment-1.png and b/docs/reference/get_split_catchment-1.png differ diff --git a/docs/reference/get_split_catchment-2.png b/docs/reference/get_split_catchment-2.png index 69dd33d2..8c0fc5f4 100644 Binary files a/docs/reference/get_split_catchment-2.png and b/docs/reference/get_split_catchment-2.png differ diff --git a/docs/reference/get_split_catchment-3.png b/docs/reference/get_split_catchment-3.png index 911f663d..8cf261f5 100644 Binary files a/docs/reference/get_split_catchment-3.png and b/docs/reference/get_split_catchment-3.png differ diff --git a/docs/reference/get_split_catchment.html b/docs/reference/get_split_catchment.html index a3dd87d0..9cbe41d6 100644 --- a/docs/reference/get_split_catchment.html +++ b/docs/reference/get_split_catchment.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,7 +80,7 @@

Get split catchment

-
get_split_catchment(point, upstream = TRUE)
+
get_split_catchment(point, upstream = TRUE)
@@ -88,109 +88,158 @@

Arguments

point

scf POINT including crs as created by: sf::st_sfc(sf::st_point(.. ,..), crs)

+ +
upstream

logical If TRUE, the entire drainage basin upstream of the point provided is returned in addition to the local catchment.

+

Value

-

sf data.frame containing the local catchment, the split portion + + +

sf data.frame containing the local catchment, the split portion and optionally the total dranage basin.

Examples

-
# \donttest{
-point <- sf::st_sfc(sf::st_point(x = c(-89.2158, 42.9561)), crs = 4326)
-
-trace <- get_raindrop_trace(point)
-
-(snap_point <- sf::st_sfc(sf::st_point(trace$intersection_point[[1]]),
-                          crs = 4326))
+    
# \donttest{
+point <- sf::st_sfc(sf::st_point(x = c(-89.2158, 42.9561)), crs = 4326)
+
+trace <- get_raindrop_trace(point)
+
+(snap_point <- sf::st_sfc(sf::st_point(trace$intersection_point[[1]]),
+                          crs = 4326))
 #> Geometry set for 1 feature 
 #> Geometry type: POINT
 #> Dimension:     XY
 #> Bounding box:  xmin: -89.21343 ymin: 42.95671 xmax: -89.21343 ymax: 42.95671
 #> Geodetic CRS:  WGS 84
 #> POINT (-89.21343 42.95671)
-
-(catchment <- get_split_catchment(snap_point))
+
+(catchment <- get_split_catchment(snap_point))
 #> Simple feature collection with 2 features and 2 fields
 #> Geometry type: POLYGON
 #> Dimension:     XY
 #> Bounding box:  xmin: -89.60479 ymin: 42.9205 xmax: -89.17455 ymax: 43.36611
 #> Geodetic CRS:  WGS 84
-#> # A tibble: 2 x 3
+#> # A tibble: 2 × 3
 #>   id              catchmentID                                           geometry
 #>   <chr>           <chr>                                            <POLYGON [°]>
-#> 1 catchment       13297178    ((-89.22801 42.94979, -89.22669 42.95053, -89.224~
-#> 2 mergedCatchment NA          ((-89.60268 43.20938, -89.6039 43.21025, -89.6041~
-
-bbox <- sf::st_bbox(catchment) + c(-0.005, -0.005, 0.005, 0.005)
-
-nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE)
+#> 1 catchment       13297178    ((-89.22801 42.94979, -89.22669 42.95053, -89.224…
+#> 2 mergedCatchment NA          ((-89.60268 43.20938, -89.6039 43.21025, -89.6041…
+
+bbox <- sf::st_bbox(catchment) + c(-0.005, -0.005, 0.005, 0.005)
+
+nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE)
+#> Spherical geometry (s2) switched off
 #> Found invalid geometry, attempting to fix.
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
 #> Zoom: 11
 #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
 #> Audotdetect projection: assuming Google Mercator (epsg 3857)
-
-plot(sf::st_transform(sf::st_geometry(catchment)[2], 3857), add = TRUE, col = "black")
-plot(sf::st_transform(sf::st_geometry(catchment)[1], 3857), add = TRUE, col = "red")
-plot(sf::st_transform(sf::st_sfc(point, crs = 4326), 3857), add = TRUE, col = "white")
+
+plot(sf::st_transform(sf::st_geometry(catchment)[2], 3857), add = TRUE, col = "black")
+plot(sf::st_transform(sf::st_geometry(catchment)[1], 3857), add = TRUE, col = "red")
+plot(sf::st_transform(sf::st_sfc(point, crs = 4326), 3857), add = TRUE, col = "white")
 
-
-(catchment <- get_split_catchment(snap_point, upstream = FALSE))
+
+(catchment <- get_split_catchment(snap_point, upstream = FALSE))
 #> Simple feature collection with 2 features and 2 fields
 #> Geometry type: POLYGON
 #> Dimension:     XY
 #> Bounding box:  xmin: -89.22801 ymin: 42.94856 xmax: -89.19011 ymax: 42.9972
 #> Geodetic CRS:  WGS 84
-#> # A tibble: 2 x 3
+#> # A tibble: 2 × 3
 #>   id             catchmentID                                            geometry
 #>   <chr>          <chr>                                             <POLYGON [°]>
-#> 1 catchment      13297178    ((-89.22801 42.94979, -89.22669 42.95053, -89.2248~
-#> 2 splitCatchment NA          ((-89.19219 42.9972, -89.19145 42.99716, -89.19156~
-
-bbox <- sf::st_bbox(catchment) + c(-0.005, -0.005, 0.005, 0.005)
-
-nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE)
+#> 1 catchment      13297178    ((-89.22801 42.94979, -89.22669 42.95053, -89.2248…
+#> 2 splitCatchment NA          ((-89.19219 42.9972, -89.19145 42.99716, -89.19156…
+
+bbox <- sf::st_bbox(catchment) + c(-0.005, -0.005, 0.005, 0.005)
+
+nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE)
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
 #> Zoom: 13
 #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
 #> Audotdetect projection: assuming Google Mercator (epsg 3857)
-
-plot(sf::st_transform(sf::st_geometry(catchment)[1], 3857), add = TRUE, col = "red")
-plot(sf::st_transform(sf::st_geometry(catchment)[2], 3857), add = TRUE, col = "black")
-plot(sf::st_transform(sf::st_sfc(point, crs = 4326), 3857), add = TRUE, col = "white")
+
+plot(sf::st_transform(sf::st_geometry(catchment)[1], 3857), add = TRUE, col = "red")
+plot(sf::st_transform(sf::st_geometry(catchment)[2], 3857), add = TRUE, col = "black")
+plot(sf::st_transform(sf::st_sfc(point, crs = 4326), 3857), add = TRUE, col = "white")
 
-
-pour_point <- sf::st_sfc(sf::st_point(x = c(-89.25619, 42.98646)), crs = 4326)
-
-(catchment <- get_split_catchment(pour_point, upstream = FALSE))
+
+pour_point <- sf::st_sfc(sf::st_point(x = c(-89.25619, 42.98646)), crs = 4326)
+
+(catchment <- get_split_catchment(pour_point, upstream = FALSE))
 #> Simple feature collection with 2 features and 2 fields
 #> Geometry type: POLYGON
 #> Dimension:     XY
 #> Bounding box:  xmin: -89.27379 ymin: 42.97976 xmax: -89.2321 ymax: 43.00384
 #> Geodetic CRS:  WGS 84
-#> # A tibble: 2 x 3
+#> # A tibble: 2 × 3
 #>   id             catchmentID                                            geometry
 #>   <chr>          <chr>                                             <POLYGON [°]>
-#> 1 catchment      13296592    ((-89.26258 42.98281, -89.26505 42.98306, -89.2664~
-#> 2 splitCatchment NA          ((-89.25813 42.99039, -89.25824 42.98931, -89.2578~
-
-bbox <- sf::st_bbox(catchment) + c(-0.005, -0.005, 0.005, 0.005)
-
-nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE)
+#> 1 catchment      13296592    ((-89.26258 42.98281, -89.26505 42.98306, -89.2664…
+#> 2 splitCatchment NA          ((-89.25813 42.99039, -89.25824 42.98931, -89.2578…
+
+bbox <- sf::st_bbox(catchment) + c(-0.005, -0.005, 0.005, 0.005)
+
+nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE)
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+#> Spherical geometry (s2) switched off
 #> Warning: No nonnetwork features found
+#> Spherical geometry (s2) switched on
 #> Zoom: 14
 #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
 #> Audotdetect projection: assuming Google Mercator (epsg 3857)
-
-plot(sf::st_transform(sf::st_geometry(catchment)[1], 3857), add = TRUE, col = "red")
-plot(sf::st_transform(sf::st_geometry(catchment)[2], 3857), add = TRUE, col = "black")
-plot(sf::st_transform(sf::st_sfc(pour_point, crs = 4326), 3857), add = TRUE, col = "white")
+
+plot(sf::st_transform(sf::st_geometry(catchment)[1], 3857), add = TRUE, col = "red")
+plot(sf::st_transform(sf::st_geometry(catchment)[2], 3857), add = TRUE, col = "black")
+plot(sf::st_transform(sf::st_sfc(pour_point, crs = 4326), 3857), add = TRUE, col = "white")
 
-# }
-
+# }
+
 
@@ -205,7 +254,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_streamlevel.html b/docs/reference/get_streamlevel.html index 6c93694d..732e8d82 100644 --- a/docs/reference/get_streamlevel.html +++ b/docs/reference/get_streamlevel.html @@ -23,7 +23,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -90,7 +90,7 @@

Get Streamlevel

-
get_streamlevel(x)
+
get_streamlevel(x)
@@ -99,41 +99,44 @@

Arguments

data.frame with levelpathi, dnlevelpat, and optionally a coastal flag. If no coastal flag is included, all terminal paths are assumed to be coastal.

+

Value

-

numeric stream order in same order as input

+ + +

numeric stream order in same order as input

Examples

-
source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
-
-test_flowline <- data.frame(
- levelpathi = walker_flowline$LevelPathI,
- dnlevelpat = walker_flowline$DnLevelPat)
-
- test_flowline$dnlevelpat[1] <- 0
-
-(level <- get_streamlevel(test_flowline))
+    
source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
+
+test_flowline <- data.frame(
+ levelpathi = walker_flowline$LevelPathI,
+ dnlevelpat = walker_flowline$DnLevelPat)
+
+ test_flowline$dnlevelpat[1] <- 0
+
+(level <- get_streamlevel(test_flowline))
 #>  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 3 2 2 2 2 2 2 2 3 2 2 3 2 2 2 2
 #> [39] 3 2 2 3 2 3 3 4 2 2 2 3 3 3 2 2 2 2 2 2 2 1 2 1
-
-walker_flowline$level <- level
-
-plot(sf::st_geometry(walker_flowline), lwd = walker_flowline$level, col = "blue")
+
+walker_flowline$level <- level
+
+plot(sf::st_geometry(walker_flowline), lwd = walker_flowline$level, col = "blue")
 
-
-test_flowline$coastal <- rep(FALSE, nrow(test_flowline))
-(level <- get_streamlevel(test_flowline))
+
+test_flowline$coastal <- rep(FALSE, nrow(test_flowline))
+(level <- get_streamlevel(test_flowline))
 #>  [1] 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 6 5 5 5 5 5 5 5 6 5 5 6 5 5 5 5
 #> [39] 6 5 5 6 5 6 6 7 5 5 5 6 6 6 5 5 5 5 5 5 5 4 5 4
-
-test_flowline$coastal[!test_flowline$dnlevelpat %in% test_flowline$levelpathi] <- TRUE
-(level <- get_streamlevel(test_flowline))
+
+test_flowline$coastal[!test_flowline$dnlevelpat %in% test_flowline$levelpathi] <- TRUE
+(level <- get_streamlevel(test_flowline))
 #>  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 3 2 2 2 2 2 2 2 3 2 2 3 2 2 2 2
 #> [39] 3 2 2 3 2 3 3 4 2 2 2 3 3 3 2 2 2 2 2 2 2 1 2 1
-
+
 
@@ -148,7 +151,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_streamorder.html b/docs/reference/get_streamorder.html index fb9f69bd..9a2f31eb 100644 --- a/docs/reference/get_streamorder.html +++ b/docs/reference/get_streamorder.html @@ -20,7 +20,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -84,44 +84,49 @@

Get Streamorder

-
get_streamorder(x, status = TRUE)
+
get_streamorder(x, status = TRUE)

Arguments

x

data.frame with dendritic ID and toID columns.

+ +
status

logical show progress update messages?

+

Value

-

numeric stream order in same order as input

+ + +

numeric stream order in same order as input

Examples

-
source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
-
-test_flowline <- prepare_nhdplus(walker_flowline, 0, 0, FALSE)
+    
source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
+
+test_flowline <- prepare_nhdplus(walker_flowline, 0, 0, FALSE)
 #> Warning: removing geometry
 #> Warning: Removed 0 flowlines that don't apply.
 #>  Includes: Coastlines, non-dendritic paths, 
 #> and networks with drainage area less than 0 sqkm, and drainage basins smaller than FALSE
-
-test_flowline <- data.frame(
-  ID = test_flowline$COMID,
-  toID = test_flowline$toCOMID)
-
-(order <- get_streamorder(test_flowline))
+
+test_flowline <- data.frame(
+  ID = test_flowline$COMID,
+  toID = test_flowline$toCOMID)
+
+(order <- get_streamorder(test_flowline))
 #>  [1] 4 4 4 4 4 3 3 3 3 2 2 2 2 2 2 1 3 3 3 3 2 2 1 1 2 2 1 1 1 2 1 2 1 1 1 1 1 2
 #> [39] 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2
-
-walker_flowline$order <- order
-
-plot(sf::st_geometry(walker_flowline), lwd = walker_flowline$order, col = "blue")
+
+walker_flowline$order <- order
+
+plot(sf::st_geometry(walker_flowline), lwd = walker_flowline$order, col = "blue")
 
-
+
 
@@ -136,7 +141,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_terminal.html b/docs/reference/get_terminal.html index edbac147..e4f4ce37 100644 --- a/docs/reference/get_terminal.html +++ b/docs/reference/get_terminal.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,35 +80,40 @@

Get Terminal ID (DEPRECATED)

-
get_terminal(x, outlets)
+
get_terminal(x, outlets)

Arguments

x

two column data.frame with IDs and toIDs. Names are ignored.

+ +
outlets

IDs of outlet flowlines

+

Value

-

data.frame containing the terminal ID for each outlet

+ + +

data.frame containing the terminal ID for each outlet

Examples

-
source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
-
-fl <- dplyr::select(prepare_nhdplus(walker_flowline, 0, 0),
-                    ID = COMID, toID = toCOMID)
+    
source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
+
+fl <- dplyr::select(prepare_nhdplus(walker_flowline, 0, 0),
+                    ID = COMID, toID = toCOMID)
 #> 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 0
-
-outlet <- fl$ID[which(!fl$toID %in% fl$ID)]
-
-get_terminal(fl, outlet)
+
+outlet <- fl$ID[which(!fl$toID %in% fl$ID)]
+
+get_terminal(fl, outlet)
 #> Deprecated, use get_sorted.
 #>         ID terminalID
 #> 1  5329303    5329303
@@ -173,7 +178,7 @@ 

Examples

#> 60 5329847 5329303 #> 61 5329845 5329303 #> 62 5329843 5329303 - +
@@ -188,7 +193,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_tocomid.html b/docs/reference/get_tocomid.html index a8e55f3b..217e92b8 100644 --- a/docs/reference/get_tocomid.html +++ b/docs/reference/get_tocomid.html @@ -24,7 +24,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -92,13 +92,13 @@

Get tocomid

-
get_tocomid(
-  x,
-  return_dendritic = TRUE,
-  missing = 0,
-  remove_coastal = TRUE,
-  add = TRUE
-)
+
get_tocomid(
+  x,
+  return_dendritic = TRUE,
+  missing = 0,
+  remove_coastal = TRUE,
+  add = TRUE
+)
@@ -106,35 +106,46 @@

Arguments

x

data.frame with comid, tonode, fromnode, and (optionally) divergence and terminalpa attributes.

+ +
return_dendritic

logical if TRUE, a divergence attribute is required (2 indicates diverted path, 1 is main) and diverted paths will be treated as headwaters. If this is FALSE, the return value is a data.frame including the comid and tocomid attributes.

+ +
missing

integer value to use for terminal nodes.

+ +
remove_coastal

logical remove coastal features prior to generating tocomid values? ftype or fcode are required if `TRUE`. fcode == 56600 or fcode == "Coastline" will be fremoved.

+ +
add

logical if TRUE, a tocomid column will be added, otherwise a data.frame with two columns will be returned.

+

Value

-

data.frame containing comid and tocomid attributes or all + + +

data.frame containing comid and tocomid attributes or all attributes provided with comid and tocomid in the first and second columns..

Examples

-
source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
-
-tocomid <- get_tocomid(sample_flines)
-
-tocomid <- get_tocomid(sample_flines, return_dendritic = FALSE)
-
+    
source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
+
+tocomid <- get_tocomid(sample_flines)
+
+tocomid <- get_tocomid(sample_flines, return_dendritic = FALSE)
+
 
@@ -149,7 +160,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_vaa.html b/docs/reference/get_vaa.html index b3f38d4e..bc0a5b4c 100644 --- a/docs/reference/get_vaa.html +++ b/docs/reference/get_vaa.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -78,33 +78,42 @@

NHDPlusV2 Attribute Subset

-
get_vaa(
-  atts = NULL,
-  path = get_vaa_path(),
-  download = TRUE,
-  updated_network = FALSE
-)
+
get_vaa(
+  atts = NULL,
+  path = get_vaa_path(),
+  download = TRUE,
+  updated_network = FALSE
+)

Arguments

atts

character The variable names you would like, always includes comid

+ +
path

character path where the file should be saved. Default is a persistent system data as retrieved by nhdplusTools_data_dir. Also see: get_vaa_path

+ +
download

logical if TRUE, the default, will download VAA table if not found at path.

+ +
updated_network

logical default FALSE. If TRUE, updated network attributes from E2NHD and National Water Model retrieved from here.

+

Value

-

data.frame containing requested VAA data

+ + +

data.frame containing requested VAA data

Details

@@ -120,18 +129,18 @@

Details

Examples

-
if (FALSE) {
-# This will download the vaa file to the path from get_vaa_path()
-
-get_vaa("slope")
-get_vaa(c("slope", "lengthkm"))
-
-get_vaa(updated_network = TRUE)
-get_vaa("reachcode", updated_network = TRUE)
-
-#cleanup if desired
-unlink(dirname(get_vaa_path()), recursive = TRUE)
-}
+    
if (FALSE) {
+# This will download the vaa file to the path from get_vaa_path()
+
+get_vaa("slope")
+get_vaa(c("slope", "lengthkm"))
+
+get_vaa(updated_network = TRUE)
+get_vaa("reachcode", updated_network = TRUE)
+
+#cleanup if desired
+unlink(dirname(get_vaa_path()), recursive = TRUE)
+}
 
@@ -146,7 +155,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_vaa_names.html b/docs/reference/get_vaa_names.html index 98921910..cb4121ce 100644 --- a/docs/reference/get_vaa_names.html +++ b/docs/reference/get_vaa_names.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -78,7 +78,7 @@

Available NHDPlusV2 Attributes

-
get_vaa_names(updated_network = FALSE)
+
get_vaa_names(updated_network = FALSE)
@@ -87,10 +87,13 @@

Arguments

logical default FALSE. If TRUE, updated network attributes from E2NHD and National Water Model retrieved from here.

+

Value

-

character vector

+ + +

character vector

Details

@@ -106,13 +109,13 @@

Details

Examples

-
if (FALSE) {
-# This will download the vaa file to the path from get_vaa_path()
-get_vaa_names()
-
-#cleanup if desired
-unlink(dirname(get_vaa_path()), recursive = TRUE)
-}
+    
if (FALSE) {
+# This will download the vaa file to the path from get_vaa_path()
+get_vaa_names()
+
+#cleanup if desired
+unlink(dirname(get_vaa_path()), recursive = TRUE)
+}
 
@@ -127,7 +130,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_vaa_path.html b/docs/reference/get_vaa_path.html index 9d9be514..e6782a6c 100644 --- a/docs/reference/get_vaa_path.html +++ b/docs/reference/get_vaa_path.html @@ -20,7 +20,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -84,7 +84,7 @@

File path to value added attribute (vaa) Cache

-
get_vaa_path(updated_network = FALSE)
+
get_vaa_path(updated_network = FALSE)
@@ -92,10 +92,13 @@

Arguments

updated_network

logical default FALSE. If TRUE, returns path to updated network parameters. See get_vaa for more.

+

Value

-

character file path

+ + +

character file path

Details

@@ -111,12 +114,12 @@

Details

Examples

-
get_vaa_path()
+    
get_vaa_path()
 #> [1] "C:\\Users\\dblodgett\\AppData\\Roaming/R/data/R/nhdplusTools/nhdplusVAA.fst"
-
-get_vaa_path(updated_network = TRUE)
+
+get_vaa_path(updated_network = TRUE)
 #> [1] "C:\\Users\\dblodgett\\AppData\\Roaming/R/data/R/nhdplusTools/enhd_nhdplusatts.fst"
-
+
 
@@ -131,7 +134,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_waterbodies.html b/docs/reference/get_waterbodies.html index b37299a8..7672f313 100644 --- a/docs/reference/get_waterbodies.html +++ b/docs/reference/get_waterbodies.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,7 +80,7 @@

Find NHD Water Bodies

-
get_waterbodies(AOI = NULL, id = NULL, t_srs = NULL, buffer = 0.5)
+
get_waterbodies(AOI = NULL, id = NULL, t_srs = NULL, buffer = 0.5)
@@ -89,19 +89,28 @@

Arguments

sf (MULTI)POINT or (MULTI)POLYGON. An 'area of interest' can be provided as either a location (sf POINT) or area (sf POLYGON) in any Spatial Reference System.

+ +
id

NHD Waterbody COMID(s)

+ +
t_srs

character (PROJ string or EPSG code) or numeric (EPSG code). A user specified - target -Spatial Reference System (SRS/CRS) for returned objects. Will default to the CRS of the input AOI if provided, and to 4326 for ID requests.

+ +
buffer

numeric. The amount (in meters) to buffer a POINT AOI by for an extended search. Default = 0.5

+

Value

-

a simple features (sf) object

+ + +

a simple features (sf) object

Details

@@ -126,7 +135,7 @@

Details

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_waterbody_index.html b/docs/reference/get_waterbody_index.html index b1cc77d4..db01b40f 100644 --- a/docs/reference/get_waterbody_index.html +++ b/docs/reference/get_waterbody_index.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,7 +80,7 @@

Get Waterbody Index

-
get_waterbody_index(waterbodies, points, flines = NULL, search_radius = NULL)
+
get_waterbody_index(waterbodies, points, flines = NULL, search_radius = NULL)
@@ -88,39 +88,48 @@

Arguments

waterbodies

sf data.frame of type POLYGON or MULTIPOLYGON including COMID attributes.

+ +
points

sfc of type POINT

+ +
flines

sf data.frame of type LINESTRING or MULTILINESTRING including COMID, WBAREACOMI, and Hydroseq attributes

+ +
search_radius

units class with a numeric value indicating how far to search for a waterbody boundary in units of provided projection. Set units with set_units.

+

Value

-

data.frame with two columns, COMID, in_wb_COMID, near_wb_COMID, + + +

data.frame with two columns, COMID, in_wb_COMID, near_wb_COMID, near_wb_dist, and outlet_fline_COMID. Distance is in units of provided projection.

Examples

-

-source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
-
-waterbodies <- sf::st_transform(
-  sf::read_sf(sample_data, "NHDWaterbody"), 5070)
-
-points <- sf::st_transform(
-  sf::st_sfc(sf::st_point(c(-89.356086, 43.079943)),
-             crs = 4326), 5070)
-
-get_waterbody_index(waterbodies, points,
-                    search_radius = units::set_units(500, "m"))
+    

+source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
+
+waterbodies <- sf::st_transform(
+  sf::read_sf(sample_data, "NHDWaterbody"), 5070)
+
+points <- sf::st_transform(
+  sf::st_sfc(sf::st_point(c(-89.356086, 43.079943)),
+             crs = 4326), 5070)
+
+get_waterbody_index(waterbodies, points,
+                    search_radius = units::set_units(500, "m"))
 #>   near_wb_COMID near_wb_dist in_wb_COMID
 #> 1     167120949     272.8278   167120949
-
+
 
@@ -135,7 +144,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_wb_outlet.html b/docs/reference/get_wb_outlet.html index d4334664..4a1fa3f6 100644 --- a/docs/reference/get_wb_outlet.html +++ b/docs/reference/get_wb_outlet.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -78,34 +78,39 @@

Get Waterbody Outlet

-
get_wb_outlet(lake_id, network)
+
get_wb_outlet(lake_id, network)

Arguments

lake_id

integer COMID (or character permenent identifier for hi res) of lake.

+ +
network

data.frame of network features containing wbareacomi, and Hydroseq

+

Value

-

sf data.frame with single record of network COMID + + +

sf data.frame with single record of network COMID associated with most-downstream reach in the NHD Waterbody

Examples

-
# \donttest{
-
-source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
-
-fline <- sf::read_sf(sample_data, "NHDFlowline_Network")
-wtbdy <- sf::read_sf(sample_data, "NHDWaterbody")
-
-lake_COMID <- wtbdy$COMID[wtbdy$GNIS_NAME=='Lake Mendota 254']
-
-get_wb_outlet(13293262, fline)
+    
# \donttest{
+
+source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
+
+fline <- sf::read_sf(sample_data, "NHDFlowline_Network")
+wtbdy <- sf::read_sf(sample_data, "NHDWaterbody")
+
+lake_COMID <- wtbdy$COMID[wtbdy$GNIS_NAME=='Lake Mendota 254']
+
+get_wb_outlet(13293262, fline)
 #> Simple feature collection with 1 feature and 136 fields
 #> Geometry type: MULTILINESTRING
 #> Dimension:     XYZM
@@ -113,20 +118,20 @@ 

Examples

#> z_range: zmin: 0 zmax: 0 #> m_range: mmin: 0 mmax: 100 #> Geodetic CRS: GRS 1980(IUGG, 1980) -#> # A tibble: 1 x 137 +#> # A tibble: 1 × 137 #> # Groups: wbareacomi [1] #> comid fdate resolution gnis_id gnis_name lengthkm reachcode #> * <int> <dttm> <chr> <chr> <chr> <dbl> <chr> -#> 1 13294312 2009-05-01 00:00:00 Medium 1577073 Yahara Riv~ 1.27 07090002~ -#> # ... with 130 more variables: flowdir <chr>, wbareacomi <int>, ftype <chr>, +#> 1 13294312 2009-05-01 00:00:00 Medium 1577073 Yahara Riv… 1.27 07090002… +#> # … with 130 more variables: flowdir <chr>, wbareacomi <int>, ftype <chr>, #> # fcode <int>, shape_length <dbl>, streamleve <int>, streamorde <int>, #> # streamcalc <int>, fromnode <dbl>, tonode <dbl>, hydroseq <dbl>, #> # levelpathi <dbl>, pathlength <dbl>, terminalpa <dbl>, arbolatesu <dbl>, #> # divergence <int>, startflag <int>, terminalfl <int>, dnlevel <int>, #> # uplevelpat <dbl>, uphydroseq <dbl>, dnlevelpat <dbl>, dnminorhyd <dbl>, -#> # dndraincou <int>, dnhydroseq <dbl>, frommeas <dbl>, tomeas <dbl>, ... - -# } +#> # dndraincou <int>, dnhydroseq <dbl>, frommeas <dbl>, tomeas <dbl>, … + +# }
@@ -141,7 +146,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_xs_point-1.png b/docs/reference/get_xs_point-1.png index 72eb8d38..1887d0ad 100644 Binary files a/docs/reference/get_xs_point-1.png and b/docs/reference/get_xs_point-1.png differ diff --git a/docs/reference/get_xs_point.html b/docs/reference/get_xs_point.html index 2654d886..571cc7f3 100644 --- a/docs/reference/get_xs_point.html +++ b/docs/reference/get_xs_point.html @@ -20,7 +20,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -84,7 +84,7 @@

Get Cross Section From Point (experimental)

-
get_xs_point(point, width, num_pts)
+
get_xs_point(point, width, num_pts)
@@ -92,28 +92,35 @@

Arguments

point

sfc POINT including crs as created by: sf::st_sfc(sf::st_point(.. ,..), crs)crs.

+ +
width

Cross section width in meters.

+ +
num_pts

numeric number of points to retrieve along the cross section.

+

Value

-

sf data.frame containing points retrieved.

+ + +

sf data.frame containing points retrieved.

Examples

-
# \donttest{
-point <- sf::st_sfc(sf::st_point(x = c(-105.97218, 36.17592)), crs = 4326)
-
-(xs <- get_xs_point(point, 300, 100))
+    
# \donttest{
+point <- sf::st_sfc(sf::st_point(x = c(-105.97218, 36.17592)), crs = 4326)
+
+(xs <- get_xs_point(point, 300, 100))
 #> Simple feature collection with 101 features and 4 fields
 #> Geometry type: POINT
 #> Dimension:     XY
 #> Bounding box:  xmin: -105.9735 ymin: 36.1757 xmax: -105.9709 ymax: 36.17609
 #> Geodetic CRS:  WGS 84
-#> # A tibble: 101 x 5
+#> # A tibble: 101 × 5
 #>    id    distance_m elevation_m spatial_ref             geometry
 #>    <chr>      <dbl>       <dbl>       <int>          <POINT [°]>
 #>  1 0           0          1772.           0  (-105.9735 36.1757)
@@ -126,28 +133,40 @@ 

Examples

#> 8 7 16.8 1769. 0 (-105.9733 36.17572) #> 9 8 19.2 1768. 0 (-105.9733 36.17573) #> 10 9 21.6 1768. 0 (-105.9733 36.17573) -#> # ... with 91 more rows - -bbox <- sf::st_bbox(xs) + c(-0.005, -0.005, 0.005, 0.005) - -nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE) +#> # … with 91 more rows + +bbox <- sf::st_bbox(xs) + c(-0.005, -0.005, 0.005, 0.005) + +nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE) +#> Spherical geometry (s2) switched off #> Found invalid geometry, attempting to fix. +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off #> Warning: No nhdarea features found +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off #> Warning: No waterbodies features found +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off #> Warning: No nonnetwork features found +#> Spherical geometry (s2) switched on #> Zoom: 16 #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL. #> Audotdetect projection: assuming Google Mercator (epsg 3857) - -plot(sf::st_transform(sf::st_geometry(xs), 3857), pch = ".", add = TRUE, col = "red") -plot(sf::st_transform(sf::st_sfc(point, crs = 4326), 3857), add = TRUE) + +plot(sf::st_transform(sf::st_geometry(xs), 3857), pch = ".", add = TRUE, col = "red") +plot(sf::st_transform(sf::st_sfc(point, crs = 4326), 3857), add = TRUE) - -plot(xs$distance_m, xs$elevation_m) + +plot(xs$distance_m, xs$elevation_m) - -# } - + +# } +
@@ -162,7 +181,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/get_xs_points-1.png b/docs/reference/get_xs_points-1.png index 167fe5a7..37215a97 100644 Binary files a/docs/reference/get_xs_points-1.png and b/docs/reference/get_xs_points-1.png differ diff --git a/docs/reference/get_xs_points.html b/docs/reference/get_xs_points.html index 5febe553..6fa6eba7 100644 --- a/docs/reference/get_xs_points.html +++ b/docs/reference/get_xs_points.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,7 +80,7 @@

Get Cross Section Endpoints (experimental)

-
get_xs_points(point1, point2, num_pts, res = 1)
+
get_xs_points(point1, point2, num_pts, res = 1)
@@ -88,32 +88,41 @@

Arguments

point1

sfc POINT including crs as created by: sf::st_sfc(sf::st_point(.. ,..), crs)

+ +
point2

sfc POINT including crs.

+ +
num_pts

numeric number of points to retrieve along the cross section.

+ +
res

integer resolution of 3D Elevation Program data to request. Must be on of: 1, 3, 5, 10, 30, 60.

+

Value

-

sf data.frame containing points retrieved.

+ + +

sf data.frame containing points retrieved.

Examples

-
# \donttest{
-point1 <- sf::st_sfc(sf::st_point(x = c(-105.9667, 36.17602)), crs = 4326)
-point2 <- sf::st_sfc(sf::st_point(x = c(-105.97768, 36.17526)), crs = 4326)
-
-(xs <- get_xs_points(point1, point2, 100))
+    
# \donttest{
+point1 <- sf::st_sfc(sf::st_point(x = c(-105.9667, 36.17602)), crs = 4326)
+point2 <- sf::st_sfc(sf::st_point(x = c(-105.97768, 36.17526)), crs = 4326)
+
+(xs <- get_xs_points(point1, point2, 100))
 #> Simple feature collection with 101 features and 4 fields
 #> Geometry type: POINT
 #> Dimension:     XY
 #> Bounding box:  xmin: -105.9776 ymin: 36.17531 xmax: -105.9667 ymax: 36.176
 #> Geodetic CRS:  WGS 84
-#> # A tibble: 101 x 5
+#> # A tibble: 101 × 5
 #>    id    distance_m elevation_m spatial_ref             geometry
 #>    <chr>      <dbl>       <dbl>       <int>          <POINT [°]>
 #>  1 0           0          1779.           0   (-105.9667 36.176)
@@ -126,29 +135,41 @@ 

Examples

#> 8 7 68.2 1775. 0 (-105.9675 36.17595) #> 9 8 77.9 1775. 0 (-105.9676 36.17594) #> 10 9 87.6 1774. 0 (-105.9677 36.17594) -#> # ... with 91 more rows - -bbox <- sf::st_bbox(xs) + c(-0.005, -0.005, 0.005, 0.005) - -nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE) +#> # … with 91 more rows + +bbox <- sf::st_bbox(xs) + c(-0.005, -0.005, 0.005, 0.005) + +nhdplusTools::plot_nhdplus(bbox = bbox, cache_data = FALSE) +#> Spherical geometry (s2) switched off #> Found invalid geometry, attempting to fix. +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off #> Warning: No nhdarea features found +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off #> Warning: No waterbodies features found +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off #> Warning: No nonnetwork features found +#> Spherical geometry (s2) switched on #> Zoom: 15 #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL. #> Audotdetect projection: assuming Google Mercator (epsg 3857) - -plot(sf::st_transform(sf::st_geometry(xs), 3857), pch = ".", add = TRUE, col = "red") -plot(sf::st_transform(sf::st_sfc(point1, crs = 4326), 3857), add = TRUE) -plot(sf::st_transform(sf::st_sfc(point2, crs = 4326), 3857), add = TRUE) + +plot(sf::st_transform(sf::st_geometry(xs), 3857), pch = ".", add = TRUE, col = "red") +plot(sf::st_transform(sf::st_sfc(point1, crs = 4326), 3857), add = TRUE) +plot(sf::st_transform(sf::st_sfc(point2, crs = 4326), 3857), add = TRUE) - -plot(xs$distance_m, xs$elevation_m) + +plot(xs$distance_m, xs$elevation_m) - -# } - + +# } +
@@ -163,7 +184,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/index.html b/docs/reference/index.html index 3facf2a2..c5fa7db4 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -133,6 +133,10 @@

Data Access

VPU Boundaries Vector Processing Unit boundaries

+ +

get_boundaries()

+ +

Return RPU or VPU boundaries

Discovery and Subsetting

Functions for finding and saving the part of the NHDPlus you are interested in working with. (All U.S. context)

@@ -253,6 +257,10 @@

Indexing and Network Navigation get_path_lengths()

Get Path Lengths

+ +

get_path_members()

+ +

Get Path Members

Network Navigation

Functions to traverse and return network subsets. All except navigate_nldi() have applicability outside the U.S. context.

@@ -369,6 +377,10 @@

Network Attributes get_streamorder()

Get Streamorder

+ +

get_terminal()

+ +

Get Terminal ID (DEPRECATED)

add_plus_network_attributes()

@@ -390,7 +402,7 @@

Network Attributes
-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/make_standalone-1.png b/docs/reference/make_standalone-1.png index 8334a9b2..84140cc0 100644 Binary files a/docs/reference/make_standalone-1.png and b/docs/reference/make_standalone-1.png differ diff --git a/docs/reference/make_standalone.html b/docs/reference/make_standalone.html index 2f21b9ac..2d8ee68d 100644 --- a/docs/reference/make_standalone.html +++ b/docs/reference/make_standalone.html @@ -20,7 +20,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -84,76 +84,79 @@

Make isolated NHDPlusHR region a standalone dataset

-
make_standalone(flowlines)
+
make_standalone(flowlines)

Arguments

flowlines

sf data.frame of NHDPlusHR flowlines.

+

Value

-

sf data.frame containing standalone network

+ + +

sf data.frame containing standalone network

Examples

-
# \donttest{
-library(dplyr)
-library(sf)
-source(system.file("extdata/nhdplushr_data.R", package = "nhdplusTools"))
-
-(outlet <- filter(hr_data$NHDFlowline, Hydroseq == min(Hydroseq)))
+    
# \donttest{
+library(dplyr)
+library(sf)
+source(system.file("extdata/nhdplushr_data.R", package = "nhdplusTools"))
+
+(outlet <- filter(hr_data$NHDFlowline, Hydroseq == min(Hydroseq)))
 #> Simple feature collection with 1 feature and 57 fields
 #> Geometry type: LINESTRING
 #> Dimension:     XY
 #> Bounding box:  xmin: -79.01402 ymin: 35.79464 xmax: -79.00523 ymax: 35.80153
 #> Geodetic CRS:  GRS 1980(IUGG, 1980)
-#> # A tibble: 1 x 58
+#> # A tibble: 1 × 58
 #>   Permanent_Identifier FDate               Resolution GNIS_ID GNIS_Name LENGTHKM
 #> * <chr>                <dttm>                   <int> <chr>   <chr>        <dbl>
-#> 1 46353268             2012-03-11 06:52:19          2 009910~ New Hope~     1.10
-#> # ... with 52 more variables: REACHCODE <chr>, FlowDir <int>,
+#> 1 46353268             2012-03-11 06:52:19          2 009910… New Hope…     1.10
+#> # … with 52 more variables: REACHCODE <chr>, FlowDir <int>,
 #> #   WBArea_Permanent_Identifier <chr>, FTYPE <int>, FCODE <int>,
 #> #   MainPath <int>, InNetwork <int>, VisibilityFilter <int>,
 #> #   Shape_Length <dbl>, COMID <dbl>, VPUID <chr>, Enabled <int>,
 #> #   StreamLeve <dbl>, StreamOrde <dbl>, StreamCalc <dbl>, FromNode <dbl>,
 #> #   ToNode <dbl>, Hydroseq <dbl>, LevelPathI <dbl>, Pathlength <dbl>,
-#> #   TerminalPa <dbl>, ArbolateSu <dbl>, Divergence <dbl>, StartFlag <dbl>, ...
-nrow(filter(hr_data$NHDFlowline, TerminalPa == outlet$Hydroseq))
+#> #   TerminalPa <dbl>, ArbolateSu <dbl>, Divergence <dbl>, StartFlag <dbl>, …
+nrow(filter(hr_data$NHDFlowline, TerminalPa == outlet$Hydroseq))
 #> [1] 2691
-
-hr_data$NHDFlowline <- make_standalone(hr_data$NHDFlowline)
-
-(outlet <- filter(hr_data$NHDFlowline, Hydroseq == min(Hydroseq)))
+
+hr_data$NHDFlowline <- make_standalone(hr_data$NHDFlowline)
+
+(outlet <- filter(hr_data$NHDFlowline, Hydroseq == min(Hydroseq)))
 #> Simple feature collection with 1 feature and 57 fields
 #> Geometry type: LINESTRING
 #> Dimension:     XY
 #> Bounding box:  xmin: -79.01402 ymin: 35.79464 xmax: -79.00523 ymax: 35.80153
 #> Geodetic CRS:  GRS 1980(IUGG, 1980)
-#> # A tibble: 1 x 58
+#> # A tibble: 1 × 58
 #>   Permanent_Identifier FDate               Resolution GNIS_ID GNIS_Name LENGTHKM
 #> * <chr>                <dttm>                   <int> <chr>   <chr>        <dbl>
-#> 1 46353268             2012-03-11 06:52:19          2 009910~ New Hope~     1.10
-#> # ... with 52 more variables: REACHCODE <chr>, FlowDir <int>,
+#> 1 46353268             2012-03-11 06:52:19          2 009910… New Hope…     1.10
+#> # … with 52 more variables: REACHCODE <chr>, FlowDir <int>,
 #> #   WBArea_Permanent_Identifier <chr>, FTYPE <int>, FCODE <int>,
 #> #   MainPath <int>, InNetwork <int>, VisibilityFilter <int>,
 #> #   Shape_Length <dbl>, COMID <dbl>, VPUID <chr>, Enabled <int>,
 #> #   StreamLeve <dbl>, StreamOrde <dbl>, StreamCalc <dbl>, FromNode <dbl>,
 #> #   ToNode <dbl>, Hydroseq <dbl>, LevelPathI <dbl>, Pathlength <dbl>,
-#> #   TerminalPa <dbl>, ArbolateSu <dbl>, Divergence <dbl>, StartFlag <dbl>, ...
-nrow(filter(hr_data$NHDFlowline, TerminalPa == outlet$Hydroseq))
+#> #   TerminalPa <dbl>, ArbolateSu <dbl>, Divergence <dbl>, StartFlag <dbl>, …
+nrow(filter(hr_data$NHDFlowline, TerminalPa == outlet$Hydroseq))
 #> [1] 2691
-
-source(system.file("extdata/nhdplushr_data.R", package = "nhdplusTools"))
-
-# Remove mainstem and non-dendritic stuff.
-subset <- filter(hr_data$NHDFlowline,
-                        StreamLeve > min(hr_data$NHDFlowline$StreamLeve) &
-                          StreamOrde == StreamCalc)
-
-subset <- subset_nhdplus(subset$COMID, nhdplus_data = hr_gpkg)$NHDFlowline
+
+source(system.file("extdata/nhdplushr_data.R", package = "nhdplusTools"))
+
+# Remove mainstem and non-dendritic stuff.
+subset <- filter(hr_data$NHDFlowline,
+                        StreamLeve > min(hr_data$NHDFlowline$StreamLeve) &
+                          StreamOrde == StreamCalc)
+
+subset <- subset_nhdplus(subset$COMID, nhdplus_data = hr_gpkg)$NHDFlowline
 #> All intersections performed in latitude/longitude.
 #> Reading NHDFlowline
 #> 1000 comids of 2182
@@ -172,25 +175,25 @@ 

Examples

#> Writing NHDWaterbody #> Reading NHDPlusSink #> Writing NHDPlusSink - -plot(sf::st_geometry(hr_data$NHDFlowline)) - -flowline_mod <- make_standalone(subset) - -terminals <- unique(flowline_mod$TerminalPa) - -colors <- sample(hcl.colors(length(terminals), palette = "Zissou 1")) - -for(i in 1:length(terminals)) { - fl <- flowline_mod[flowline_mod$TerminalPa == terminals[i], ] - plot(st_geometry(fl), col = colors[i], lwd = 2, add = TRUE) -} - -ol <- filter(flowline_mod, TerminalFl == 1 & TerminalPa %in% terminals) - -plot(st_geometry(ol), lwd = 2, add = TRUE) + +plot(sf::st_geometry(hr_data$NHDFlowline)) + +flowline_mod <- make_standalone(subset) + +terminals <- unique(flowline_mod$TerminalPa) + +colors <- sample(hcl.colors(length(terminals), palette = "Zissou 1")) + +for(i in 1:length(terminals)) { + fl <- flowline_mod[flowline_mod$TerminalPa == terminals[i], ] + plot(st_geometry(fl), col = colors[i], lwd = 2, add = TRUE) +} + +ol <- filter(flowline_mod, TerminalFl == 1 & TerminalPa %in% terminals) + +plot(st_geometry(ol), lwd = 2, add = TRUE) -# } +# }
@@ -205,7 +208,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/map_nhdplus.html b/docs/reference/map_nhdplus.html index 3ea9d5f1..893ef0a3 100644 --- a/docs/reference/map_nhdplus.html +++ b/docs/reference/map_nhdplus.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,48 +80,69 @@

Make Interactive Map of NHDPlus

-
map_nhdplus(
-  outlets = NULL,
-  bbox = NULL,
-  streamorder = NULL,
-  nhdplus_data = NULL,
-  gpkg = NULL,
-  flowline_only = NULL,
-  plot_config = NULL,
-  overwrite = TRUE,
-  cache_data = NULL,
-  return_map = FALSE
-)
+
map_nhdplus(
+  outlets = NULL,
+  bbox = NULL,
+  streamorder = NULL,
+  nhdplus_data = NULL,
+  gpkg = NULL,
+  flowline_only = NULL,
+  plot_config = NULL,
+  overwrite = TRUE,
+  cache_data = NULL,
+  return_map = FALSE
+)

Arguments

outlets

list of nldi outlets. Other inputs are coerced into nldi outlets, see details.

+ +
bbox

object of class bbox with a defined crs. See examples.

+ +
streamorder

integer only streams of order greater than or equal will be returned

+ +
nhdplus_data

geopackage containing source nhdplus data (omit to download)

+ +
gpkg

path and file with .gpkg ending. If omitted, no file is written.

+ +
flowline_only

boolean only subset and plot flowlines only, default=FALSE

+ +
plot_config

list containing plot configuration, see details.

+ +
overwrite

passed on the subset_nhdplus.

+ +
cache_data

character path to rds file where all plot data can be cached. If file doesn't exist, it will be created. If set to FALSE, all caching will be turned off -- this includes basemap tiles.

+ +
return_map

if FALSE (default), a data.frame of plot data is returned invisibly in NAD83 Lat/Lon, if TRUE the leaflet object is returned

+

Value

-

data.frame or leaflet map (see return_map)

+ + +

data.frame or leaflet map (see return_map)

Details

@@ -142,20 +163,32 @@

Details

Examples

-
# \donttest{
-map_nhdplus("05428500")
-
-map_nhdplus("05428500", streamorder = 2)
-
-map_nhdplus(list(13293970, 13293750))
-
-source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
-
-map_nhdplus(list(13293970, 13293750), streamorder = 3, nhdplus_data = sample_data)
-
-#return leaflet object
-map_nhdplus("05428500", return_map = TRUE)
-# }
+    
# \donttest{
+map_nhdplus("05428500")
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+
+map_nhdplus("05428500", streamorder = 2)
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+
+map_nhdplus(list(13293970, 13293750))
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+
+source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
+
+map_nhdplus(list(13293970, 13293750), streamorder = 3, nhdplus_data = sample_data)
+
+#return leaflet object
+map_nhdplus("05428500", return_map = TRUE)
+#> Spherical geometry (s2) switched off
+#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
+#> Spherical geometry (s2) switched on
+# }
 
@@ -170,7 +203,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/navigate_network-1.png b/docs/reference/navigate_network-1.png index 0807a73a..34891bbb 100644 Binary files a/docs/reference/navigate_network-1.png and b/docs/reference/navigate_network-1.png differ diff --git a/docs/reference/navigate_network.html b/docs/reference/navigate_network.html index ca03b3cd..32917b36 100644 --- a/docs/reference/navigate_network.html +++ b/docs/reference/navigate_network.html @@ -19,7 +19,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -82,16 +82,16 @@

Navigate Network

-
navigate_network(
-  start,
-  mode = "UM",
-  network = NULL,
-  output = "flowlines",
-  distance_km = 10,
-  trim_start = FALSE,
-  trim_stop = FALSE,
-  trim_tolerance = 5
-)
+
navigate_network(
+  start,
+  mode = "UM",
+  network = NULL,
+  output = "flowlines",
+  distance_km = 10,
+  trim_start = FALSE,
+  trim_stop = FALSE,
+  trim_tolerance = 5
+)
@@ -99,80 +99,97 @@

Arguments

start

list, integer, sf, or sfc if list must be a valid NLDI feature if integer must be a valid comid. If sf, must contain a "comid" field.

+ +
mode

character chosen from c(UM, DM, UT, or DD)

+ +
network

sf should be compatible with network navigation functions If NULL, network will be derived from requests to the NLDI

+ +
output

character flowline or a valid NLDI data source

+ +
distance_km

numeric distance to navigate in km

+ +
trim_start

logical should start be trimmed or include entire catchment?

+ +
trim_stop

logical should stop(s) be trimmed or include entire catchment(s)? # Not supported

+ +
trim_tolerance

numeric from 0 to 100 percent of flowline length. If amount to trim is less than this tolerance, no trim will be applied.

+

Examples

-

-# \donttest{
-navigate_network(list(featureSource = "nwissite", featureID = "USGS-06287800"),
-                "UM",
-                output = "flowlines",
-                trim_start = TRUE)
+    

+# \donttest{
+navigate_network(list(featureSource = "nwissite", featureID = "USGS-06287800"),
+                "UM",
+                output = "flowlines",
+                trim_start = TRUE)
 #> All intersections performed in latitude/longitude.
 #> Reading NHDFlowline_Network
+#> Spherical geometry (s2) switched off
+#> Spherical geometry (s2) switched on
 #> Writing NHDFlowline_Network
 #> Simple feature collection with 8 features and 138 fields
 #> Geometry type: LINESTRING
 #> Dimension:     XY
 #> Bounding box:  xmin: -107.8095 ymin: 45.39128 xmax: -107.7478 ymax: 45.46232
 #> Geodetic CRS:  NAD83
-#> # A tibble: 8 x 139
+#> # A tibble: 8 × 139
 #>   id             comid fdate               resolution gnis_id gnis_name lengthkm
 #> * <chr>          <int> <dttm>              <chr>      <chr>   <chr>        <dbl>
-#> 1 nhdflowline_~ 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn ~    0.176
-#> 2 nhdflowline_~ 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn ~    1.26 
-#> 3 nhdflowline_~ 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn ~    2.79 
-#> 4 nhdflowline_~ 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn ~    1.42 
-#> 5 nhdflowline_~ 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn ~    1.43 
-#> 6 nhdflowline_~ 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn ~    1.44 
-#> 7 nhdflowline_~ 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn ~    1.40 
-#> 8 nhdflowline_~ 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn ~    0.207
-#> # ... with 132 more variables: reachcode <chr>, flowdir <chr>,
-#> #   wbareacomi <int>, ftype <chr>, fcode <int>, shape_length <dbl>,
-#> #   streamleve <int>, streamorde <int>, streamcalc <int>, fromnode <dbl>,
-#> #   tonode <dbl>, hydroseq <dbl>, levelpathi <dbl>, pathlength <dbl>,
-#> #   terminalpa <dbl>, arbolatesu <dbl>, divergence <int>, startflag <int>,
-#> #   terminalfl <int>, dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>,
-#> #   dnlevelpat <dbl>, dnminorhyd <dbl>, dndraincou <int>, dnhydroseq <dbl>, ...
-# }
-
-source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
-hydro_location <- list(comid = 5329339,
-                      reachcode = "18050005000078",
-                       reach_meas = 30)
-
-hydro_location <- sf::st_sf(
-  hydro_location,
-  geom = nhdplusTools::get_hydro_location(data.frame(hydro_location),
-                                          walker_flowline))
-
-net <- navigate_network(hydro_location,
-                       mode = "DM", network = walker_flowline,
-                       trim_start = TRUE, distance_km = 20)
-
-plot(sf::st_geometry(walker_flowline))
-plot(sf::st_geometry(hydro_location), add = TRUE)
-plot(sf::st_geometry(net), add = TRUE, col = "blue", lwd = 2)
+#> 1 nhdflowline_… 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn …    0.176
+#> 2 nhdflowline_… 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn …    1.26 
+#> 3 nhdflowline_… 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn …    2.79 
+#> 4 nhdflowline_… 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn …    1.42 
+#> 5 nhdflowline_… 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn …    1.43 
+#> 6 nhdflowline_… 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn …    1.44 
+#> 7 nhdflowline_… 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn …    1.40 
+#> 8 nhdflowline_… 1.28e7 2009-06-15 23:00:00 Medium     779903  Bighorn …    0.207
+#> # … with 132 more variables: reachcode <chr>, flowdir <chr>, wbareacomi <int>,
+#> #   ftype <chr>, fcode <int>, shape_length <dbl>, streamleve <int>,
+#> #   streamorde <int>, streamcalc <int>, fromnode <dbl>, tonode <dbl>,
+#> #   hydroseq <dbl>, levelpathi <dbl>, pathlength <dbl>, terminalpa <dbl>,
+#> #   arbolatesu <dbl>, divergence <int>, startflag <int>, terminalfl <int>,
+#> #   dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>, dnlevelpat <dbl>,
+#> #   dnminorhyd <dbl>, dndraincou <int>, dnhydroseq <dbl>, frommeas <dbl>, …
+# }
+
+source(system.file("extdata", "walker_data.R", package = "nhdplusTools"))
+hydro_location <- list(comid = 5329339,
+                      reachcode = "18050005000078",
+                       reach_meas = 30)
+
+hydro_location <- sf::st_sf(
+  hydro_location,
+  geom = nhdplusTools::get_hydro_location(data.frame(hydro_location),
+                                          walker_flowline))
+
+net <- navigate_network(hydro_location,
+                       mode = "DM", network = walker_flowline,
+                       trim_start = TRUE, distance_km = 20)
+
+plot(sf::st_geometry(walker_flowline))
+plot(sf::st_geometry(hydro_location), add = TRUE)
+plot(sf::st_geometry(net), add = TRUE, col = "blue", lwd = 2)
 
-
+
 
@@ -187,7 +204,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/navigate_nldi.html b/docs/reference/navigate_nldi.html index 230744c3..df60dbb9 100644 --- a/docs/reference/navigate_nldi.html +++ b/docs/reference/navigate_nldi.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -78,12 +78,12 @@

Navigate NLDI

-
navigate_nldi(
-  nldi_feature,
-  mode = "upstreamMain",
-  data_source = "flowlines",
-  distance_km = 10
-)
+
navigate_nldi(
+  nldi_feature,
+  mode = "upstreamMain",
+  data_source = "flowlines",
+  distance_km = 10
+)
@@ -93,63 +93,72 @@

Arguments

`featureSource` is derived from the "source" column of the response of dataRetrieval::get_nldi_sources() and the `featureID` is a known identifier from the specified `featureSource`.

+ +
mode

character chosen from ("UM", "UT", DM", "DD"). See examples.

+ +
data_source

character chosen from "source" column of the response of dataRetrieval::get_nldi_sources() or empty string for flowline geometry.

+ +
distance_km

numeric distance in km to stop navigating.

+

Value

-

sf data.frame with result

+ + +

sf data.frame with result

Examples

-
# \donttest{
-library(sf)
-library(dplyr)
-
-nldi_nwis <- list(featureSource = "nwissite", featureID = "USGS-05428500")
-
-navigate_nldi(nldi_feature = nldi_nwis,
-              mode = "upstreamTributaries")$UT %>%
-  st_geometry() %>%
-  plot()
-
-navigate_nldi(nldi_feature = nldi_nwis,
-              mode = "UM")$UM %>%
-  st_geometry() %>%
-  plot(col = "blue", add = TRUE)
-
-
-
-nwissite <- navigate_nldi(nldi_feature = nldi_nwis,
-                          mode = "UT",
-                          data_source = "nwissite")$UT_nwissite
-
-st_geometry(nwissite) %>%
-  plot(col = "green", add = TRUE)
+    
# \donttest{
+library(sf)
+library(dplyr)
+
+nldi_nwis <- list(featureSource = "nwissite", featureID = "USGS-05428500")
+
+navigate_nldi(nldi_feature = nldi_nwis,
+              mode = "upstreamTributaries")$UT %>%
+  st_geometry() %>%
+  plot()
+
+navigate_nldi(nldi_feature = nldi_nwis,
+              mode = "UM")$UM %>%
+  st_geometry() %>%
+  plot(col = "blue", add = TRUE)
+
+
+
+nwissite <- navigate_nldi(nldi_feature = nldi_nwis,
+                          mode = "UT",
+                          data_source = "nwissite")$UT_nwissite
+
+st_geometry(nwissite) %>%
+  plot(col = "green", add = TRUE)
 
-
-nwissite
+
+nwissite
 #> Simple feature collection with 4 features and 8 fields
 #> Geometry type: POINT
 #> Dimension:     XY
 #> Bounding box:  xmin: -89.45556 ymin: 43.08944 xmax: -89.36083 ymax: 43.14083
 #> Geodetic CRS:  WGS 84
-#> # A tibble: 4 x 9
-#>   sourceName               identifier  comid name  reachcode measure     X     Y
-#>   <chr>                    <chr>       <chr> <chr> <chr>     <chr>   <dbl> <dbl>
-#> 1 NWIS Surface Water Sites USGS-43060~ 1329~ LAKE~ 07090002~ 59.334~ -89.5  43.1
-#> 2 NWIS Surface Water Sites USGS-05428~ 1329~ YAHA~ 07090002~ 42.858~ -89.4  43.1
-#> 3 NWIS Surface Water Sites USGS-05428~ 1329~ LAKE~ 07090002~ 1.3666~ -89.4  43.1
-#> 4 NWIS Surface Water Sites USGS-05427~ 1329~ SIXM~ 07090002~ 86.756~ -89.4  43.1
-#> # ... with 1 more variable: geometry <POINT [°]>
-# }
-
+#> # A tibble: 4 × 9
+#>   sourceName               identifier  comid measure reachcode name      X     Y
+#>   <chr>                    <chr>       <chr>   <dbl> <chr>     <chr> <dbl> <dbl>
+#> 1 NWIS Surface Water Sites USGS-05428… 1329…    1.37 07090002… LAKE… -89.4  43.1
+#> 2 NWIS Surface Water Sites USGS-05428… 1329…   42.9  07090002… YAHA… -89.4  43.1
+#> 3 NWIS Surface Water Sites USGS-05427… 1329…   86.8  07090002… SIXM… -89.4  43.1
+#> 4 NWIS Surface Water Sites USGS-43060… 1329…   59.3  07090002… LAKE… -89.5  43.1
+#> # … with 1 more variable: geometry <POINT [°]>
+# }
+
 
@@ -164,7 +173,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/nhdplusTools_data_dir.html b/docs/reference/nhdplusTools_data_dir.html index 203888ef..78e3af62 100644 --- a/docs/reference/nhdplusTools_data_dir.html +++ b/docs/reference/nhdplusTools_data_dir.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,28 +80,31 @@

Get or set nhdplusTools data directory

-
nhdplusTools_data_dir(dir = NULL)
+
nhdplusTools_data_dir(dir = NULL)

Arguments

dir

path of desired data directory

+

Value

-

character path of data directory (silent when setting)

+ + +

character path of data directory (silent when setting)

Examples

-
nhdplusTools_data_dir()
+    
nhdplusTools_data_dir()
 #> [1] "C:\\Users\\dblodgett\\AppData\\Roaming/R/data/R/nhdplusTools"
-
-nhdplusTools_data_dir("demo")
-
-nhdplusTools_data_dir(tools::R_user_dir("nhdplusTools"))
-
+
+nhdplusTools_data_dir("demo")
+
+nhdplusTools_data_dir(tools::R_user_dir("nhdplusTools"))
+
 
@@ -116,7 +119,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/nhdplus_path.html b/docs/reference/nhdplus_path.html index 27541040..82554054 100644 --- a/docs/reference/nhdplus_path.html +++ b/docs/reference/nhdplus_path.html @@ -19,7 +19,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -82,30 +82,35 @@

NHDPlus Data Path

-
nhdplus_path(path = NULL, warn = FALSE)
+
nhdplus_path(path = NULL, warn = FALSE)

Arguments

path

character path ending in .gdb or .gpkg

+ +
warn

boolean controls whether warning an status messages are printed

+

Value

-

0 (invisibly) if set successfully, character path if no input.

+ + +

0 (invisibly) if set successfully, character path if no input.

Examples

-
nhdplus_path("/data/NHDPlusV21_National_Seamless.gdb")
-
-nhdplus_path("/data/NHDPlusV21_National_Seamless.gdb", warn=FALSE)
-
-nhdplus_path()
+    
nhdplus_path("/data/NHDPlusV21_National_Seamless.gdb")
+
+nhdplus_path("/data/NHDPlusV21_National_Seamless.gdb", warn=FALSE)
+
+nhdplus_path()
 #> [1] "/data/NHDPlusV21_National_Seamless.gdb"
-
+
 
@@ -120,7 +125,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/plot_nhdplus-1.png b/docs/reference/plot_nhdplus-1.png index da98979c..55388cd6 100644 Binary files a/docs/reference/plot_nhdplus-1.png and b/docs/reference/plot_nhdplus-1.png differ diff --git a/docs/reference/plot_nhdplus-10.png b/docs/reference/plot_nhdplus-10.png index 0e9ba80b..cb3829f3 100644 Binary files a/docs/reference/plot_nhdplus-10.png and b/docs/reference/plot_nhdplus-10.png differ diff --git a/docs/reference/plot_nhdplus-11.png b/docs/reference/plot_nhdplus-11.png index 903a5e18..623827d2 100644 Binary files a/docs/reference/plot_nhdplus-11.png and b/docs/reference/plot_nhdplus-11.png differ diff --git a/docs/reference/plot_nhdplus-2.png b/docs/reference/plot_nhdplus-2.png index 91896198..6dc316a0 100644 Binary files a/docs/reference/plot_nhdplus-2.png and b/docs/reference/plot_nhdplus-2.png differ diff --git a/docs/reference/plot_nhdplus-3.png b/docs/reference/plot_nhdplus-3.png index 63a757e5..e0f0ca8a 100644 Binary files a/docs/reference/plot_nhdplus-3.png and b/docs/reference/plot_nhdplus-3.png differ diff --git a/docs/reference/plot_nhdplus-4.png b/docs/reference/plot_nhdplus-4.png index a9da5c6b..039b9dd7 100644 Binary files a/docs/reference/plot_nhdplus-4.png and b/docs/reference/plot_nhdplus-4.png differ diff --git a/docs/reference/plot_nhdplus-5.png b/docs/reference/plot_nhdplus-5.png index 7b58db93..98182b61 100644 Binary files a/docs/reference/plot_nhdplus-5.png and b/docs/reference/plot_nhdplus-5.png differ diff --git a/docs/reference/plot_nhdplus-6.png b/docs/reference/plot_nhdplus-6.png index bd8debbc..bacb8850 100644 Binary files a/docs/reference/plot_nhdplus-6.png and b/docs/reference/plot_nhdplus-6.png differ diff --git a/docs/reference/plot_nhdplus-7.png b/docs/reference/plot_nhdplus-7.png index d418f851..2264cf89 100644 Binary files a/docs/reference/plot_nhdplus-7.png and b/docs/reference/plot_nhdplus-7.png differ diff --git a/docs/reference/plot_nhdplus-8.png b/docs/reference/plot_nhdplus-8.png index dc577f7d..21882808 100644 Binary files a/docs/reference/plot_nhdplus-8.png and b/docs/reference/plot_nhdplus-8.png differ diff --git a/docs/reference/plot_nhdplus-9.png b/docs/reference/plot_nhdplus-9.png index 09ab1650..590256ba 100644 Binary files a/docs/reference/plot_nhdplus-9.png and b/docs/reference/plot_nhdplus-9.png differ diff --git a/docs/reference/plot_nhdplus.html b/docs/reference/plot_nhdplus.html index 9a653787..d66b186f 100644 --- a/docs/reference/plot_nhdplus.html +++ b/docs/reference/plot_nhdplus.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,58 +80,85 @@

Plot NHDPlus

-
plot_nhdplus(
-  outlets = NULL,
-  bbox = NULL,
-  streamorder = NULL,
-  nhdplus_data = NULL,
-  gpkg = NULL,
-  plot_config = NULL,
-  basemap = "cartolight",
-  add = FALSE,
-  actually_plot = TRUE,
-  overwrite = TRUE,
-  flowline_only = NULL,
-  cache_data = NULL,
-  ...
-)
+
plot_nhdplus(
+  outlets = NULL,
+  bbox = NULL,
+  streamorder = NULL,
+  nhdplus_data = NULL,
+  gpkg = NULL,
+  plot_config = NULL,
+  basemap = "cartolight",
+  add = FALSE,
+  actually_plot = TRUE,
+  overwrite = TRUE,
+  flowline_only = NULL,
+  cache_data = NULL,
+  ...
+)

Arguments

outlets

list of nldi outlets. Other inputs are coerced into nldi outlets, see details.

+ +
bbox

object of class bbox with a defined crs. See examples.

+ +
streamorder

integer only streams of order greater than or equal will be returned

+ +
nhdplus_data

geopackage containing source nhdplus data (omit to download)

+ +
gpkg

path and file with .gpkg ending. If omitted, no file is written.

+ +
plot_config

list containing plot configuration, see details.

+ +
basemap

character indicating which basemap type to use. Chose from: osm.types.

+ +
add

boolean should this plot be added to an already built map.

+ +
actually_plot

boolean actually draw the plot? Use to get data subset only.

+ +
overwrite

passed on the subset_nhdplus.

+ +
flowline_only

boolean only subset and plot flowlines only, default=FALSE

+ +
cache_data

character path to rds file where all plot data can be cached. If file doesn't exist, it will be created. If set to FALSE, all caching will be turned off -- this includes basemap tiles.

+ +
...

parameters passed on to rosm.

+

Value

-

data.frame plot data is returned invisibly in NAD83 Lat/Lon.

+ + +

data.frame plot data is returned invisibly in NAD83 Lat/Lon.

Details

@@ -149,12 +176,15 @@

Details

is performed and upstream with tributaries from the identified catchments is plotted.

The plot_config parameter is a list with names "basin", "flowline", "outlets", "network_wtbd", and "off_network_wtbd". -The following shows the defaults that can be altered.

  1. basin

    list(lwd = 1, col = NA, border = "black")
  2. -
  3. flowline

    list(lwd = 1, col = "blue")
  4. -
  5. outlets

    list(default = list(col = "black", border = NA, pch = 19, cex = 1),
    -        nwissite = list(col = "grey40", border = NA, pch = 17, cex = 1),
    -        huc12pp = list(col = "white", border = "black", pch = 22, cex = 1),
    -        wqp = list(col = "red", border = NA, pch = 20, cex = 1))
  6. +The following shows the defaults that can be altered.

    1. basin

      
      +    list(lwd = 1, col = NA, border = "black")
    2. +
    3. flowline

      
      +    list(lwd = 1, col = "blue")
    4. +
    5. outlets

      
      +   list(default = list(col = "black", border = NA, pch = 19, cex = 1),
      +        nwissite = list(col = "grey40", border = NA, pch = 17, cex = 1),
      +        huc12pp = list(col = "white", border = "black", pch = 22, cex = 1),
      +        wqp = list(col = "red", border = NA, pch = 20, cex = 1))
    6. network_wtbd list(lwd = 1, col = "lightblue", border = "black")

    7. off_network_wtbd list(lwd = 1, col = "darkblue", border = "black")

    If adding additional layers to the plot, data must be projected to EPSG:3857 with @@ -163,115 +193,140 @@

    Details

    Examples

    -
    # \donttest{
    -options("rgdal_show_exportToProj4_warnings"="none")
    -# Beware plot_nhdplus caches data to the default location.
    -# If you do not want data in "user space" change the default.
    -old_dir <- nhdplusTools::nhdplusTools_data_dir()
    -nhdplusTools_data_dir(tempdir())
    -
    -plot_nhdplus("05428500")
    +    
    # \donttest{
    +options("rgdal_show_exportToProj4_warnings"="none")
    +# Beware plot_nhdplus caches data to the default location.
    +# If you do not want data in "user space" change the default.
    +old_dir <- nhdplusTools::nhdplusTools_data_dir()
    +nhdplusTools_data_dir(tempdir())
    +
    +plot_nhdplus("05428500")
    +#> Spherical geometry (s2) switched off
    +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
    +#> Spherical geometry (s2) switched on
     #> Zoom: 11
     #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
     #> Audotdetect projection: assuming Google Mercator (epsg 3857)
     
    -
    -plot_nhdplus("05428500", streamorder = 2)
    +
    +plot_nhdplus("05428500", streamorder = 2)
    +#> Spherical geometry (s2) switched off
    +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
    +#> Spherical geometry (s2) switched on
     #> Zoom: 11
     #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
     #> Audotdetect projection: assuming Google Mercator (epsg 3857)
     
    -
    -plot_nhdplus(list(13293970, 13293750))
    +
    +plot_nhdplus(list(13293970, 13293750))
    +#> Spherical geometry (s2) switched off
    +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
    +#> Spherical geometry (s2) switched on
     #> Zoom: 11
     #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
     #> Audotdetect projection: assuming Google Mercator (epsg 3857)
     
    -
    -source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
    -
    -plot_nhdplus(list(13293970, 13293750), streamorder = 3, nhdplus_data = sample_data)
    +
    +source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
    +
    +plot_nhdplus(list(13293970, 13293750), streamorder = 3, nhdplus_data = sample_data)
     #> Zoom: 11
     #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
     #> Audotdetect projection: assuming Google Mercator (epsg 3857)
     
    -
    -plot_nhdplus(list(list("comid", "13293970"),
    -                  list("nwissite", "USGS-05428500"),
    -                  list("huc12pp", "070900020603"),
    -                  list("huc12pp", "070900020602")),
    -             streamorder = 2,
    -             nhdplus_data = sample_data)
    +
    +plot_nhdplus(list(list("comid", "13293970"),
    +                  list("nwissite", "USGS-05428500"),
    +                  list("huc12pp", "070900020603"),
    +                  list("huc12pp", "070900020602")),
    +             streamorder = 2,
    +             nhdplus_data = sample_data)
     #> Zoom: 11
     #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
     #> Audotdetect projection: assuming Google Mercator (epsg 3857)
     
    -
    -
    -plot_nhdplus(sf::st_as_sf(data.frame(x = -89.36083,
    -                                     y = 43.08944),
    -                          coords = c("x", "y"), crs = 4326),
    -             streamorder = 2,
    -             nhdplus_data = sample_data)
    +
    +
    +plot_nhdplus(sf::st_as_sf(data.frame(x = -89.36083,
    +                                     y = 43.08944),
    +                          coords = c("x", "y"), crs = 4326),
    +             streamorder = 2,
    +             nhdplus_data = sample_data)
     #> Zoom: 11
     #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
     #> Audotdetect projection: assuming Google Mercator (epsg 3857)
     
    -
    -plot_nhdplus(list(list("comid", "13293970"),
    -                  list("nwissite", "USGS-05428500"),
    -                  list("huc12pp", "070900020603"),
    -                  list("huc12pp", "070900020602")),
    -             streamorder = 2,
    -             nhdplus_data = sample_data,
    -             plot_config = list(basin = list(lwd = 2),
    -                                outlets = list(huc12pp = list(cex = 1.5),
    -                                               comid = list(col = "green"))))
    +
    +plot_nhdplus(list(list("comid", "13293970"),
    +                  list("nwissite", "USGS-05428500"),
    +                  list("huc12pp", "070900020603"),
    +                  list("huc12pp", "070900020602")),
    +             streamorder = 2,
    +             nhdplus_data = sample_data,
    +             plot_config = list(basin = list(lwd = 2),
    +                                outlets = list(huc12pp = list(cex = 1.5),
    +                                               comid = list(col = "green"))))
     #> Zoom: 11
     #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
     #> Audotdetect projection: assuming Google Mercator (epsg 3857)
     
    -
    -bbox <- sf::st_bbox(c(xmin = -89.43, ymin = 43, xmax = -89.28, ymax = 43.1),
    -                    crs = "+proj=longlat +datum=WGS84 +no_defs")
    -
    -fline <- sf::read_sf(sample_data, "NHDFlowline_Network")
    -comids <- nhdplusTools::get_UT(fline, 13293970)
    -
    -plot_nhdplus(comids)
    +
    +bbox <- sf::st_bbox(c(xmin = -89.43, ymin = 43, xmax = -89.28, ymax = 43.1),
    +                    crs = "+proj=longlat +datum=WGS84 +no_defs")
    +
    +fline <- sf::read_sf(sample_data, "NHDFlowline_Network")
    +comids <- nhdplusTools::get_UT(fline, 13293970)
    +
    +plot_nhdplus(comids)
    +#> Spherical geometry (s2) switched off
    +#> Spherical geometry (s2) switched on
     #> Zoom: 11
     #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
     #> Audotdetect projection: assuming Google Mercator (epsg 3857)
     
    -
    -#' # With Local Data
    -plot_nhdplus(bbox = bbox, nhdplus_data = sample_data)
    +
    +#' # With Local Data
    +plot_nhdplus(bbox = bbox, nhdplus_data = sample_data)
     #> Zoom: 13
     #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
     #> Audotdetect projection: assuming Google Mercator (epsg 3857)
     
    -
    -# With downloaded data
    -plot_nhdplus(bbox = bbox, streamorder = 3)
    +
    +# With downloaded data
    +plot_nhdplus(bbox = bbox, streamorder = 3)
    +#> Spherical geometry (s2) switched off
    +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
    +#> Spherical geometry (s2) switched on
    +#> Spherical geometry (s2) switched off
    +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
    +#> Spherical geometry (s2) switched on
    +#> Spherical geometry (s2) switched off
     #> Warning: No nhdarea features found
    +#> Spherical geometry (s2) switched on
    +#> Spherical geometry (s2) switched off
    +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
    +#> Spherical geometry (s2) switched on
    +#> Spherical geometry (s2) switched off
    +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
    +#> Spherical geometry (s2) switched on
     #> Zoom: 13
     #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
     #> Audotdetect projection: assuming Google Mercator (epsg 3857)
     
    -
    -# Can also plot on top of the previous!
    -plot_nhdplus(bbox = bbox, nhdplus_data = sample_data,
    -             plot_config = list(flowline = list(lwd = 0.5)))
    +
    +# Can also plot on top of the previous!
    +plot_nhdplus(bbox = bbox, nhdplus_data = sample_data,
    +             plot_config = list(flowline = list(lwd = 0.5)))
     #> Zoom: 13
     #> Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
     #> Audotdetect projection: assuming Google Mercator (epsg 3857)
    -plot_nhdplus(comids, nhdplus_data = sample_data, streamorder = 3, add = TRUE,
    -             plot_config = list(flowline = list(col = "darkblue")))
    +plot_nhdplus(comids, nhdplus_data = sample_data, streamorder = 3, add = TRUE,
    +             plot_config = list(flowline = list(col = "darkblue")))
     #> Audotdetect projection: assuming Google Mercator (epsg 3857)
     
    -
    -nhdplusTools::nhdplusTools_data_dir(old_dir)
    -# }
    +
    +nhdplusTools::nhdplusTools_data_dir(old_dir)
    +# }
     
    @@ -286,7 +341,7 @@

    Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/prepare_nhdplus.html b/docs/reference/prepare_nhdplus.html index 221cc6ea..bbcb4a03 100644 --- a/docs/reference/prepare_nhdplus.html +++ b/docs/reference/prepare_nhdplus.html @@ -17,7 +17,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -78,17 +78,17 @@

Prep NHDPlus Data

-
prepare_nhdplus(
-  flines,
-  min_network_size = 0,
-  min_path_length = 0,
-  min_path_size = 0,
-  purge_non_dendritic = TRUE,
-  warn = TRUE,
-  error = TRUE,
-  skip_toCOMID = FALSE,
-  align_names = TRUE
-)
+
prepare_nhdplus(
+  flines,
+  min_network_size = 0,
+  min_path_length = 0,
+  min_path_size = 0,
+  purge_non_dendritic = TRUE,
+  warn = TRUE,
+  error = TRUE,
+  skip_toCOMID = FALSE,
+  align_names = TRUE
+)
@@ -98,42 +98,61 @@

Arguments

COMID, LENGTHKM, FTYPE (or FCODE), TerminalFl, FromNode, ToNode, TotDASqKM, StartFlag, StreamOrde, StreamCalc, TerminalPa, Pathlength, and Divergence variables.

+ +
min_network_size

numeric Minimum size (sqkm) of drainage network to include in output.

+ +
min_path_length

numeric Minimum length (km) of terminal level path of a network.

+ +
min_path_size

numeric Minimum size (sqkm) of outlet level path of a drainage basin. Drainage basins with an outlet drainage area smaller than this will be removed.

+ +
purge_non_dendritic

logical Should non dendritic paths be removed or not.

+ +
warn

logical controls whether warning an status messages are printed

+ +
error

logical controls whether to return potentially invalid data with a warning rather than an error

+ +
skip_toCOMID

logical if TRUE, toCOMID will not be added to output.

+ +
align_names

logical

+

Value

-

data.frame ready to be used with the refactor_flowlines function.

+ + +

data.frame ready to be used with the refactor_flowlines function.

Examples

-

-source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
-
-prepare_nhdplus(sample_flines,
-                min_network_size = 10,
-                min_path_length = 1,
-                warn = FALSE)
+    

+source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
+
+prepare_nhdplus(sample_flines,
+                min_network_size = 10,
+                min_path_length = 1,
+                warn = FALSE)
 #>         COMID   toCOMID LENGTHKM  Hydroseq LevelPathI TotDASqKM
 #> 1    11689204  11689212    0.730 200027394  200024046  149.9148
 #> 2    11689212  11689228    0.819 200026423  200024046  164.6676
@@ -832,7 +851,7 @@ 

Examples

#> 695 11690072 11690088 0.115 200059972 200059972 7.4457 #> 696 11690074 11690088 0.090 200029708 200021126 85.8609 #> 697 11690088 11688910 0.871 200028469 200021126 93.8475 - +
@@ -847,7 +866,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/query_usgs_geoserver.html b/docs/reference/query_usgs_geoserver.html index a7e8dac6..73940fde 100644 --- a/docs/reference/query_usgs_geoserver.html +++ b/docs/reference/query_usgs_geoserver.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,14 +80,14 @@

Query USGS Geoserver

-
query_usgs_geoserver(
-  AOI = NULL,
-  ids = NULL,
-  type = NULL,
-  filter = NULL,
-  t_srs = NULL,
-  buffer = 0.5
-)
+
query_usgs_geoserver(
+  AOI = NULL,
+  ids = NULL,
+  type = NULL,
+  filter = NULL,
+  t_srs = NULL,
+  buffer = 0.5
+)
@@ -96,26 +96,39 @@

Arguments

sf (MULTI)POINT or (MULTI)POLYGON. An 'area of interest' can be provided as either a location (sf POINT) or area (sf POLYGON) in any Spatial Reference System.

+ +
ids

character or numeric. A set of identifier(s) from the data type requested, for example if NHD, then a set of COMID(s).

+ +
type

character. Type of feature to return ('huc08','huc12', 'nhd', 'catchment', 'waterbodies', 'gagesII'). If NULL (default) a data.frame of available resources is returned

+ +
filter

character. An XML filter to pass to httr POST query

+ +
t_srs

character (PROJ string or EPSG code) or numeric (EPSG code). A user specified - target -Spatial Reference System (SRS/CRS) for returned objects. Will default to the CRS of the input AOI if provided, and to 4326 for ID requests.

+ +
buffer

numeric. The amount (in meters) to buffer a POINT AOI by for an extended search. Default = 0.5

+

Value

-

a simple features (sf) object

+ + +

a simple features (sf) object

Details

@@ -140,7 +153,7 @@

Details

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/rename_geometry.html b/docs/reference/rename_geometry.html index bcb08e42..a31bff58 100644 --- a/docs/reference/rename_geometry.html +++ b/docs/reference/rename_geometry.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,21 +80,24 @@

rename_geometry

-
rename_geometry(g, name)
+
rename_geometry(g, name)

Arguments

g

sf data.table

+ +
name

character name to be used for geometry

+

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
@@ -102,7 +105,7 @@ 

Examples

#> CRS: NA #> a geo #> 1 3 POINT (1 2) -rename_geometry(g, "geometry") +rename_geometry(g, "geometry") #> Simple feature collection with 1 feature and 1 field #> Geometry type: POINT #> Dimension: XY @@ -110,7 +113,7 @@

Examples

#> CRS: NA #> a geometry #> 1 3 POINT (1 2) - +
@@ -125,7 +128,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/rescale_measures.html b/docs/reference/rescale_measures.html index 4d668002..8ea01a67 100644 --- a/docs/reference/rescale_measures.html +++ b/docs/reference/rescale_measures.html @@ -25,7 +25,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -94,30 +94,37 @@

Rescale reachcode measure to comid flowline measure

-
rescale_measures(measure, from, to)
+
rescale_measures(measure, from, to)

Arguments

measure

numeric reach measure between 0 and 100

+ +
from

numeric flowline from-measure relative to the reach

+ +
to

numeric flowline to-measure relative to the reach

+

Value

-

numeric rescaled measure

+ + +

numeric rescaled measure

Examples

-
rescale_measures(40, 0, 50)
+    
rescale_measures(40, 0, 50)
 #> [1] 80
-rescale_measures(60, 50, 100)
+rescale_measures(60, 50, 100)
 #> [1] 20
-
+
 
@@ -132,7 +139,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/rpu_boundaries.html b/docs/reference/rpu_boundaries.html index 785eb993..91c9fd59 100644 --- a/docs/reference/rpu_boundaries.html +++ b/docs/reference/rpu_boundaries.html @@ -20,7 +20,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -83,7 +83,7 @@

RPU Boundaries
-
rpu_boundaries
+
rpu_boundaries
@@ -103,7 +103,7 @@

Format

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/st_compatibalize.html b/docs/reference/st_compatibalize.html index e4495eff..53abd5b2 100644 --- a/docs/reference/st_compatibalize.html +++ b/docs/reference/st_compatibalize.html @@ -19,7 +19,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -82,87 +82,90 @@

make spatial inputs compatible

-
st_compatibalize(sf1, sf2)
+
st_compatibalize(sf1, sf2)

Arguments

sf1

sf data.frame

+ +
sf2

sf data.frame

+

Examples

-

-source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
-
-(one <- dplyr::select(sample_flines))
+    

+source(system.file("extdata", "sample_flines.R", package = "nhdplusTools"))
+
+(one <- dplyr::select(sample_flines))
 #> Simple feature collection with 707 features and 0 fields
 #> Geometry type: MULTILINESTRING
 #> Dimension:     XY
 #> Bounding box:  xmin: -77.16175 ymin: 39.11307 xmax: -76.43622 ymax: 39.64679
 #> Geodetic CRS:  WGS 84
-#> # A tibble: 707 x 1
+#> # A tibble: 707 × 1
 #>                                                                             geom
 #>                                                            <MULTILINESTRING [°]>
-#>  1 ((-76.66157 39.27636, -76.6614 39.27636, -76.66057 39.27545, -76.66051 39.27~
-#>  2 ((-76.65498 39.27543, -76.65436 39.27497, -76.65398 39.27431, -76.65386 39.2~
-#>  3 ((-76.64835 39.27115, -76.64812 39.27115, -76.64771 39.2709, -76.64662 39.27~
-#>  4 ((-76.63034 39.2693, -76.63021 39.26919, -76.62808 39.26881, -76.62708 39.26~
-#>  5 ((-76.61201 39.25434, -76.61183 39.25413, -76.61068 39.25344, -76.60962 39.2~
-#>  6 ((-76.68668 39.30612, -76.68492 39.30628, -76.6835 39.30608, -76.68218 39.30~
-#>  7 ((-76.71434 39.32628, -76.71457 39.32592, -76.7146 39.32432, -76.71425 39.32~
-#>  8 ((-76.72432 39.32412, -76.7235 39.32383, -76.72247 39.32387, -76.72152 39.32~
-#>  9 ((-76.73594 39.34748, -76.73455 39.34652, -76.73208 39.34574, -76.73143 39.3~
-#> 10 ((-76.7446 39.36049, -76.7446 39.35959, -76.74451 39.35934, -76.74424 39.359~
-#> # ... with 697 more rows
-(two <- sf::st_transform(one, 5070))
+#>  1 ((-76.66157 39.27636, -76.6614 39.27636, -76.66057 39.27545, -76.66051 39.27…
+#>  2 ((-76.65498 39.27543, -76.65436 39.27497, -76.65398 39.27431, -76.65386 39.2…
+#>  3 ((-76.64835 39.27115, -76.64812 39.27115, -76.64771 39.2709, -76.64662 39.27…
+#>  4 ((-76.63034 39.2693, -76.63021 39.26919, -76.62808 39.26881, -76.62708 39.26…
+#>  5 ((-76.61201 39.25434, -76.61183 39.25413, -76.61068 39.25344, -76.60962 39.2…
+#>  6 ((-76.68668 39.30612, -76.68492 39.30628, -76.6835 39.30608, -76.68218 39.30…
+#>  7 ((-76.71434 39.32628, -76.71457 39.32592, -76.7146 39.32432, -76.71425 39.32…
+#>  8 ((-76.72432 39.32412, -76.7235 39.32383, -76.72247 39.32387, -76.72152 39.32…
+#>  9 ((-76.73594 39.34748, -76.73455 39.34652, -76.73208 39.34574, -76.73143 39.3…
+#> 10 ((-76.7446 39.36049, -76.7446 39.35959, -76.74451 39.35934, -76.74424 39.359…
+#> # … with 697 more rows
+(two <- sf::st_transform(one, 5070))
 #> Simple feature collection with 707 features and 0 fields
 #> Geometry type: MULTILINESTRING
 #> Dimension:     XY
 #> Bounding box:  xmin: 1597686 ymin: 1956259 xmax: 1663643 ymax: 2010159
 #> Projected CRS: NAD83 / Conus Albers
-#> # A tibble: 707 x 1
+#> # A tibble: 707 × 1
 #>                                                                             geom
 #>  *                                                         <MULTILINESTRING [m]>
-#>  1 ((1641586 1973488, 1641601 1973491, 1641690 1973404, 1641699 1973388, 164172~
-#>  2 ((1642159 1973499, 1642221 1973459, 1642268 1973393, 1642289 1973342, 164233~
-#>  3 ((1642811 1973144, 1642831 1973148, 1642871 1973127, 1642970 1973109, 164303~
-#>  4 ((1644361 1973252, 1644374 1973243, 1644561 1973238, 1644645 1973252, 164474~
-#>  5 ((1646235 1971928, 1646255 1971908, 1646367 1971852, 1646465 1971824, 164695~
-#>  6 ((1638811 1976321, 1638955 1976369, 1639078 1976371, 1639181 1976429, 163923~
-#>  7 ((1636041 1978058, 1636030 1978013, 1636063 1977837, 1636107 1977775, 163625~
-#>  8 ((1635254 1977649, 1635330 1977630, 1635415 1977653, 1635482 1977730, 163554~
-#>  9 ((1633756 1980012, 1633893 1979931, 1634118 1979888, 1634173 1979894, 163427~
-#> 10 ((1632738 1981292, 1632758 1981194, 1632771 1981168, 1632799 1981145, 163287~
-#> # ... with 697 more rows
-
-attr(one, "sf_column") <- "geotest"
-names(one)[names(one) == "geom"] <- "geotest"
-
-st_compatibalize(one, two)
+#>  1 ((1641586 1973488, 1641601 1973491, 1641690 1973404, 1641699 1973388, 164172…
+#>  2 ((1642159 1973499, 1642221 1973459, 1642268 1973393, 1642289 1973342, 164233…
+#>  3 ((1642811 1973144, 1642831 1973148, 1642871 1973127, 1642970 1973109, 164303…
+#>  4 ((1644361 1973252, 1644374 1973243, 1644561 1973238, 1644645 1973252, 164474…
+#>  5 ((1646235 1971928, 1646255 1971908, 1646367 1971852, 1646465 1971824, 164695…
+#>  6 ((1638811 1976321, 1638955 1976369, 1639078 1976371, 1639181 1976429, 163923…
+#>  7 ((1636041 1978058, 1636030 1978013, 1636063 1977837, 1636107 1977775, 163625…
+#>  8 ((1635254 1977649, 1635330 1977630, 1635415 1977653, 1635482 1977730, 163554…
+#>  9 ((1633756 1980012, 1633893 1979931, 1634118 1979888, 1634173 1979894, 163427…
+#> 10 ((1632738 1981292, 1632758 1981194, 1632771 1981168, 1632799 1981145, 163287…
+#> # … with 697 more rows
+
+attr(one, "sf_column") <- "geotest"
+names(one)[names(one) == "geom"] <- "geotest"
+
+st_compatibalize(one, two)
 #> Simple feature collection with 707 features and 0 fields
 #> Geometry type: MULTILINESTRING
 #> Dimension:     XY
 #> Bounding box:  xmin: 1597686 ymin: 1956259 xmax: 1663643 ymax: 2010159
 #> Projected CRS: NAD83 / Conus Albers
-#> # A tibble: 707 x 1
+#> # A tibble: 707 × 1
 #>                                                                             geom
 #>  *                                                         <MULTILINESTRING [m]>
-#>  1 ((1641586 1973488, 1641601 1973491, 1641690 1973404, 1641699 1973388, 164172~
-#>  2 ((1642159 1973499, 1642221 1973459, 1642268 1973393, 1642289 1973342, 164233~
-#>  3 ((1642811 1973144, 1642831 1973148, 1642871 1973127, 1642970 1973109, 164303~
-#>  4 ((1644361 1973252, 1644374 1973243, 1644561 1973238, 1644645 1973252, 164474~
-#>  5 ((1646235 1971928, 1646255 1971908, 1646367 1971852, 1646465 1971824, 164695~
-#>  6 ((1638811 1976321, 1638955 1976369, 1639078 1976371, 1639181 1976429, 163923~
-#>  7 ((1636041 1978058, 1636030 1978013, 1636063 1977837, 1636107 1977775, 163625~
-#>  8 ((1635254 1977649, 1635330 1977630, 1635415 1977653, 1635482 1977730, 163554~
-#>  9 ((1633756 1980012, 1633893 1979931, 1634118 1979888, 1634173 1979894, 163427~
-#> 10 ((1632738 1981292, 1632758 1981194, 1632771 1981168, 1632799 1981145, 163287~
-#> # ... with 697 more rows
-
+#>  1 ((1641586 1973488, 1641601 1973491, 1641690 1973404, 1641699 1973388, 164172…
+#>  2 ((1642159 1973499, 1642221 1973459, 1642268 1973393, 1642289 1973342, 164233…
+#>  3 ((1642811 1973144, 1642831 1973148, 1642871 1973127, 1642970 1973109, 164303…
+#>  4 ((1644361 1973252, 1644374 1973243, 1644561 1973238, 1644645 1973252, 164474…
+#>  5 ((1646235 1971928, 1646255 1971908, 1646367 1971852, 1646465 1971824, 164695…
+#>  6 ((1638811 1976321, 1638955 1976369, 1639078 1976371, 1639181 1976429, 163923…
+#>  7 ((1636041 1978058, 1636030 1978013, 1636063 1977837, 1636107 1977775, 163625…
+#>  8 ((1635254 1977649, 1635330 1977630, 1635415 1977653, 1635482 1977730, 163554…
+#>  9 ((1633756 1980012, 1633893 1979931, 1634118 1979888, 1634173 1979894, 163427…
+#> 10 ((1632738 1981292, 1632758 1981194, 1632771 1981168, 1632799 1981145, 163287…
+#> # … with 697 more rows
+
 
@@ -177,7 +180,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/stage_national_data.html b/docs/reference/stage_national_data.html index 9c0c01e6..e16b1bf8 100644 --- a/docs/reference/stage_national_data.html +++ b/docs/reference/stage_national_data.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,12 +80,12 @@

Stage NHDPlus National Data (deprecated)

-
stage_national_data(
-  include = c("attribute", "flowline", "catchment"),
-  output_path = NULL,
-  nhdplus_data = NULL,
-  simplified = TRUE
-)
+
stage_national_data(
+  include = c("attribute", "flowline", "catchment"),
+  output_path = NULL,
+  nhdplus_data = NULL,
+  simplified = TRUE
+)
@@ -93,20 +93,29 @@

Arguments

include

character vector containing one or more of: "attributes", "flowline", "catchment".

+ +
output_path

character path to save the output to defaults to the directory of the nhdplus_data.

+ +
nhdplus_data

character path to the .gpkg or .gdb containing the national seamless dataset. Not required if nhdplus_path has been set.

+ +
simplified

boolean if TRUE (the default) the CatchmentSP layer will be included.

+

Value

-

list containing paths to the .rds files.

+ + +

list containing paths to the .rds files.

Details

@@ -121,20 +130,20 @@

Details

Examples

-

-source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
-
-stage_national_data(nhdplus_data = sample_data, output_path = tempdir())
+    

+source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
+
+stage_national_data(nhdplus_data = sample_data, output_path = tempdir())
 #> $attributes
-#> [1] "C:\\Users\\DBLODG~2\\AppData\\Local\\Temp\\1\\RtmpW88Iq5/nhdplus_flowline_attributes.rds"
+#> [1] "C:\\Users\\DBLODG~2\\AppData\\Local\\Temp\\1\\RtmpoXfXKH/nhdplus_flowline_attributes.rds"
 #> 
 #> $flowline
-#> [1] "C:\\Users\\DBLODG~2\\AppData\\Local\\Temp\\1\\RtmpW88Iq5/nhdplus_flowline.rds"
+#> [1] "C:\\Users\\DBLODG~2\\AppData\\Local\\Temp\\1\\RtmpoXfXKH/nhdplus_flowline.rds"
 #> 
 #> $catchment
-#> [1] "C:\\Users\\DBLODG~2\\AppData\\Local\\Temp\\1\\RtmpW88Iq5/nhdplus_catchment.rds"
+#> [1] "C:\\Users\\DBLODG~2\\AppData\\Local\\Temp\\1\\RtmpoXfXKH/nhdplus_catchment.rds"
 #> 
-
+
 
@@ -149,7 +158,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/subset_nhdplus.html b/docs/reference/subset_nhdplus.html index c09229a4..46a29a2d 100644 --- a/docs/reference/subset_nhdplus.html +++ b/docs/reference/subset_nhdplus.html @@ -21,7 +21,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -86,59 +86,82 @@

Subset NHDPlus

-
subset_nhdplus(
-  comids = NULL,
-  output_file = NULL,
-  nhdplus_data = NULL,
-  bbox = NULL,
-  simplified = TRUE,
-  overwrite = FALSE,
-  return_data = TRUE,
-  status = TRUE,
-  flowline_only = NULL,
-  streamorder = NULL,
-  out_prj = 4269
-)
+
subset_nhdplus(
+  comids = NULL,
+  output_file = NULL,
+  nhdplus_data = NULL,
+  bbox = NULL,
+  simplified = TRUE,
+  overwrite = FALSE,
+  return_data = TRUE,
+  status = TRUE,
+  flowline_only = NULL,
+  streamorder = NULL,
+  out_prj = 4269
+)

Arguments

comids

integer vector of COMIDs to include.

+ +
output_file

character path to save the output to defaults to the directory of the nhdplus_data.

+ +
nhdplus_data

character path to the .gpkg or .gdb containing the national seamless database, a subset of NHDPlusHR, or "download" to use a web service to download NHDPlusV2.1 data. Not required if nhdplus_path has been set or the default has been adopted. See details for more.

+ +
bbox

object of class "bbox" as returned by sf::st_bbox in Latitude/Longitude. If no CRS is present, will be assumed to be in WGS84 Latitude Longitude.

+ +
simplified

boolean if TRUE (the default) the CatchmentSP layer will be included. Not relevant to the "download" option or NHDPlusHR data.

+ +
overwrite

boolean should the output file be overwritten

+ +
return_data

boolean if FALSE path to output file is returned silently otherwise data is returned in a list.

+ +
status

boolean should the function print status messages

+ +
flowline_only

boolean WARNING: experimental if TRUE only the flowline network and attributes will be returned

+ +
streamorder

integer only streams of order greater than or equal will be downloaded. Not implemented for local data.

+ +
out_prj

character override the default output CRS of NAD83 lat/lon (EPSG:4269)

+

Value

-

character path to the saved subset geopackage

+ + +

character path to the saved subset geopackage

Details

@@ -152,43 +175,43 @@

Details

Examples

-
# \donttest{
-
-source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
-
-nhdplus_path(sample_data)
-
-staged_nhdplus <- stage_national_data(output_path = tempdir())
+    
# \donttest{
+
+source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
+
+nhdplus_path(sample_data)
+
+staged_nhdplus <- stage_national_data(output_path = tempdir())
 #> Warning: attributes file exists
 #> Warning: flowline file exists
 #> Warning: catchment already exists.
-
-sample_flines <- readRDS(staged_nhdplus$flowline)
-
-geom_col <- attr(sample_flines, "sf_column")
-
-plot(sample_flines[[geom_col]],
-     lwd = 3)
-
-start_point <- sf::st_sfc(sf::st_point(c(-89.362239, 43.090266)),
-                          crs = 4326)
-
-plot(start_point, cex = 1.5, lwd = 2, col = "red", add = TRUE)
-
-start_comid <- discover_nhdplus_id(start_point)
-
-comids <- get_UT(sample_flines, start_comid)
-
-plot(dplyr::filter(sample_flines, COMID %in% comids)[[geom_col]],
-     add=TRUE, col = "red", lwd = 2)
-
-output_file <- tempfile(fileext = ".gpkg")
-
-subset_nhdplus(comids = comids,
-               output_file = output_file,
-               nhdplus_data = sample_data,
-               overwrite = TRUE,
-               status = TRUE)
+
+sample_flines <- readRDS(staged_nhdplus$flowline)
+
+geom_col <- attr(sample_flines, "sf_column")
+
+plot(sample_flines[[geom_col]],
+     lwd = 3)
+
+start_point <- sf::st_sfc(sf::st_point(c(-89.362239, 43.090266)),
+                          crs = 4326)
+
+plot(start_point, cex = 1.5, lwd = 2, col = "red", add = TRUE)
+
+start_comid <- discover_nhdplus_id(start_point)
+
+comids <- get_UT(sample_flines, start_comid)
+
+plot(dplyr::filter(sample_flines, COMID %in% comids)[[geom_col]],
+     add=TRUE, col = "red", lwd = 2)
+
+output_file <- tempfile(fileext = ".gpkg")
+
+subset_nhdplus(comids = comids,
+               output_file = output_file,
+               nhdplus_data = sample_data,
+               overwrite = TRUE,
+               status = TRUE)
 #> All intersections performed in latitude/longitude.
 #> Reading NHDFlowline_Network
 #> 168 comids of 168
@@ -212,26 +235,26 @@ 

Examples

#> Dimension: XY #> Bounding box: xmin: -89.58537 ymin: 43.08521 xmax: -89.21254 ymax: 43.30179 #> Geodetic CRS: NAD83 -#> # A tibble: 168 x 137 +#> # A tibble: 168 × 137 #> COMID FDATE RESOLUTION GNIS_ID GNIS_NAME LENGTHKM REACHCODE #> * <int> <dttm> <chr> <chr> <chr> <dbl> <chr> -#> 1 13293750 1999-10-29 00:00:00 Medium 1577073 Yahara Ri~ 1.72 07090002~ -#> 2 13293504 1999-10-29 00:00:00 Medium 1577073 Yahara Ri~ 1.41 07090002~ -#> 3 13294134 1999-10-29 00:00:00 Medium 1577073 Yahara Ri~ 0.74 07090002~ -#> 4 13294128 1999-10-29 00:00:00 Medium 1577073 Yahara Ri~ 3.70 07090002~ -#> 5 13294394 1999-10-29 00:00:00 Medium 1577073 Yahara Ri~ 0.077 07090002~ -#> 6 13293454 1999-10-29 00:00:00 Medium 1577073 Yahara Ri~ 0.94 07090002~ -#> 7 13293430 1999-10-29 00:00:00 Medium 1577073 Yahara Ri~ 1.14 07090002~ -#> 8 13293424 1999-10-29 00:00:00 Medium 1577073 Yahara Ri~ 1.27 07090002~ -#> 9 13294110 1999-10-29 00:00:00 Medium 1577073 Yahara Ri~ 7.48 07090002~ -#> 10 13293398 1999-10-29 00:00:00 Medium 1577073 Yahara Ri~ 0.082 07090002~ -#> # ... with 158 more rows, and 130 more variables: FLOWDIR <chr>, +#> 1 13293750 1999-10-29 00:00:00 Medium 1577073 Yahara Ri… 1.72 07090002… +#> 2 13293504 1999-10-29 00:00:00 Medium 1577073 Yahara Ri… 1.41 07090002… +#> 3 13294134 1999-10-29 00:00:00 Medium 1577073 Yahara Ri… 0.74 07090002… +#> 4 13294128 1999-10-29 00:00:00 Medium 1577073 Yahara Ri… 3.70 07090002… +#> 5 13294394 1999-10-29 00:00:00 Medium 1577073 Yahara Ri… 0.077 07090002… +#> 6 13293454 1999-10-29 00:00:00 Medium 1577073 Yahara Ri… 0.94 07090002… +#> 7 13293430 1999-10-29 00:00:00 Medium 1577073 Yahara Ri… 1.14 07090002… +#> 8 13293424 1999-10-29 00:00:00 Medium 1577073 Yahara Ri… 1.27 07090002… +#> 9 13294110 1999-10-29 00:00:00 Medium 1577073 Yahara Ri… 7.48 07090002… +#> 10 13293398 1999-10-29 00:00:00 Medium 1577073 Yahara Ri… 0.082 07090002… +#> # … with 158 more rows, and 130 more variables: FLOWDIR <chr>, #> # WBAREACOMI <int>, FTYPE <chr>, FCODE <int>, Shape_Length <dbl>, #> # StreamLeve <int>, StreamOrde <int>, StreamCalc <int>, FromNode <dbl>, #> # ToNode <dbl>, Hydroseq <dbl>, LevelPathI <dbl>, Pathlength <dbl>, #> # TerminalPa <dbl>, ArbolateSu <dbl>, Divergence <int>, StartFlag <int>, #> # TerminalFl <int>, DnLevel <int>, UpLevelPat <dbl>, UpHydroseq <dbl>, -#> # DnLevelPat <dbl>, DnMinorHyd <dbl>, DnDrainCou <int>, DnHydroseq <dbl>, ... +#> # DnLevelPat <dbl>, DnMinorHyd <dbl>, DnDrainCou <int>, DnHydroseq <dbl>, … #> #> $CatchmentSP #> Simple feature collection with 167 features and 6 fields @@ -239,7 +262,7 @@

Examples

#> Dimension: XY #> Bounding box: xmin: -89.60479 ymin: 43.03507 xmax: -89.20378 ymax: 43.36607 #> Geodetic CRS: NAD83 -#> # A tibble: 167 x 7 +#> # A tibble: 167 × 7 #> GRIDCODE FEATUREID SOURCEFC AreaSqKM Shape_Length Shape_Area #> * <int> <int> <chr> <dbl> <dbl> <dbl> #> 1 1085160 13293454 NHDFlowline 0.328 0.0256 0.0000364 @@ -252,7 +275,7 @@

Examples

#> 8 1085478 13293614 NHDFlowline 3.15 0.0953 0.000348 #> 9 1085502 13294264 NHDFlowline 24.8 0.348 0.00275 #> 10 1085509 13293384 NHDFlowline 0.291 0.0296 0.0000323 -#> # ... with 157 more rows, and 1 more variable: geom <MULTIPOLYGON [°]> +#> # … with 157 more rows, and 1 more variable: geom <MULTIPOLYGON [°]> #> #> $NHDArea #> [1] "NHDArea" @@ -269,71 +292,84 @@

Examples

#> $Sink #> NULL #> - -sf::st_layers(output_file) + +sf::st_layers(output_file) #> Driver: GPKG #> Available layers: -#> layer_name geometry_type features fields crs_name -#> 1 NHDFlowline_Network Line String 168 136 NAD83 -#> 2 CatchmentSP Multi Polygon 167 6 NAD83 -#> 3 NHDArea Polygon 1 14 NAD83 -#> 4 NHDWaterbody Polygon 90 21 NAD83 -#> 5 NHDFlowline_NonNetwork Line String 45 12 NAD83 -#> 6 Gage Point 33 19 NAD83 - -catchment <- sf::read_sf(output_file, "CatchmentSP") - -plot(catchment[[attr(catchment, "sf_column")]], add = TRUE) - -waterbody <- sf::read_sf(output_file, "NHDWaterbody") - -plot(waterbody[[attr(waterbody, "sf_column")]], - col = rgb(0, 0, 1, alpha = 0.5), add = TRUE) +#> layer_name geometry_type features fields +#> 1 NHDFlowline_Network Line String 168 136 +#> 2 CatchmentSP Multi Polygon 167 6 +#> 3 NHDArea Polygon 1 14 +#> 4 NHDWaterbody Polygon 90 21 +#> 5 NHDFlowline_NonNetwork Line String 45 12 +#> 6 Gage Point 33 19 + +catchment <- sf::read_sf(output_file, "CatchmentSP") + +plot(catchment[[attr(catchment, "sf_column")]], add = TRUE) + +waterbody <- sf::read_sf(output_file, "NHDWaterbody") + +plot(waterbody[[attr(waterbody, "sf_column")]], + col = rgb(0, 0, 1, alpha = 0.5), add = TRUE) - -# Cleanup temp -sapply(staged_nhdplus, unlink) + +# Cleanup temp +sapply(staged_nhdplus, unlink) #> attributes flowline catchment #> 0 0 0 -unlink(output_file) - -# Download Option: -subset_nhdplus(comids = comids, - output_file = output_file, - nhdplus_data = "download", - overwrite = TRUE, - status = TRUE, flowline_only = FALSE) +unlink(output_file) + +# Download Option: +subset_nhdplus(comids = comids, + output_file = output_file, + nhdplus_data = "download", + overwrite = TRUE, + status = TRUE, flowline_only = FALSE) #> All intersections performed in latitude/longitude. #> Reading NHDFlowline_Network +#> Spherical geometry (s2) switched off +#> Spherical geometry (s2) switched on #> Writing NHDFlowline_Network #> Reading CatchmentSP +#> Spherical geometry (s2) switched off +#> Spherical geometry (s2) switched on #> Writing CatchmentSP +#> Spherical geometry (s2) switched off +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar +#> Spherical geometry (s2) switched on +#> Spherical geometry (s2) switched off +#> although coordinates are longitude/latitude, st_intersects assumes that they are planar +#> Spherical geometry (s2) switched on #> $NHDFlowline_Network #> Simple feature collection with 168 features and 138 fields #> Geometry type: LINESTRING #> Dimension: XY #> Bounding box: xmin: -89.58537 ymin: 43.08522 xmax: -89.21254 ymax: 43.30179 #> Geodetic CRS: NAD83 -#> # A tibble: 168 x 139 +#> # A tibble: 168 × 139 #> id comid fdate resolution gnis_id gnis_name lengthkm #> * <chr> <int> <dttm> <chr> <chr> <chr> <dbl> -#> 1 nhdflowline~ 1.33e7 1999-10-28 23:00:00 Medium " " " " 3.04 -#> 2 nhdflowline~ 1.33e7 1999-10-28 23:00:00 Medium " " " " 1.44 -#> 3 nhdflowline~ 1.33e7 1999-10-28 23:00:00 Medium "15770~ "Yahara ~ 4.84 -#> 4 nhdflowline~ 1.33e7 1999-10-28 23:00:00 Medium " " " " 4.40 -#> 5 nhdflowline~ 1.33e7 1999-10-28 23:00:00 Medium "15770~ "Yahara ~ 0.839 -#> 6 nhdflowline~ 1.33e7 1999-10-28 23:00:00 Medium " " " " 4.67 -#> 7 nhdflowline~ 1.33e7 1999-10-28 23:00:00 Medium "15770~ "Yahara ~ 0.402 -#> 8 nhdflowline~ 1.33e7 1999-10-28 23:00:00 Medium " " " " 1.08 -#> 9 nhdflowline~ 1.33e7 1999-10-28 23:00:00 Medium "15770~ "Yahara ~ 1.12 -#> 10 nhdflowline~ 1.33e7 1999-10-28 23:00:00 Medium " " " " 0.351 -#> # ... with 158 more rows, and 132 more variables: reachcode <chr>, -#> # flowdir <chr>, wbareacomi <int>, ftype <chr>, fcode <int>, -#> # shape_length <dbl>, streamleve <int>, streamorde <int>, streamcalc <int>, -#> # fromnode <dbl>, tonode <dbl>, hydroseq <dbl>, levelpathi <dbl>, -#> # pathlength <dbl>, terminalpa <dbl>, arbolatesu <dbl>, divergence <int>, -#> # startflag <int>, terminalfl <int>, dnlevel <int>, uplevelpat <dbl>, -#> # uphydroseq <dbl>, dnlevelpat <dbl>, dnminorhyd <dbl>, dndraincou <int>, ... +#> 1 nhdflowline… 1.33e7 1999-10-28 23:00:00 Medium " " " " 3.04 +#> 2 nhdflowline… 1.33e7 1999-10-28 23:00:00 Medium " " " " 1.44 +#> 3 nhdflowline… 1.33e7 1999-10-28 23:00:00 Medium "15770… "Yahara … 4.84 +#> 4 nhdflowline… 1.33e7 1999-10-28 23:00:00 Medium " " " " 4.40 +#> 5 nhdflowline… 1.33e7 1999-10-28 23:00:00 Medium "15770… "Yahara … 0.839 +#> 6 nhdflowline… 1.33e7 1999-10-28 23:00:00 Medium " " " " 4.67 +#> 7 nhdflowline… 1.33e7 1999-10-28 23:00:00 Medium "15770… "Yahara … 0.402 +#> 8 nhdflowline… 1.33e7 1999-10-28 23:00:00 Medium " " " " 1.08 +#> 9 nhdflowline… 1.33e7 1999-10-28 23:00:00 Medium "15770… "Yahara … 1.12 +#> 10 nhdflowline… 1.33e7 1999-10-28 23:00:00 Medium " " " " 0.351 +#> # … with 158 more rows, and 132 more variables: reachcode <chr>, flowdir <chr>, +#> # wbareacomi <int>, ftype <chr>, fcode <int>, shape_length <dbl>, +#> # streamleve <int>, streamorde <int>, streamcalc <int>, fromnode <dbl>, +#> # tonode <dbl>, hydroseq <dbl>, levelpathi <dbl>, pathlength <dbl>, +#> # terminalpa <dbl>, arbolatesu <dbl>, divergence <int>, startflag <int>, +#> # terminalfl <int>, dnlevel <int>, uplevelpat <dbl>, uphydroseq <dbl>, +#> # dnlevelpat <dbl>, dnminorhyd <dbl>, dndraincou <int>, dnhydroseq <dbl>, … #> #> $CatchmentSP #> Simple feature collection with 167 features and 7 fields @@ -341,20 +377,20 @@

Examples

#> Dimension: XY #> Bounding box: xmin: -89.60479 ymin: 43.03507 xmax: -89.20378 ymax: 43.36607 #> Geodetic CRS: NAD83 -#> # A tibble: 167 x 8 +#> # A tibble: 167 × 8 #> id gridcode featureid sourcefc areasqkm shape_length shape_area #> * <chr> <int> <int> <chr> <dbl> <dbl> <dbl> -#> 1 catchmentsp.948~ 1085512 13293376 NHDFlow~ 47.8 0.465 0.00530 -#> 2 catchmentsp.948~ 1085714 13293378 NHDFlow~ 3.30 0.0899 0.000366 -#> 3 catchmentsp.948~ 1085651 13293380 NHDFlow~ 19.1 0.247 0.00212 -#> 4 catchmentsp.948~ 1085750 13293382 NHDFlow~ 12.1 0.197 0.00135 -#> 5 catchmentsp.948~ 1085509 13293384 NHDFlow~ 0.291 0.0296 0.0000323 -#> 6 catchmentsp.948~ 1085979 13293386 NHDFlow~ 9.94 0.175 0.00110 -#> 7 catchmentsp.948~ 1085517 13293388 NHDFlow~ 0.154 0.0187 0.0000171 -#> 8 catchmentsp.948~ 1085768 13293390 NHDFlow~ 1.41 0.0612 0.000157 -#> 9 catchmentsp.948~ 1085605 13293392 NHDFlow~ 0.461 0.0393 0.0000511 -#> 10 catchmentsp.948~ 1085893 13293394 NHDFlow~ 0.0796 0.0124 0.00000882 -#> # ... with 157 more rows, and 1 more variable: geometry <MULTIPOLYGON [°]> +#> 1 catchmentsp.948… 1085512 13293376 NHDFlow… 47.8 0.465 0.00530 +#> 2 catchmentsp.948… 1085714 13293378 NHDFlow… 3.30 0.0899 0.000366 +#> 3 catchmentsp.948… 1085651 13293380 NHDFlow… 19.1 0.247 0.00212 +#> 4 catchmentsp.948… 1085750 13293382 NHDFlow… 12.1 0.197 0.00135 +#> 5 catchmentsp.948… 1085509 13293384 NHDFlow… 0.291 0.0296 0.0000323 +#> 6 catchmentsp.948… 1085979 13293386 NHDFlow… 9.94 0.175 0.00110 +#> 7 catchmentsp.948… 1085517 13293388 NHDFlow… 0.154 0.0187 0.0000171 +#> 8 catchmentsp.948… 1085768 13293390 NHDFlow… 1.41 0.0612 0.000157 +#> 9 catchmentsp.948… 1085605 13293392 NHDFlow… 0.461 0.0393 0.0000511 +#> 10 catchmentsp.948… 1085893 13293394 NHDFlow… 0.0796 0.0124 0.00000882 +#> # … with 157 more rows, and 1 more variable: geometry <MULTIPOLYGON [°]> #> #> $NHDArea #> Simple feature collection with 1 feature and 15 fields @@ -362,11 +398,11 @@

Examples

#> Dimension: XY #> Bounding box: xmin: -89.40194 ymin: 43.15016 xmax: -89.36131 ymax: 43.18112 #> Geodetic CRS: NAD83 -#> # A tibble: 1 x 16 +#> # A tibble: 1 × 16 #> id comid fdate resolution gnis_id gnis_name areasqkm #> * <chr> <int> <dttm> <chr> <chr> <chr> <dbl> #> 1 nhdarea.5849 1.47e7 1999-10-28 23:00:00 Medium " " " " 1.36 -#> # ... with 9 more variables: elevation <int>, ftype <chr>, fcode <int>, +#> # … with 9 more variables: elevation <int>, ftype <chr>, fcode <int>, #> # shape_length <dbl>, shape_area <dbl>, onoffnet <int>, purpcode <chr>, #> # purpdesc <chr>, geometry <POLYGON [°]> #> @@ -376,24 +412,24 @@

Examples

#> Dimension: XY #> Bounding box: xmin: -89.72879 ymin: 42.9897 xmax: -89.20939 ymax: 43.40395 #> Geodetic CRS: NAD83 -#> # A tibble: 90 x 23 +#> # A tibble: 90 × 23 #> id comid fdate resolution gnis_id gnis_name areasqkm #> * <chr> <int> <dttm> <chr> <chr> <chr> <dbl> -#> 1 nhdwaterbod~ 1.47e7 1999-10-28 23:00:00 Medium " " " " 1.72 -#> 2 nhdwaterbod~ 1.36e7 1999-10-28 23:00:00 Medium " " " " 0.015 -#> 3 nhdwaterbod~ 1.36e7 1999-10-28 23:00:00 Medium "15769~ "Lake Wi~ 29.0 -#> 4 nhdwaterbod~ 1.36e7 1999-10-28 23:00:00 Medium " " " " 0.018 -#> 5 nhdwaterbod~ 1.36e7 1999-10-28 23:00:00 Medium " " " " 0.016 -#> 6 nhdwaterbod~ 1.36e7 1999-10-28 23:00:00 Medium " " " " 0.014 -#> 7 nhdwaterbod~ 1.33e7 1999-10-28 23:00:00 Medium " " " " 0.062 -#> 8 nhdwaterbod~ 1.33e7 1999-10-28 23:00:00 Medium "15737~ "Schoenb~ 0.473 -#> 9 nhdwaterbod~ 1.33e7 1999-10-28 23:00:00 Medium " " " " 0.045 -#> 10 nhdwaterbod~ 1.33e7 1999-10-28 23:00:00 Medium " " " " 0.123 -#> # ... with 80 more rows, and 16 more variables: elevation <int>, -#> # reachcode <chr>, ftype <chr>, fcode <int>, shape_length <dbl>, -#> # shape_area <dbl>, onoffnet <int>, purpcode <chr>, purpdesc <chr>, -#> # meandepth <dbl>, lakevolume <dbl>, maxdepth <dbl>, meandused <dbl>, -#> # meandcode <chr>, lakearea <dbl>, geometry <POLYGON [°]> +#> 1 nhdwaterbod… 1.47e7 1999-10-28 23:00:00 Medium " " " " 1.72 +#> 2 nhdwaterbod… 1.36e7 1999-10-28 23:00:00 Medium " " " " 0.015 +#> 3 nhdwaterbod… 1.36e7 1999-10-28 23:00:00 Medium "15769… "Lake Wi… 29.0 +#> 4 nhdwaterbod… 1.36e7 1999-10-28 23:00:00 Medium " " " " 0.018 +#> 5 nhdwaterbod… 1.36e7 1999-10-28 23:00:00 Medium " " " " 0.016 +#> 6 nhdwaterbod… 1.36e7 1999-10-28 23:00:00 Medium " " " " 0.014 +#> 7 nhdwaterbod… 1.33e7 1999-10-28 23:00:00 Medium " " " " 0.062 +#> 8 nhdwaterbod… 1.33e7 1999-10-28 23:00:00 Medium "15737… "Schoenb… 0.473 +#> 9 nhdwaterbod… 1.33e7 1999-10-28 23:00:00 Medium " " " " 0.045 +#> 10 nhdwaterbod… 1.33e7 1999-10-28 23:00:00 Medium " " " " 0.123 +#> # … with 80 more rows, and 16 more variables: elevation <int>, reachcode <chr>, +#> # ftype <chr>, fcode <int>, shape_length <dbl>, shape_area <dbl>, +#> # onoffnet <int>, purpcode <chr>, purpdesc <chr>, meandepth <dbl>, +#> # lakevolume <dbl>, maxdepth <dbl>, meandused <dbl>, meandcode <chr>, +#> # lakearea <dbl>, geometry <POLYGON [°]> #> #> $NHDFlowline_NonNetwork #> Simple feature collection with 45 features and 13 fields @@ -401,42 +437,42 @@

Examples

#> Dimension: XY #> Bounding box: xmin: -89.62331 ymin: 43.04214 xmax: -89.25271 ymax: 43.35874 #> Geodetic CRS: NAD83 -#> # A tibble: 45 x 14 +#> # A tibble: 45 × 14 #> id comid fdate resolution gnis_id gnis_name lengthkm #> * <chr> <int> <dttm> <chr> <chr> <chr> <dbl> -#> 1 nhdflowline~ 1.36e7 1999-10-28 19:00:00 Medium " " " " 1.90 -#> 2 nhdflowline~ 1.36e7 1999-10-28 19:00:00 Medium " " " " 1.80 -#> 3 nhdflowline~ 1.36e7 1999-10-28 19:00:00 Medium " " " " 1.39 -#> 4 nhdflowline~ 1.36e7 1999-10-28 19:00:00 Medium " " " " 2.36 -#> 5 nhdflowline~ 1.36e7 1999-10-28 19:00:00 Medium " " " " 1.56 -#> 6 nhdflowline~ 1.36e7 1999-10-28 19:00:00 Medium " " " " 2.87 -#> 7 nhdflowline~ 1.36e7 1999-10-28 19:00:00 Medium " " " " 2.42 -#> 8 nhdflowline~ 1.36e7 1999-10-28 19:00:00 Medium " " " " 2.12 -#> 9 nhdflowline~ 1.36e7 1999-10-28 19:00:00 Medium " " " " 2.19 -#> 10 nhdflowline~ 1.36e7 1999-10-28 19:00:00 Medium " " " " 1.29 -#> # ... with 35 more rows, and 7 more variables: reachcode <chr>, flowdir <chr>, +#> 1 nhdflowline… 1.36e7 1999-10-28 19:00:00 Medium " " " " 1.90 +#> 2 nhdflowline… 1.36e7 1999-10-28 19:00:00 Medium " " " " 1.80 +#> 3 nhdflowline… 1.36e7 1999-10-28 19:00:00 Medium " " " " 1.39 +#> 4 nhdflowline… 1.36e7 1999-10-28 19:00:00 Medium " " " " 2.36 +#> 5 nhdflowline… 1.36e7 1999-10-28 19:00:00 Medium " " " " 1.56 +#> 6 nhdflowline… 1.36e7 1999-10-28 19:00:00 Medium " " " " 2.87 +#> 7 nhdflowline… 1.36e7 1999-10-28 19:00:00 Medium " " " " 2.42 +#> 8 nhdflowline… 1.36e7 1999-10-28 19:00:00 Medium " " " " 2.12 +#> 9 nhdflowline… 1.36e7 1999-10-28 19:00:00 Medium " " " " 2.19 +#> 10 nhdflowline… 1.36e7 1999-10-28 19:00:00 Medium " " " " 1.29 +#> # … with 35 more rows, and 7 more variables: reachcode <chr>, flowdir <chr>, #> # wbareacomi <int>, ftype <chr>, fcode <int>, shape_length <dbl>, #> # geometry <LINESTRING [°]> #> - -sf::st_layers(output_file) + +sf::st_layers(output_file) #> Driver: GPKG #> Available layers: -#> layer_name geometry_type features fields crs_name -#> 1 NHDFlowline_Network Line String 168 138 NAD83 -#> 2 CatchmentSP Multi Polygon 167 7 NAD83 -#> 3 NHDArea Polygon 1 15 NAD83 -#> 4 NHDWaterbody Polygon 90 22 NAD83 -#> 5 NHDFlowline_NonNetwork Line String 45 13 NAD83 - -# NHDPlusHR -source(system.file("extdata/nhdplushr_data.R", package = "nhdplusTools")) - -up_ids <- get_UT(hr_data$NHDFlowline, 15000500028335) - -sub_gpkg <- file.path(work_dir, "sub.gpkg") -sub_nhdhr <- subset_nhdplus(up_ids, output_file = sub_gpkg, - nhdplus_data = hr_gpkg, overwrite = TRUE) +#> layer_name geometry_type features fields +#> 1 NHDFlowline_Network Line String 168 138 +#> 2 CatchmentSP Multi Polygon 167 7 +#> 3 NHDArea Polygon 1 15 +#> 4 NHDWaterbody Polygon 90 22 +#> 5 NHDFlowline_NonNetwork Line String 45 13 + +# NHDPlusHR +source(system.file("extdata/nhdplushr_data.R", package = "nhdplusTools")) + +up_ids <- get_UT(hr_data$NHDFlowline, 15000500028335) + +sub_gpkg <- file.path(work_dir, "sub.gpkg") +sub_nhdhr <- subset_nhdplus(up_ids, output_file = sub_gpkg, + nhdplus_data = hr_gpkg, overwrite = TRUE) #> All intersections performed in latitude/longitude. #> Reading NHDFlowline #> 1000 comids of 1427 @@ -453,28 +489,28 @@

Examples

#> Writing NHDWaterbody #> Reading NHDPlusSink #> No features to write in NHDPlusSink - -sf::st_layers(sub_gpkg) + +sf::st_layers(sub_gpkg) #> Driver: GPKG #> Available layers: -#> layer_name geometry_type features fields crs_name -#> 1 NHDFlowline Line String 1427 57 NAD83 -#> 2 NHDPlusCatchment Multi Polygon 1361 7 NAD83 -#> 3 NHDArea Polygon 8 14 NAD83 -#> 4 NHDWaterbody Polygon 740 15 NAD83 -names(sub_nhdhr) +#> layer_name geometry_type features fields +#> 1 NHDFlowline Line String 1427 57 +#> 2 NHDPlusCatchment Multi Polygon 1361 7 +#> 3 NHDArea Polygon 8 14 +#> 4 NHDWaterbody Polygon 740 15 +names(sub_nhdhr) #> [1] "NHDFlowline" "NHDPlusCatchment" "NHDArea" "NHDWaterbody" #> [5] "NHDPlusSink" - -plot(sf::st_geometry(hr_data$NHDFlowline), lwd = 0.5) -plot(sf::st_geometry(sub_nhdhr$NHDFlowline), lwd = 0.6, col = "red", add = TRUE) + +plot(sf::st_geometry(hr_data$NHDFlowline), lwd = 0.5) +plot(sf::st_geometry(sub_nhdhr$NHDFlowline), lwd = 0.6, col = "red", add = TRUE) - -unlink(output_file) -unlink(sub_gpkg) - -# } - + +unlink(output_file) +unlink(sub_gpkg) + +# } +
@@ -489,7 +525,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/subset_rpu.html b/docs/reference/subset_rpu.html index b54680a4..ce45f800 100644 --- a/docs/reference/subset_rpu.html +++ b/docs/reference/subset_rpu.html @@ -19,7 +19,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -82,7 +82,7 @@

Subset by Raster Processing Unit

-
subset_rpu(fline, rpu, run_make_standalone = TRUE, strict = FALSE)
+
subset_rpu(fline, rpu, run_make_standalone = TRUE, strict = FALSE)
@@ -91,28 +91,37 @@

Arguments

sf data.frame NHD Flowlines with comid, pathlength, lengthkm, hydroseq, levelpathi, rpuid, and arbolatesu (dnhydroseq is required if tocomid is not provided).

+ +
rpu

character e.g. "01a"

+ +
run_make_standalone

logical default TRUE should the run_make_standalone function be run on result?

+ +
strict

logical if TRUE, paths that extend outside the RPU but have no tributaries in the upstream RPU will be included in the output.

+

Value

-

data.frame containing subset network

+ + +

data.frame containing subset network

Examples

-

-source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
-
-sample_flines <- sf::read_sf(sample_data, "NHDFlowline_Network")
-
-subset_rpu(sample_flines, rpu = "07b")
+    

+source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
+
+sample_flines <- sf::read_sf(sample_data, "NHDFlowline_Network")
+
+subset_rpu(sample_flines, rpu = "07b")
 #> Simple feature collection with 267 features and 136 fields
 #> Geometry type: MULTILINESTRING
 #> Dimension:     XYZM
@@ -120,27 +129,27 @@ 

Examples

#> z_range: zmin: 0 zmax: 0 #> m_range: mmin: 0 mmax: 100 #> Geodetic CRS: GRS 1980(IUGG, 1980) -#> # A tibble: 267 x 137 +#> # A tibble: 267 × 137 #> COMID FDATE RESOLUTION GNIS_ID GNIS_NAME LENGTHKM REACHCODE #> <int> <dttm> <chr> <chr> <chr> <dbl> <chr> -#> 1 13296606 1999-10-15 00:00:00 Medium "157707~ "Yahara ~ 0.091 07090002~ -#> 2 13297170 2009-05-01 00:00:00 Medium "157707~ "Yahara ~ 2.85 07090002~ -#> 3 13297160 2009-05-01 00:00:00 Medium "157707~ "Yahara ~ 0.041 07090002~ -#> 4 13293970 1999-10-29 00:00:00 Medium "157707~ "Yahara ~ 0.096 07090002~ -#> 5 13293750 1999-10-29 00:00:00 Medium "157707~ "Yahara ~ 1.72 07090002~ -#> 6 13296614 1999-10-15 00:00:00 Medium " " " " 4.59 07090002~ -#> 7 13297104 1999-10-15 00:00:00 Medium "156066~ "Murphys~ 4.53 07090002~ -#> 8 13297106 1999-10-15 00:00:00 Medium "156066~ "Murphys~ 2.70 07090002~ -#> 9 13294002 1999-10-29 00:00:00 Medium "157516~ "Swan Cr~ 0.111 07090002~ -#> 10 13297098 1999-10-15 00:00:00 Medium "157516~ "Swan Cr~ 1.44 07090002~ -#> # ... with 257 more rows, and 130 more variables: FLOWDIR <chr>, +#> 1 13296606 1999-10-15 00:00:00 Medium "157707… "Yahara … 0.091 07090002… +#> 2 13297170 2009-05-01 00:00:00 Medium "157707… "Yahara … 2.85 07090002… +#> 3 13297160 2009-05-01 00:00:00 Medium "157707… "Yahara … 0.041 07090002… +#> 4 13293970 1999-10-29 00:00:00 Medium "157707… "Yahara … 0.096 07090002… +#> 5 13293750 1999-10-29 00:00:00 Medium "157707… "Yahara … 1.72 07090002… +#> 6 13296614 1999-10-15 00:00:00 Medium " " " " 4.59 07090002… +#> 7 13297104 1999-10-15 00:00:00 Medium "156066… "Murphys… 4.53 07090002… +#> 8 13297106 1999-10-15 00:00:00 Medium "156066… "Murphys… 2.70 07090002… +#> 9 13294002 1999-10-29 00:00:00 Medium "157516… "Swan Cr… 0.111 07090002… +#> 10 13297098 1999-10-15 00:00:00 Medium "157516… "Swan Cr… 1.44 07090002… +#> # … with 257 more rows, and 130 more variables: FLOWDIR <chr>, #> # WBAREACOMI <int>, FTYPE <chr>, FCODE <int>, Shape_Length <dbl>, #> # StreamLeve <int>, StreamOrde <int>, StreamCalc <int>, FromNode <dbl>, #> # ToNode <dbl>, Hydroseq <dbl>, LevelPathI <dbl>, Pathlength <dbl>, #> # TerminalPa <dbl>, ArbolateSu <dbl>, Divergence <int>, StartFlag <int>, #> # TerminalFl <dbl>, DnLevel <dbl>, UpLevelPat <dbl>, UpHydroseq <dbl>, -#> # DnLevelPat <dbl>, DnMinorHyd <dbl>, DnDrainCou <int>, DnHydroseq <dbl>, ... - +#> # DnLevelPat <dbl>, DnMinorHyd <dbl>, DnDrainCou <int>, DnHydroseq <dbl>, … +
@@ -155,7 +164,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/subset_vpu.html b/docs/reference/subset_vpu.html index 1852a5ca..7457a2c3 100644 --- a/docs/reference/subset_vpu.html +++ b/docs/reference/subset_vpu.html @@ -18,7 +18,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -80,7 +80,7 @@

Subset by Vector Processing Unit

-
subset_vpu(fline, vpu, include_null_rpuid = TRUE, run_make_standalone = TRUE)
+
subset_vpu(fline, vpu, include_null_rpuid = TRUE, run_make_standalone = TRUE)
@@ -89,29 +89,38 @@

Arguments

sf data.frame NHD Flowlines with comid, pathlength, lengthkm, hydroseq, levelpathi, rpuid, vpuid, and arbolatesu (dnhydroseq is required if tocomid is not provided).

+ +
vpu

character e.g. "01"

+ +
include_null_rpuid

logical default TRUE. Note that there are some flowlines that may have a NULL rpuid but be included in the vector processing unit.

+ +
run_make_standalone

logical default TRUE should the run_make_standalone function be run on result?

+

Value

-

data.frame containing subset network

+ + +

data.frame containing subset network

Examples

-

-source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
-
-sample_flines <- sf::read_sf(sample_data, "NHDFlowline_Network")
-
-subset_vpu(sample_flines, "07")
+    

+source(system.file("extdata/sample_data.R", package = "nhdplusTools"))
+
+sample_flines <- sf::read_sf(sample_data, "NHDFlowline_Network")
+
+subset_vpu(sample_flines, "07")
 #> Simple feature collection with 267 features and 136 fields
 #> Geometry type: MULTILINESTRING
 #> Dimension:     XYZM
@@ -119,27 +128,27 @@ 

Examples

#> z_range: zmin: 0 zmax: 0 #> m_range: mmin: 0 mmax: 100 #> Geodetic CRS: GRS 1980(IUGG, 1980) -#> # A tibble: 267 x 137 +#> # A tibble: 267 × 137 #> COMID FDATE RESOLUTION GNIS_ID GNIS_NAME LENGTHKM REACHCODE #> * <int> <dttm> <chr> <chr> <chr> <dbl> <chr> -#> 1 13296606 1999-10-15 00:00:00 Medium "157707~ "Yahara ~ 0.091 07090002~ -#> 2 13297170 2009-05-01 00:00:00 Medium "157707~ "Yahara ~ 2.85 07090002~ -#> 3 13297160 2009-05-01 00:00:00 Medium "157707~ "Yahara ~ 0.041 07090002~ -#> 4 13293970 1999-10-29 00:00:00 Medium "157707~ "Yahara ~ 0.096 07090002~ -#> 5 13293750 1999-10-29 00:00:00 Medium "157707~ "Yahara ~ 1.72 07090002~ -#> 6 13296614 1999-10-15 00:00:00 Medium " " " " 4.59 07090002~ -#> 7 13297104 1999-10-15 00:00:00 Medium "156066~ "Murphys~ 4.53 07090002~ -#> 8 13297106 1999-10-15 00:00:00 Medium "156066~ "Murphys~ 2.70 07090002~ -#> 9 13294002 1999-10-29 00:00:00 Medium "157516~ "Swan Cr~ 0.111 07090002~ -#> 10 13297098 1999-10-15 00:00:00 Medium "157516~ "Swan Cr~ 1.44 07090002~ -#> # ... with 257 more rows, and 130 more variables: FLOWDIR <chr>, +#> 1 13296606 1999-10-15 00:00:00 Medium "157707… "Yahara … 0.091 07090002… +#> 2 13297170 2009-05-01 00:00:00 Medium "157707… "Yahara … 2.85 07090002… +#> 3 13297160 2009-05-01 00:00:00 Medium "157707… "Yahara … 0.041 07090002… +#> 4 13293970 1999-10-29 00:00:00 Medium "157707… "Yahara … 0.096 07090002… +#> 5 13293750 1999-10-29 00:00:00 Medium "157707… "Yahara … 1.72 07090002… +#> 6 13296614 1999-10-15 00:00:00 Medium " " " " 4.59 07090002… +#> 7 13297104 1999-10-15 00:00:00 Medium "156066… "Murphys… 4.53 07090002… +#> 8 13297106 1999-10-15 00:00:00 Medium "156066… "Murphys… 2.70 07090002… +#> 9 13294002 1999-10-29 00:00:00 Medium "157516… "Swan Cr… 0.111 07090002… +#> 10 13297098 1999-10-15 00:00:00 Medium "157516… "Swan Cr… 1.44 07090002… +#> # … with 257 more rows, and 130 more variables: FLOWDIR <chr>, #> # WBAREACOMI <int>, FTYPE <chr>, FCODE <int>, Shape_Length <dbl>, #> # StreamLeve <int>, StreamOrde <int>, StreamCalc <int>, FromNode <dbl>, #> # ToNode <dbl>, Hydroseq <dbl>, LevelPathI <dbl>, Pathlength <dbl>, #> # TerminalPa <dbl>, ArbolateSu <dbl>, Divergence <int>, StartFlag <int>, #> # TerminalFl <dbl>, DnLevel <dbl>, UpLevelPat <dbl>, UpHydroseq <dbl>, -#> # DnLevelPat <dbl>, DnMinorHyd <dbl>, DnDrainCou <int>, DnHydroseq <dbl>, ... - +#> # DnLevelPat <dbl>, DnMinorHyd <dbl>, DnDrainCou <int>, DnHydroseq <dbl>, … +
@@ -154,7 +163,7 @@

Examples

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/reference/vpu_boundaries.html b/docs/reference/vpu_boundaries.html index 016188bf..77f3e919 100644 --- a/docs/reference/vpu_boundaries.html +++ b/docs/reference/vpu_boundaries.html @@ -20,7 +20,7 @@ nhdplusTools - 0.5.3 + 0.5.6 @@ -83,7 +83,7 @@

VPU Boundaries
-
vpu_boundaries
+
vpu_boundaries
@@ -103,7 +103,7 @@

Format

-

Site built with pkgdown 2.0.2.

+

Site built with pkgdown 2.0.5.

diff --git a/docs/sitemap.xml b/docs/sitemap.xml index db30ca03..172b298e 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -84,6 +84,9 @@ https://usgs-r.github.io/nhdplusTools/reference/fix_flowdir.html + + https://usgs-r.github.io/nhdplusTools/reference/get_boundaries.html + https://usgs-r.github.io/nhdplusTools/reference/get_DD.html @@ -150,6 +153,9 @@ https://usgs-r.github.io/nhdplusTools/reference/get_path_lengths.html + + https://usgs-r.github.io/nhdplusTools/reference/get_path_members.html + https://usgs-r.github.io/nhdplusTools/reference/get_pfaf.html diff --git a/vignettes/levelpath.gif b/vignettes/levelpath.gif index b055f71d..76456cd1 100644 Binary files a/vignettes/levelpath.gif and b/vignettes/levelpath.gif differ