Claudia
Claudia

Reputation: 1016

R - How to download ascii raster and unzip it?

I'm trying to download an ascii raster and unzip it using R:

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

but I get the following error message:

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

Is there any alternative method?

Upvotes: 2

Views: 300

Answers (1)

Spacedman
Spacedman

Reputation: 94182

Unzip your file to the working folder and then read it:

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

use tempdir() to create a temp directory and pass it as the exdir option to unzip if you want to save it elsewhere.

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

Upvotes: 2

Related Questions