3

给所有可能相关的人:

这是源代码:

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 包中的函数有关。

有人可以帮助我吗?

预先感谢您的慷慨。

干杯,广告

4

2 回答 2

4

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

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

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

于 2014-07-01T19:12:38.000 回答
1

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

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

(并且该文件名工作得很好)

于 2016-01-23T22:58:33.117 回答