R - get a specific band of a RasterLayer

孤街浪徒 提交于 2019-12-05 18:31:12

You should be able to do:

f <- "/media/karimdion/Passport/Essais/po_3804017_bgrn_0000000 tif"
rx<-raster(f)
for( i in 1:rx@file@nbands ){
  assign( paste("rx" , i , sep = "." , raster(f, band=i)
}

This should give you four files, rx.1 , rx.2 , rx.3 , rx.4, one for each band of the raster file. I am sure there is a better (more efficient and correct 'raster') way of doing this, but I can't remember off the top of my head right now.

With filename f (here using an example file for reproducibility)

 f <- system.file("external/rlogo.grd", package="raster")

For a particular band, you can do

 r <- raster(f, band=2)

Or for all bands

 b <- brick(f)

Or (less efficient):

 s <- stack(f)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!