Skip to contents

Provides a formal client to the USGS Network Linked Data Index.

Usage

findNLDI(
  comid = NULL,
  nwis = NULL,
  wqp = NULL,
  huc12 = NULL,
  location = NULL,
  origin = NULL,
  nav = NULL,
  find = c("flowlines"),
  distance_km = 100,
  no_sf = FALSE,
  warn = TRUE
)

Arguments

comid

numeric or character. An NHDPlusV2 COMID

nwis

numeric or character. A USGS NWIS surface water siteID

wqp

numeric or character. A water quality point ID

huc12

numeric or character. A WBD HUC12 unit ID

location

numeric vector. Coordinate pair in WGS84 SRS ordered lng/lat (X,Y)

origin

named list. Specifying a feature type and ID (e.g. list("comid" = 101))

nav

character vector. where to navigate from the starting point. Options include along the upper mainsteam (UM), upstream tributary (UT), downstream mainstem (DM) and downstream divergences (DD). You may select one or more of the abbreviations ("UM", "UT", DM", "DD").

find

character vector. Define what resources to find along the navigation path(s) (see get_nldi_sources()$source). Can also include 'basin' or 'flowline', which will return the upstream basin of the starting feature or flowlines along the navigation respectively. The default is "flowlines". If you provide any other resource, AND want flowlines, then flowlines must be explicitly requested.

distance_km

numeric. Define how far to look along the navigation path in kilometers (default = 100)

no_sf

if available, should `sf` be used for parsing, defaults to `TRUE` if `sf` is locally installed

warn

(default TRUE) should warnings be printed

Value

a list of data.frames if sf is not installed, a list of sf objects if it is

Details

The function is useful for topology and location based feature discovery. A user must specify an origin feature, optional navigation direction(s) along the network, as well as features to identify along the navigated paths. Valid starting options can be given by one of the following arguments: comid, nwis, huc12, wqp, location, and start.

Examples

# \donttest{
# Find Features / Define origin features

## Find feature by COMID
findNLDI(comid = 101)
#> $origin
#> Simple feature collection with 1 feature and 3 fields
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -94.64845 ymin: 31.0838 xmax: -94.62997 ymax: 31.09915
#> Geodetic CRS:  WGS 84
#> # A tibble: 1 × 4
#>   sourceName    identifier comid                                        geometry
#>   <chr>         <chr>      <chr>                                <LINESTRING [°]>
#> 1 NHDPlus comid 101        101   (-94.64845 31.09915, -94.64803 31.09871, -94.6…
#> 

## Find feature by NWIS ID
findNLDI(nwis = "11120000")
#> $origin
#> Simple feature collection with 1 feature and 8 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -119.8118 ymin: 34.42472 xmax: -119.8118 ymax: 34.42472
#> Geodetic CRS:  WGS 84
#> # A tibble: 1 × 9
#>   sourceName               identifier  comid measure reachcode name      X     Y
#>   <chr>                    <chr>       <chr>   <dbl> <chr>     <chr> <dbl> <dbl>
#> 1 NWIS Surface Water Sites USGS-11120… 1759…    92.5 18060013… ATAS… -120.  34.4
#> # ℹ 1 more variable: geometry <POINT [°]>
#> 

## Find feature by WQP ID
findNLDI(wqp = "USGS-04024315")
#> $origin
#> Simple feature collection with 1 feature and 6 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -92.23492 ymin: 46.50355 xmax: -92.23492 ymax: 46.50355
#> Geodetic CRS:  WGS 84
#> # A tibble: 1 × 7
#>   sourceName        identifier comid name      X     Y             geometry
#>   <chr>             <chr>      <chr> <chr> <dbl> <dbl>          <POINT [°]>
#> 1 Water Quality Po… USGS-0402… 1800… LITT… -92.2  46.5 (-92.23492 46.50355)
#> 

## Find feature by LOCATION
findNLDI(location = c(-115, 40))
#> $origin
#> Simple feature collection with 1 feature and 3 fields
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -115.0326 ymin: 40.04013 xmax: -115.0182 ymax: 40.05183
#> Geodetic CRS:  WGS 84
#> # A tibble: 1 × 4
#>   sourceName    identifier comid                                        geometry
#>   <chr>         <chr>      <chr>                                <LINESTRING [°]>
#> 1 NHDPlus comid 946060315  946060315 (-115.0182 40.05183, -115.0185 40.05176, -…
#> 

## GENERAL ORIGIN: COMID
findNLDI(origin = list("comid" = 101))
#> $origin
#> Simple feature collection with 1 feature and 3 fields
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -94.64845 ymin: 31.0838 xmax: -94.62997 ymax: 31.09915
#> Geodetic CRS:  WGS 84
#> # A tibble: 1 × 4
#>   sourceName    identifier comid                                        geometry
#>   <chr>         <chr>      <chr>                                <LINESTRING [°]>
#> 1 NHDPlus comid 101        101   (-94.64845 31.09915, -94.64803 31.09871, -94.6…
#> 

## GENERAL ORIGIN: WaDE
findNLDI(origin = list("wade" = "CA_45206"))
#> Error in: https://labs.waterdata.usgs.gov/api/nldi/linked-data/wade/CA_45206/
#> named list()

# Navigation (flowlines will be returned if find is unspecified)
# UPPER MAINSTEM of USGS-11120000
findNLDI(nwis = "11120000", nav = "UM")
#> $origin
#> Simple feature collection with 1 feature and 8 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -119.8118 ymin: 34.42472 xmax: -119.8118 ymax: 34.42472
#> Geodetic CRS:  WGS 84
#> # A tibble: 1 × 9
#>   sourceName               identifier  comid measure reachcode name      X     Y
#>   <chr>                    <chr>       <chr>   <dbl> <chr>     <chr> <dbl> <dbl>
#> 1 NWIS Surface Water Sites USGS-11120… 1759…    92.5 18060013… ATAS… -120.  34.4
#> # ℹ 1 more variable: geometry <POINT [°]>
#> 
#> $UM_flowlines
#> Simple feature collection with 4 features and 1 field
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -119.8296 ymin: 34.42015 xmax: -119.7607 ymax: 34.46831
#> Geodetic CRS:  WGS 84
#> # A tibble: 4 × 2
#>   nhdplus_comid                                                         geometry
#>   <chr>                                                         <LINESTRING [°]>
#> 1 17595429      (-119.8104 34.42513, -119.8112 34.42476, -119.8123 34.42447, -1…
#> 2 17595395      (-119.7859 34.43139, -119.7861 34.43114, -119.7868 34.43091, -1…
#> 3 17595361      (-119.7755 34.43447, -119.7761 34.43406, -119.7782 34.43337, -1…
#> 4 17596117      (-119.7631 34.46831, -119.7626 34.46781, -119.7623 34.46721, -1…
#> 

# MULTI-REQUEST
# UPPER MAINSTEM and TRIBUTARY of USGS-11120000
findNLDI(nwis = "11120000", nav = c("UT", "UM"))
#> $origin
#> Simple feature collection with 1 feature and 8 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -119.8118 ymin: 34.42472 xmax: -119.8118 ymax: 34.42472
#> Geodetic CRS:  WGS 84
#> # A tibble: 1 × 9
#>   sourceName               identifier  comid measure reachcode name      X     Y
#>   <chr>                    <chr>       <chr>   <dbl> <chr>     <chr> <dbl> <dbl>
#> 1 NWIS Surface Water Sites USGS-11120… 1759…    92.5 18060013… ATAS… -120.  34.4
#> # ℹ 1 more variable: geometry <POINT [°]>
#> 
#> $UT_flowlines
#> Simple feature collection with 25 features and 1 field
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -119.8296 ymin: 34.42015 xmax: -119.7332 ymax: 34.51769
#> Geodetic CRS:  WGS 84
#> # A tibble: 25 × 2
#>    nhdplus_comid                                                        geometry
#>    <chr>                                                        <LINESTRING [°]>
#>  1 17595429      (-119.8104 34.42513, -119.8112 34.42476, -119.8123 34.42447, -…
#>  2 17595393      (-119.8052 34.44199, -119.8051 34.44135, -119.8052 34.44069, -…
#>  3 17595395      (-119.7859 34.43139, -119.7861 34.43114, -119.7868 34.43091, -…
#>  4 17596113      (-119.7658 34.47264, -119.7658 34.47214, -119.766 34.4718, -11…
#>  5 17596111      (-119.7944 34.45971, -119.7952 34.45938, -119.7956 34.45906, -…
#>  6 17595361      (-119.7755 34.43447, -119.7761 34.43406, -119.7782 34.43337, -…
#>  7 17596115      (-119.7709 34.45809, -119.7714 34.45738, -119.772 34.45692, -1…
#>  8 17595239      (-119.7624 34.4798, -119.7626 34.47978, -119.7631 34.4796, -11…
#>  9 17596077      (-119.7435 34.5, -119.7439 34.49933, -119.7447 34.49844, -119.…
#> 10 17595277      (-119.7914 34.47602, -119.7915 34.47557, -119.7914 34.47421, -…
#> # ℹ 15 more rows
#> 
#> $UM_flowlines
#> Simple feature collection with 4 features and 1 field
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -119.8296 ymin: 34.42015 xmax: -119.7607 ymax: 34.46831
#> Geodetic CRS:  WGS 84
#> # A tibble: 4 × 2
#>   nhdplus_comid                                                         geometry
#>   <chr>                                                         <LINESTRING [°]>
#> 1 17595429      (-119.8104 34.42513, -119.8112 34.42476, -119.8123 34.42447, -1…
#> 2 17595395      (-119.7859 34.43139, -119.7861 34.43114, -119.7868 34.43091, -1…
#> 3 17595361      (-119.7755 34.43447, -119.7761 34.43406, -119.7782 34.43337, -1…
#> 4 17596117      (-119.7631 34.46831, -119.7626 34.46781, -119.7623 34.46721, -1…
#> 

# Discover Features(flowlines will not be returned unless included in find)

## Find feature(s) on the upper tributary of USGS-11120000
findNLDI(nwis = "11120000", nav = "UT", find = c("nwis", "wqp"))
#> Warning: No data returned for: https://labs.waterdata.usgs.gov/api/nldi/linked-data/nwissite/USGS-11120000/navigation/UT/WQP?f=json&distance=100
#> $origin
#> Simple feature collection with 1 feature and 8 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -119.8118 ymin: 34.42472 xmax: -119.8118 ymax: 34.42472
#> Geodetic CRS:  WGS 84
#> # A tibble: 1 × 9
#>   sourceName               identifier  comid measure reachcode name      X     Y
#>   <chr>                    <chr>       <chr>   <dbl> <chr>     <chr> <dbl> <dbl>
#> 1 NWIS Surface Water Sites USGS-11120… 1759…    92.5 18060013… ATAS… -120.  34.4
#> # ℹ 1 more variable: geometry <POINT [°]>
#> 
#> $UT_nwissite
#> Simple feature collection with 3 features and 8 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -119.8118 ymin: 34.42472 xmax: -119.7843 ymax: 34.445
#> Geodetic CRS:  WGS 84
#> # A tibble: 3 × 9
#>   sourceName               identifier  comid measure reachcode name      X     Y
#>   <chr>                    <chr>       <chr>   <dbl> <chr>     <chr> <dbl> <dbl>
#> 1 NWIS Surface Water Sites USGS-11120… 1759…    92.5 18060013… ATAS… -120.  34.4
#> 2 NWIS Surface Water Sites USGS-11119… 1759…    15.5 18060013… ATAS… -120.  34.4
#> 3 NWIS Surface Water Sites USGS-11119… 1759…    14.3 18060013… MARI… -120.  34.4
#> # ℹ 1 more variable: geometry <POINT [°]>
#> 

## Find upstream basin boundary and  of USGS-11120000
findNLDI(nwis = "11120000", find = "basin")
#> $origin
#> Simple feature collection with 1 feature and 8 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -119.8118 ymin: 34.42472 xmax: -119.8118 ymax: 34.42472
#> Geodetic CRS:  WGS 84
#> # A tibble: 1 × 9
#>   sourceName               identifier  comid measure reachcode name      X     Y
#>   <chr>                    <chr>       <chr>   <dbl> <chr>     <chr> <dbl> <dbl>
#> 1 NWIS Surface Water Sites USGS-11120… 1759…    92.5 18060013… ATAS… -120.  34.4
#> # ℹ 1 more variable: geometry <POINT [°]>
#> 
#> $basin
#> Simple feature collection with 1 feature and 0 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -119.8295 ymin: 34.41806 xmax: -119.7307 ymax: 34.52034
#> Geodetic CRS:  WGS 84
#> # A tibble: 1 × 1
#>                                                                         geometry
#>                                                                    <POLYGON [°]>
#> 1 ((-119.7479 34.45901, -119.7452 34.45292, -119.745 34.44701, -119.7473 34.443…
#> 

# Control Distance
## Limit search to 50 km
findNLDI(comid = 101, nav = "DM", find = c("nwis", "wqp", "flowlines"), distance_km = 50)
#> $origin
#> Simple feature collection with 1 feature and 3 fields
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -94.64845 ymin: 31.0838 xmax: -94.62997 ymax: 31.09915
#> Geodetic CRS:  WGS 84
#> # A tibble: 1 × 4
#>   sourceName    identifier comid                                        geometry
#>   <chr>         <chr>      <chr>                                <LINESTRING [°]>
#> 1 NHDPlus comid 101        101   (-94.64845 31.09915, -94.64803 31.09871, -94.6…
#> 
#> $DM_nwissite
#> Simple feature collection with 1 feature and 8 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -94.39944 ymin: 31.025 xmax: -94.39944 ymax: 31.025
#> Geodetic CRS:  WGS 84
#> # A tibble: 1 × 9
#>   sourceName               identifier  comid name  reachcode measure     X     Y
#>   <chr>                    <chr>       <chr> <chr> <chr>     <chr>   <dbl> <dbl>
#> 1 NWIS Surface Water Sites USGS-08033… 1109… Nech… 12020003… 68.708… -94.4  31.0
#> # ℹ 1 more variable: geometry <POINT [°]>
#> 
#> $DM_WQP
#> Simple feature collection with 3 features and 6 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -94.3995 ymin: 31.0247 xmax: -94.38492 ymax: 31.03547
#> Geodetic CRS:  WGS 84
#> # A tibble: 3 × 7
#>   sourceName        identifier comid name      X     Y             geometry
#>   <chr>             <chr>      <chr> <chr> <dbl> <dbl>          <POINT [°]>
#> 1 Water Quality Po… USGS-0803… 1109… Nech… -94.4  31.0   (-94.39944 31.025)
#> 2 Water Quality Po… TCEQMAIN-… 1109… NECH… -94.4  31.0   (-94.3995 31.0247)
#> 3 Water Quality Po… USGS-3102… 1109… PR-3… -94.4  31.0 (-94.38492 31.03547)
#> 
#> $DM_flowlines
#> Simple feature collection with 20 features and 1 field
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -94.64845 ymin: 31.00305 xmax: -94.37394 ymax: 31.09915
#> Geodetic CRS:  WGS 84
#> # A tibble: 20 × 2
#>    nhdplus_comid                                                        geometry
#>    <chr>                                                        <LINESTRING [°]>
#>  1 101           (-94.64845 31.09915, -94.64803 31.09871, -94.64774 31.0981, -9…
#>  2 1078719       (-94.62997 31.0838, -94.62957 31.08367, -94.6288 31.08371, -94…
#>  3 1078721       (-94.61139 31.07963, -94.61205 31.07897, -94.61226 31.07844, -…
#>  4 1078725       (-94.61216 31.07787, -94.61085 31.07759, -94.60894 31.07762, -…
#>  5 1078733       (-94.60537 31.07764, -94.60502 31.07796, -94.60481 31.07805, -…
#>  6 1078739       (-94.59281 31.07283, -94.59113 31.07301, -94.58833 31.07262, -…
#>  7 1078769       (-94.56965 31.06817, -94.56946 31.06814, -94.56909 31.06826, -…
#>  8 1078783       (-94.53857 31.05436, -94.53809 31.05429, -94.53764 31.05388, -…
#>  9 1078807       (-94.53096 31.05568, -94.53093 31.05499, -94.53045 31.05451, -…
#> 10 1078835       (-94.51641 31.04992, -94.51633 31.04939, -94.5159 31.04891, -9…
#> 11 1079065       (-94.50175 31.04448, -94.50175 31.04438, -94.50101 31.0431, -9…
#> 12 1078885       (-94.49899 31.04272, -94.49737 31.04286, -94.49689 31.04275, -…
#> 13 1078897       (-94.48568 31.03226, -94.48568 31.03155, -94.48536 31.03128, -…
#> 14 1109679       (-94.45777 31.03345, -94.45771 31.033, -94.45779 31.03261, -94…
#> 15 1109681       (-94.45096 31.00347, -94.45066 31.00314, -94.45048 31.00305, -…
#> 16 1109675       (-94.4342 31.00714, -94.43401 31.00755, -94.43401 31.00787, -9…
#> 17 1109669       (-94.43277 31.01319, -94.43402 31.01303, -94.43455 31.01278, -…
#> 18 1109665       (-94.43287 31.01461, -94.43279 31.0147, -94.43138 31.01482, -9…
#> 19 1109655       (-94.40199 31.02606, -94.40188 31.02606, -94.401 31.02521, -94…
#> 20 1109651       (-94.39707 31.02849, -94.39696 31.02906, -94.39672 31.02917, -…
#> 
# }