尝试堆叠栅格图层时出错

时间:2019-05-07 13:41:43

标签: r

我正在运行某人开发的代码。我正在尝试创建栅格堆栈。当我运行代码时,它给了我这个错误

  

.local(.Object,...)中的错误:.rasterObjectFromFile(x,band)中的错误   = band,对象类型=“ RasterLayer” ,:无法从此文件创建RasterLayer对象。 (文件不存在)

gcmDir <- "C:\\Users\\sangay\\Documents\\Eco Crop Modelling\\Future Scenario\\Results\\RCP8.5\\analyses\\runs-future" # directory where different results exists that are to be ensembled
outFolder <- "C:\\Users\\sangay\\Documents\\Eco Crop Modelling\\Future Scenario\\Results\\RCP8.5Assembled" # directory to save results
rsn <- "MaizeAssembled" # full name of the results to be ensembled

if (!file.exists(outFolder)) {dir.create(outFolder)}

gcmList <- list.files(gcmDir)
for (gcm in gcmList) {
    cat(gcm, "/n")
    rDir <- paste(gcmDir, "/", gcm, sep="") # gcm location for future data
    rs <- raster(paste(rDir, "/", rsn, ".tif", sep=""))
    if (gcm == gcmList[1]) {
        gcmstack <- c(rs)
    } else {
        gcmstack <- c(gcmstack, rs)
    }
}

###I am including the error below:
*bcc_csm1_1 /n
Error in .local(.Object, ...) : 
Error in .rasterObjectFromFile(x, band = band, objecttype =   "RasterLayer",  : 
Cannot create a RasterLayer object from this file. (file does not exist)
gcmstack <- stack(gcmstack)*

## again the code starts below:
# Stack averages
avg <- mean(gcmstack)

#Stack standar deviation
fun <- function(x) { sd(x) }
std <- calc(gcmstack, fun)


avg <- writeRaster(avg, paste(outFolder, "/", rsn, "_avg.asc", sep=""),        format="ascii", overwrite=T)
std <- writeRaster(std, paste(outFolder, "/", rsn, "_std.asc", sep=""), format="ascii", overwrite=T)

有人可以帮我解决这个问题吗?我已经尝试过自己,但是什么也找不到。我是R的新手。

非常感谢您!

0 个答案:

没有答案