Skip to contents

This function downloads 1km resolution DEM (Digital Elevation Model) raster data for a given vector of ISO3 country codes, and writes each raster to a GeoTIFF file.

Usage

download_country_DEM(PATHS, iso_codes, zoom_level = 6, overwrite = FALSE)

Arguments

PATHS

A list containing paths where DEM data will be saved. Typically generated by the get_paths() function and should include:

  • DATA_DEM: Path to the directory where DEM rasters will be saved.

iso_codes

A character vector of ISO3 country codes for which DEM data should be downloaded.

zoom_level

An integer representing the zoom level for the DEM data. Zoom levels 6-8 are recommended for 1km resolution (default = 6).

overwrite

If FALSE (default), a country whose DEM file already exists is skipped; TRUE re-downloads and replaces it.

Value

Invisibly, the paths of the DEM files that exist after the call. Each is written atomically (temporary file, then rename), so a failed or interrupted download never replaces a good raster.

Details

Terrain does not change between refreshes, and PATHS$DATA_DEM lives under MOSAIC-data/raw/, so existing rasters are never rewritten unless overwrite = TRUE. Each download appends a row to PATHS$DATA_DEM/PROVENANCE.md. File names stay undated because get_elevation() reads <ISO>_1km_DEM.tif.

Examples

if (FALSE) { # \dontrun{
# Define the ISO3 country codes
iso_codes <- c("ZAF", "KEN", "NGA")

# Get paths for data storage
PATHS <- get_paths()

# Download DEM rasters for the countries
download_country_DEM(PATHS, iso_codes)
} # }