Get the cell numbers covered by a SpatVector or SpatExtent. Or all non NA
values.
# S4 method for SpatRaster,missing
cells(x, y, ...)# S4 method for SpatRaster,SpatVector
cells(x, y, touches=is.lines(y), method="simple", ...)
# S4 method for SpatRaster,SpatExtent
cells(x, y, ...)
SpatRaster
SpatVector, SpatExtent, 2-column matrix representing points, or missing
logical. If TRUE
, values for all cells touched by lines or polygons are extracted, not just those on the line render path, or whose center point is within the polygon. Not relevant for points
character. method for extracting values with points. The default is "simple", the alternative is "bilinear"
additional arguments. None implemented
matrix if y
is a SpatVector
, otherwise a vector.
# NOT RUN {
r <- rast(ncols=10, nrows=10)
values(r) <- 1:ncell(r)
r[c(1:25, 31:100)] <- NA
cells(r)
m <- cbind(x=c(0,10,-30), y=c(40,-10,20))
cellFromXY(r, m)
v <- vect(m)
cells(r, v)
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
r <- rast(v)
#cv <- cells(r, v)
#z <- cells(r,ext(v))
#xy <- xyFromCell(r, z)
#plot(v)
#points(xy)
# }
Run the code above in your browser using DataLab