Calls the 3DHP_all web service and returns sf data.frames for the selected layers. See https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer for source data documentation.

get_3dhp(
  AOI = NULL,
  ids = NULL,
  type = NULL,
  universalreferenceid = NULL,
  t_srs = NULL,
  buffer = 0.5,
  page_size = 2000
)

Arguments

AOI

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 vector of id3dhp ids, mainstem uris, or workunitid prefixed ids (e.g. "workunitid:300585")

type

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

universalreferenceid

character vector of hydrolocation universal reference ids such as reachcodes

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

page_size

numeric default number of features to request at a time. Reducing may help if 500 errors are experienced.

Value

a simple features (sf) object or valid types if no type supplied

Details

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

Examples

# \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")
#> GET https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/?f=json
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/50/query
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/50/query
hydrolocation <- get_3dhp(AOI = AOI, type = "hydrolocation")
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/20/query
#> Warning: No hydrolocation - sink, spring, waterbody outlet features found in area of interest.
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/30/query
#> Warning: No hydrolocation - headwater, terminus, divergence, confluence, catchment outlet features found in area of interest.
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/40/query
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/40/query
waterbody <- get_3dhp(AOI = AOI, type = "waterbody")
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/60/query
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/60/query

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.

SU <- get_3dhp(ids = "https://geoconnex.us/ref/mainstems/194408",
               type = "flowline")
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/50/query
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/50/query

if(!is.null(SU))
  plot(sf::st_geometry(SU), col = "blue")


# get all the waterbodies along the Susquehanna river
SU_wb <- get_3dhp(ids = unique(SU$waterbodyid3dhp), type = "waterbody")
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/60/query
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/60/query

if(!is.null(SU_wb)) {
plot(sf::st_geometry(SU_wb[grepl("Otsego", SU_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")
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/50/query
#> Getting features 0 to 2000 of 14676
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/50/query
#> Getting features 2000 to 4000 of 14676
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/50/query
#> Getting features 4000 to 6000 of 14676
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/50/query
#> Getting features 6000 to 8000 of 14676
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/50/query
#> Getting features 8000 to 10000 of 14676
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/50/query
#> Getting features 10000 to 12000 of 14676
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/50/query
#> Getting features 12000 to 14000 of 14676
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/50/query
#> Getting features 14000 to 14676 of 14676
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/50/query

# given universalreferenceid (reachcodes), can query for them but only
# for hydrolocations. This is useful for looking up mainstem ids.

if(!is.null(hydrolocation)) {
get_3dhp(universalreferenceid = unique(hydrolocation$universalreferenceid),
         type = "hydrolocation")
}
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/20/query
#> Warning: No hydrolocation - sink, spring, waterbody outlet features found in area of interest.
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/30/query
#> Warning: No hydrolocation - headwater, terminus, divergence, confluence, catchment outlet features found in area of interest.
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/40/query
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/40/query
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/20/query
#> Warning: No hydrolocation - sink, spring, waterbody outlet features found in area of interest.
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/30/query
#> Warning: No hydrolocation - headwater, terminus, divergence, confluence, catchment outlet features found in area of interest.
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/40/query
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/40/query
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/20/query
#> Warning: No hydrolocation - sink, spring, waterbody outlet features found in area of interest.
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/30/query
#> Warning: No hydrolocation - headwater, terminus, divergence, confluence, catchment outlet features found in area of interest.
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/40/query
#> POST https://3dhp.nationalmap.gov/arcgis/rest/services/usgs_3dhp_all/FeatureServer/40/query
#> Simple feature collection with 558 features and 9 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -89.60105 ymin: 43.00059 xmax: -89.23201 ymax: 43.17772
#> 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
#>    workunitid                   geometry
#> 1         NHD POINT (-89.56127 43.09289)
#> 2         NHD POINT (-89.54642 43.10016)
#> 3         NHD POINT (-89.56127 43.09289)
#> 4         NHD POINT (-89.38225 43.02575)
#> 5         NHD POINT (-89.29928 43.06225)
#> 6         NHD POINT (-89.55788 43.11944)
#> 7         NHD  POINT (-89.4028 43.05283)
#> 8         NHD POINT (-89.35483 43.15197)
#> 9         NHD POINT (-89.36414 43.03815)
#> 10        NHD POINT (-89.32593 43.10539)
# }