tiles,GRaster-method | R Documentation |
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.
## S4 method for signature 'GRaster'
tiles(x, n, overlap = 0, verbose = FALSE)
x |
A |
n |
Numeric vector: Number of tiles to create. This can be a single number, in which case |
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 |
verbose |
Logical: If |
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 list
s, with each sub-list
containing the tiles for one GRaster
layer.
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.