Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
rhijmans committed Jan 2, 2025
1 parent 4b512d4 commit 64e88ec
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions R/extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,8 @@ extractAlong <- function(x, y, ID=TRUE, cells=FALSE, xy=FALSE, online=FALSE, bil
setMethod("extractRange", signature(x="SpatRaster", y="ANY"),
function(x, y, first, last, lyr_fun=NULL, geom_fun=NULL, ID=FALSE, na.rm=TRUE, ...) {

first <- getLyrNrs(first, names(x), nrow(y)) + 1
last <- getLyrNrs(last, names(x), nrow(y)) + 1
first <- getLyrNrs(sort(first), names(x), nrow(y)) + 1
last <- getLyrNrs(sort(last), names(x), nrow(y)) + 1
e <- extract(x, y, geom_fun, ID=TRUE, na.rm=na.rm, ...)
if (nrow(e) != nrow(y)) {
error("range_extract", "geom_fun must return a single value for each geometry/layer")
Expand Down
2 changes: 1 addition & 1 deletion man/extractRange.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ r <- rast(system.file("ex/logo.tif", package="terra"))
xy <- data.frame(c(50,80), c(30, 60))
extract(r, xy)
extract(r, xy, layer=c("red", "green"))
extractRange(r, xy, first=1:2, last=3:2, lyr_fun=sum)
extractRange(r, xy, first=1:2, last=2:3, lyr_fun=sum)
}

\keyword{methods}
Expand Down

0 comments on commit 64e88ec

Please sign in to comment.