Skip to main content

Basic tool for downloading and merging mapzen terrain tile geotiffs from AWS

Project description


A (yet another) basic Python script for downloading and accessing Mapzen Terrain Tiles geotiffs from AWS. Designed to integrate with rasterio and to provide a familiar command line tool for quick reprojection of downloads.


pip install terraincache

Set the TERRAINCACHE environment variable to save typing:

export TERRAINCACHE=/users/snorris/Data/terrain-tiles


Python module

from matplotlib import pyplot as plt
import rasterio

from terraincache import TerrainTiles

bounds =[-125.2714, 51.3706, -125.2547, 51.3768]

# Initialize with bounds and zoom of interest
tt = TerrainTiles(bounds, 11)

# load to numpy array
array = tt.load()

# plot the array directly
plt.imshow(array, cmap='terrain', extent=bounds)

alt text

Dump to file and plot the array using (for correct axis labels):"dem.tif")
with"dem.tif", "r") as src:
    fig, ax = plt.subplots(), ax=ax, title='terrain-tiles', cmap="terrain")

alt text


$ terraincache --help
Usage: terraincache [OPTIONS]

  Write terrain tiles to geotiff

  -o, --out_file, --out-file PATH
                                  Output file name/path
  --bounds TEXT                   Bounds: "left bottom right top" or "[left,
                                  bottom, right, top]".  [required]
  -z, --zoom INTEGER              Web map zoom level  [required]
  -p, --cache-dir, --cache_dir TEXT
                                  Path to cache folder
  -tr, --resolution FLOAT         Output dataset target resolution in meters
                                  (square pixels)
  --bounds-crs, --bounds_crs TEXT
                                  CRS of provided bounds
  --dst-crs, --dst_crs TEXT       Target coordinate reference system.
  -r, --resampling_algorithm [bilinear|nearest|cubic|cubicspline|lanczos|average|mode]
                                  GDAL resampling algorithm
  -v, --verbose                   Increase verbosity.
  -q, --quiet                     Decrease verbosity.
  --help                          Show this message and exit.

For example, create a geotiff around the summit of Mt Fairweather (at BC / AK border) that aligns with the BC TRIM DEM. Note that this is almost certainly upsampling the data available, see below link to review source resolutions.

terraincache \
  --bounds "336637.5, 1597112.5, 346637.5, 1607112.5" \
  --bounds-crs EPSG:3005 \
  --zoom 11 \
  -tr 25 \
  -r bilinear \
  -o dem.tif

Data sources

See the data sources reference document

Credits / other implementations

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

terraincache-0.0.1.tar.gz (5.5 kB view hashes)

Uploaded source

Built Distribution

terraincache-0.0.1-py3-none-any.whl (7.0 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page