Download OpenLandMap Datasets

Introduction

This script automates the download of global land cover datasets from the OpenLandMap collection. The data covers the period from 1985 to 2022, with each file representing one year.

Packages

# Load required packages
library(httr)

Settings

Define the range of years and URL pattern for downloading the files.

# Range of years
years <- 1985:2022

# URL template with placeholder for year (YYYY)
base_url <- "https://s3.openlandmap.org/arco/lc_glc.fcs30d_c_30m_s_YYYY0101_YYYY1231_go_epsg.4326_v20231026.tif"

# Local folder to save the data
output_dir <- "./data/openlandmap"
dir.create(output_dir, recursive = TRUE, showWarnings = FALSE)

Download Loop

# Function to download one file
download_openlandmap <- function(year) {
  url <- gsub("YYYY", year, base_url)
  destfile <- file.path(output_dir, basename(url))
  
  if (!file.exists(destfile)) {
    message(paste0("Downloading ",year,"..."))
    GET(url, write_disk(destfile, overwrite = TRUE))
  } else {
    message(paste0(year," already downloaded."))
  }
}

# Run the download loop
lapply(years[1], download_openlandmap)