[GIS] Stack rasters with different origin, dimensions and resolution in R

dimensionsrrasterresolutionstack

I have three raster files with the same extent and CRS, but with different origin, dimensions and resolution.

r1
class       : RasterLayer 
dimensions  : 3020, 3043, 9189860  (nrow, ncol, ncell)
resolution  : 0.003446425, 0.003657477  (x, y)
extent      : -8.69165, 1.79582, 49.83774, 60.88332  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
names       : r1
values      : -0.272593, 5616  (min, max)

r2
class       : RasterLayer 
dimensions  : 1221, 655, 799755  (nrow, ncol, ncell)
resolution  : 0.0160114, 0.009046339  (x, y)
extent      : -8.69165, 1.79582, 49.83774, 60.88332  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
names       : r2
values      : 0, 10  (min, max)

r3
class       : RasterLayer 
dimensions  : 1326, 1259, 1669434  (nrow, ncol, ncell)
resolution  : 0.00833, 0.00833  (x, y)
extent      : -8.69165, 1.79582, 49.83774, 60.88332  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
names       : r3
values      : -0.4956901, 8.6887  (min, max)

When I try to create a raster stack, I get the following error:

predictors<-stack(r1, r2, r3)
Error in compareRaster(x) : different number or columns

I tried to re-sample r1,r2 according to one raster, lets say r3 – but it did not work.

Any advice how to solve this issue?

The rasters can be downloaded here: https://www.dropbox.com/sh/zfbm05qwmsgp0lh/AAC7xGxSUuEyYeIQbqSqh1FPa?dl=0

Best Answer

You can use projectRaster() to resample to a new resolution (also extent and CRS):

r2resampled <- projectRaster(r2,r1,method = 'ngb')
r3resampled <- projectRaster(r3,r1,method = 'bilinear')

The first one is categorical, so it's necessary to use nearest neighbor as method (ngb). The second one is numeric, so you can use bilinear (bilinear) or nearest neighbor (some researchers prefer to use ngb as method because with bilinear you are changing the original information to the new resolution, especially in RS products).

Check the result:

plot(stack(r1,r2resampled,r3resampled))

enter image description here