gpt4 book ai didi

R - 获取 RasterLayer 的特定波段

转载 作者:行者123 更新时间:2023-12-01 10:01:40 25 4
gpt4 key购买 nike

一个有 4 个波段的 RasterLayer:

    >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 做到这一点?

最佳答案

使用文件名 f(这里使用示例文件进行重现)

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

对于特定的乐队,你可以这样做

 r <- raster(f, band=2)

或适用于所有乐队

 b <- brick(f)

或者(效率较低):

 s <- stack(f)

关于R - 获取 RasterLayer 的特定波段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15270107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com