R/query.R
nhd_plus_query.Rd
Select NHDplus features via polygon or circular buffer of coordinate pair
nhd_plus_query(
lon = NA,
lat = NA,
poly = NA,
dsn,
buffer_dist = units::as_units(1, "km"),
approve_all_dl = FALSE,
temporary = TRUE,
...
)
numeric longitude. optional
numeric latitude. optional
sfc polygon. optional
character data source
numeric buffer in units of coordinate degrees
logical blanket approval to download all missing data. Defaults to TRUE if session is non-interactive.
logical set FALSE to save data to a persistent rappdirs location
parameters passed on to sf::st_read
A list of sf spatial objects
if (FALSE) {
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")
}