R/download_fisbroker_atom.R

Defines functions download_fisbroker_atom

Documented in download_fisbroker_atom

#' Download data from fisbroker
#' @param zip_link the atom url of the data from fisbroker.
#' @param name name of the folder where the data should be stored. If dolder does not exist the folder will be created
#' @param path path where it has to be stored
#' @return A folder with the data as a geopackage.
#' @export
#' @examples
#' \dontrun{
#' download_fisbroker_atom()
#' }

#### Function
download_fisbroker_atom <- function(zip_link, path ,name){
  curl::curl_download(zip_link, destfile = here::here(path ,paste0(name, ".zip")))
  utils::unzip(zipfile = here::here(path, paste0(name, ".zip")), exdir = here::here(path, name))
  suppressMessages(file.remove(here::here(path, paste0(name, ".zip"))))
  curl::curl_download(zip_link, destfile = here::here(path, name, paste0(name, ".tif")))

  # you have to set the crs because it is missing sometimes. The default epsg on fisbroker is 25833
  ras <- terra::rast(list.files(here::here(path, name),
                                    pattern = ".tif$", full.names = TRUE)[1])
  return(ras)
}
EcoDynIZW/d6geodata documentation built on Sept. 30, 2024, 2:15 p.m.