7️⃣ Fetch DEM for any country in the world using elevatr to analyze terrain, flood risks, and infrastructure planning.
Why it matters: DEMs are crucial for environmental studies and engineering projects.
💻 # 5. AWS Terrain Tiles digital elevation model
#---------------------------------------------
# install elevatr and load packages
pacman::p_load(elevatr, geodata, tidyverse, terra)
# get Switzerland's boundary (area of interest)
locations <- geodata::gadm(
country = "CHE",
level = 0,
path = tempdir()
) |> sf::st_as_sf()
# if error occurs, try again
locations <- geodata::gadm(
country = "CHE",
level = 0,
path = tempdir()
)
locations <- sf::st_as_sf(locations)
# fetch the DEM (z = zoom level 8)
elevation_country <- elevatr::get_elev_raster(
locations = locations,
z = 8, clip = "locations"
)
# plot DEM
terra::plot(elevation_country)