我有一個光柵棧,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