r - raster images stacked recursively -
i have following problem, please. need read recursively raster images, stack , store them in file different names (e.g. name1.tiff, name2.tiff, ...)
i tried following:
(i in 10) { fn <- system.file ("external / test.grd", package = "raster") fn <-stack (fn) # not sure if idea can work. fnstack[,, i] <-fn }
here expect result of form:
dim (fnstack)
[1] 115 80 10
or that
but didn't work.
actually, have around 300 images have store different names. purpose extract time series information (if know method or suggestions appreciate it)
any suggestions welcomed. thank in advance time.
what first put *.tiff in single folder. read names list. stack them , write multi-layered raster. i'm assuming images have same extent , projection.
### load necessary packages library(tiff) library(raster) library(sp) library(rgdal) #i cant recall packages might need library(grid) # overkill library(car) ############ function extracts last n characters string ############ without counting last m subs <- function(x, n=1,m=0){ substr(x, nchar(x)-n-m+1, nchar(x)-m) } setwd("your working directory path") # set wd images filez <- list.files() # creates list files in wd no <- length(filez) # amount of files found imagestack <- stack() # initialize raster stack (i in 1:no){ if (subs(filez[i],4)=="tiff"){ image <- raster(filez[i]) # fill raster stack tiffs imagestack <- addlayer(imagestack,image) } } writeraster(imagestack,filename="output path",options="interleave=band",overwrite=true) # write stack
i did not try this, should work.
Comments
Post a Comment