| chunk | R Documentation |
This method allows for running a function that takes a SpatRaster as first argument in chunks (tiles). This can be useful if the functions is not memory-safe, typically because it reads all the raster cell values into memory.
This method is not designed to be especially efficient, and there might be more efficient ways to accomplish what the the goal of the function that is not memory-safe.
Also, some functions must have access to all cells at once to be valid. In those cases, chunk would return incorrect results.
## S4 method for signature 'SpatRaster'
chunk(x, fun, ..., n=NULL, buffer=0, filename="", wopt=list())
x |
SpatRaster |
fun |
function that takes a SpatRaster as first argument |
... |
additional arguments for fun |
n |
NULL or positive integer to specifying the number of rows and columns for each chunk (or 2 numbers for a different number of rows and columns, as in |
buffer |
integer. The number of additional rows and columns added to each tile. Can be a single number, or two numbers to specify a separate number of rows and columns. This allows for creating overlapping tiles that can be used for computing spatial context dependent values with e.g. |
filename |
character. Output filename |
wopt |
list with additional arguments for writing files as in |
SpatRaster
s <- rast(system.file("ex/logo.tif", package="terra"))
f <- function(x, a = 0) {
print("chunk")
sum(x) + a
}
x <- chunk(s, f, a=100)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.