1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! # HTG - SRTM Elevation Library
//!
//! High-performance, memory-efficient library for querying elevation data from
//! SRTM (Shuttle Radar Topography Mission) `.hgt` files.
//!
//! ## Features
//!
//! - **Fast**: Memory-mapped I/O for instant data access
//! - **Memory Efficient**: LRU cache limits memory usage
//! - **Automatic Detection**: Determines tile resolution (SRTM1/SRTM3) from file size
//! - **Offline**: Works with local `.hgt` files, no internet required
//! - **Auto-Download** (optional): Download missing tiles automatically
//!
//! ## Quick Start
//!
//! The easiest way to use htg is through [`SrtmService`], which handles tile
//! loading and caching automatically:
//!
//! ```ignore
//! use htg::SrtmService;
//!
//! // Create service with up to 100 cached tiles
//! let service = SrtmService::new("/path/to/hgt/files", 100);
//!
//! // Query elevation - tile loading is automatic
//! let elevation = service.get_elevation(35.6762, 139.6503)?; // Tokyo
//! println!("Elevation: {}m", elevation);
//!
//! // Check cache performance
//! let stats = service.cache_stats();
//! println!("Cache hit rate: {:.1}%", stats.hit_rate() * 100.0);
//! ```
//!
//! ## Auto-Download Feature
//!
//! Enable the `download` feature to automatically download missing tiles:
//!
//! ```toml
//! [dependencies]
//! htg = { version = "0.1", features = ["download"] }
//! ```
//!
//! ```ignore
//! use htg::{SrtmServiceBuilder, download::DownloadConfig};
//!
//! let service = SrtmServiceBuilder::new("/data/srtm")
//! .cache_size(100)
//! .auto_download(DownloadConfig::with_url_template(
//! "https://example.com/srtm/{filename}.hgt.gz", // compression auto-detected
//! ))
//! .build()?;
//!
//! // Will download N35E138.hgt if not present locally
//! let elevation = service.get_elevation(35.5, 138.5)?;
//! ```
//!
//! Supported compression formats (auto-detected from URL extension):
//! - `.hgt.gz` - Gzip compression
//! - `.hgt.zip` - ZIP archive
//! - `.hgt` - No compression
//!
//! ## Low-Level API
//!
//! For more control, you can work with tiles directly:
//!
//! ```ignore
//! use htg::{SrtmTile, filename};
//!
//! // Determine which file to load
//! let filename = filename::lat_lon_to_filename(35.5, 138.7);
//! assert_eq!(filename, "N35E138.hgt");
//!
//! // Load the tile and query elevation
//! let tile = SrtmTile::from_file(&format!("/data/{}", filename))?;
//! let elevation = tile.get_elevation(35.5, 138.7)?;
//! ```
//!
//! ## SRTM Data Format
//!
//! SRTM files contain elevation data in a simple binary format:
//!
//! - **SRTM1**: 3601×3601 samples, 1 arc-second (~30m) resolution
//! - **SRTM3**: 1201×1201 samples, 3 arc-second (~90m) resolution
//!
//! Each sample is a 16-bit big-endian signed integer representing elevation in meters.
//! The special value -32768 indicates void (no data).
//!
//! ## Data Sources
//!
//! Download SRTM data from:
//! - <https://dwtkns.com/srtm30m/>
//! - <https://earthexplorer.usgs.gov/>
// Re-export main types at crate root for convenience
pub use ;
pub use ;
pub use ;