Description Usage Arguments Value Examples

Get the cell numbers covered by a SpatVector or SpatExtent. Or that match values in a vector; or all non `NA`

values.

1 2 3 4 5 6 7 8 9 10 11 | ```
## S4 method for signature 'SpatRaster,missing'
cells(x, y)
## S4 method for signature 'SpatRaster,numeric'
cells(x, y)
## S4 method for signature 'SpatRaster,SpatVector'
cells(x, y, method="simple", weights=FALSE, exact=FALSE, touches=is.lines(y))
## S4 method for signature 'SpatRaster,SpatExtent'
cells(x, y)
``` |

`x` |
SpatRaster |

`y` |
SpatVector, SpatExtent, 2-column matrix representing points, numeric representing values to match, or missing |

`method` |
character. Method for getting cell numbers for points. The default is "simple", the alternative is "bilinear". If it is "bilinear", the four nearest cells and their weights are returned |

`weights` |
logical. If |

`exact` |
logical. If |

`touches` |
logical. If |

numeric vector or matrix

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ```
r <- rast(ncols=10, nrows=10)
values(r) <- 1:ncell(r)
r[c(1:25, 31:100)] <- NA
r <- ifel(r > 28, r + 10, r)
# all cell numbers of cells that are not NA
cells(r)
# cell numbers that match values
x <- cells(r, c(28,38))
x$lyr.1
# cells for points
m <- cbind(x=c(0,10,-30), y=c(40,-10,20))
cellFromXY(r, m)
v <- vect(m)
cells(r, v)
cells(r, v, method="bilinear")
# cells for polygons
#f <- system.file("ex/lux.shp", package="terra")
#v <- vect(f)
#r <- rast(v)
#cv <- cells(r, v)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.