Calls the 3DHP_all web service and returns sf data.frames for the selected layers. See https://hydro.nationalmap.gov/arcgis/rest/services/3DHP_all/MapServer for source data documentation.
get_3dhp(
AOI = NULL,
ids = NULL,
type = NULL,
universalreferenceid = NULL,
t_srs = NULL,
buffer = 0.5,
page_size = 2000
)
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.
character vector of id3dhp ids or mainstem uris
character. Type of feature to return ("hydrolocation", "flowline", "waterbody", "drainage area", "catchment"). If NULL (default) a data.frame of available resources is returned
character vector of hydrolocation universal reference ids such as reachcodes
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.
numeric. The amount (in meters) to buffer a POINT AOI by for an extended search. Default = 0.5
numeric default number of features to request at a time. Reducing may help if 500 errors are experienced.
a simple features (sf) object or valid types if no type supplied
The returned object(s) will have the same
Spatial Reference System (SRS) as the input AOI. If a individual or set of
IDs are used to query, then the default CRS of EPSG:4269 is
preserved. In all cases, a user-defined SRS can be passed to t_srs
which will override all previous SRS (either input or default).
All buffer and distance operations are handled internally using in
EPSG:5070 Albers Equal Area projection
# \donttest{
AOI <- sf::st_as_sfc(sf::st_bbox(c(xmin = -89.56684, ymin = 42.99816,
xmax = -89.24681, ymax = 43.17192),
crs = "+proj=longlat +datum=WGS84 +no_defs"))
# get flowlines and hydrolocations
flowlines <- get_3dhp(AOI = AOI, type = "flowline")
hydrolocation <- get_3dhp(AOI = AOI, type = "hydrolocation")
#> Warning: No sink, spring, waterbody outlet features found in area of interest.
#> Warning: No headwater, terminus, divergence, confluence, catchment outlet features found in area of interest.
waterbody <- get_3dhp(AOI = AOI, type = "waterbody")
if(!is.null(waterbody) & !is.null(flowlines) & !is.null(hydrolocation)) {
plot(sf::st_geometry(waterbody), col = "lightblue", border = "lightgrey")
plot(sf::st_geometry(flowlines), col = "blue", add = TRUE)
plot(sf::st_geometry(hydrolocation), col = "grey", pch = "+", add = TRUE) }
# given mainstem ids from any source, can query for them in ids.
CO <- get_3dhp(ids = "https://geoconnex.us/ref/mainstems/29559",
type = "flowline")
#> Getting features 0 to 2000 of 4467
#> Getting features 2000 to 4000 of 4467
#> Getting features 4000 to 4467 of 4467
if(!is.null(CO))
plot(sf::st_geometry(CO), col = "blue")
# get all the waterbodies along the CO river
CO_wb <- get_3dhp(ids = unique(CO$waterbodyid3dhp), type = "waterbody")
if(!is.null(CO_wb)) {
plot(sf::st_geometry(CO_wb[grepl("Powell", CO_wb$gnisidlabel),]),
col = "blue", border = "NA") }
# given universalreferenceid (reachcodes), can query for them but only
# for hydrolocations. This is useful for looking up mainstem ids.
get_3dhp(universalreferenceid = unique(hydrolocation$universalreferenceid),
type = "hydrolocation")
#> Warning: No sink, spring, waterbody outlet features found in area of interest.
#> Warning: No headwater, terminus, divergence, confluence, catchment outlet features found in area of interest.
#> Simple feature collection with 558 features and 10 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: -89.60105 ymin: 42.98449 xmax: -89.23181 ymax: 43.19571
#> Geodetic CRS: WGS 84
#> First 10 features:
#> id3dhp featuredate mainstemid
#> 1 01HAK1Q 1.69465e+12 https://geoconnex.us/ref/mainstems/437170
#> 2 01HAK1R 1.69465e+12 https://geoconnex.us/ref/mainstems/437170
#> 3 01HAL98 1.69465e+12 https://geoconnex.us/usgs/mainstems/9985579
#> 4 01HBUU9 1.69465e+12 https://geoconnex.us/usgs/mainstems/2171769
#> 5 01HBUUH 1.69465e+12 https://geoconnex.us/usgs/mainstems/10678439
#> 6 01HBUV1 1.69465e+12 https://geoconnex.us/usgs/mainstems/3994119
#> 7 01HBUV3 1.69465e+12 https://geoconnex.us/usgs/mainstems/12977726
#> 8 01HBUV6 1.69465e+12 https://geoconnex.us/usgs/mainstems/9466058
#> 9 01HBUVC 1.69465e+12 https://geoconnex.us/usgs/mainstems/7547107
#> 10 01HBUVP 1.69465e+12 https://geoconnex.us/ref/mainstems/666526
#> universalreferenceid gnisid gnisidlabel featuretype featuretypelabel
#> 1 07070005000218 1561862 Black Earth Creek 10 Reachcode Start
#> 2 07070005000219 1561862 Black Earth Creek 10 Reachcode Start
#> 3 07070005001966 NA <NA> 10 Reachcode Start
#> 4 07090002004516 1570296 Nine Springs Creek 10 Reachcode Start
#> 5 07090002004524 NA <NA> 10 Reachcode Start
#> 6 07090002004544 NA <NA> 10 Reachcode Start
#> 7 07090002004546 NA <NA> 10 Reachcode Start
#> 8 07090002004549 NA <NA> 10 Reachcode Start
#> 9 07090002004555 NA <NA> 10 Reachcode Start
#> 10 07090002004568 1574821 Starkweather Creek 10 Reachcode Start
#> edhuniqueid workunitid geometry
#> 1 <NA> <NA> POINT (-89.56127 43.09289)
#> 2 <NA> <NA> POINT (-89.54642 43.10016)
#> 3 <NA> <NA> POINT (-89.56127 43.09289)
#> 4 <NA> <NA> POINT (-89.38225 43.02575)
#> 5 <NA> <NA> POINT (-89.29928 43.06225)
#> 6 <NA> <NA> POINT (-89.55788 43.11944)
#> 7 <NA> <NA> POINT (-89.4028 43.05283)
#> 8 <NA> <NA> POINT (-89.35483 43.15197)
#> 9 <NA> <NA> POINT (-89.36414 43.03815)
#> 10 <NA> <NA> POINT (-89.32593 43.10539)
# }