我有一个光栅栈,stk
,在R.由三个光栅图像下面是一个简单的例子R:写RasterStack和保留层名称
# set up a raster stack with three layers
> library(raster)
> r <- raster(nrows=10,ncols=10)
> r[] <- rnorm(100)
> stk <- stack(r,r,r)
# layer names are set by default
> names(stk)
[1] "layer.1" "layer.2" "layer.3"
我将名称指定给光栅层:
# set layer names to "one", "two" and "three"
> names(stk) <- c('one','two','three')
> names(stk)
[1] "one" "two" "three"
当我使用写RasterStack到支持GeoTiff(多层):
writeRaster(stk,"myStack.tif", format="GTiff")
根据文件名重命名图层(请参阅下面的> names(stk)
)。
当我在光栅堆栈阅读:
> stk <- stack("myStack.tif")
# the layer names have been set automatically based on the filename
# they should be "one", "two" and "three"
> names(stk)
[1] "myStack.1" "myStack.2" "myStack.3"
你知道有什么方法在R写入RasterStacks时保留图层名称?我已经尝试将堆栈写入GeoTIFF和NetCDF格式。
谢谢,凯文
你在哪里阅读堆叠的tif文件? – 2014-11-06 23:31:30
Paulo,感谢您的关注。我刚刚清理了这个例子,使其更加清晰并修正了一些措辞。我使用'stk < - stack(“myStack.tif”)'(最后一个代码块的第一行)读入堆栈的tif文件。再次感谢。 – kguay 2014-11-07 18:52:10