3

I have a list of rasters with the same projection and resolution but different origins and I need to merge them in a single raster file.

Here's my code

l <- list.files('path', full.names=TRUE)
lst <- lapply(l, raster)
r_merged <- do.call(raster::merge, lst)

Error in compareRaster(x, extent = FALSE, rowcol = FALSE, orig = TRUE,  
 : different origin

Here's what I'd like to get. Blue squares are original rasters, I want to get a single raster as the red square.

enter image description here

  • 1
    Please explain what you mean by merge. raster::merge is a mosaicking tool – Loïc Dutrieux Jan 17 '17 at 15:00
  • 1
    By running lapply(lst, origin) you'll be able to see if the difference in origin detected by compareRaster() comes from a minor precision issue which you'll be able to ignore or if your rasters really do have different origins – Loïc Dutrieux Jan 18 '17 at 10:39
1

I would suggest that you use the stack function from the raster package. For instance, as the example in the documentation shows:

# file with one layer
fn <- system.file("external/test.grd", package="raster")
s <- stack(fn, fn)
r <- raster(fn)
s <- stack(r, fn) 
nlayers(s)
  • Sorry @dmci, actually the origins are not the same, see edits. – Quechua Jan 18 '17 at 8:24
  • If the extents are different, then I would suggest checking these solutions – dmci Dec 6 '17 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.