SpaDES (version 1.1.4)

splitRaster: Split a raster into multiple tiles.

Description

Divides up a raster into an arbitrary number of pieces. Split rasters can be recombined using do.call(merge, x).

Usage

splitRaster(x, nx, ny)

## S3 method for class 'RasterLayer,integer,integer': splitRaster(x, nx, ny)

## S3 method for class 'RasterLayer,numeric,numeric': splitRaster(x, nx, ny)

Arguments

x
The raster to be split.
nx
The number of tiles to make along the x-axis.
ny
The number of tiles to make along the y-axis.

Value

  • A list of cropped raster tiles.

See Also

do.call, merge.

Examples

Run this code
library(raster)
# an example with dimensions:
# nrow = 77
# ncol = 101
# nlayers = 3
b <- brick(system.file("external/rlogo.grd", package = "raster"))
r <- b[[1]] # use first layer only
nx <- 3
ny <- 4
y <- splitRaster(r, nx, ny)

# the original raster:
plot(r) # may require a call to `dev()` if using RStudio

# the split raster:
layout(mat = matrix(seq_len(nx*ny), ncol = nx, nrow = ny))
plotOrder <- c(4,8,12,3,7,11,2,6,10,1,5,9)
invisible(lapply(y[plotOrder], plot))

# can be recombined using `raster::merge`
m <- do.call(merge, y)
all.equal(m, r)

Run the code above in your browser using DataLab