Skip to main content

terraincache

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.

Installation

pip install terraincache

Set the TERRAINCACHE environment variable to save typing:

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

Usage

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 rasterio.plot.show() (for correct axis labels):

tt.save(out_file="dem.tif")
with rasterio.open("dem.tif", "r") as src:
    fig, ax = plt.subplots()
    rasterio.plot.show(src, ax=ax, title='terrain-tiles', cmap="terrain")

alt text

CLI

$ terraincache --help
Usage: terraincache [OPTIONS]

  Write terrain tiles to geotiff

Options:
  -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

Metadata

Release files for terraincache 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for terraincache 0.0.1
File Size Uploaded Provenance
terraincache-0.0.1.tar.gz 5.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for terraincache 0.0.1
File Interpreter ABI Platform
terraincache-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.5 kB

Release files / terraincache-0.0.1.tar.gz

Download URL terraincache-0.0.1.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a46365dd9640c095564a2a21e104a70938dc07c451601ece9837658559ef69c6
BLAKE2b-256 checksum
How to use checksums
2e6fe2b68d99f47f3f0026d9716ff515ae201b0d394e377885b346a4f63622c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.7.4

Release files / terraincache-0.0.1-py3-none-any.whl

Download URL terraincache-0.0.1-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e57559087771875127bafee0d9078af161ffd24725203bfe466850efcf05bfe7
BLAKE2b-256 checksum
How to use checksums
93c4e63e3d51fbbcee761d2ba7173c0e779cbc915c584643c5cc3f42b6a5c0ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.7.4

Security for terraincache 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page