From 5fe8a82c746cd2be242b4ff0f30eeb1c8a654901 Mon Sep 17 00:00:00 2001 From: David Blodgett Date: Mon, 1 Apr 2024 12:27:21 -0500 Subject: [PATCH 1/3] update to handle lowercase nhdplushr variable names --- DESCRIPTION | 2 +- R/get_nhdplushr.R | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b564dfcd..bffd05f4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,7 +32,7 @@ Imports: hydroloom, dataRetrieval, dplyr, sf, units, magrittr, jsonlite, httr, x Suggests: testthat, knitr, rmarkdown, ggmap, ggplot2, lwgeom, gifski, leaflet, httptest, future, future.apply License: CC0 Encoding: UTF-8 -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 VignetteBuilder: knitr Config/testthat/parallel: true Config/testthat/edition: 3 diff --git a/R/get_nhdplushr.R b/R/get_nhdplushr.R index 420de67a..7aa0547b 100644 --- a/R/get_nhdplushr.R +++ b/R/get_nhdplushr.R @@ -123,8 +123,11 @@ get_hr_data <- function(gdb, layer = NULL, min_size_sqkm = NULL, simp = NULL, proj = NULL, rename = TRUE) { if(layer == "NHDFlowline") { hr_data <- suppressWarnings(read_sf(gdb, "NHDPlusFlowlineVAA")) - hr_data <- select(hr_data, -ReachCode, -VPUID) - hr_data <- left_join(st_zm(read_sf(gdb, layer)), hr_data, by = "NHDPlusID") + hr_data <- select(hr_data, -dplyr::matches(c("ReachCode", "VPUID"), ignore.case = TRUE)) + + join_col <- names(hr_data)[grepl("nhdplusid", names(hr_data), ignore.case = TRUE)] + + hr_data <- left_join(st_zm(read_sf(gdb, layer)), hr_data, by = join_col) fix <- which( # In the case things come in as non-linestring geometries !sapply(st_geometry(hr_data), From 372d5ee3b9f4df07bec0b8fed5eb5fc2473b98d0 Mon Sep 17 00:00:00 2001 From: David Blodgett Date: Wed, 8 May 2024 14:30:41 -0500 Subject: [PATCH 2/3] remove unneeded buffer --- R/index_nhdplus.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/index_nhdplus.R b/R/index_nhdplus.R index 3cb242df..2a57ea3a 100644 --- a/R/index_nhdplus.R +++ b/R/index_nhdplus.R @@ -71,16 +71,18 @@ get_flowline_index <- function(flines, points, precision = NA, max_matches = 1) { - search_radius <- hydroloom:::check_search_radius(search_radius, points) - - point_buffer <- sf::st_buffer(points, search_radius) - if(is.character(flines) && flines == "download_nhdplusv2") { if((!is.null(nrow(points)) && nrow(points)) == 1 | length(points) == 1) { + + search_radius <- hydroloom:::check_search_radius(search_radius, points) + req <- sf::st_buffer(points, search_radius) + } else { + req <- points + } flines <- align_nhdplus_names( From c13b32be4905d00f2ec0f8b5398183dbf2061d9f Mon Sep 17 00:00:00 2001 From: David Blodgett Date: Wed, 8 May 2024 14:31:05 -0500 Subject: [PATCH 3/3] fixes #380 --- R/get_nhdplushr.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/get_nhdplushr.R b/R/get_nhdplushr.R index 7aa0547b..97e84b68 100644 --- a/R/get_nhdplushr.R +++ b/R/get_nhdplushr.R @@ -86,7 +86,7 @@ get_nhdplushr <- function(hr_dir, out_gpkg = NULL, layer_set <- lapply(gdbs, get_hr_data, layer = layer, ...) - out <- do.call(rbind, layer_set) + out <- dplyr::bind_rows(layer_set) try(out <- st_sf(out)) }