2014-06-25 20 views
0

我试图下载一个ASCII光栅并解压,用R:R - 如何下载ascii光栅并解压缩?

require(raster) 
temp <- tempfile() 
download.file("http://goo.gl/yGC4GU",temp) 
myRaster <- raster(unz(temp, "koppen_ascii.txt")) 

,但我得到了以下错误消息:

Error in (function (classes, fdef, mtable) : 
    unable to find an inherited method for function ‘raster’ for signature ‘"unz"’ 

是否有任何其他方法?

+1

从解读中分离出来。栅格需要一个文件名,而不是unz的输出 – mdsumner

+0

也许你可以在[gis.stackexchange.com](http://gis.stackexchange.com/questions/tagged/r+raster)找到有用的提示 – Hastur

回答

0

解压缩文件的工作文件夹,然后阅读:

> unzip(temp) 
> myRaster = raster("./koppen_ascii.txt") 

使用tempdir()创建一个临时目录,并将它传递的exdir选项unzip,如果你想在其他地方保存。

> zipd = tempdir() 
> unzip(temp, exdir=zipd) 
> myRaster = raster(file.path(zipd,"koppen_ascii.txt")) 
+0

很棒很多谢谢! – Claudia