Search code examples
rresolutionrasterutm

How to change the resolution of a raster layer in R


I have several high resolution raster layers in R that I am working with. The level of detail is excessive for some of the analyses I am running, so I would like to speed things up by reducing the resolution.

The coordinate system is UTM so the units are meters. The resolution says it is 30, 30 (x, y). So it seems that the resolution here is 30m.

Could someone please advise me on how to change the resolution to 120m instead? I have read the help for the resample() and projectRaster() functions but they seem to require a template raster with the desired resolution, which I don't have.

Here is an example of one of my raster layers:

alt.utm
class : RasterLayer
dimensions : 4572, 2495, 11407140 (nrow, ncol, ncell)
resolution : 30, 30 (x, y)
extent : 421661, 496511, 4402939, 4540099 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=13 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
data source : in memory
names : layer
values : 1485.127, 4275.202 (min, max)


Solution

  • You can use aggregate or disaggregate.

    library(raster)
    
    #get some sample data
    data(meuse.grid)
    gridded(meuse.grid) <- ~x+y
    meuse.raster <- raster(meuse.grid)
    res(meuse.raster)
    #[1] 40 40
    
    #aggregate from 40x40 resolution to 120x120 (factor = 3)
    meuse.raster.aggregate <- aggregate(meuse.raster, fact=3)
    res(meuse.raster.aggregate)
    #[1] 120 120
    
    #disaggregate from 40x40 resolution to 10x10 (factor = 4)
    meuse.raster.disaggregate <- disaggregate(meuse.raster, fact=4)
    res(meuse.raster.disaggregate)
    #[1] 10 10