I am interested in downloading the 2020 UN Adjusted Population Count for Democratic Republic of the Congo at the 30 arc second resolution from WorldPop (See here ) as a GeoTIFF (.tif) file. I am trying to do this for multiple countries to I was exploring the wpgpDownloadR package.
devtools::install_github("wpgp/wpgpDownloadR")
library(wpgpDownloadR)
wpgpListCountryDatasets(ISO3="COD")
Could I get some help with directly downloading the WorldPop Population Count .tif file for a specific country (for example, DRC, Nigeria, Belgium, France etc.)?
I have an R code for converting this GeoTIFF raster (.tif file) to a NetCDF (.nc file) if I already have the tif file locally pre-downloaded but if I want for a different country I have to download it and do this over again.
library(raster)
# Downloaded from above website
DRCWorldPop <- raster("cod_ppp_2020_1km_Aggregated_UNadj.tif")
rnc <- writeRaster(DRCWorldPop, filename ='DRC_0000.nc', format = "CDF", varname = "Susceptible", varunit = "Persons", longname = "Susceptible", overwrite = TRUE)
I am trying to have a single generic code to use ftp to download the rasters for any country. Could you please point me in the right direction? Thank you for your time.
You can do something like this
library(raster)
library(wpgpDownloadR)
iso3 <- "RWA"
cov <- "ppp_2000"
path <- dirname(tempdir())
f <- file.path(path, tolower(paste0(iso3, "_", cov, ".tif")))
if (!file.exists(f)) {
f <- wpgpGetCountryDataset(ISO3 = "RWA", covariate = "ppp_2000", destDir=path)
}
r <- raster(f)
This allows you to loop over country and covariate. It also avoids downloading files that you already have.