# Load required packages
library(httr)
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
Settings
Define the range of years and URL pattern for downloading the files.
# Range of years
<- 1985:2022
years
# URL template with placeholder for year (YYYY)
<- "https://s3.openlandmap.org/arco/lc_glc.fcs30d_c_30m_s_YYYY0101_YYYY1231_go_epsg.4326_v20231026.tif"
base_url
# Local folder to save the data
<- "./data/openlandmap"
output_dir dir.create(output_dir, recursive = TRUE, showWarnings = FALSE)
Download Loop
# Function to download one file
<- function(year) {
download_openlandmap <- gsub("YYYY", year, base_url)
url <- file.path(output_dir, basename(url))
destfile
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)