Closed fBedecarrats closed 3 months ago
There are several things going on here:
As of recently (#308) the source server of the nelson_et_al
resource seems to be somewhat unreliable which is why we now recommend to set respective GDAL options so that the download does not fail:
For worldpop
, we also recommend increasing the timeout options so the data can be download successfully:
Both of these resources represent global raster files. Their respective source code thus does not interact with the geometries you provide as the portfolio, meaning that it does not matter if the geometries overlap or not.
Given the mentioned error message:
1: In CPL_gdaltranslate(source, destination, options, oo, config_options, : GDAL Error 4: Attempt to create new tiff file `data/nelson_et_al/traveltime-20k_110mio.tif' failed: No such file or directory
I suspect that the directory data
did not exists when you run the first part of your code example. It was only created once you ran
# Get GADM polygon for Hessen (includes Frankfurt and Darmstatt)
hessen <- gadm("Germany", level = 1, path = "data") %>%
st_as_sf() %>%
filter(NAME_1 == "Hessen")
with the gadm()
call creating the data
directory on disk to put its respective files there. Since that directory now existed,
your subsequent get_resource()
calls ran successfully.
Why don't we check if outdir
exists in mapme.biodiversity
?
Because the value of outdir
can as well point towards a remote cloud storage, so we cannot run dir.exist()
or dir.create()
against it and expect meaningful outcomes.
Given these considerations, the below code example (sorry to say it) "works on my machine". Could you please run it and post your output here?
reprex::reprex({
library(sf)
library(mapme.biodiversity)
locations <- data.frame(
long = c(8.682127, 8.646927),
lat = c(50.110924, 49.878708),
city = c("Frankfurt", "Darmstadt")
)
locations_sf <- st_as_sf(locations, coords = c("long", "lat"), crs = st_crs(4326))
buffers <- st_buffer(locations_sf, dist = 20000)
st_overlaps(buffers)
# create output directory
outdir <- tempfile()
dir.create(outdir)
dir.exists(outdir)
# set timeout and retry options as per documentation
options(timeout = 600)
Sys.setenv(GDAL_HTTP_MAX_RETRY = "5",
GDAL_HTTP_RETRY_DELAY = "15")
mapme_options(outdir = outdir)
get_resources(buffers,
get_nelson_et_al(ranges = "20k_110mio"),
get_worldpop(years = 2000))
list.files(outdir, recursive = TRUE)
}, session_info = TRUE)
Sometimes we need to compute indicators for overlapping polygons (eg. buffers around villages or PAs). In case of a portfolio containing overlapping polygons, get_nelson_et_al() and get_worldpop(). It works however for others I tried: get_nasa_srtm and getgfw* . I think that this might be related to https://github.com/mapme-initiative/mapme.biodiversity/issues/319 Here is a reprex :
Throws the following error:
Throws the following error: