Dear list,
I was given three raster files with 'slope', 'aspect' and 'altitude' of my
study site. I realised that one of the three rasters (namely 'altitude')
has a slightly different raster cell resolution, which results in a
slightly different raster extent and does not allow me to raster::stack()
the three layers to create a single stack object.
I tried to change the raster resolution using raster::res() for the raster
'altitude' but, when I subsequently cropped the three rasters with an
object of class extent, I still got different extents between "slope and
aspect" vs. "altitude".
Any advice on how to solve this cell resolution incongruence is very
welcome.
Here below I report the output to make things more understandable.
Thanks in advance,
Gabriele
#----------------
#----------------
aspect <- raster("~/Envir/aspect/prj.adf")
slope <- raster("~/Envir/slope/prj.adf")
altitude <- raster("~/Envir/20130508094222_992463356.tif")
aspect ( N.B. 'slope' returns exactly the same attributes!)
#class : RasterLayer
#dimensions : 9813, 8428, 82703964 (nrow, ncol, ncell)
#resolution : 27.28532, 27.28532 (x, y)
#extent : 135446.9, 365407.6, 4345919, 4613669 (xmin, xmax, ymin,
ymax)
#coord. ref. : +proj=utm +zone=38 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0
+units=m +no_defs
altitude
#class : RasterLayer
#dimensions : 9812, 8428, 82695536 (nrow, ncol, ncell)
#resolution : 27.28532, 27.28677 (x, y)
#extent : 135446.9, 365407.6, 4345919, 4613656 (xmin, xmax, ymin,
ymax)
#coord. ref. : +proj=utm +zone=38 +datum=WGS84 +units=m +no_defs
+ellps=WGS84 +towgs84=0,0,0
ex <- extent(animal_locations)
ex
#class : Extent
#xmin : 257473.1
#xmax : 312499.1
#ymin : 4452821
#ymax : 4570717
Before using the function raster.crop <- crop('raster_file', ex) to crop
all rasters to the same extent, I tried to change the resolution of
'altitude' using
res(altitude) <- 27.28532
altitude
#class : RasterLayer
#dimensions : 9813, 8428, 82703964 (nrow, ncol, ncell)
#resolution : 27.28532, 27.28532 (x, y)
#extent : 135446.9, 365407.6, 4345905, 4613656 (xmin, xmax, ymin,
ymax)
#coord. ref. : +proj=utm +zone=38 +datum=WGS84 +units=m +no_defs
+ellps=WGS84 +towgs84=0,0,0
When I then run crop() for aspect and the new defined altitude I however
become different extents (i.e. ymin and ymax) despite now the dimensions
and resolutions are the same
crop(aspect, ex)
#class : RasterLayer
#dimensions : 5054, 2749, 13893446 (nrow, ncol, ncell)
#resolution : 27.28532, 27.28532 (x, y)
#extent : 247480.5, 322487.8, 4442809, 4580709 (xmin, xmax, ymin,
ymax)
#coord. ref. : +proj=utm +zone=38 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0
+units=m +no_defs
#names : prj
#values : -1, 359.8158 (min, max)
crop(altitude, ex)
#class : RasterLayer
#dimensions : 5054, 2749, 13893446 (nrow, ncol, ncell)
#resolution : 27.28532, 27.28532 (x, y)
#extent : 247480.5, 322487.8, 4442823, 4580723 (xmin, xmax, ymin,
ymax)
#coord. ref. : +proj=utm +zone=38 +datum=WGS84 +units=m +no_defs
+ellps=WGS84 +towgs84=0,0,0
It also appears to me that by redefining res(altitude) I loose the actual
values assigned to each pixel. Is there an argument to assign to the new
pixels the value of the centre of the pixel?