I have the following raster:
> modis
class : RasterLayer
dimensions : 1776, 4320, 7672320 (nrow, ncol, ncell)
resolution : 0.08333333, 0.08333333 (x, y)
extent : -180, 180, -64, 84 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : /Users/maps/MODIS_PANratios.tif
names : MODIS_PANratios
values : 1, 20 (min, max)
attributes :
ID category
from: 0
to : 20 Woody savannas
Please note this raster contains categorical attributes.
I want to create a raster stack
with modis
and a second raster with different resolution and extent:
> rDif
class : RasterLayer
dimensions : 720, 1440, 1036800 (nrow, ncol, ncell)
resolution : 0.25, 0.25 (x, y)
extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : /Users/maps/liuDif.tif
names : liuDif
values : 0, 4150641 (min, max)
I use project raster
to adapt extent and resolution from modis
to rDif
to be able to stack both:
modis.new <- projectRaster(from=modis, to=rDif, method="ngb")
The problem is that the new raster has lost its original attributes:
> modis.new
class : RasterLayer
dimensions : 720, 1440, 1036800 (nrow, ncol, ncell)
resolution : 0.25, 0.25 (x, y)
extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names : MODIS_PANratios
values : 1, 20 (min, max)
How can I standardise the extent and resolution of two rasters without loosing the original attributes?
dimensions
andresolution
? Or value 0? Seems that 0 has no class assignedbackup <- levels(modis) ; levels(modis.new) <- backup
modis[modis==0] <- NA
but the 0 class with no name assigned still appearslevels(modis)
consider value 0? An option could be erasing it from this list