我有一个光栅堆栈,stk
由 R 中的三个光栅图像组成。这是一个简单的例子
# 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 格式。
谢谢,凯文