chrisvwn / Rnightlights

R package to extract data from satellite nightlights.
GNU General Public License v3.0
47 stars 14 forks source link

getCtryNlData cannot open destfile SHP_KEN_GADM-3.6.zip #34

Closed RobsonTigre closed 5 years ago

RobsonTigre commented 5 years ago

Dear Chris,

Thank you for sharing your amazing package! I am trying to learn by doing, so I went to replicate your example code. After running the following piece...


devtools::install_github("chrisvwn/Rnightlights")
install.packages("lubridate")
install.packages("reshape2")
install.packages("ggplot2")

library(Rnightlights)
library(lubridate)
library(reshape2)

#(Optional performance enhancement if you have aria2c and gdal installed)
#pkgOptions(downloadMethod = "aria", cropMaskMethod = "gdal", extractMethod = "gdal", deleteTiles = TRUE)

#Optional performance enhancement. If extractMethod="rast" you can specify the number of
#CPU cores to use in parallel
#pkgOptions(extractMethod = "rast", numCores=4)

ctry <- "KEN" #replace to run for any other country

#download and process monthly VIIRS stats at the highest admin level
highestAdmLevelStats <- getCtryNlData(ctryCode = ctry, 
                                     admLevel = "highest",
                                     nlType = "VIIRS.M", 
                                     nlPeriods = nlRange("201401", "201412","VIIRS.M"), 
                                     nlStats = list("sum",na.rm=TRUE),
                                     ignoreMissing=FALSE)

I come across the error below:


2019-05-28 16:02:11: Downloading ctry poly: KEN
2019-05-28 16:02:11: Downloading https://biogeo.ucdavis.edu/data/gadm3.6/shp/gadm36_KEN_shp.zip
Error in utils::download.file(url = fullPolyUrl, destfile = getPolyFnameZip(ctryCode = ctryCode,  : 
  cannot open destfile 'C:/Users/Robson/Documents/.Rnightlights/polygons/SHP_KEN_GADM-3.6.zip', reason 'No such file or directory'

The same happens if i try other countries. I read the previous issues reported, and my impression is that GADM may have changed something not accounted for in the code. I am relatively novice in R, so if you may propose a workaround it would be great.

Thanks in advance and congrats on the package once again.

chrisvwn commented 5 years ago

Hi @RobsonTigre

Thank you for the compliment. And thanks for choosing the Rnightlights package.

I have just tested the package and the GADM downloads are still okay. The error you are getting seems related to the download in terms of the destination. Could you check that you have disk space on the host drive and that you have write permissions to the folder?

If the above don't yield anything, could you try changing the destination folder probably to a different drive and see if you still get the same error? You can change the Rnightlights data folder by running setupDataPath().

All the best with your learning

RobsonTigre commented 5 years ago

Dear @chrisvwn , thank you for your quick and effective reply! In fact setupDataPath() solved that problem.

All the best

chrisvwn commented 5 years ago

Great! I am glad to hear that! Happy learning.