Skip to main content

No project description provided

Project description

GeoSol Research Logo

gri-terrain

Terrain elevation data access for geolocation applications.

Status: Early Development -- Class interfaces are defined but source-level elevation lookups are not yet implemented. Ray-terrain intersection is functional.

Overview

gri-terrain provides unified access to terrain elevation data from multiple sources with automatic fallback, caching, and interpolation. It is part of the GRI FOSS (GeoSol Research Free and Open Source Software) ecosystem. Requires Python 3.14+.

Features

  • Multiple data sources: DTED, GeoTIFF/COG, Copernicus DEM
  • Automatic fallback: Query sources in priority order
  • Vectorized lookups: Efficient batch elevation queries
  • Interpolation options: Nearest neighbor, bilinear, bicubic
  • Tile caching: Memory and disk caching for performance
  • Pre-caching: Download regions for offline use

Installation

pip install gri-terrain

Or for development:

git clone https://gitlab.com/geosol-foss/python/gri-terrain.git
cd gri-terrain
. .init_venv.sh

Quick Start

from gri_terrain import Terrain

# Use default sources (Copernicus DEM with DTED-0 fallback)
terrain = Terrain()

# Get elevation at a single point (not yet implemented)
altitude = terrain.get_altitude(lat=40.0, lon=-105.0)

# Vectorized lookup (not yet implemented)
import numpy as np
lats = np.array([40.0, 41.0, 42.0])
lons = np.array([-105.0, -106.0, -107.0])
altitudes = terrain.get_altitude(lats, lons)

Data Sources

Copernicus DEM (Default)

High-quality global elevation data from ESA, freely available on AWS:

  • GLO-30: 30m resolution (default)
  • GLO-90: 90m resolution
from gri_terrain.sources import CopernicusSource

source = CopernicusSource(resolution="30m")  # not yet implemented
terrain = Terrain(sources=[source])

DTED

Digital Terrain Elevation Data (military standard):

  • Level 0: ~1km resolution
  • Level 1: ~100m resolution
  • Level 2: ~30m resolution
from gri_terrain.sources import DTEDSource

source = DTEDSource("/path/to/dted/data")  # not yet implemented
terrain = Terrain(sources=[source])

GeoTIFF

Local elevation data in GeoTIFF format:

from gri_terrain.sources import GeoTiffSource

source = GeoTiffSource("/path/to/elevation.tif")  # not yet implemented
terrain = Terrain(sources=[source])

Interpolation

Three interpolation methods are supported:

# Nearest neighbor (fastest)
alt = terrain.get_altitude(lat, lon, interpolation="nearest")

# Bilinear (default, good balance)
alt = terrain.get_altitude(lat, lon, interpolation="bilinear")

# Bicubic (smoothest)
alt = terrain.get_altitude(lat, lon, interpolation="bicubic")

Pre-caching

Download tiles for offline use:

terrain.precache_region(
    lat_min=39.0, lat_max=41.0,
    lon_min=-106.0, lon_max=-104.0
)

Dependencies

  • numpy
  • scipy
  • rasterio (GeoTIFF support)
  • dted (DTED file parsing)
  • gri-utils (coordinate conversions)

Ray-Terrain Intersection

Find where a ray intersects the terrain surface:

from gri_terrain.intersect import ray_terrain
from gri_utils.conversion import lla_to_xyz
import numpy as np

# Observer at 45N, 0E, 10km altitude looking down
origin_lla = np.array([45.0, 0.0, 10000.0])
origin_xyz = lla_to_xyz(origin_lla)

# Direction toward Earth center (descending)
direction_xyz = -origin_xyz / np.linalg.norm(origin_xyz)

# Find intersection
hit_xyz = ray_terrain(terrain, origin_xyz, direction_xyz)

if hit_xyz is not None:
    hit_lla = xyz_to_lla(hit_xyz)
    print(f"Hit at {hit_lla[0]:.4f}N, {hit_lla[1]:.4f}E, {hit_lla[2]:.1f}m")

The algorithm uses adaptive step sizes based on:

  1. Altitude band skip: Fast-forward to the terrain altitude band (-500m to 9000m)
  2. Tile skip: When above a tile's maximum elevation, skip to tile boundary
  3. Slope-based skip: Use 45-degree max terrain slope assumption for safe step sizes

The altitude_epsilon_m parameter offsets the terrain surface (useful for vegetation canopy or safety margins):

# Find where ray passes within 10m of terrain
hit = ray_terrain(terrain, origin, direction, altitude_epsilon_m=10.0)

Development Status

  • Source abstraction (TerrainSource ABC)
  • Terrain class with fallback chain
  • Ray-terrain intersection
  • DTED source elevation lookup
  • GeoTIFF/COG source elevation lookup
  • Copernicus DEM source (AWS access)
  • Tile caching (memory and disk)
  • Pre-caching for offline use

Attribution

When using Copernicus DEM data, include:

(c) DLR e.V. 2010-2014 and (c) Airbus Defence and Space GmbH 2014-2018 provided under COPERNICUS by the European Union and ESA; all rights reserved

Other Projects

Current list of other GRI FOSS Projects we are building and maintaining.

License

MIT License. See LICENSE for details.

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

gri_terrain-0.2.0.post1.tar.gz (137.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gri_terrain-0.2.0.post1-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file gri_terrain-0.2.0.post1.tar.gz.

File metadata

  • Download URL: gri_terrain-0.2.0.post1.tar.gz
  • Upload date:
  • Size: 137.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gri_terrain-0.2.0.post1.tar.gz
Algorithm Hash digest
SHA256 6516cc48421ccd7e03af0ff350ec013208c8d35ee1e7df1785b1a96475a4ef67
MD5 542b13e89fddf8c534cecec8ee0f02c6
BLAKE2b-256 8e614327973a9b52e5beb5cedd0198fab7d3485fc632ac2bc21b424169b2627a

See more details on using hashes here.

File details

Details for the file gri_terrain-0.2.0.post1-py3-none-any.whl.

File metadata

  • Download URL: gri_terrain-0.2.0.post1-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for gri_terrain-0.2.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 4565e9e7184db8d04ce85d7d75dfcc1583122d0bc17195adab4db16a9e2cee84
MD5 8ecb641d14da1861f30c0935ff9b45be
BLAKE2b-256 281cf6ed1333a9fc2be23a1a7d8810933fd596e1d966d30eb1418e3fdda67495

See more details on using hashes here.

Supported by

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