This function divides a GRaster into "tiles" or spatial subsets which can be used for speeding some raster calculations. Tiles can be mutually exclusive or overlap by a user-defined number of cells.
Arguments
- x
A
GRasterwith one or more layers.- n
Numeric vector: Number of tiles to create. This can be a single number, in which case
xis divided inton×ntiles, or two values in which case it is divided inton[1]×n[2]tiles (rows x columns).- overlap
Numeric vector (default is 0): Number of rows/columns by which to expand the size of tiles so they overlap. This can be a single value or two values. If just one is provided, the tiles will be expanded by
overlaprows andoverlapscolumns. If two numbers are provided, the tiles will be expanded byoverlap[1]rows andoverlap[2]columns.- verbose
Logical: If
TRUE, display progress. Default isFALSE. Progress is only displayed ifxis a multi-layerGRaster.
Value
If x has just one layer, then the output is a list with one element per tile. The lapply() and sapply() functions can be used to apply functions to each tile in the list. If x has more than one layer, then the output will be a list of lists, with each sub-list containing the tiles for one GRaster layer.
Examples
if (grassStarted()) {
# Setup
library(terra)
# Elevation raster
madElev <- fastData("madElev")
# Convert a SpatRaster to a GRaster:
elev <- fast(madElev)
# Create spatially exclusive tiles:
exclusive <- tiles(elev, n = 2, verbose = TRUE)
startpar <- par(mfrow = c(2, 3))
plot(elev, main = "Original")
for (i in seq_along(exclusive)) {
plot(exclusive[[i]], ext = elev, main = paste("Tile", i))
}
par(startpar)
# Create tiles that overlap:
overlaps <- tiles(elev, n = 2, overlap = 200, verbose = TRUE)
startpar <- par(mfrow = c(2, 3))
plot(elev, main = "Original")
for (i in seq_along(overlaps)) {
plot(overlaps[[i]], ext = elev, main = paste("Tile", i))
}
par(startpar)
}
