Skip to content

Commit

Permalink
Fix USEPA#91
Browse files Browse the repository at this point in the history
Also add error message to avoid confusion like USEPA#96 and USEPA#94
  • Loading branch information
elipousson committed Aug 20, 2024
1 parent 5418936 commit e2da1f1
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions R/internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ loc_check <- function(locations,
stop("Please supply a valid crs via locations or prj.")
}

stopifnot(
"`locations` must contain column names matching `coords`" = all(coords %in% names(locations))
)

locations <- sf::st_as_sf(x = locations, coords = coords, crs = prj)
} else if (inherits(locations, c("sf", "sfc", "sfg"))) {
sf_crs <- sf::st_crs(locations)
Expand All @@ -112,11 +116,15 @@ loc_check <- function(locations,

} else if (any(class(locations) %in% c("SpatRaster", "SpatVector"))) {
sf_crs <- sf::st_crs(locations)
locations <- sf::st_as_sf(
terra::as.points(locations, values = FALSE),
coords = terra::crds(locations, df = TRUE),
crs = sf_crs
)
coords <- terra::crds(locations, df = TRUE)

if (inherits(locations, "SpatVector")) {
locations <- terra::as.points(locations)
} else {
locations <- terra::as.points(locations, values = FALSE)
}

locations <- sf::st_as_sf(locations, coords = coords, crs = sf_crs)

if ((is.null(sf_crs) || is.na(sf_crs)) && is.null(prj)) {
stop("Please supply a valid crs via locations or prj.")
Expand Down

0 comments on commit e2da1f1

Please sign in to comment.