Skip to content

Commit

Permalink
fixes #34
Browse files Browse the repository at this point in the history
  • Loading branch information
dblodgett-usgs committed Jun 25, 2024
1 parent 59f5958 commit 011232d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions R/index_points_to_lines.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ match_crs <- function(x, y, warn_text = "") {
x
}

make_singlepart <- function(x, warn_text = "") {
make_singlepart <- function(x, warn_text = "", stop_on_real_multi = FALSE) {
check <- nrow(x)

gt <- st_geometry_type(x, by_geometry = FALSE)
Expand All @@ -75,6 +75,7 @@ make_singlepart <- function(x, warn_text = "") {
}

if (nrow(x) != check) {
if(stop_on_real_multi) stop("Multipart geometries not supported.")
warning(warn_text)
}

Expand Down Expand Up @@ -428,7 +429,9 @@ index_points_to_waterbodies <- function(waterbodies, points, flines = NULL,

wb_atts <- mutate(st_drop_geometry(waterbodies), index = seq_len(nrow(waterbodies)))

waterbodies <- make_singlepart(waterbodies, "Converting to singlepart.")
waterbodies <- make_singlepart(waterbodies, stop_on_real_multi = TRUE)

if(nrow(waterbodies) != nrow(wb_atts)) stop("Multipart waterbody polygons not supported.")

waterbodies <- st_coordinates(waterbodies)

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test_index.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ test_that("index to waterbodies", {
# point near waterbody
expect_equal(match[7,]$outlet_fline_COMID, 13294312)

sf::st_geometry(wb_l)[[1]] <- sf::st_multipolygon(list(sf::st_geometry(wb_l)[[1]][[1]], sf::st_geometry(wb_l)[[1]][[1]]))

expect_error(match <- index_points_to_waterbodies(wb_l, gage_l, search_radius = units::set_units(50, "m")),
"Multipart geometries not supported.")
})

sr <- units::set_units(0.1, "degrees")
Expand Down

0 comments on commit 011232d

Please sign in to comment.