mapme-initiative / mapme.biodiversity

Efficient analysis of spatial biodiversity datasets for global portfolios
https://mapme-initiative.github.io/mapme.biodiversity/
GNU General Public License v3.0
24 stars 7 forks source link

GMW 2018 data #276

Closed karpfen closed 1 month ago

karpfen commented 1 month ago

In the Global Mangrove Watch resource function, 2018 is excluded as a valid year.

However, there is also some code included, specifically to deal with the 2018 data. I was trying to fix this manually by using a custom resource function:

get_gmw2 <- function(years) {
  avail_years <- c(1996, 2007:2010, 2015:2020)
  years <- check_available_years(years, avail_years, "gmw2")

  function(x,
           name = "gmw2",
           type = "vector",
           outdir = mapme_options()[["outdir"]],
           verbose = mapme_options()[["verbose"]],
           testing = mapme_options()[["testing"]]) {
    urls <- unlist(sapply(years, function(year) mapme.biodiversity:::.get_mangrove_url(year)))
    bbox <- c(xmin = -180., ymin = -38.85822, xmax = 180., ymax = 32.36822)
    fps <- st_as_sfc(st_bbox(bbox, crs = "EPSG:4326"))
    fps <- st_as_sf(rep(fps, length(urls)))
    fps[["source"]] <- urls
    make_footprints(fps, filenames = gsub(".shp", ".gpkg", basename(urls)), what = "vector")
  }
}

register_resource(
  name = "gmw2",
  description = "Global Mangrove Watch - Vector data of mangrove extent",
  licence = "CC BY 4.0",
  source = "https://data.unep-wcmc.org/datasets/45",
  type = "vector"
)

This seems to work for downloading the data, but prep_resources() still doesn't return the 2018 data. For now, I didn't manage to dig further into the problem, maybe we can have a look together this week, @goergen95

goergen95 commented 1 month ago

Hi @karpfen, so I had some issues with opening the data set for 2018 with GDAL which now I am unable to reproduce... I will re-enable 2018 as a valid year and let's hope that nothing else pops up!

karpfen commented 1 month ago

Hi @goergen95, that's strange, your fix is exactly what I tried first yesterday, but it still doesn't seem to work for me. I just ran this snippet in with an empty data directory:

remotes::install_github("mapme-initiative/mapme.biodiversity", ref = "dev")
library(sf)
library(mapme.biodiversity)
mapme_options(outdir = tempdir(), verbose = TRUE)

x <- read_sf(
  system.file("extdata", "shell_beach_protected_area_41057_B.gpkg",
              package = "mapme.biodiversity"
  )
)

x <- get_resources(x, get_gmw(years = 2018:2019))
resources <- prep_resources(x)
names(resources$gmw)

# [1] "gmw_v3_2018_vec.gpkg"     "gmw_v3_2019_vec.gpkg"

Is there anything else I could be doing wrong?

goergen95 commented 1 month ago

Ah, now I got it! I did not translate the 2018 data to geodetic coordinates which resulted in no intersections. Please find b5b12d5 which should work now. I also adapted your sample code a little bit to make it run on other machines as well. Please re-open if the issue persists.

karpfen commented 1 month ago

Aah, that was it. Thanks @goergen95!