本文介绍了R - 获取 RasterLayer 的特定波段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A 有一个带有 4 个波段的 RasterLayer:

A have a RasterLayer with 4 bands:

    >rx<-raster("/media/karimdion/Passport/Essais/po_3804017_bgrn_0000000 tif")
    > str(rx)
      Formal class 'RasterLayer' [package "raster"] with 12 slots
  @ file    :Formal class '.RasterFile' [package "raster"] with 12 slots
      @ nbands      : int 4
      @ bandorder   : chr "BIL"
 @ data    :Formal class '.SingleLayerData' [package "raster"] with 13 slots
      @ min       : num 0
      @ max       : num 65535
      @ band      : int 1
@ history : list()
@ title   : chr(0) 
@ extent  :Formal class 'Extent' [package "raster"] with 4 slots
      @ xmin: num 655781
      @ xmax: num 666701
      @ ymin: num 4071522
      @ ymax: num 4084598
@ rotated : logi FALSE
@ rotation:Formal class '.Rotation' [package "raster"] with 2 slots
      @ geotrans: num(0) 
      @ transfun:function ()  
@ ncols   : int 5460
@ nrows   : int 6538
@ crs     :Formal class 'CRS' [package "sp"] with 1 slots
      @ projargs: chr "+proj=utm +zone=32 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0"
@ z       : list()

我想将单个变量中的每个波段作为 RasterLayer.因此,我会得到 4 个具有 1 个波段的 RasterLayers.我怎样才能用 R 做到这一点?

I want to get each band in a single variable as a RasterLayer. So as a result I would get 4 RasterLayers having 1 band. How can I do this with R?

推荐答案

你应该能够做到:

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)
}

这应该给你四个文件, rx.1 , rx.2 , rx.3 , rx.4,光栅文件的每个波段一个.我确信有一种更好的(更有效和更正确的光栅")方法可以做到这一点,但我现在想不起来了.

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.

这篇关于R - 获取 RasterLayer 的特定波段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 11:51