[R-sig-Geo] Merge rasters with different extent

Thiago Veloso thi_veloso at yahoo.com.br
Tue Jun 19 18:20:58 CEST 2012


 Dear list,

 I have two rasters (r1 and r2). r1 has larger extent; r2 is smaller and its extents fall totally within r1. Here are the rasters:

> r1

class       : RasterLayer 
dimensions  : 360, 720, 259200  (nrow, ncol, ncell)
resolution  : 0.5, 0.5  (x, y)
extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
values      : in memory
layer name  : layer 
min value   : 0 
max value   : 0.055233 

> r2

class       : RasterLayer 
dimensions  : 47, 65, 3055  (nrow, ncol, ncell)
resolution  : 0.5, 0.5  (x, y)
extent      : -74.5, -42, -18, 5.5  (xmin, xmax, ymin, ymax)
coord. ref. : NA 
values      : in memory
layer name  : layer 
min value   : 0 
max value   : 1 

 What I would like to be able to do is merge both rasters, but keeping r2 values when cells overlap. In other words, replace r1 values with r2 values only when cells overlap. Following older discussions, I have tried "merge" command without sucess. Neither "r3 <- merge(r1,r2)" nor "r3 <- merge(r2,r1)" yield what I pursue. 

 Any ideas?

 Many thanks in advance,

 Thiago.




More information about the R-sig-Geo mailing list