# NOT RUN {
sample_data <- system.file("extdata/sample_natseamless.gpkg",
package = "nhdplusTools")
nhdplus_path(sample_data)
staged_nhdplus <- stage_national_data(output_path = tempdir())
sample_flines <- readRDS(staged_nhdplus$flowline)
geom_col <- attr(sample_flines, "sf_column")
plot(sample_flines[[geom_col]],
lwd = 3)
start_point <- sf::st_sfc(sf::st_point(c(-89.362239, 43.090266)),
crs = 4326)
plot(start_point, cex = 1.5, lwd = 2, col = "red", add = TRUE)
start_comid <- discover_nhdplus_id(start_point)
comids <- get_UT(sample_flines, start_comid)
plot(dplyr::filter(sample_flines, COMID %in% comids)[[geom_col]],
add=TRUE, col = "red", lwd = 2)
output_file <- tempfile(fileext = ".gpkg")
subset_nhdplus(comids = comids,
output_file = output_file,
nhdplus_data = sample_data,
overwrite = TRUE,
status = TRUE)
sf::st_layers(output_file)
catchment <- sf::read_sf(output_file, "CatchmentSP")
plot(catchment[[attr(catchment, "sf_column")]], add = TRUE)
waterbody <- sf::read_sf(output_file, "NHDWaterbody")
plot(waterbody[[attr(waterbody, "sf_column")]],
col = rgb(0, 0, 1, alpha = 0.5), add = TRUE)
# Cleanup temp
sapply(staged_nhdplus, unlink)
unlink(output_file)
# Download Option:
subset_nhdplus(comids = comids,
output_file = output_file,
nhdplus_data = "download",
overwrite = TRUE,
status = TRUE)
sf::st_layers(output_file)
# NHDPlusHR
source(system.file("extdata/nhdplushr_data.R", package = "nhdplusTools"))
up_ids <- get_UT(hr_data$NHDFlowline, 15000500028335)
sub_gpkg <- file.path(work_dir, "sub.gpkg")
sub_nhdhr <- subset_nhdplus(up_ids, output_file = sub_gpkg,
nhdplus_data = hr_gpkg, overwrite = TRUE)
sf::st_layers(sub_gpkg)
names(sub_nhdhr)
plot(sf::st_geometry(hr_data$NHDFlowline), lwd = 0.5)
plot(sf::st_geometry(sub_nhdhr$NHDFlowline), lwd = 0.6, col = "red", add = TRUE)
unlink(output_file)
unlink(sub_gpkg)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab