overwrite geopackage when combining data

This commit is contained in:
Ben Varick 2023-10-16 12:53:23 -05:00
parent 72bb31e878
commit ddac18fac2
Signed by: ben
SSH Key Fingerprint: SHA256:jWnpFDAcacYM5aPFpYRqlsamlDyKNpSj3jj+k4ojtUo
3 changed files with 18 additions and 15 deletions

View File

@ -2,6 +2,7 @@
library(nhdplusTools)
library(sf)
# set data dir
nhdplusTools_data_dir(dir = "data")
# load extent of map
@ -28,9 +29,18 @@ extent <- list(longitude_max = max(extent$longitude),
extent_huc <- get_huc(AOI = extent_poly, buffer = 0, type = "huc04")
# download data
download_nhdplushr("data", extent_huc$huc4, download_files = TRUE)
download_nhdplushr(nhdplusTools_data_dir(), extent_huc$huc4, download_files = TRUE)
# get vaa
get_vaa()
# combine data into geopackage
data <- get_nhdplushr(hr_dir = "data",
out_gpkg = "data/data.gpkg",
layers = NULL)
layers <- c("NHDArea",
"NHDFlowline",
"NHDWaterbody",
"NHDPlusLandSea")
data <- get_nhdplushr(hr_dir = nhdplusTools_data_dir(),
out_gpkg = paste0(nhdplusTools_data_dir(),"/data.gpkg"),
layers = layers,
overwrite = TRUE)

View File

@ -1,16 +1,9 @@
# load libraries
library(sf)
# load data
layers <- c("NHDArea",
"NHDFlowline",
"NHDWaterbody",
"NHDPlusLandSea")
# load and crop data
data <- list(NULL)
sf_use_s2(FALSE)
for (layer in layers){
data[[layer]] <- st_crop(st_read("data/data.gpkg", layer = layer), y = extent_bbox)
data[[layer]] <- st_crop(st_read(paste0(nhdplusTools_data_dir(),"/data.gpkg"), layer = layer), y = extent_bbox)
}

View File

@ -1,3 +1,3 @@
latitude,longitude
43.63839,-89.97779
42.52677,-88.52104
47.33402,-93.10419
42.43754,-86.832

1 latitude longitude
2 43.63839 47.33402 -89.97779 -93.10419
3 42.52677 42.43754 -88.52104 -86.832