Skip to content

Repository files navigation

elevation

Global geographic elevation data made easy. Elevation provides easy download, cache and access of the global datasets:

Note that any download policies and attribution requirements of the respective providers apply.

This Open Source project is sponsored by B-Open - https://bopen.eu.

Installation

Install the latest version of Elevation from the Python Package Index:

$ pip install elevation

The following dependencies need to be installed and working:

  • GDAL command line tools, i.e. gdal_translate, gdalbuildvrt, gdalinfo and ogrinfo

The following command runs some basic checks and reports common issues:

$ eio selfcheck
Your system is ready.

The best way to install GDAL command line tools varies across operating systems and distributions, please refer to the GDAL install documentation.

Note that elevation v2.0 requires Python 3.11 or later.

Command line usage

Identify the geographic bounds of the area of interest and fetch the DEM with the eio command. For example to clip the 30m DEM of Rome, around 41.9N 12.5E, to the Rome-MAPZEN-DEM.tif file using the default MAPZEN product:

$ eio clip -o Rome-MAPZEN-DEM.tif --bounds 12.35 41.8 12.65 42

For the SRTM global 30m v3 DEM use:

$ eio --product SRTM1_GEOID clip -o Rome-SRTM1_GEOID-DEM.tif --bounds 12.35 41.8 12.65 42

For the SRTM global 90m v4.1 DEM use:

$ eio --product SRTM3 clip -o Rome-SRTM3-DEM.tif --bounds 12.35 41.8 12.65 42

The --bounds option accepts latitude and longitude coordinates (more precisely in geodetic coordinates in the WGS84 reference system EPSG:4326 for those who care) given as left bottom right top similarly to the rio command form rasterio.

The --reference option clips a DEM on the same extent of any other geospatial data source supported by GDAL and OGR, for example if you have a georeferenced image MyImage.tif you can clip the corresponding DEM with:

$ eio clip -o MyImage-DEM.tif --reference MyImage.tif

The --reference option can also take vector data as input:

$ eio clip -o MyShapefile-DEM.tif --reference MyShapefile.shp

The first time an area is accessed Elevation downloads the data tiles from the AWS S3, CGIAR-CSI or OpenTopography servers and caches them in GeoTIFF compressed formats, subsequent accesses to the same and nearby areas are much faster.

The clip sub-command doesn't allow automatic download of a large amount of DEM tiles, please refer to the upstream providers' websites to learn the preferred procedures for bulk download.

To show the STAC metadata of the datasets use:

$ eio dataset

The optional argument selects a single dataset by id, e.g. eio dataset SRTM3.

To clean up stale temporary files and fix the cache in the event of a server error use:

$ eio clean

Command line reference

The eio command has the following sub-commands and options:

$ eio --help

 Usage: eio [OPTIONS] COMMAND [ARGS]...

╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ --version                                                 Show the version and exit.             │
│                                                           [env var: EIO_VERSION]                 │
│ --product          [MAPZEN|SRTM1_GEOID|SRTM1_ELLIP|SRTM3  DEM product choice.                    │
│                    ]                                      [env var: EIO_PRODUCT]                 │
│                                                           [default: MAPZEN]                      │
│ --cache_dir        <directory>                            Root of the DEM cache folder.          │
│                                                           [env var: EIO_CACHE_DIR]               │
│                                                           [default:                              │
│                                                           /Users/amici/Library/Caches/elevation] │
│ --help                                                    Show this message and exit.            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────────────────────────╮
│ selfcheck  Audit the system for common issues.                                                   │
│ info       Show info about the product cache.                                                    │
│ dataset    Show the STAC metadata of the datasets.                                               │
│ seed       Seed the DEM to given bounds.                                                         │
│ clip       Clip the DEM to given bounds.                                                         │
│ clean      Clean up the product cache from temporary files.                                      │
│ distclean  Remove the product cache entirely.                                                    │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

The clip sub-command:

$ eio clip --help

 Usage: eio clip [OPTIONS]

╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ --output        -o      <file>                        Path to output file. Existing files will   │
│                                                       be overwritten.                            │
│                                                       [env var: EIO_CLIP_OUTPUT]                 │
│                                                       [default: out.tif]                         │
│ --bounds                <float float float float>...  Output bounds in 'left bottom right top'   │
│                                                       order.                                     │
│                                                       [env var: EIO_CLIP_BOUNDS]                 │
│ --margin        -m      <str>                         Decimal degree margin added to the bounds. │
│                                                       Use '%' for percent margin.                │
│                                                       [env var: EIO_CLIP_MARGIN]                 │
│                                                       [default: 0]                               │
│ --reference     -r      <path>                        Use the extent of a reference GDAL/OGR     │
│                                                       data source as output bounds.              │
│                                                       [env var: EIO_CLIP_REFERENCE]              │
│ --gdal-options          <str>                         GDAL creation options of the output file,  │
│                                                       e.g. '-co COMPRESS=LZW'.                   │
│                                                       [env var: EIO_CLIP_GDAL_OPTIONS]           │
│                                                       [default: -co TILED=YES -co                │
│                                                       COMPRESS=DEFLATE -co ZLEVEL=9 -co          │
│                                                       PREDICTOR=2]                               │
│ --help                                                Show this message and exit.                │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

Defaults can be defined by setting environment variables prefixed with EIO, e.g. EIO_PRODUCT=SRTM3, EIO_CLIP_MARGIN=10% and EIO_CACHE_DIR=/tmp/elevation. EIO_CACHE_DIR selects the DEM cache folder and is honoured by the Python API as well.

Python API

Every command has a corresponding API function in the elevation module:

>>> import elevation
>>> # clip the 30m DEM of Rome and save it to Rome-DEM.tif
>>> elevation.clip(bounds=(12.35, 41.8, 12.65, 42), output="Rome-DEM.tif")
>>> # clean up stale temporary files and fix the cache in the event of a server error
>>> elevation.clean()

Project resources

Resource Link
Documentation https://elevation.bopen.eu
Support https://stackoverflow.com/search?q=python+elevation
Development https://github.com/bopen/elevation
Download https://pypi.org/project/elevation
Code quality Coverage status on Codecov

Contributing

The main repository is hosted on GitHub. Testing, bug reports and contributions are highly welcomed and appreciated:

https://github.com/bopen/elevation

Lead developer:

See also the list of contributors who participated in this project.

Sponsoring

B-Open commits to maintain the project long term and we are happy to accept sponsorships to develop new features.

License

Copyright 2016-2026 B-Open Solutions srl

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Download, cache and clip global terrain digital elevation models: Mapzen terrain tiles, SRTM 30m and 90m DEMs

Topics

Resources

Contributing

Stars

329 stars

Watchers

14 watching

Forks

Releases

Packages

Used by

Contributors

Languages