htg
High-performance, memory-efficient Rust library for querying elevation data from SRTM (Shuttle Radar Topography Mission) .hgt files.
Features
- Fast: Memory-mapped I/O for <10ms lookups
- Memory Efficient: LRU cache keeps memory bounded
- Offline: Works with local
.hgtfiles - Auto-Download: Optional automatic tile download (enable
downloadfeature) - Bilinear Interpolation: Sub-pixel accuracy for smooth elevation profiles
Installation
[]
= "0.2"
# With auto-download support
= { = "0.2", = ["download"] }
Quick Start
use SrtmService;
// Create service with data directory and cache size
let service = new;
// Query elevation (returns meters as i16)
let elevation = service.get_elevation?;
println!;
// Query with bilinear interpolation (returns Option<f64>)
if let Some = service.get_elevation_interpolated?
Auto-Download
Enable the download feature to automatically fetch missing tiles:
use ;
// Using ArduPilot terrain server (recommended)
let service = new
.cache_size
.auto_download
.build?;
// Tiles are downloaded automatically when needed
let elevation = service.get_elevation?;
Custom Download Source
use ;
let service = new
.auto_download
.build?;
Environment Configuration
use SrtmServiceBuilder;
// Configure via environment variables:
// - HTG_DATA_DIR: Directory containing .hgt files (required)
// - HTG_CACHE_SIZE: Max tiles in cache (default: 100)
// - HTG_DOWNLOAD_SOURCE: "ardupilot", "ardupilot-srtm1", or "ardupilot-srtm3"
let service = from_env?.build?;
SRTM Data Format
- SRTM1: 1 arc-second (~30m resolution), 3601×3601 samples, ~25MB/tile
- SRTM3: 3 arc-second (~90m resolution), 1201×1201 samples, ~2.8MB/tile
- Coverage: Global between ±60° latitude
- Filename:
N35E138.hgt(latitude + longitude of SW corner)
Data Sources
- SRTM Tile Grabber - Interactive map
- USGS Earth Explorer - Official source
- ArduPilot Terrain - Auto-download source
Related Crates
This is part of the htg workspace:
- htg (this crate) - Core library
- htg-service - HTTP microservice (DockerHub)
- htg-cli - Command-line tool
License
MIT