Skip to content

Commit

Permalink
Merge pull request #381 from DOI-USGS/hr_bind_bug
Browse files Browse the repository at this point in the history
Hr bind bug
  • Loading branch information
dblodgett-usgs authored May 8, 2024
2 parents 4372a01 + c13b32b commit 251550a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions R/get_nhdplushr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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),
Expand Down
10 changes: 6 additions & 4 deletions R/index_nhdplus.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 251550a

Please sign in to comment.