I have 10 raster files. I want to stack them. How to keep same extent for all these 10 files ?
library(raster)
rasterfile <- list.files(file.path("E:/NDVI RESULT FINAL"), full.names = T, pattern = '.tif$')
f1 <- "E:/NDVI RESULT FINAL/NDVI converted 2009.tif"
r1 <- raster(f1)
f2 <- "E:/NDVI RESULT FINAL/NDVI converted 2010.tif"
r2 <- raster(f2)
f3 <- "E:/NDVI RESULT FINAL/NDVI converted 2011.tif"
r3 <- raster(f3)
# and so on
extent(rasterf1)
#class : Extent xmin : 72.23081 xmax : 77.79537 ymin : 34.26277 ymax : 37.35659
extent(rasterf2)
#class : Extent xmin : 72.51037 xmax : 77.68996 ymin : 34.51186 ymax : 37.098
extent(rasterf3)
#class : Extent xmin : 72.2514 xmax : 77.94309 ymin : 34.20765 ymax : 37.40778
extent(rasterf4)
#class : Extent xmin : 72.23081 xmax : 77.79537 ymin : 34.26277 ymax : 37.35659
etcetera
Normally, you would do
Does this not work? If so, you can do something like this to see what the extents are.
Later:
You have now shows that all the extents are different. The first question to ask is why? How were these files generated? They should probably be re-generated so that they do have the same extent. You can also use resample, but then there is some data quality loss.
Example data
Problem
Solution