Skip to content

Commit e2da1f1

Browse files
committed
Fix USEPA#91
Also add error message to avoid confusion like USEPA#96 and USEPA#94
1 parent 5418936 commit e2da1f1

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

R/internal.R

+13-5
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ loc_check <- function(locations,
9595
stop("Please supply a valid crs via locations or prj.")
9696
}
9797

98+
stopifnot(
99+
"`locations` must contain column names matching `coords`" = all(coords %in% names(locations))
100+
)
101+
98102
locations <- sf::st_as_sf(x = locations, coords = coords, crs = prj)
99103
} else if (inherits(locations, c("sf", "sfc", "sfg"))) {
100104
sf_crs <- sf::st_crs(locations)
@@ -112,11 +116,15 @@ loc_check <- function(locations,
112116

113117
} else if (any(class(locations) %in% c("SpatRaster", "SpatVector"))) {
114118
sf_crs <- sf::st_crs(locations)
115-
locations <- sf::st_as_sf(
116-
terra::as.points(locations, values = FALSE),
117-
coords = terra::crds(locations, df = TRUE),
118-
crs = sf_crs
119-
)
119+
coords <- terra::crds(locations, df = TRUE)
120+
121+
if (inherits(locations, "SpatVector")) {
122+
locations <- terra::as.points(locations)
123+
} else {
124+
locations <- terra::as.points(locations, values = FALSE)
125+
}
126+
127+
locations <- sf::st_as_sf(locations, coords = coords, crs = sf_crs)
120128

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

0 commit comments

Comments
 (0)