nhd_plus_query: Select NHDplus features via polygon or circular buffer of...

Description Usage Arguments Value Examples

View source: R/query.R

Description

Select NHDplus features via polygon or circular buffer of coordinate pair

Usage

1
2
3
4
5
6
7
8
9
nhd_plus_query(
  lon = NA,
  lat = NA,
  poly = NA,
  dsn,
  buffer_dist = 0.05,
  approve_all_dl = FALSE,
  ...
)

Arguments

lon

numeric longitude. optional

lat

numeric latitude. optional

poly

sfc polygon. optional

dsn

character data source

buffer_dist

numeric buffer in units of coordinate degrees

approve_all_dl

logical blanket approval to download all missing data. Defaults to TRUE if session is non-interactive.

...

parameters passed on to sf::st_read

Value

A list of sf spatial objects

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
## Not run: 
library(sf)
wk <- wikilake::lake_wiki("Gull Lake (Michigan)")

pnt <- st_as_sf(wk, coords = c("Lon", "Lat"), crs = 4326)
pnt <- st_transform(pnt, st_crs(vpu_shp))
# nhd_plus_list(nhdR::find_vpu(pnt))

# set a non-geographic (projected) buffer size
qry <- nhd_plus_query(wk$Lon, wk$Lat,
  dsn = c("NHDWaterbody", "NHDFlowLine"),
  buffer_dist = units::as_units(5, "km"))

qry <- nhd_plus_query(wk$Lon, wk$Lat,
  dsn = c("NHDWaterbody", "NHDFlowLine"), buffer_dist = 0.05)

plot(qry$sp$NHDWaterbody$geometry, col = "blue")
plot(qry$sp$NHDFlowLine$geometry, col = "cyan", add = TRUE)
plot(qry$pnt, col = "red", pch = 19, add = TRUE)
axis(1)
axis(2)

library(ggplot2)
ggplot(qry$sp$NHDWaterbody) + geom_sf()

# query with a polygon
wbd <- qry$sp$NHDWaterbody[which.max(st_area(qry$sp$NHDWaterbody)), ]
qry_lines <- nhd_plus_query(poly = st_as_sfc(st_bbox(wbd)),
  dsn = "NHDFlowLine")
ggplot() +
  geom_sf(data = qry$sp$NHDWaterbody) +
  geom_sf(data = qry_lines$sp$NHDFlowLine, color = "red")

## End(Not run)

nhdR documentation built on July 17, 2021, 5:06 p.m.