Learn R Programming

raster (version 1.9-44)

mosaic: Merge Raster* objects, using a function to compute cell value for overlapping areas.

Description

Mosaic Raster* objects to form a new object with a larger spatial extent. A functions is used to compute cell values in areas where layers overlap (in contrast to the merge function which uses the values of the 'upper' layer). All objects must have the same origin, resolution, and coordinate reference system.

Usage

mosaic(x, y, ...)

Arguments

x
Raster* object
y
Raster* object
...
Additional RasterLayers and other arguments. See below, under Methods

Value

  • RasterLayer or RasterBrick object.

Details

The RasterLayer objects must have the same origin and resolution.

See Also

merge, expand

Examples

Run this code
r <- raster(ncol=100, nrow=100)
r1 <- crop(r, extent(-10, 11, -10, 11))
r2 <- crop(r, extent(0, 20, 0, 20))
r3 <- crop(r, extent(9, 30, 9, 30))

r1[] <- 1:ncell(r1)
r2[] <- 1:ncell(r2)
r3[] <- 1:ncell(r3)

m1 <- mosaic(r1, r2, r3, fun=mean)

s1 <- stack(r1, r1*2)
s2 <- stack(r2, r2/2)
s3 <- stack(r3, r3*4)
m2 <- mosaic(s1, s2, s3, fun=min)

Run the code above in your browser using DataLab