89_Simple
89_Simple

Reputation: 3805

Downloading data from the internet using R

I am trying to download data from the following website

https://gimms.gsfc.nasa.gov/MODIS/std/GMOD09Q1/tif/NDVI/

This website has NDVI data from MODIS sensors. The folders are arranged according to years and days of the year all of which I need to download.

As a test, I tried downloading just one data

URL <- "https://gimms.gsfc.nasa.gov/MODIS/std/GMOD09Q1/tif/NDVI/2010/001/GMOD09Q1.A2010001.08d.latlon.x39y03.6v1.NDVI.tif.gz"

library(RCurl)

x <- getURL(URL, ssl.verifypeer = FALSE)

I get this error

Error in function (type, msg, asError = TRUE)  : 
Unknown SSL protocol error in connection to 
gimms.gsfc.nasa.gov:443

Then I tried this:

download.file(url = URL,
          destfile = 'localfile.gz', method='curl')

Error in download.file(url = URL, destfile = "localfile.gz", method = "curl") : 
'curl' call had nonzero exit status

Could anyone tell me what is it I am doing wrong.

Thanks

Upvotes: 1

Views: 243

Answers (1)

Thomas
Thomas

Reputation: 44527

To read in memory, try:

library("curl")
x <- curl::curl_fetch_memory("https://gimms.gsfc.nasa.gov/MODIS/std/GMOD09Q1/tif/NDVI/2010/001/GMOD09Q1.A2010001.08d.latlon.x39y03.6v1.NDVI.tif.gz")

Or, to save locally:

f <- "local.tif.gz"
curl::curl_fetch_disk("https://gimms.gsfc.nasa.gov/MODIS/std/GMOD09Q1/tif/NDVI/2010/001/GMOD09Q1.A2010001.08d.latlon.x39y03.6v1.NDVI.tif.gz", path = f)

Upvotes: 2

Related Questions