Python parser for the Shuttle Radar Topography Mission elevation data
npx @tessl/cli install tessl/pypi-srtm-py@0.3.0A 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.
pip install SRTM.pyimport srtmimport 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")SRTM.py uses a modular architecture for efficient elevation data management:
get_data() function creates configured elevation data objectsCore 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
) -> GeoElevationDataclass 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]: ...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: ...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: ...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: ...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]: ...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 outputUsage 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.gpxCore 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)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