diff --git a/docs/apple-touch-icon-120x120.png b/docs/apple-touch-icon-120x120.png index d2adb709..5ef57fbc 100644 Binary files a/docs/apple-touch-icon-120x120.png and b/docs/apple-touch-icon-120x120.png differ diff --git a/docs/apple-touch-icon-152x152.png b/docs/apple-touch-icon-152x152.png index 60d28d9c..f81abd51 100644 Binary files a/docs/apple-touch-icon-152x152.png and b/docs/apple-touch-icon-152x152.png differ diff --git a/docs/apple-touch-icon-180x180.png b/docs/apple-touch-icon-180x180.png index 7fd895ab..ab373aa8 100644 Binary files a/docs/apple-touch-icon-180x180.png and b/docs/apple-touch-icon-180x180.png differ diff --git a/docs/apple-touch-icon-60x60.png b/docs/apple-touch-icon-60x60.png index b6419b84..eac0aac9 100644 Binary files a/docs/apple-touch-icon-60x60.png and b/docs/apple-touch-icon-60x60.png differ diff --git a/docs/apple-touch-icon-76x76.png b/docs/apple-touch-icon-76x76.png index 22541997..9d359a42 100644 Binary files a/docs/apple-touch-icon-76x76.png and b/docs/apple-touch-icon-76x76.png differ diff --git a/docs/apple-touch-icon.png b/docs/apple-touch-icon.png index 18b3e92f..0d26c4b8 100644 Binary files a/docs/apple-touch-icon.png and b/docs/apple-touch-icon.png differ diff --git a/docs/articles/nhdplusTools.html b/docs/articles/nhdplusTools.html index 8456399a..95fe218f 100644 --- a/docs/articles/nhdplusTools.html +++ b/docs/articles/nhdplusTools.html @@ -115,6 +115,7 @@
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 as described in the Discovery and Subsetting section. For large subsets, greater than a few thousand square kilometers, you can download the National Seamless database at this web page. You will need 7z or the archive
package to extract it.
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 as described in the Discovery and Subsetting section. For large subsets, greater than a few thousand square kilometers, you can download the National Seamless database at this web page. You will need 7z or the archive
package to extract it.
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"))
nhdplus_path()
-#> [1] "C:\\Users\\DBLODG~1\\AppData\\Local/usgs_r/nhdplusTools/nhdpt_v_cache/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\\1\\RtmpKeO6lA/nhdplus_flowline_attributes.rds"
-#> $ flowline : chr "C:\\Users\\DBLODG~1\\AppData\\Local\\Temp\\1\\RtmpKeO6lA/nhdplus_flowline.rds"
-#> $ catchment : chr "C:\\Users\\DBLODG~1\\AppData\\Local\\Temp\\1\\RtmpKeO6lA/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.frame
s 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)
@@ -226,13 +228,8 @@
#> Driver: GPKG
#> Available layers:
#> layer_name geometry_type features fields
-#> 1 NHDWaterbody Polygon 1044 15
-#> 2 NHDArea Polygon 10 14
-#> 3 NHDLine Line String 142 12
-#> 4 NHDPlusSink Point 1 10
-#> 5 NHDPoint 3D Point 7 10
-#> 6 NHDFlowline Line String 2691 57
-#> 7 NHDPlusCatchment Multi Polygon 2603 7
+#> 1 NHDFlowline Line String 2691 57
+#> 2 NHDPlusCatchment Multi Polygon 2603 7
names(hr_data)
#> [1] "NHDFlowline" "NHDPlusCatchment"
unlink(out_gpkg)
@@ -326,6 +323,7 @@
overwrite = TRUE)
#> All intersections performed in latitude/longitude.
#> Reading NHDFlowline_Network
+#> Found invalid geometry, attempting to fix.
#> Writing NHDFlowline_Network
sf::st_layers(output_file_download)
@@ -361,6 +359,7 @@
return_data = FALSE, overwrite = TRUE)
#> All intersections performed in latitude/longitude.
#> Reading NHDFlowline_Network
+#> Found invalid geometry, attempting to fix.
#> Writing NHDFlowline_Network
sf::st_layers(output_file_download)
@@ -452,7 +451,7 @@
#> Available layers:
#> layer_name geometry_type features fields
#> 1 NHDFlowline_Network Line String 168 136
-#> 2 CatchmentSP 167 6
+#> 2 CatchmentSP Polygon 167 6
#> 3 NHDArea Polygon 1 14
#> 4 NHDWaterbody Polygon 90 21
#> 5 NHDFlowline_NonNetwork Line String 45 12
diff --git a/docs/articles/nhdplusTools_files/figure-html/nldi_nwissite-1.png b/docs/articles/nhdplusTools_files/figure-html/nldi_nwissite-1.png
index 79e583a0..5d4e5450 100644
Binary files a/docs/articles/nhdplusTools_files/figure-html/nldi_nwissite-1.png and b/docs/articles/nhdplusTools_files/figure-html/nldi_nwissite-1.png differ
diff --git a/docs/articles/nhdplusTools_files/figure-html/plot_result-1.png b/docs/articles/nhdplusTools_files/figure-html/plot_result-1.png
index 9ac13a09..d5e9b008 100644
Binary files a/docs/articles/nhdplusTools_files/figure-html/plot_result-1.png and b/docs/articles/nhdplusTools_files/figure-html/plot_result-1.png differ
diff --git a/docs/articles/nhdplusTools_files/figure-html/subset_nhdplus_download-1.png b/docs/articles/nhdplusTools_files/figure-html/subset_nhdplus_download-1.png
index 9b22cb7f..82c2ace4 100644
Binary files a/docs/articles/nhdplusTools_files/figure-html/subset_nhdplus_download-1.png and b/docs/articles/nhdplusTools_files/figure-html/subset_nhdplus_download-1.png differ
diff --git a/docs/articles/nhdplusTools_files/figure-html/tldr-1.png b/docs/articles/nhdplusTools_files/figure-html/tldr-1.png
index caf72601..74de63e4 100644
Binary files a/docs/articles/nhdplusTools_files/figure-html/tldr-1.png and b/docs/articles/nhdplusTools_files/figure-html/tldr-1.png differ
diff --git a/docs/articles/nhdplushr.html b/docs/articles/nhdplushr.html
index 41505d72..32ff0457 100644
--- a/docs/articles/nhdplushr.html
+++ b/docs/articles/nhdplushr.html
@@ -113,6 +113,7 @@
library(nhdplusTools)
library(sf)
+#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
work_dir <- file.path(nhdplusTools_data_dir(), "hr_v_cache")
@@ -123,14 +124,14 @@
# 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)
-#> although coordinates are longitude/latitude, st_union assumes that they are planar
-#> Zoom: 11
-#> 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.
+ 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
@@ -142,58 +143,57 @@
(start_index <- get_flowline_index(st_transform(hr$NHDFlowline, 5070),
st_transform(plot_data$outlets, 5070),
- search_radius = 200)) # meters albers eq area
-#> # A tibble: 1 x 5
-#> id COMID REACHCODE REACH_meas offset
-#> <int> <dbl> <chr> <dbl> <dbl>
-#> 1 1 2.20e13 07090002006114 37.7 87.7
-
-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
+ search_radius = 200)) # meters albers eq area
+#> # A tibble: 1 x 5
+#> id COMID REACHCODE REACH_meas offset
+#> <int> <dbl> <chr> <dbl> <dbl>
+#> 1 1 2.20e13 07090002006114 37.7 87.7
+
+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)
-#> although coordinates are longitude/latitude, st_union assumes that they are planar
-#> Zoom: 11
-#> 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) + 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)
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"
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"
- +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))-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.
-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")
+
+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.
-
+
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
+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
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 = 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), + 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")
@@ -281,7 +275,7 @@
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) @@ -297,71 +291,69 @@
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>, -#> # StreamCalc <int>, FromNode <dbl>, ToNode <dbl>, Hydroseq <dbl>, -#> # LevelPathI <dbl>, Pathlength <dbl>, TerminalPa <dbl>, ArbolateSu <dbl>, -#> # Divergence <int>, StartFlag <int>, TerminalFl <int>, UpLevelPat <dbl>, -#> # UpHydroSeq <dbl>, DnLevel <int>, DnLevelPat <dbl>, DnHydroseq <dbl>, -#> # DnMinorHyd <dbl>, DnDrainCou <int>, FromMeas <dbl>, ToMeas <dbl>, -#> # RtnDiv <int>, Thinner <int>, VPUIn <int>, VPUOut <int>, AreaSqKM <dbl>, -#> # TotDASqKM <dbl>, DivDASqKm <dbl>, MaxElevRaw <dbl>, MinElevRaw <dbl>, -#> # MaxElevSmo <dbl>, MinElevSmo <dbl>, Slope <dbl>, SlopeLenKm <dbl>, -#> # ElevFixed <int>, HWType <int>, HWNodeSqKm <dbl>, StatusFlag <chr>
--(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_Identi~ FDate Resolution GNIS_ID GNIS_Name LENGTHKM -#> * <chr> <dttm> <int> <chr> <chr> <dbl> -#> 1 156038282 2012-03-19 01:32:25 2 004155~ Pecatonica~ 1.34 -#> 2 155714162 2014-10-28 19:00:00 2 004248~ Fairfield ~ 0.417 -#> 3 156035374 2012-03-19 01:35:08 2 015619~ Gordon Cre~ 0.39 -#> 4 145600320 2012-03-19 01:34:47 2 004168~ Rock Creek 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 River 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 Fork~ 0.665 -#> 9 143246785 2012-03-18 12:56:42 2 004168~ Rock River 0.165 -#> 10 155712415 2012-03-19 02:05:51 2 004241~ Willow Cre~ 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>, -#> # Divergence <int>, StartFlag <int>, TerminalFl <dbl>, UpLevelPat <dbl>, -#> # UpHydroSeq <dbl>, DnLevel <dbl>, DnLevelPat <dbl>, DnHydroseq <dbl>, -#> # DnMinorHyd <dbl>, DnDrainCou <int>, FromMeas <dbl>, ToMeas <dbl>, -#> # RtnDiv <int>, Thinner <int>, VPUIn <int>, VPUOut <int>, AreaSqKM <dbl>, -#> # TotDASqKM <dbl>, DivDASqKm <dbl>, MaxElevRaw <dbl>, MinElevRaw <dbl>, -#> # MaxElevSmo <dbl>, MinElevSmo <dbl>, Slope <dbl>, SlopeLenKm <dbl>, -#> # ElevFixed <int>, HWType <int>, HWNodeSqKm <dbl>, StatusFlag <chr>
- +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>, +#> # StreamCalc <int>, FromNode <dbl>, ToNode <dbl>, Hydroseq <dbl>, +#> # LevelPathI <dbl>, Pathlength <dbl>, TerminalPa <dbl>, ArbolateSu <dbl>, +#> # Divergence <int>, StartFlag <int>, TerminalFl <int>, UpLevelPat <dbl>, +#> # UpHydroSeq <dbl>, DnLevel <int>, DnLevelPat <dbl>, DnHydroseq <dbl>, +#> # DnMinorHyd <dbl>, DnDrainCou <int>, FromMeas <dbl>, ToMeas <dbl>, +#> # RtnDiv <int>, Thinner <int>, VPUIn <int>, VPUOut <int>, AreaSqKM <dbl>, +#> # TotDASqKM <dbl>, DivDASqKm <dbl>, MaxElevRaw <dbl>, MinElevRaw <dbl>, +#> # MaxElevSmo <dbl>, MinElevSmo <dbl>, Slope <dbl>, SlopeLenKm <dbl>, +#> # ElevFixed <int>, HWType <int>, HWNodeSqKm <dbl>, StatusFlag <chr> +(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_Identi~ FDate Resolution GNIS_ID GNIS_Name LENGTHKM +#> * <chr> <dttm> <int> <chr> <chr> <dbl> +#> 1 156038282 2012-03-19 01:32:25 2 004155~ Pecatonica~ 1.34 +#> 2 155714162 2014-10-28 19:00:00 2 004248~ Fairfield ~ 0.417 +#> 3 156035374 2012-03-19 01:35:08 2 015619~ Gordon Cre~ 0.39 +#> 4 145600320 2012-03-19 01:34:47 2 004168~ Rock Creek 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 River 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 Fork~ 0.665 +#> 9 143246785 2012-03-18 12:56:42 2 004168~ Rock River 0.165 +#> 10 155712415 2012-03-19 02:05:51 2 004241~ Willow Cre~ 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>, +#> # Divergence <int>, StartFlag <int>, TerminalFl <dbl>, UpLevelPat <dbl>, +#> # UpHydroSeq <dbl>, DnLevel <dbl>, DnLevelPat <dbl>, DnHydroseq <dbl>, +#> # DnMinorHyd <dbl>, DnDrainCou <int>, FromMeas <dbl>, ToMeas <dbl>, +#> # RtnDiv <int>, Thinner <int>, VPUIn <int>, VPUOut <int>, AreaSqKM <dbl>, +#> # TotDASqKM <dbl>, DivDASqKm <dbl>, MaxElevRaw <dbl>, MinElevRaw <dbl>, +#> # MaxElevSmo <dbl>, MinElevSmo <dbl>, Slope <dbl>, SlopeLenKm <dbl>, +#> # ElevFixed <int>, HWType <int>, HWNodeSqKm <dbl>, StatusFlag <chr> + +plot(st_geometry(standalone))-plot(st_geometry(standalone))
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)
+#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(nhdplusTools)
nwissite <- list(featureSource = "nwissite",
featureID = "USGS-05428500")
diff --git a/docs/articles/plot_nhdplus_files/figure-html/bbox_plotting-1.png b/docs/articles/plot_nhdplus_files/figure-html/bbox_plotting-1.png
index 7c034425..ebd82bc2 100644
Binary files a/docs/articles/plot_nhdplus_files/figure-html/bbox_plotting-1.png and b/docs/articles/plot_nhdplus_files/figure-html/bbox_plotting-1.png differ
diff --git a/docs/articles/plot_nhdplus_files/figure-html/nwis_simple1-1.png b/docs/articles/plot_nhdplus_files/figure-html/nwis_simple1-1.png
index 73f3debb..dc323ea8 100644
Binary files a/docs/articles/plot_nhdplus_files/figure-html/nwis_simple1-1.png and b/docs/articles/plot_nhdplus_files/figure-html/nwis_simple1-1.png differ
diff --git a/docs/articles/plot_nhdplus_files/figure-html/nwis_simple2-1.png b/docs/articles/plot_nhdplus_files/figure-html/nwis_simple2-1.png
index e220a5f1..9b7009a8 100644
Binary files a/docs/articles/plot_nhdplus_files/figure-html/nwis_simple2-1.png and b/docs/articles/plot_nhdplus_files/figure-html/nwis_simple2-1.png differ
diff --git a/docs/articles/plot_nhdplus_files/figure-html/plot_styles-1.png b/docs/articles/plot_nhdplus_files/figure-html/plot_styles-1.png
index 4a0228a2..65556a9f 100644
Binary files a/docs/articles/plot_nhdplus_files/figure-html/plot_styles-1.png and b/docs/articles/plot_nhdplus_files/figure-html/plot_styles-1.png differ
diff --git a/docs/articles/plot_nhdplus_files/figure-html/point_location-1.png b/docs/articles/plot_nhdplus_files/figure-html/point_location-1.png
index e6fafd51..c17e03ad 100644
Binary files a/docs/articles/plot_nhdplus_files/figure-html/point_location-1.png and b/docs/articles/plot_nhdplus_files/figure-html/point_location-1.png differ
diff --git a/docs/articles/plot_nhdplus_files/figure-html/two_outlets-1.png b/docs/articles/plot_nhdplus_files/figure-html/two_outlets-1.png
index e220a5f1..9b7009a8 100644
Binary files a/docs/articles/plot_nhdplus_files/figure-html/two_outlets-1.png and b/docs/articles/plot_nhdplus_files/figure-html/two_outlets-1.png differ
diff --git a/docs/articles/point_indexing.html b/docs/articles/point_indexing.html
index cb6ef392..93fa5c9a 100644
--- a/docs/articles/point_indexing.html
+++ b/docs/articles/point_indexing.html
@@ -124,7 +124,7 @@
search_radius = 0.01,
max_matches = 1)
-indexes <- left_join(sf::st_sf(id = c(1:nrow(gages)),
+indexes <- left_join(sf::st_sf(id = c(1:nrow(gages)),
geom = sf::st_geometry(gages)),
indexes, by = "id")
@@ -172,8 +172,9 @@
sf::st_geometry(gages),
search_radius = 0.1,
precision = 10)
+#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
-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)
@@ -215,14 +216,11 @@
search_radius = 0.01,
max_matches = 10)
-indexes <- left_join(sf::st_sf(id = 1,
+indexes <- left_join(sf::st_sf(id = 1,
geom = sf::st_geometry(gages)[42]),
indexes, by = "id")
plot(sf::st_geometry(sf::st_buffer(indexes, 0.005)), border = NA)
-#> Warning in st_buffer.sfc(st_geometry(x), dist, nQuadSegs, endCapStyle =
-#> endCapStyle, : st_buffer does not correctly buffer longitude/latitude data
-#> dist is assumed to be in decimal degrees (arc_degrees).
plot(sf::st_geometry(indexes), add = TRUE)
plot(sf::st_geometry(sf::st_zm(flowlines)), col = "blue", add = TRUE)
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))),
+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)),
diff --git a/docs/articles/point_indexing_files/figure-html/multi-1.png b/docs/articles/point_indexing_files/figure-html/multi-1.png
index a12225ff..71b4c943 100644
Binary files a/docs/articles/point_indexing_files/figure-html/multi-1.png and b/docs/articles/point_indexing_files/figure-html/multi-1.png differ
diff --git a/docs/favicon-16x16.png b/docs/favicon-16x16.png
index feff5062..114d8222 100644
Binary files a/docs/favicon-16x16.png and b/docs/favicon-16x16.png differ
diff --git a/docs/favicon-32x32.png b/docs/favicon-32x32.png
index b706c6e2..de895fd9 100644
Binary files a/docs/favicon-32x32.png and b/docs/favicon-32x32.png differ
diff --git a/docs/index.html b/docs/index.html
index 29a8e31a..ed9a3c2b 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -201,6 +201,12 @@
devtools::build()
In addition to typical R package checking, a Dockerfile is included in this repository. Once built, it can be run with the following command.
+docker run --rm -it -v %cd%:/src nhdplustools_test /bin/bash -c "cp -r /src/* /check/ && cp /src/.Rbuildignore /check/ && cd /check && Rscript -e 'devtools::build()' && R CMD check --as-cran ../nhdplusTools_*"
+data.frame with added attributes
diff --git a/docs/reference/align_nhdplus_names.html b/docs/reference/align_nhdplus_names.html
index adc5e74f..3253ecfe 100644
--- a/docs/reference/align_nhdplus_names.html
+++ b/docs/reference/align_nhdplus_names.html
@@ -158,7 +158,7 @@ Arg
Value
-
a renamed sf
object
+ data.frame renamed sf
object
Examples
source(system.file("extdata/new_hope_data.R", package = "nhdplusTools"))
diff --git a/docs/reference/disambiguate_flowline_indexes.html b/docs/reference/disambiguate_flowline_indexes.html
index 6f2f2b99..e7ee6c9f 100644
--- a/docs/reference/disambiguate_flowline_indexes.html
+++ b/docs/reference/disambiguate_flowline_indexes.html
@@ -179,7 +179,7 @@ Arg
Value
-
The indexes data.frame 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.
diff --git a/docs/reference/discover_nldi_characteristics.html b/docs/reference/discover_nldi_characteristics.html
index bdb78fa8..79be6a2e 100644
--- a/docs/reference/discover_nldi_characteristics.html
+++ b/docs/reference/discover_nldi_characteristics.html
@@ -156,6 +156,9 @@ Arg
+ Value
+
+
data.frame containing available characteristics
Examples
chars <- discover_nldi_characteristics()
diff --git a/docs/reference/download_nhdplushr.html b/docs/reference/download_nhdplushr.html
index a1dcf8fa..755a5ea3 100644
--- a/docs/reference/download_nhdplushr.html
+++ b/docs/reference/download_nhdplushr.html
@@ -169,13 +169,12 @@ Arg
Value
-
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))
#> Found invalid geometry, attempting to fix.
-#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
(hu <- substr(hu$huc8, 1, 2))
#> [1] "01"
diff --git a/docs/reference/download_nhdplusv2.html b/docs/reference/download_nhdplusv2.html
index 837c6555..254631d6 100644
--- a/docs/reference/download_nhdplusv2.html
+++ b/docs/reference/download_nhdplusv2.html
@@ -181,7 +181,7 @@ Arg
Value
-
the path to the local geodatabase
+ character path to the local geodatabase
Examples
if (FALSE) {
diff --git a/docs/reference/download_rf1.html b/docs/reference/download_rf1.html
index 8e891a3a..175fd1fb 100644
--- a/docs/reference/download_rf1.html
+++ b/docs/reference/download_rf1.html
@@ -172,7 +172,7 @@ Arg
Value
-
the path to the local e00 file
+ character path to the local e00 file
Examples
if (FALSE) {
diff --git a/docs/reference/download_vaa.html b/docs/reference/download_vaa.html
index b05f1f67..ef59df42 100644
--- a/docs/reference/download_vaa.html
+++ b/docs/reference/download_vaa.html
@@ -164,7 +164,7 @@ Arg
Value
-
path to cached data
+ character path to cached data
Details
The VAA data is a aggregate table of information from the NHDPlusV2
diff --git a/docs/reference/download_wbd.html b/docs/reference/download_wbd.html
index 23c169d3..96ceb475 100644
--- a/docs/reference/download_wbd.html
+++ b/docs/reference/download_wbd.html
@@ -177,7 +177,7 @@
Arg
Value
-
the path to the local geodatabase
+ character path to the local geodatabase
Examples
if (FALSE) {
diff --git a/docs/reference/get_flowline_index.html b/docs/reference/get_flowline_index.html
index c731cdf1..a0b3f2a1 100644
--- a/docs/reference/get_flowline_index.html
+++ b/docs/reference/get_flowline_index.html
@@ -203,6 +203,7 @@ Details
the flowlines.
Note 4: See `dfMaxLength` input to sf::st_segmentize() for details of
handling of precision parameter.
+Note 5: "from" is downstream -- 0 is the outlet "to" is upstream -- 100 is the inlet
Examples
# \donttest{
@@ -222,8 +223,6 @@ Examp
sf::st_sfc(sf::st_point(c(-76.87479,
39.48233)),
crs = 4326))
-#> Warning: st_buffer does not correctly buffer longitude/latitude data
-#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
#> # A tibble: 1 x 5
#> id COMID REACHCODE REACH_meas offset
#> <int> <int> <chr> <dbl> <dbl>
diff --git a/docs/reference/get_hr_data.html b/docs/reference/get_hr_data.html
index e84718f1..31c371ef 100644
--- a/docs/reference/get_hr_data.html
+++ b/docs/reference/get_hr_data.html
@@ -186,6 +186,9 @@ Arg
+ Value
+
+
sf data.frame containing requested data