{ "cells": [ { "cell_type": "markdown", "id": "2d4c9e4d", "metadata": {}, "source": [ "# Downloading elevation data\n", "\n", "This short tutorial demonstrates how to download elevation data for specific areas using a library called `elevation`.\n", "`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.\n", "\n", "Let's first import required libraries:" ] }, { "cell_type": "code", "execution_count": 4, "id": "4eca1eca", "metadata": {}, "outputs": [], "source": [ "import elevation\n", "import pathlib\n", "import osmnx as ox" ] }, { "cell_type": "markdown", "id": "223cd8e8", "metadata": {}, "source": [ "## Elevation data for Helsinki" ] }, { "cell_type": "code", "execution_count": 6, "id": "16e1a881", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/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.\n", " gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid))\n", "/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.\n", " gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid))\n", "/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.\n", " gdf = gdf.append(_geocode_query_to_gdf(q, wr, by_osmid))\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "make: Entering directory '/home/hentenka/.cache/elevation/SRTM1'\n", "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\n", "gunzip spool/N59/N59E024.hgt.gz 2>/dev/null || touch spool/N59/N59E024.hgt\n", "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\n", "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\n", "gunzip spool/N59/N59E025.hgt.gz 2>/dev/null || touch spool/N59/N59E025.hgt\n", "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\n", "rm spool/N59/N59E024.hgt spool/N59/N59E025.hgt\n", "make: Leaving directory '/home/hentenka/.cache/elevation/SRTM1'\n", "make: Entering directory '/home/hentenka/.cache/elevation/SRTM1'\n", "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\n", "make: Leaving directory '/home/hentenka/.cache/elevation/SRTM1'\n", "make: Entering directory '/home/hentenka/.cache/elevation/SRTM1'\n", "cp SRTM1.vrt SRTM1.6c58550bed364daaa292eb9b6cfd07ef.vrt\n", "make: Leaving directory '/home/hentenka/.cache/elevation/SRTM1'\n", "make: Entering directory '/home/hentenka/.cache/elevation/SRTM1'\n", "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\n", "rm -f SRTM1.6c58550bed364daaa292eb9b6cfd07ef.vrt\n", "make: Leaving directory '/home/hentenka/.cache/elevation/SRTM1'\n", "make: Entering directory '/home/hentenka/.cache/elevation/SRTM1'\n", "find cache -size 0 -name \"*.tif\" -delete\n", "rm -f SRTM1.*.vrt\n", "rm -f -r spool/*\n", "make: Leaving directory '/home/hentenka/.cache/elevation/SRTM1'\n" ] } ], "source": [ "# Parse boundaries for Helsinki, Espoo and Vantaa\n", "helsinki = ox.geocoder.geocode_to_gdf([\"Helsinki\", \"Espoo\", \"Vantaa\"])\n", "bounds = helsinki.geometry.total_bounds\n", "\n", "# Output filepath (get a full path, i.e. absolute)\n", "outfp = pathlib.Path(\"Helsinki-DEM.tif\").absolute()\n", "\n", "# Get the elevation data for the area\n", "elevation.clip(bounds=bounds, output=outfp)\n", "\n", "# Clean temp files\n", "elevation.clean()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" } }, "nbformat": 4, "nbformat_minor": 5 }