【问题标题】:R: Error thrown while using RGDAL and RASTER packagesR:使用 RGDAL 和 RASTER 包时抛出错误
【发布时间】:2014-08-21 03:23:12
【问题描述】:

这可能与谁有关:

这里是源代码:

GRA_D1<- raster(files[[1]])
//Sets up an empty output raster: 
GRA_D1<- writeStart(GRA_D1,filename='GRA_D1.tif', format='GTiff', overwrite=TRUE)

//Write to the raster, for loop:
for(i in 1:dim(GRA_D1)[1]){

//Extract raster values at rows
d.Frame<- matrix(NA,ncol=2,nrow=dim(GRA_D1)[2])
d.Frame[,1]<- getValues(r1[[1]],i) 
d.Frame[,2]<- getValues(r1[[2]],i)

w.Frame<- as.data.frame(d.Frame)
names(w.Frame)<- c("D1_pred_disAg","D1_pred_RK")
//Apply the predictive model:
m.pred<-predict(mod.1, w.Frame) 

//Write the predictions to the empty TIFF raster
GRA_D1<-writeValues(GRA_D1,m.pred,i) 
print(i)}

//Finish writing to the raster
GRA_D1<- writeStop(GRA_D1) 

我正在尝试将输出写入一个空的 TIFF 栅格,但我不断收到以下错误消息:

#Error in .local(.Object, ...) : 
`general_file_path\GRA_D1.tif' does not exist in the file system,
and is not recognised as a supported dataset name.

我想知道这是否与滥用 RGDAL 或 RASTER 包中的函数有关。

有人可以帮助我吗?

提前感谢您的慷慨。

干杯, 广告

【问题讨论】:

    标签: r error-handling rgdal r-raster


    【解决方案1】:

    超级简单的修复。不敢相信它是这么简单,我花了这么长时间,但这里是答案:

    “rgdal”和/或“GTiff”文件不喜欢在其数据集名称中使用下划线。

    使用“GRAD1.tif”(而不是“GRA_D1.tif”)运行代码时,一切正常。

    【讨论】:

    • 你并不孤单。我还花了很多时间找出错误的原因。删除下划线使 R 提供更详细的错误消息。所以这是因为下划线('_')和'在EOF解析错误,并非所有元素都已关闭,从VRTDataset开始'
    • 这对我不起作用
    【解决方案2】:

    我认为你真的不应该这样做,因为你可以这样做:

     p <- predict(r1, mod.1, filename='GRA_D1.tif')
    

    (并且该文件名可以正常工作)

    【讨论】:

      猜你喜欢
      • 2015-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-01
      • 2014-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多