0
votes

I have three rasters. Raster1 is a landcover file for a land cover types. Raster2 and raster3 are rasters showing variable 'NPP'. As you can see each raster has different extent & resolution. I want to know how much NPP is in both raster 2 and 3 in accordance with the landcover for raster1. However what could be done in order to bring all rasters to same extent and resolution and find NPP in raster2 and raster3 accordance with the landcover class in raster1?

(How can I know which resolution should I choose for all the rasters?)

> raster1
    class      : RasterLayer 
    dimensions : 2803, 5303, 14864309  (nrow, ncol, ncell)
    resolution : 0.008333333, 0.008333333  (x, y)
    extent     : 60.85, 105.0417, 15.95833, 39.31667  (xmin, xmax, ymin, ymax)
    crs        : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
    source     :XXXXX
    names      : landusemaskedme 
    values     : 1, 12  (min, max)

    raster2
    class      : RasterLayer 
    dimensions : 2336, 4419, 10322784  (nrow, ncol, ncell)
    resolution : 0.01, 0.01  (x, y)
    extent     : 60.85, 105.04, 15.96, 39.32  (xmin, xmax, ymin, ymax)
    crs        : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
    source     : memory
    names      : NPP
    values     : 0, 31.78096  (min, max)

    > raster3
    class      : RasterLayer 
    dimensions : 47, 89, 4183  (nrow, ncol, ncell)
    resolution : 0.5, 0.5  (x, y)
    extent     : 60.75, 105.25, 15.75, 39.25  (xmin, xmax, ymin, ymax)
    crs        : NA 
    source     : memory
    names      : NPP 
    values     : 0, 21.141  (min, max)
1

1 Answers

1
votes

I can see that your rasters are having almost same extent and coordinate system except for raster3 which does not have any reference system (crs: NA). First, you need to have rasters of the same extent and coordinate reference system, then you can use resample function from raster package like

library(raster)

#To have the same projection for raster3 as that of your base landcover class in raster1
newproj <- projection(raster1)
praster3 <- projectRaster(raster3, crs=newproj)
  
#Conversion of rasters into same extent
raster2_resampled <- resample(raster2, raster1, method='bilinear')
raster3_resampled <- resample(praster3, raster1, method='bilinear')

It is always better to resample a finer resolution raster to coarser resolution, not the vice versa though it can be done as you have asked in your question. In your case, raster1 has the finer resolution (0.008333333 x 0.008333333) followed by raster2 (0.01 x 0.01). raster3 has the coarsest resolution (0.5 x 0.5). So, it would be better to convert all the rasters to the resolution and extent of raster3. Hope that helps you out.