This function divides a raster 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 amount.
Arguments
- x
A
GRaster
.- n
Numeric vector: Number of tiles to create. This can be a single number, in which case
x
is divided inton
×n
tiles, 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
overlap
rows andoverlaps
columns. If two numbers are provided, the tiles will be expanded byoverlap[1]
rows andoverlap[2]
columns.- verbose
Logical: If
TRUE
, display progress. Default isFALSE
.
Value
A list
with one element per tile. The lapply()
and sapply()
functions can be used to apply functions to each tile in the list.
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)
}