Martin Jung's avatar
Martin Jung committed
library(sf)
library(terra)
library(ncdf4)
library(dplyr)
library(stringr)

# Paths
path_input <- "Inputs/"
path_output <- "Outputs/"
path_scripts <- "Scripts/"

# -------------------------- #

p <- read_sf("/mnt/pdrive/bec_data/100_rawdata/GADM_AdminBoundaries/gadm_410.gpkg",quiet = T)

# Get all countries on the European continent and subset
co <- p |> sf::st_drop_geometry() |> filter(CONTINENT == "Europe") |> select(SOVEREIGN) |> collect() |> distinct()

# Now select all countries with this information
sub <- p |> filter(COUNTRY %in% co$SOVEREIGN)

write_sf(sub, "/home/martin/GADM_Europesubset.gpkg")

# --- #
# Download gridded Reference from CHELSA
chelsa_reference <- str_trim(readLines(paste0(path_input,"envidatS3paths.txt")))

curl::curl_download(
  chelsa_reference,
  paste0(path_input, basename(chelsa_reference) )
)
# Load the object
ras <- rast(   paste0(path_input, basename(chelsa_reference) ) )

# --- #
# Download European reference grids
# Source: https://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/grids
grid_1km <- "https://gisco-services.ec.europa.eu/grid/grid_1km_surf.gpkg"
curl::curl_download(
  grid_1km,
  paste0(path_input, basename(grid_1km) )
)

grid <- sf::st_read( paste0(path_input, "grid_1km_surf.gpkg"))