or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

advanced-interpolation.mddata-management.mdelevation-queries.mdgpx-processing.mdimage-generation.mdindex.md
tile.json

tessl/pypi-srtm-py

Python parser for the Shuttle Radar Topography Mission elevation data

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/srtm.py@0.3.x

To install, run

npx @tessl/cli install tessl/pypi-srtm-py@0.3.0

index.mddocs/

SRTM.py

A comprehensive Python library for parsing and working with Shuttle Radar Topography Mission (SRTM) elevation data. It enables developers to retrieve elevation information for specific coordinates, process GPS tracks by adding elevation data, and generate elevation images for geographic regions.

Package Information

  • Package Name: SRTM.py
  • Language: Python
  • Installation: pip install SRTM.py

Core Imports

import srtm

Basic Usage

import srtm

# Create elevation data object
elevation_data = srtm.get_data()

# Get elevation for specific coordinates (latitude, longitude)
elevation = elevation_data.get_elevation(50.8682, 7.1377)
print(f"Elevation: {elevation} meters")

# Get elevation with approximation for better accuracy
elevation_approx = elevation_data.get_elevation(50.8682, 7.1377, approximate=True)
print(f"Approximate elevation: {elevation_approx} meters")

Architecture

SRTM.py uses a modular architecture for efficient elevation data management:

  • Data Factory: The get_data() function creates configured elevation data objects
  • Automatic Caching: SRTM files are automatically downloaded and cached locally for reuse
  • Multi-Resolution Support: Supports both SRTM1 (30m resolution, US only) and SRTM3 (90m resolution, global)
  • Memory Management: Batch mode available for processing large datasets efficiently
  • Interpolation Engine: Advanced algorithms for accurate elevation estimation between data points

Capabilities

Elevation Queries

Core functionality for retrieving elevation data at specific coordinates with support for both SRTM1 and SRTM3 data sources, automatic file downloading, and interpolation options.

def get_data(
    srtm1: bool = True,
    srtm3: bool = True, 
    leave_zipped: bool = False,
    file_handler: Optional[FileHandler] = None,
    use_included_urls: bool = True,
    batch_mode: bool = False,
    local_cache_dir: str = "",
    timeout: int = 0
) -> GeoElevationData
class GeoElevationData:
    def get_elevation(self, latitude: float, longitude: float, approximate: bool = False) -> Optional[float]: ...
    def get_file(self, latitude: float, longitude: float) -> Optional[GeoElevationFile]: ...
    def get_file_name(self, latitude: float, longitude: float) -> Optional[str]: ...

Elevation Queries

GPX Track Processing

Integration with GPX files to add elevation data to GPS tracks, with options for smoothing, interpolation, and batch processing of multiple tracks.

class GeoElevationData:
    def add_elevations(
        self, 
        gpx, 
        only_missing: bool = False, 
        smooth: bool = False, 
        gpx_smooth_no: int = 0
    ) -> None: ...

GPX Processing

Image Generation

Create elevation maps and visualizations as PIL images or numpy arrays with customizable color schemes, elevation ranges, and geographic bounds.

class GeoElevationData:
    def get_image(
        self,
        size: Tuple[int, int],
        latitude_interval: Tuple[float, float],
        longitude_interval: Tuple[float, float],
        max_elevation: float,
        min_elevation: float = 0,
        unknown_color: Color = Color(255, 255, 255, 255),
        zero_color: Color = Color(0, 0, 255, 255),
        min_color: Color = Color(0, 0, 0, 255),
        max_color: Color = Color(0, 255, 0, 255),
        mode: str = 'image'
    ) -> Any: ...

Image Generation

Data Management

File handling, caching, and configuration options for managing SRTM data files including custom cache directories, batch processing modes, and network settings.

class FileHandler:
    def __init__(self, local_cache_dir: Optional[str] = None): ...
    def exists(self, file_name: str) -> bool: ...
    def write(self, file_name: str, contents: bytes) -> None: ...
    def read(self, file_name: str) -> bytes: ...

Data Management

Advanced Interpolation

Sophisticated algorithms for elevation estimation including Inverse Distance Weighted (IDW) interpolation and approximation methods for improved accuracy between data points.

class GeoElevationData:
    def _IDW(self, latitude: float, longitude: float, radius: float = 1) -> Optional[float]: ...

class GeoElevationFile:
    def approximation(self, latitude: float, longitude: float) -> Optional[float]: ...
    def _InverseDistanceWeighted(self, latitude: float, longitude: float, radius: float = 1) -> Optional[float]: ...

Advanced Interpolation

Command Line Tools

The package includes the gpxelevations command-line utility for adding elevation data to GPX files directly from the command line.

gpxelevations [-h] [-o] [-p] [-s] [-c] [-f FILE] [-v] [gpx_files ...]

Options:

  • -h, --help: Show help message and exit
  • -o, --overwrite: Overwrite existing elevations (otherwise will add elevations only where not yet present)
  • -p, --approximate: Approximate elevations with neighbour points elevation
  • -s, --smooth: Smooth elevations
  • -c, --calculate: Calculate elevations (but don't change the GPX file)
  • -f FILE, --file FILE: Output filename
  • -v, --verbose: Verbose output

Usage Example:

# Add elevations to a GPX file
gpxelevations track.gpx

# Add smoothed elevations with verbose output
gpxelevations -s -v hiking_track.gpx

# Calculate elevations without modifying the file
gpxelevations -c route.gpx

Utility Functions

Core utility functions for distance calculations, color operations, and data processing.

from srtm.utils import Color, distance, get_color_between

def distance(latitude_1: float, longitude_1: float, latitude_2: float, longitude_2: float) -> float: ...
def get_color_between(color1: Color, color2: Color, i: float) -> Color: ...

# Constants
ONE_DEGREE: float  # Meters per degree (approximately 111,000)
DEFAULT_TIMEOUT: int  # Default network timeout in seconds (15)

Types

from typing import Optional, Tuple, Any, NamedTuple

class Color(NamedTuple):
    red: int
    green: int 
    blue: int
    alpha: int

class GeoElevationFile:
    file_name: str
    latitude: float
    longitude: float
    resolution: float
    square_side: int