Calls the NHDPlus_HR web service and returns sf data.frames for the selected layers. See https://hydro.nationalmap.gov/arcgis/rest/services/NHDPlus_HR/MapServer for source data documentation.

get_nhdphr(
  AOI = NULL,
  ids = NULL,
  type = NULL,
  reachcode = 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 nhdplusid ids

type

character. Type of feature to return e.g. c("networknhdflowline", nonnetworknhdflowline", nhdwaterbody", "nhdpluscatchment"). If NULL (default) a data.frame of available types is returned

reachcode

character vector of reachcodes NOTE: performance of this query is currently very poor, spatial queries are the primary use of this function.

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_nhdphr(AOI = AOI, type = "networknhdflowline")
point <- get_nhdphr(AOI = AOI, type = "nhdpoint")
waterbody <- get_nhdphr(AOI = AOI, type = "nhdwaterbody")

if(!is.null(waterbody) & !is.null(flowlines) & !is.null(point)) {
plot(sf::st_geometry(waterbody), col = "lightblue", border = "lightgrey")
plot(sf::st_geometry(flowlines), col = "blue", add = TRUE)
plot(sf::st_geometry(point), col = "grey", pch = "+", add = TRUE) }


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

get_nhdphr(reachcode = "13020101021927", type = "networknhdflowline")
#> Simple feature collection with 10 features and 82 fields
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -105.9805 ymin: 36.17496 xmax: -105.9253 ymax: 36.21542
#> Geodetic CRS:  WGS 84
#>    permanent_identifier        fdate resolution  gnis_id  gnis_name   lengthkm
#> 1             120928749 1.502237e+12          2 01385432 Rio Grande 0.12637349
#> 2             120928746 1.502237e+12          2 01385432 Rio Grande 1.77445619
#> 3             120928753 1.502237e+12          2 01385432 Rio Grande 0.10023801
#> 4             120928745 1.502237e+12          2 01385432 Rio Grande 0.64380256
#> 5             120928744 1.502237e+12          2 01385432 Rio Grande 1.96787731
#> 6             120928752 1.502237e+12          2 01385432 Rio Grande 0.09364129
#> 7             120928748 1.502237e+12          2 01385432 Rio Grande 0.35127735
#> 8             120928754 1.502237e+12          2 01385432 Rio Grande 0.86485354
#> 9             120928751 1.502237e+12          2 01385432 Rio Grande 0.07149613
#> 10            120928747 1.502237e+12          2 01385432 Rio Grande 2.12124057
#>         reachcode flowdir wbarea_permanent_identifier ftype fcode mainpath
#> 1  13020101021927       1                   120932465   558 55800        0
#> 2  13020101021927       1                   120932465   558 55800        0
#> 3  13020101021927       1                   120932465   558 55800        0
#> 4  13020101021927       1                   120932465   558 55800        0
#> 5  13020101021927       1                   120932465   558 55800        0
#> 6  13020101021927       1                   120932465   558 55800        0
#> 7  13020101021927       1                   120932465   558 55800        0
#> 8  13020101021927       1                   120932465   558 55800        0
#> 9  13020101021927       1                   120932465   558 55800        0
#> 10 13020101021927       1                   120932465   558 55800        0
#>    innetwork visibilityfilter   nhdplusid vpuid streamleve streamorde
#> 1          1          5000000 3.50006e+13  1302          4          8
#> 2          1          5000000 3.50006e+13  1302          4          8
#> 3          1          5000000 3.50006e+13  1302          4          8
#> 4          1          5000000 3.50006e+13  1302          4          8
#> 5          1          5000000 3.50006e+13  1302          4          8
#> 6          1          5000000 3.50006e+13  1302          4          8
#> 7          1          5000000 3.50006e+13  1302          4          8
#> 8          1          5000000 3.50006e+13  1302          4          8
#> 9          1          5000000 3.50006e+13  1302          4          8
#> 10         1          5000000 3.50006e+13  1302          4          8
#>    streamcalc    fromnode      tonode    hydroseq  levelpathi pathlength
#> 1           8 3.50006e+13 3.50006e+13 3.50006e+13 3.50001e+13   2706.329
#> 2           8 3.50006e+13 3.50006e+13 3.50006e+13 3.50001e+13   2704.203
#> 3           8 3.50006e+13 3.50006e+13 3.50006e+13 3.50001e+13   2699.370
#> 4           8 3.50006e+13 3.50006e+13 3.50006e+13 3.50001e+13   2703.560
#> 5           8 3.50006e+13 3.50006e+13 3.50006e+13 3.50001e+13   2701.592
#> 6           8 3.50006e+13 3.50006e+13 3.50006e+13 3.50001e+13   2706.527
#> 7           8 3.50006e+13 3.50006e+13 3.50006e+13 3.50001e+13   2705.978
#> 8           8 3.50006e+13 3.50006e+13 3.50006e+13 3.50001e+13   2698.505
#> 9           8 3.50006e+13 3.50006e+13 3.50006e+13 3.50001e+13   2706.455
#> 10          8 3.50006e+13 3.50006e+13 3.50006e+13 3.50001e+13   2699.470
#>     terminalpa arbolatesu divergence startflag terminalfl  uplevelpat
#> 1  3.50001e+13   33149.18          1         0          0 3.50001e+13
#> 2  3.50001e+13   33152.93          0         0          0 3.50001e+13
#> 3  3.50001e+13   33165.89          1         0          0 3.50001e+13
#> 4  3.50001e+13   33158.34          0         0          0 3.50001e+13
#> 5  3.50001e+13   33161.50          0         0          0 3.50001e+13
#> 6  3.50001e+13   33145.15          0         0          0 3.50001e+13
#> 7  3.50001e+13   33150.69          0         0          0 3.50001e+13
#> 8  3.50001e+13   33166.75          1         0          0 3.50001e+13
#> 9  3.50001e+13   33149.05          0         0          0 3.50001e+13
#> 10 3.50001e+13   33165.79          0         0          0 3.50001e+13
#>     uphydroseq dnlevel  dnlevelpat  dnhydroseq  dnminorhyd dndraincou frommeas
#> 1  3.50006e+13       4 3.50001e+13 3.50006e+13 0.00000e+00          1 96.38273
#> 2  3.50006e+13       4 3.50001e+13 3.50006e+13 0.00000e+00          1 70.06044
#> 3  3.50006e+13       4 3.50001e+13 3.50006e+13 3.50006e+13          2 10.61793
#> 4  3.50006e+13       4 3.50001e+13 3.50006e+13 0.00000e+00          1 62.06700
#> 5  3.50006e+13       4 3.50001e+13 3.50006e+13 0.00000e+00          1 37.84511
#> 6  3.50006e+13       4 3.50001e+13 3.50006e+13 0.00000e+00          1 98.83942
#> 7  3.50006e+13       4 3.50001e+13 3.50006e+13 0.00000e+00          1 92.04084
#> 8  3.50006e+13       4 3.50001e+13 3.50006e+13 0.00000e+00          1  0.00000
#> 9  3.50006e+13       4 3.50001e+13 3.50006e+13 3.50006e+13          2 97.95167
#> 10 3.50006e+13       4 3.50001e+13 3.50006e+13 3.50006e+13          2 11.85308
#>       tomeas rtndiv thinner vpuin vpuout   areasqkm totdasqkm divdasqkm
#> 1   97.95167      0    <NA>     0      0 0.01670001  15674.28  14789.65
#> 2   92.04084      1    <NA>     0      0 2.64680001  15678.19  14793.55
#> 3   11.85308      0    <NA>     0      0 0.08019999  15694.47  14809.84
#> 4   70.06044      0    <NA>     0      0 1.28390001  15682.44  14797.80
#> 5   62.06700      0    <NA>     0      0 3.88990000  15687.72  14803.08
#> 6  100.00000      0    <NA>     0      0 0.03410001  15671.63  14787.00
#> 7   96.38273      0    <NA>     0      0 0.08129999  15675.28  14790.65
#> 8   10.61793      0    <NA>     0      0 0.06200002  15694.54  14809.90
#> 9   98.83942      0    <NA>     0      0 0.01359998  15674.26  14789.63
#> 10  37.84511      0    <NA>     0      0 4.35159998  15694.39  14809.76
#>    maxelevraw minelevraw maxelevsmo minelevsmo      slope slopelenkm elevfixed
#> 1       -9998     177474     177652     177474 0.01408523 0.12637349      <NA>
#> 2       -9998     177019     177269     177051 0.00122855 1.77445619      <NA>
#> 3       -9998     175774     175780     175780 0.00001000 0.10023801      <NA>
#> 4       -9998     176572     177051     176672 0.00588690 0.64380256      <NA>
#> 5       -9998     176567     176672     176590 0.00041669 1.96787731      <NA>
#> 6       -9998     177678     177678     177678 0.00001000 0.09364129      <NA>
#> 7       -9998     177262     177474     177269 0.00583584 0.35127735      <NA>
#> 8       -9998     175728     175780     175780 0.00001000 0.86485354      <NA>
#> 9       -9998     177652     177678     177652 0.00363656 0.07149613      <NA>
#> 10      -9998     175714     176590     175780 0.00381852 2.12124057      <NA>
#>    hwtype hwnodesqkm statusflag     qama     vama qincrama     qbma     vbma
#> 1    <NA>       <NA>          A 3714.387 3.536884 0.000243 3714.387 3.536884
#> 2    <NA>       <NA>          A 3714.445 2.499065 0.039421 3714.445 2.499065
#> 3    <NA>       <NA>          A 3714.690 1.328012 0.001217 3714.690 1.328012
#> 4    <NA>       <NA>          A 3714.507 3.118966 0.018690 3714.507 3.118966
#> 5    <NA>       <NA>          A 3714.584 2.153226 0.056736 3714.584 2.153226
#> 6    <NA>       <NA>          A 3714.347 1.327770 0.000496 3714.347 1.327770
#> 7    <NA>       <NA>          A 3714.402 3.114867 0.001184 3714.402 3.114867
#> 8    <NA>       <NA>          A 3714.691 1.328012 0.000931 3714.691 1.328012
#> 9    <NA>       <NA>          A 3714.387 2.911523 0.000198 3714.387 2.911523
#> 10   <NA>       <NA>          A 3714.689 2.932359 0.068250 3714.689 2.932359
#>    qincrbma     qcma     vcma   qincrcma     qdma     vdma   qincrdma     qema
#> 1  0.000243 3714.387 3.536884 0.00024300 3714.387 3.536884 0.00024300 1711.386
#> 2  0.039421 3714.445 2.499065 0.04207118 3714.445 2.499065 0.04207118 1711.444
#> 3  0.001217 3714.690 1.328012 0.00121700 3714.690 1.328012 0.00121700 1711.690
#> 4  0.018690 3714.507 3.118966 0.04763696 3714.507 3.118966 0.04763696 1711.506
#> 5  0.056736 3714.584 2.153226 0.07050796 3714.584 2.153226 0.07050796 1711.583
#> 6  0.000496 3714.347 1.327770 0.42352419 3714.347 1.327770 0.42352419 1711.347
#> 7  0.001184 3714.402 3.114867 0.01036309 3714.402 3.114867 0.01036309 1711.401
#> 8  0.000931 3714.691 1.328012 0.00093100 3714.691 1.328012 0.00093100 1711.691
#> 9  0.000198 3714.387 2.911523 0.02664062 3714.387 2.911523 0.02664062 1711.386
#> 10 0.068250 3714.689 2.932359 0.09319502 3714.689 2.932359 0.09319502 1711.688
#>        vema   qincrema     qfma   qincrfma arqnavma petma qlossma qgadjma
#> 1  3.340468 0.00024300 1711.386 0.00024300        0     0       0       0
#> 2  2.365791 0.04207118 1711.444 0.04207118        0     0       0       0
#> 3  1.265987 0.00121700 1711.690 0.00121700        0     0       0       0
#> 4  2.947984 0.04763696 1711.506 0.04763696        0     0       0       0
#> 5  2.040998 0.07050796 1711.583 0.07050796        0     0       0       0
#> 6  1.265752 0.42352419 1711.347 0.42352419        0     0       0       0
#> 7  2.944127 0.01036309 1711.401 0.01036309        0     0       0       0
#> 8  1.265988 0.00093100 1711.691 0.00093100        0     0       0       0
#> 9  2.753153 0.02664062 1711.386 0.02664062        0     0       0       0
#> 10 2.772740 0.09319502 1711.688 0.09319502        0     0       0       0
#>    qgnavma gageadjma avgqadjma gageidma gageqma Shape_Length
#> 1        0         1         0        0       0    157.84395
#> 2        0         1         0        0       0   2212.36438
#> 3        0         1         0        0       0    124.42048
#> 4        0         1         0        0       0    804.11669
#> 5        0         1         0        0       0   2441.27200
#> 6        0         1         0        0       0    116.80600
#> 7        0         1         0        0       0    437.25416
#> 8        0         1         0        0       0   1070.42970
#> 9        0         1         0        0       0     89.30904
#> 10       0         1         0        0       0   2621.91428
#>                          geometry
#> 1  LINESTRING (-105.9271 36.21...
#> 2  LINESTRING (-105.9317 36.21...
#> 3  LINESTRING (-105.9782 36.18...
#> 4  LINESTRING (-105.9499 36.20...
#> 5  LINESTRING (-105.957 36.209...
#> 6  LINESTRING (-105.9253 36.21...
#> 7  LINESTRING (-105.9285 36.21...
#> 8  LINESTRING (-105.9774 36.18...
#> 9  LINESTRING (-105.9263 36.21...
#> 10 LINESTRING (-105.972 36.197...
# }