Downloading elevation data#

This short tutorial demonstrates how to download elevation data for specific areas using a library called elevation. elevation provides easy download, cache and access of the global datasets SRTM 30m Global 1 arc second V003 elaborated by NASA and NGA hosted on Amazon S3 and SRTM 90m Digital Elevation Database v4.1 elaborated by CGIAR-CSI.

Let’s first import required libraries:

import elevation
import pathlib
import osmnx as ox

Elevation data for Helsinki#

# Parse boundaries for Helsinki, Espoo and Vantaa
helsinki = ox.geocoder.geocode_to_gdf(["Helsinki", "Espoo", "Vantaa"])
bounds = helsinki.geometry.total_bounds

# Output filepath (get a full path, i.e. absolute)
outfp = pathlib.Path("Helsinki-DEM.tif").absolute()

# Get the elevation data for the area
elevation.clip(bounds=bounds, output=outfp)

# Clean temp files
elevation.clean()
/home/hentenka/.conda/envs/mamba/envs/python-gis-book/lib/python3.9/site-packages/osmnx/geocoder.py:110: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
  gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid))
/home/hentenka/.conda/envs/mamba/envs/python-gis-book/lib/python3.9/site-packages/osmnx/geocoder.py:110: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
  gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid))
/home/hentenka/.conda/envs/mamba/envs/python-gis-book/lib/python3.9/site-packages/osmnx/geocoder.py:110: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
  gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid))
make: Entering directory '/home/hentenka/.cache/elevation/SRTM1'
curl -s -o spool/N59/N59E024.hgt.gz.temp https://s3.amazonaws.com/elevation-tiles-prod/skadi/N59/N59E024.hgt.gz && mv spool/N59/N59E024.hgt.gz.temp spool/N59/N59E024.hgt.gz
gunzip spool/N59/N59E024.hgt.gz 2>/dev/null || touch spool/N59/N59E024.hgt
gdal_translate -q -co TILED=YES -co COMPRESS=DEFLATE -co ZLEVEL=9 -co PREDICTOR=2 spool/N59/N59E024.hgt cache/N59/N59E024.tif 2>/dev/null || touch cache/N59/N59E024.tif
curl -s -o spool/N59/N59E025.hgt.gz.temp https://s3.amazonaws.com/elevation-tiles-prod/skadi/N59/N59E025.hgt.gz && mv spool/N59/N59E025.hgt.gz.temp spool/N59/N59E025.hgt.gz
gunzip spool/N59/N59E025.hgt.gz 2>/dev/null || touch spool/N59/N59E025.hgt
gdal_translate -q -co TILED=YES -co COMPRESS=DEFLATE -co ZLEVEL=9 -co PREDICTOR=2 spool/N59/N59E025.hgt cache/N59/N59E025.tif 2>/dev/null || touch cache/N59/N59E025.tif
rm spool/N59/N59E024.hgt spool/N59/N59E025.hgt
make: Leaving directory '/home/hentenka/.cache/elevation/SRTM1'
make: Entering directory '/home/hentenka/.cache/elevation/SRTM1'
gdalbuildvrt -q -overwrite SRTM1.vrt cache/N59/N59E025.tif cache/N59/N59E024.tif cache/N50/N50E000.tif cache/N50/N50W001.tif cache/N60/N60E024.tif cache/N60/N60E025.tif cache/N51/N51W001.tif cache/N51/N51E000.tif
make: Leaving directory '/home/hentenka/.cache/elevation/SRTM1'
make: Entering directory '/home/hentenka/.cache/elevation/SRTM1'
cp SRTM1.vrt SRTM1.6c58550bed364daaa292eb9b6cfd07ef.vrt
make: Leaving directory '/home/hentenka/.cache/elevation/SRTM1'
make: Entering directory '/home/hentenka/.cache/elevation/SRTM1'
gdal_translate -q -co TILED=YES -co COMPRESS=DEFLATE -co ZLEVEL=9 -co PREDICTOR=2 -projwin 24.4992905 60.4013745 25.2545116 59.9010905 SRTM1.6c58550bed364daaa292eb9b6cfd07ef.vrt /home/hentenka/edu/FinEst-workshop/source/notebooks/data_access/Helsinki-DEM.tif
rm -f SRTM1.6c58550bed364daaa292eb9b6cfd07ef.vrt
make: Leaving directory '/home/hentenka/.cache/elevation/SRTM1'
make: Entering directory '/home/hentenka/.cache/elevation/SRTM1'
find cache -size 0 -name "*.tif" -delete
rm -f SRTM1.*.vrt
rm -f -r spool/*
make: Leaving directory '/home/hentenka/.cache/elevation/SRTM1'