1

I have 300 .tiff files, that i need to create raster stack of them. Can you please help me with R code for that?

I can do in Arcgis, Envi, R. I have tried:

setwd("F:\\MODIS\\Modis EVI\\HDF8 EVI")

list.files(path="F:\\MODIS\\Modis EVI\\HDF8 EVI", pattern = ".tif")

tifs <- list.files(path="F:\\MODIS\\Modis EVI\\HDF8 EVI", pattern = ".tif")
stackSave(tifs,"hdf8_EVI.TIF")

and

setwd("F:\\MODIS\\Modis EVI\\HDF8 EVI")
raster_stack=list.files(getwd(), pattern="tif$", full.names=FALSE)
for(i in raster_stack) { assign(unlist(strsplit(i, "[.]"))[1], raster(i)) }

Both didn't work!

  • 1
    Please take the community tour and edit your question to include what exactly it is that you are having problems with and what you have tried, including code snippets. – MaryBeth May 11 '16 at 12:46
  • You may also find this post from Stack Overflow useful to produce a minimal reproducible example. This will greatly help us recreate your problem and test solutions. – Phil May 11 '16 at 13:05
  • Also, describe what "didn't work" means. Did you get an error? If so, include it in your question. If not, what behavior did you get vs. what you expected? – Evil Genius May 11 '16 at 13:45
2

Try

fs <- list.files(path="F:\\MODIS\\Modis EVI\\HDF8 EVI", pattern = "tif$", full.names = TRUE)
library(raster)
s <- raster::stack(fs)
writeRaster(s, "hdf8_EVI.TIF")

I have no idea what stackSave is. Please read about asking questions here and look into the basics of the raster package. Don't use assign, and don't use setwd - both are really bad practice for general use.

EDIT: just learnt what raster::stackSave is - it's awesome. It's not for writing multi-band TIF files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.