| makeTiles | R Documentation |
Divide a SpatRaster into "tiles". The cells of another SpatRaster (normally with a much lower resolution) or a SpatVector with polygon geometry can be used to define the tiles. You can also provide one or two numbers to indicate the number of rows and columns per tile.
getTileExtents returns the extents of the (virtual) tiles, while makeTiles creates files for the tiles and returns their filenames.
## S4 method for signature 'SpatRaster'
makeTiles(x, y, filename="tile_.tif", extend=FALSE,
na.rm=FALSE, buffer=0, value="files", overwrite=FALSE, ...)
## S4 method for signature 'SpatRaster'
getTileExtents(x, y, extend=FALSE, buffer=0, cores=1)
x |
SpatRaster |
y |
SpatRaster or SpatVector defining the zones; or a positive integer specifying the number of rows and columns for each zone (or 2 numbers to differentiate the number of rows and columns). For |
filename |
character. Output filename template. Filenames will be altered by adding the tile number for each tile |
extend |
logical. If |
na.rm |
logical. If |
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. |
cores |
integer (only used by |
value |
character. The type of return value desired. Either "files" (for the filenames), "raster" (for a SpatRaster), or "collection" (for a SpatRasterCollection) |
overwrite |
logical. If |
... |
additional arguments for writing files as in |
When y is missing in getTileExtents, the tile size is chosen so that
tiles align to whole GDAL blocks of the source file(s) (as reported by fileBlocksize). When no source block size is reported, a default of 256 rows by 256 columns is used.
the per-worker peak memory (cells per tile \times nlyr \times 8 bytes \times a small ncopies factor) stays within cores workers' share of terraOptions("memfrac") of free RAM (see free_RAM, terraOptions).
there are at least a few tiles per worker, so the work load-balances.
the result never exceeds the raster's own dimensions.
In practice this means that for a tiled GeoTIFF / COG, tiles are an integer multiple of the file block size; for an in-memory or non-tiled raster the result is roughly square.
makeTiles returns a character (filenames), SpatRaster or SpatRasterCollection value. getTileExtents returns a matrix with extents
vrt to create a SpatRaster from tiles; crop for sub-setting arbitrary parts of a SpatRaster; divide to divide a SpatRaster into parts.
r <- rast(ncols=100, nrows=100)
values(r) <- 1:ncell(r)
x <- rast(ncols=2, nrows=2)
getTileExtents(r, x)
getTileExtents(r, x, buffer=3)
# auto: tile size from GDAL block size and a per-worker memory budget
getTileExtents(r) # cores = 1
getTileExtents(r, cores=4) # smaller tiles, sized for 4 concurrent workers
filename <- paste0(tempfile(), "_.tif")
ff <- makeTiles(r, x, filename)
ff
vrt(ff)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.