R:使用RGDAL和RASTER包时抛出错误



相关人员:

源代码如下:

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_pathGRA_D1.tif' does not exist in the file system,
and is not recognised as a supported dataset name.

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

有人能帮我一下吗?

提前感谢您的慷慨。

欢呼,广告

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

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

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

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

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

最新更新