【发布时间】:2015-01-01 23:42:54
【问题描述】:
我有一个光栅堆栈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 格式。
谢谢,凯文
【问题讨论】:
-
你在哪里读取堆积的 tif 文件?
-
保罗,感谢您的浏览。我只是清理了示例以使其更清晰并修复了一些措辞。我使用
stk <- stack("myStack.tif")(最后一个代码块的第一行)读取了堆叠的 tif 文件。再次感谢。