R:使用RGDAL和RASTER包时抛出错误 [英] R: Error thrown while using RGDAL and RASTER packages

查看:511
本文介绍了R:使用RGDAL和RASTER包时抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这个可能关注的人:



这是源代码:

  GRA_D1<  -  raster(files [[1]])
//设置一个空输出栅格:
GRA_D1< - writeStart(GRA_D1,filename ='GRA_D1.tif',format = 'GTiff',overwrite = TRUE)

//写入栅格,for循环:
for(i in 1:dim(GRA_D1)[1]){

//在行
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)
名称(w.F​​rame)< - c(D1_pred_disAg,D1_pred_RK)
//应用预测模型:
m。 pred< -predict(mod.1,w.Frame)

//将预测写入空的TIFF栅格
GRA_D1< -writeValues(GRA_D1,m.pred,i)
print(i)}

//完成写入栅格
GRA_D1< - writeStop(GRA_D1)






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

  #define .local(.Object,...) :
`general_file_path\GRA_D1.tif'在文件系统中不存在,
并且不被识别为支持的数据集名称。






我想知道这是否与滥用职能有关或者是RGDAL或RASTER包。



有人可以帮助我吗?



提前感谢你的慷慨。



干杯,
AD

解决方案

。不能相信这是一个简单的事情,我花了很长时间,但这里是答案:



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



当运行带有GRAD1.tif(而不是GRA_D1.tif)的代码时,都可以正常工作。 p>

To whom this may concern:

Here is the source code:

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) 


I am attempting to write output to an empty TIFF raster, but I keep receiving the following error message:

#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.


I wonder if this is related to misusing functions in either the RGDAL or RASTER package.

Could someone please assist me?

Thanks in advance for your generosity.

Cheers, AD

解决方案

Super simple fix. Cannot believe that it is this simple and that it took me this long, but here is the answer:

"rgdal" and/or "GTiff" files don't like the use of underscores in their dataset names.

When running the code with "GRAD1.tif" (instead of "GRA_D1.tif"), all works well.

这篇关于R:使用RGDAL和RASTER包时抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆