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, mainstem uris, or workunitid prefixed ids (e.g. "workunitid:300585")
character. Type of feature to return. e.g. ("hydrolocation", "flowline", "waterbody", "drainage area", "catchment"). If NULL (default) a data.frame of available types 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: "hydrolocation" not in `type` input. Must be one of:
#> "hydrolocation - sink, spring, waterbody outlet"
#> "hydrolocation - headwater, terminus, divergence, confluence, catchment outlet"
#> "hydrolocation - reach code, external connection"
#> "flowline"
#> "waterbody"
#> "drainagearea"
#> "catchment"
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 a workunitid, can query for features in that work unit
wufl <- get_3dhp(ids = "workunitid:300585", type = "flowline")
#> Getting features 0 to 2000 of 14676
#> Getting features 2000 to 4000 of 14676
#> Getting features 4000 to 6000 of 14676
#> Getting features 6000 to 8000 of 14676
#> Getting features 8000 to 10000 of 14676
#> Getting features 10000 to 12000 of 14676
#> Getting features 12000 to 14000 of 14676
#> Getting features 14000 to 14676 of 14676
# 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: "hydrolocation" not in `type` input. Must be one of:
#> "hydrolocation - sink, spring, waterbody outlet"
#> "hydrolocation - headwater, terminus, divergence, confluence, catchment outlet"
#> "hydrolocation - reach code, external connection"
#> "flowline"
#> "waterbody"
#> "drainagearea"
#> "catchment"
#> NULL
# }