如何在R中更改栅格顺序

时间:2018-10-01 14:22:26

标签: r raster

我在制作栅格堆栈时遇到了麻烦

当我读取光栅文件时(下面是代码)

clim_fut_26_2050 <- stack(list.files(path= paste('D:/hd26bi50/', sep=''), pattern='tif', full.names=TRUE ))

列表文件结果

list.files(path= paste('D:/hd26bi50/', sep='')) = [1] "D:/hd26bi50/bio1.tif"  "D:/hd26bi50/bio10.tif" "D:/hd26bi50/bio11.tif" "D:/hd26bi50/bio12.tif" "D:/hd26bi50/bio13.tif"
 [6] "D:/hd26bi50/bio14.tif" "D:/hd26bi50/bio15.tif" "D:/hd26bi50/bio16.tif" "D:/hd26bi50/bio17.tif" "D:/hd26bi50/bio18.tif"
[11] "D:/hd26bi50/bio19.tif" "D:/hd26bi50/bio2.tif"  "D:/hd26bi50/bio3.tif"  "D:/hd26bi50/bio4.tif"  "D:/hd26bi50/bio5.tif" 
[16] "D:/hd26bi50/bio6.tif"  "D:/hd26bi50/bio7.tif"  "D:/hd26bi50/bio8.tif"  "D:/hd26bi50/bio9.tif" 

文件顺序混乱(未排序)

 names(clim_fut_26_2050)
 [1] "bio1"  "bio10" "bio11" "bio12" "bio13" "bio14" "bio15" "bio16" "bio17" 
 "bio18" "bio19" "bio2"  "bio3"  "bio4"  "bio5"  "bio6"  "bio7" 
 [18] "bio8"  "bio9" 

如何重新排序这些图层?

帮助我T.T

1 个答案:

答案 0 :(得分:0)

mixedsort库中的gtools函数可以对列表中的对象重新排序:

library(gtools)
setwd('D:/hd26bi50')
s <- stack(mixedsort(list.files(pattern='tif', full.names=TRUE )))