diff --git a/R/get_nldi.R b/R/get_nldi.R index b51b20b6..c35d8371 100644 --- a/R/get_nldi.R +++ b/R/get_nldi.R @@ -105,14 +105,12 @@ type_check <- function(type) { #' nldi_nwis <- list(featureSource = "nwissite", featureID = "USGS-05428500") #' #' navigate_nldi(nldi_feature = nldi_nwis, -#' mode = "upstreamTributaries", -#' data_source = "") %>% +#' mode = "upstreamTributaries") %>% #' st_geometry() %>% #' plot() #' #' navigate_nldi(nldi_feature = nldi_nwis, -#' mode = "UM", -#' data_source = "") %>% +#' mode = "UM") %>% #' st_geometry() %>% #' plot(col = "blue", add = TRUE) #' @@ -148,7 +146,10 @@ navigate_nldi <- function(nldi_feature, mode = "upstreamMain", } # For backward compatibility - if(data_source == "flowline") data_source <- "flowlines" + if(data_source == "flowline" | data_source == "") { + data_source <- "flowlines" + warning("data source specified as flowline or '' is deprecated") + } query <- paste(nldi_feature[["featureSource"]], nldi_feature[["featureID"]], diff --git a/docs/articles/nhdplusTools.html b/docs/articles/nhdplusTools.html index c86f41f9..c51b24b1 100644 --- a/docs/articles/nhdplusTools.html +++ b/docs/articles/nhdplusTools.html @@ -38,7 +38,7 @@ nhdplusTools - 0.3.14 + 0.3.15 @@ -127,7 +127,7 @@

flowline <- navigate_nldi(list(featureSource = "comid", featureID = start_comid), mode = "upstreamTributaries", - data_source = "") + distance_km = 1000) subset_file <- tempfile(fileext = ".gpkg") subset <- subset_nhdplus(comids = flowline$nhdplus_comid, @@ -187,15 +187,15 @@

nhdplus_path(file.path(temp_dir, "natseamless.gpkg"))
 
 nhdplus_path()
-#> [1] "C:\\Users\\DBLODG~1\\AppData\\Local\\Temp\\4\\Rtmp4UXaWl/natseamless.gpkg"
+#> [1] "C:\\Users\\DBLODG~1\\AppData\\Local\\Temp\\4\\RtmpYREQZO/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(staged_data)
 #> List of 3
-#>  $ attributes: chr "C:\\Users\\DBLODG~1\\AppData\\Local\\Temp\\4\\Rtmp4UXaWl/nhdplus_flowline_attributes.rds"
-#>  $ flowline  : chr "C:\\Users\\DBLODG~1\\AppData\\Local\\Temp\\4\\Rtmp4UXaWl/nhdplus_flowline.rds"
-#>  $ catchment : chr "C:\\Users\\DBLODG~1\\AppData\\Local\\Temp\\4\\Rtmp4UXaWl/nhdplus_catchment.rds"
+#> $ attributes: chr "C:\\Users\\DBLODG~1\\AppData\\Local\\Temp\\4\\RtmpYREQZO/nhdplus_flowline_attributes.rds" +#> $ flowline : chr "C:\\Users\\DBLODG~1\\AppData\\Local\\Temp\\4\\RtmpYREQZO/nhdplus_flowline.rds" +#> $ catchment : chr "C:\\Users\\DBLODG~1\\AppData\\Local\\Temp\\4\\RtmpYREQZO/nhdplus_catchment.rds"

As you can see, 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]
@@ -283,21 +283,21 @@ 

nldi_feature <- list(featureSource = "comid", featureID = start_comid) discover_nldi_navigation(nldi_feature) #> $upstreamMain -#> [1] "https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/13293750/navigate/UM" +#> [1] "https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/13293750/navigation/UM" #> #> $upstreamTributaries -#> [1] "https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/13293750/navigate/UT" +#> [1] "https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/13293750/navigation/UT" #> #> $downstreamMain -#> [1] "https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/13293750/navigate/DM" +#> [1] "https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/13293750/navigation/DM" #> #> $downstreamDiversions -#> [1] "https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/13293750/navigate/DD"

+#> [1] "https://labs.waterdata.usgs.gov/api/nldi/linked-data/comid/13293750/navigation/DD"

The discover_nldi_navigation function is a handy way to make sure the featureID is available for the chosen “featureSource” as well as find valid navigation modes to be used with navigate_nldi. 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",
-                               data_source = "")
+                               distance_km = 1000)
 
 plot(sf::st_geometry(flowline), lwd = 3, col = "black")
 plot(sf::st_geometry(flowline_nldi), lwd = 1, col = "red", add = TRUE)
@@ -334,7 +334,7 @@

flowline_nldi <- navigate_nldi(nldi_feature, mode = "upstreamTributaries", - data_source = "") + distance_km = 1000) output_file_nwis <- file.path(temp_dir, "subset_download_nwis.gpkg") @@ -357,7 +357,8 @@

upstream_nwis <- navigate_nldi(nldi_feature, mode = "upstreamTributaries", - data_source = "nwissite") + data_source = "nwissite", + distance_km = 1000) plot(sf::st_geometry(flowline_nwis), lwd = 3, col = "blue") @@ -483,7 +484,7 @@

Refactoring

-

The NHDPlus tools package has been developed in support of an experimental NHDPlus refactoring workflow to normalize the size of catchments and resolve particular network locations. If this work is of interest, it can be found in the network_refactor branch of this repository.

+

The NHDPlus tools package has been developed in support of an experimental NHDPlus refactoring workflow to normalize the size of catchments and resolve particular network locations. If this work is of interest, it can be found here.

diff --git a/docs/news/index.html b/docs/news/index.html index a4c08424..e4b02b10 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -150,6 +150,7 @@