View source: R/getValueByCell.r
getValueByCell | R Documentation |
These functions get values from a raster at specific cells, or values to specific cells.
getValueByCell(x, cell, format = "raster")
setValueByCell(x, val, cell, format = "raster")
x |
A |
cell |
Cell indices. There must be one per value in |
format |
The type of cell indexing used. This can be either "raster" for row indexing (default) or "matrix" for column indexing. Row indexing (the default for rasters), starts with cell "1" in the upper left, cell "2" is to its right, and so on. Numbering then wraps around to the next row. Column indexing (the default for matrices) has the cell "1" in the upper left corner of the matrix. The cell "2" is below it, and so on. The numbering then wraps around to the top of the next column. |
val |
One or more values. If more the number of cells specified is greater than the number of values in |
A data frame (getValueByCell
) with cell numbers (in row format), or a SpatRaster
(setValueByCell
).
setValues
, values
library(terra)
x <- rast(nrow=10, ncol=10)
x[] <- round(10 * runif(100))
cell <- c(1, 20, 40, 80)
getValueByCell(x, cell = cell)
getValueByCell(x, cell = cell, format = 'matrix')
y <- setValueByCell(x, val = 20, cell = cell)
plot(y)
z <- setValueByCell(x, val = 30, cell = cell, format = 'matrix')
plot(c(x, y, z))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.