htg

Crates.iohtg
lib.rshtg
version0.2.1
created_at2025-12-21 00:58:21.033208+00
updated_at2025-12-21 17:47:46.077415+00
descriptionHigh-performance SRTM elevation data library
homepage
repositoryhttps://github.com/pedrosanzmtz/htg
max_upload_size
id1997177
size159,599
Pedro Sánchez (pedrosanzmtz)

documentation

README

htg

Crates.io Documentation License: MIT

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 .hgt files
  • Auto-Download: Optional automatic tile download (enable download feature)
  • Bilinear Interpolation: Sub-pixel accuracy for smooth elevation profiles

Installation

[dependencies]
htg = "0.2"

# With auto-download support
htg = { version = "0.2", features = ["download"] }

Quick Start

use htg::SrtmService;

// Create service with data directory and cache size
let service = SrtmService::new("/path/to/hgt/files", 100);

// Query elevation (returns meters as i16)
let elevation = service.get_elevation(35.6762, 139.6503)?;
println!("Elevation: {}m", elevation);

// Query with bilinear interpolation (returns Option<f64>)
if let Some(elevation) = service.get_elevation_interpolated(35.6762, 139.6503)? {
    println!("Interpolated: {:.1}m", elevation);
}

Auto-Download

Enable the download feature to automatically fetch missing tiles:

use htg::{SrtmServiceBuilder, download::DownloadConfig};

// Using ArduPilot terrain server (recommended)
let service = SrtmServiceBuilder::new("/data/srtm")
    .cache_size(100)
    .auto_download(DownloadConfig::ardupilot())
    .build()?;

// Tiles are downloaded automatically when needed
let elevation = service.get_elevation(35.6762, 139.6503)?;

Custom Download Source

use htg::{SrtmServiceBuilder, download::DownloadConfig};

let service = SrtmServiceBuilder::new("/data/srtm")
    .auto_download(DownloadConfig::with_url_template(
        "https://example.com/srtm/{filename}.hgt.gz",
    ))
    .build()?;

Environment Configuration

use htg::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 = SrtmServiceBuilder::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

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

Commit count: 0

cargo fmt