Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

merge

Merge Raster* objects


Description

Merge Raster* objects to form a new Raster object with a larger spatial extent. If objects overlap, the values get priority in the same order as the arguments, but NA values are ignored (except when overlap=FALSE). See subs to merge a Raster* object and a data.frame.

Usage

## S4 method for signature 'Raster,Raster'
merge(x, y, ..., tolerance=0.05, filename="", overlap=TRUE, ext=NULL)

## S4 method for signature 'RasterStackBrick,missing'
merge(x, ..., tolerance=0.05, filename="", ext=NULL)

## S4 method for signature 'Extent,ANY'
merge(x, y, ...)

Arguments

x

Raster* or Extent object

y

Raster* if x is a Raster* object (or missing). If x is an Extent, y can be an Extent or object from which an Extent can be extracted

...

additional Raster or Extent objects (and/or arguments for writing files as in writeRaster)

tolerance

numeric. permissible difference in origin (relative to the cell resolution). See all.equal

filename

character. Output filename (optional)

overlap

logical. If FALSE values of overlapping objects are based on the first layer, even if they are NA

ext

Extent object (optional) to limit the output to that extent

Details

The Raster objects must have the same origin and resolution. In areas where the Raster objects overlap, the values of the Raster object that is first in the sequence of arguments will be retained. If you would rather use the average of cell values, or do another computation, you can use mosaic instead of merge.

Value

RasterLayer or RasterBrick

Examples

r1 <- raster(xmx=-150, ymn=60, ncols=30, nrows=30)
values(r1) <- 1:ncell(r1)
r2 <- raster(xmn=-100, xmx=-50, ymx=50, ymn=30)
res(r2) <- c(xres(r1), yres(r1))
values(r2) <- 1:ncell(r2)
rm <- merge(r1, r2)

# if you have many RasterLayer objects in a list
# you can use do.call:
x <- list(r1, r2)
# add arguments such as filename
# x$filename <- 'test.tif'
m <- do.call(merge, x)

raster

Geographic Data Analysis and Modeling

v3.4-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Jacob van Etten [ctb], Michael Sumner [ctb], Joe Cheng [ctb], Dan Baston [ctb], Andrew Bevan [ctb], Roger Bivand [ctb], Lorenzo Busetto [ctb], Mort Canty [ctb], Ben Fasoli [ctb], David Forrest [ctb], Aniruddha Ghosh [ctb], Duncan Golicher [ctb], Josh Gray [ctb], Jonathan A. Greenberg [ctb], Paul Hiemstra [ctb], Kassel Hingee [ctb], Institute for Mathematics Applied Geosciences [cph], Charles Karney [ctb], Matteo Mattiuzzi [ctb], Steven Mosher [ctb], Babak Naimi [ctb], Jakub Nowosad [ctb], Edzer Pebesma [ctb], Oscar Perpinan Lamigueiro [ctb], Etienne B. Racine [ctb], Barry Rowlingson [ctb], Ashton Shortridge [ctb], Bill Venables [ctb], Rafael Wueest [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.