raster extent in r not working with topographic covariates and color imagery tif

69 Views Asked by At

so I have tried doing some examples I have read on here regarding multiple rasters. I am using random forest on r to make some prediction maps. So far, my topographic covariates have worked (relative slope position, saga wetness index...). I have three new images for red, green, and transparent to add. after I do the raster stack command, its give me this error "Error in compareRaster(x) : different extent" Below is the data information for the rasters and the code I used.

library(raster)
catch <- raster("Catchment Slope.tif")
EM <- raster("EM_data_April_14.tif")
red.2 <- raster("red_re1.tif"  )
green.2 <- raster("green1.tif" )
trans <- raster("extmskres1.tif" )

Here are the Rasters

red.2
#class      : RasterLayer 
#band       : 1  (of  4  bands)
#dimensions : 246, 435, 107010  (nrow, ncol, ncell)
#resolution : 1.219202, 1.219202  (x, y)
#extent     : 285721.7, 286252.1, 3732915, 3733215  (xmin, xmax, ymin, ymax)
#crs        : +proj=utm +zone=17 +datum=WGS84 +units=m +no_defs 
#source     : D:/IHF_Research/spectral image/resampled files/clipped from #arc/red_re1.tif 
#names      : red_re1 
#values     : 155, 255  (min, max)

trans
#class      : RasterLayer 
#band       : 1  (of  4  bands)
#dimensions : 246, 435, 107010  (nrow, ncol, ncell)
#resolution : 1.219202, 1.219202  (x, y)
#extent     : 285721.7, 286252.1, 3732915, 3733215  (xmin, xmax, ymin, ymax)
#crs        : +proj=utm +zone=17 +datum=WGS84 +units=m +no_defs 
#source     : D:/IHF_Research/spectral image/resampled files/clipped from arc/extmskres1.tif 
#names      : extmskres1 
#values     : 24, 255  (min, max)

green.2
#class      : RasterLayer 
#band       : 1  (of  4  bands)
#dimensions : 246, 435, 107010  (nrow, ncol, ncell)
#resolution : 1.219202, 1.219202  (x, y)
#extent     : 285721.7, 286252.1, 3732915, 3733215  (xmin, xmax, ymin, ymax)
#crs        : +proj=utm +zone=17 +datum=WGS84 +units=m +no_defs 
#source     : D:/IHF_Research/spectral image/resampled files/clipped from arc/green1.tif 
#names      : green1 
#values     : 155, 255  (min, max)

saga
#class      : RasterLayer 
#dimensions : 272, 417, 113424  (nrow, ncol, ncell)
#resolution : 1.219202, 1.219202  (x, y)
#extent     : 285741.7, 286250.1, 3732893, 3733225  (xmin, xmax, ymin, ymax)
#crs        : +proj=utm +zone=17 +datum=NAD83 +units=m +no_defs 
#source     : D:/IHF_Research/RandomForest/saga.tif 
#names      : saga 
#values     : 0.580749, 9.365674  (min, max)

I get this error

rasStack <- stack(rsp,saga,topo,tca,valley,catch,red.2)
#"Error in compareRaster(x) : different extent" 
1

There are 1 best solutions below

1
On

saga has a different extent from the other Rasters you show. You can see that like this

library(raster)
e <- extent(285721.7, 286252.1, 3732915, 3733215)
esaga <- extent(285741.7, 286250.1, 3732893, 3733225)
plot(union(e, esaga), type="n")
lines(e, col="red")
lines(esaga, col="blue")

You can perhaps use a combination of crop/extend, if not you can use resample