jeudi 15 janvier 2015

How to import multiple stacked raster images in R?


I have (I suppose) wery easy and silly question but I can´t really find my answer... I would like to import all multiple mosaic rasters (each mosaic is composed by 7 layers) from indicated folder into my R. Than access thems as single multilayers rasters.


enter image description here


So I did:



# read all mosaics named "mos....img" in R
raster_data<-list.files(path=getwd(), pattern="mos.*.img$")
# read files as rasters
s <- stack(raster_data)
# check my imported rasters p.ex. raster n°8 from "s" raster stack
s[[8]]


and my raster s[[8]] contain only 1 layer, so not the whole mosaic was imported!



nlayers(s[[8]])
[[1]]


If I read each mosaic separately, it works:



# read 1 mosaic (composed by 7 bands)
mosaic1<-brick("mosaic1.img")
# extract one band
band4<-subset(mosaic1, 4)


Why "stack" tool doesn´t import whole mosaics but only one band of the mosaic? and how it is possible to arrange it?

Thank you very much





Aucun commentaire:

Enregistrer un commentaire