【问题标题】:Preserving the layer names while writing raster在写入栅格时保留图层名称
【发布时间】:2019-04-22 21:05:27
【问题描述】:

希望在编写栅格堆栈时保留栅格图层的名称

我已尝试使用显示的代码,此代码未显示错误,但该位置未显示那里写入的任何文件。

MosaicedA<- mosaic(Stacked1A,Stacked2A, fun=mean, tolerance=0.5)
names(MosaicedA)<-c('one','Two','three')
################################################################
writeRaster(MosaicedA,filename = names(MosaicedA),bylayer=TRUE,format="ENVI",overwrite=TRUE, "C:/Users/rajeev.bhattarai/Documents/Research/Testing/Rajeev.envi" )

【问题讨论】:

    标签: raster writing


    【解决方案1】:

    这是一个变通功能:

    writeENVI <- function(x, f, ...) {
        writeRaster(x, f, overwrite=TRUE, ...)
        cat("band names = {", paste(names(x),collapse=","), "}", "\n", file=extension(f, "hdr"), append=TRUE)
    }
    

    示例数据

    library(raster)
    s <- stack(system.file("external/rlogo.grd", package="raster")) 
    names(s)
    #[1] "red"   "green" "blue" 
    

    使用函数

    writeENVI(s, "test.envi")
    

    检查它是否有效

    brick(f)
    #class      : RasterBrick 
    #dimensions : 77, 101, 7777, 3  (nrow, ncol, ncell, nlayers)
    #resolution : 1, 1  (x, y)
    #extent     : 0, 101, 0, 77  (xmin, xmax, ymin, ymax)
    #crs        : +proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
    #source     : test.envi 
    #names      : red, green, blue 
    #min values :   0,     0,    0 
    #max values : 255,   255,  255 
    

    【讨论】:

      猜你喜欢
      • 2015-01-01
      • 1970-01-01
      • 2014-11-01
      • 2018-10-11
      • 2021-05-07
      • 2018-07-08
      • 1970-01-01
      • 2020-06-10
      • 2011-12-09
      相关资源
      最近更新 更多