Reputation: 63
I am new R user and read 18 Geotiff file in R and masked the tiff according to my region of interest. I am now unable to write 18 masked Geotiff file.
require(raster)
raster_data <- list.files(path=getwd())
s <- stack(raster_data)
spf<-readShapePoly("basin.shp")
rc<-crop(s, extent(spf))
rm<-mask(rc, spf)
rf <- writeRaster(rm, filename=outputFile, overwrite=TRUE)
I want 18 Geotiff file masked form my shapefile but the output is only one tif file and It doesn't open. I use search option in the internet but couldn't find appropriate answer to my query.
Thank you
Upvotes: 1
Views: 2035
Reputation: 5856
You'll certainly find the answer to your question on SO. It was asked before here and here and answers provided here but also here with the bylayer
option provided by writeRaster
.
try bylayer = T
if you don't need to unstack them to a list.
something like
library(raster)
r1 <- raster(ncol=10, nrow=10)
r1[] <- 1:100
s <- stack(r1, r1)
writeRaster(s, '~:/r.tif', bylayer = T)
Upvotes: 3