How to do the raster package identify all bands (layers) of a image?

878 views Asked by At

i'm trying to use de raster package to read a multilayer (multiband) image (ENVI format [.hdr]) that have 160 values of refletance and 160 values of wavelength per pixel, but when i use the code that i developed, the program returns only 1 band and the refletance value associated.section1=raster("./x") getValuesBlock(section1, row=1, nrows=1, col=1, ncol=1 )

2

There are 2 answers

0
Robert Hijmans On

To create a multi-layer Raster object, you should use the brick function if they layers are in one file, or the stack function if they are in multiple files.

library(raster)
# example file name
f <- system.file("external/rlogo.grd", package="raster")
b <- brick(f)
b

# a single cell value
b[1]
0
Thedarknight On

Well, from the looks of it , it seems to me that you want to read a particular band of a raster file into the R environment ,

require("raster")
dir.file<-"dir/file.hdf"
#Reading the first band of the raster image
band1<-raster(dir.file,band=1)

Change the values of theband parameter of the raster() method to control the band id of your raster. Hope this helps