Skip to main content

High-performance SRTM elevation data library

Project description

srtm-rs - High-performance SRTM Elevation Library

PyPI License: MIT

Ultra-fast SRTM elevation queries in Python. Built with Rust, delivering 3.5x faster performance than the most popular Python SRTM library.

Python bindings for the htg Rust library, providing blazingly fast elevation queries from SRTM .hgt files with sub-microsecond latency.

Installation

pip install srtm-rs

Prebuilt wheels are available for Python 3.12+ on Linux (x86_64, aarch64), macOS (Apple Silicon, x86_64), and Windows (x86_64).

Quick Start

import srtm_rs

# Create service with up to 100 cached tiles
service = srtm_rs.SrtmService("/path/to/srtm", cache_size=100)

# Query elevation (Mount Fuji)
# Returns None for void data or missing tiles
elevation = service.get_elevation(35.3606, 138.7274)
if elevation is not None:
    print(f"Elevation: {elevation}m")  # 3776

# Interpolated query for smoother results
# Returns None if any surrounding point is void
elevation = service.get_elevation_interpolated(35.3606, 138.7274)
if elevation is not None:
    print(f"Elevation: {elevation:.2f}m")  # 3776.42

# Check cache performance
stats = service.cache_stats()
print(f"Cache hit rate: {stats.hit_rate:.1%}")

srtm.py Compatibility

If you're migrating from srtm.py, use rounding="floor" for exact value parity. srtm.py uses math.floor() for grid cell selection, while htg defaults to round() (true nearest-neighbor). The difference is typically 1-3 meters at grid cell boundaries.

import srtm_rs

service = srtm_rs.SrtmService("/path/to/srtm", cache_size=100)

# Default: true nearest-neighbor (round)
elevation = service.get_elevation(33.3448, -96.1592)  # 190

# srtm.py compatible: floor-based (southwest-biased)
elevation = service.get_elevation(33.3448, -96.1592, rounding="floor")  # 191

# Also works with batch queries
elevations = service.get_elevations_batch(coords, default=0, rounding="floor")

Batch Queries

Query multiple coordinates efficiently in a single call:

import srtm_rs

service = srtm_rs.SrtmService("/path/to/srtm", cache_size=100)

coords = [
    (35.3606, 138.7274),  # Mount Fuji
    (27.9881, 86.9250),   # Mount Everest
    (46.8523, 9.1512),    # Piz Bernina
]

# Returns a list of elevations; uses default (0) for void/missing data
elevations = service.get_elevations_batch(coords, default=0)
print(elevations)  # [3776, 8752, 3148]

Preloading Tiles

Warm the cache at startup to avoid cold-start latency (useful when tiles are on NFS):

import srtm_rs

service = srtm_rs.SrtmService("/path/to/srtm", cache_size=100)

# Preload all tiles
stats = service.preload()
print(f"Loaded {stats.tiles_loaded} tiles in {stats.elapsed_ms}ms")

# Preload only CONUS + Hawaii tiles
stats = service.preload(bounds=[
    (24.0, -125.0, 50.0, -66.0),   # CONUS
    (19.0, -161.0, 22.0, -154.0),  # Hawaii
])

# Non-blocking preload (runs in background thread)
service.preload(blocking=False)

Utility Functions

import srtm_rs

# Convert coordinates to filename
filename = srtm_rs.lat_lon_to_filename(35.5, 138.7)
print(filename)  # "N35E138.hgt"

# Parse filename to coordinates
coords = srtm_rs.filename_to_lat_lon("N35E138.hgt")
print(coords)  # (35, 138)

# Void value constant
print(srtm_rs.VOID_VALUE)  # -32768

SRTM Data

Download SRTM .hgt files from:

Both .hgt and .hgt.zip files are supported. ZIP files are transparently extracted on first access.

Performance

srtm-rs delivers exceptional performance through its Rust core and PyO3 bindings, significantly outperforming traditional Python SRTM libraries.

Benchmarks vs Popular Python Libraries

Comparison using local .hgt files only (fair, apples-to-apples test):

Library Implementation Per Query Throughput vs srtm-rs
srtm-rs Rust + PyO3 0.41 us 2,419,110 q/s 1.0x (baseline)
srtm.py Pure Python (256 stars) 1.43 us 697,654 q/s 3.5x slower
srtm4 Python + C++ subprocess 99,630 us 10 q/s 241,017x slower

Key findings:

  • 3.5x faster than srtm.py (most popular, fair comparison)
  • 241,000x faster than srtm4 (subprocess overhead dominates)
  • Sub-microsecond latency - queries complete in 0.41 microseconds
  • 2.4 million queries/second on a single thread

Benchmark environment: Python 3.12, macOS (Apple Silicon). See BENCHMARKS.md for full methodology.

Why So Fast?

  • Zero-copy memory access: Memory-mapped I/O eliminates data copying
  • No subprocess overhead: Direct Rust function calls via PyO3 (unlike srtm4's subprocess approach)
  • Optimized compilation: LLVM optimizations with inline expansion
  • Efficient caching: In-memory LRU cache vs disk-based caching

Real-World Performance

import srtm_rs
service = srtm_rs.SrtmService("/path/to/data", cache_size=100)

# Single query: ~0.4 microseconds (sub-millisecond!)
elevation = service.get_elevation(35.3606, 138.7274)

# Batch queries: ~147k per second on a single thread
for lat, lon in coordinates:
    elevation = service.get_elevation(lat, lon)

Production-ready: Can handle millions of requests per second with multiple cores.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

srtm_rs-0.4.0.tar.gz (63.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

srtm_rs-0.4.0-cp313-cp313-win_amd64.whl (376.0 kB view details)

Uploaded CPython 3.13Windows x86-64

srtm_rs-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl (484.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

srtm_rs-0.4.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (473.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

srtm_rs-0.4.0-cp313-cp313-macosx_11_0_arm64.whl (439.0 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

srtm_rs-0.4.0-cp313-cp313-macosx_10_12_x86_64.whl (460.1 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

srtm_rs-0.4.0-cp312-cp312-win_amd64.whl (376.2 kB view details)

Uploaded CPython 3.12Windows x86-64

srtm_rs-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl (485.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

srtm_rs-0.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (474.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

srtm_rs-0.4.0-cp312-cp312-macosx_11_0_arm64.whl (439.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

srtm_rs-0.4.0-cp312-cp312-macosx_10_12_x86_64.whl (461.0 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file srtm_rs-0.4.0.tar.gz.

File metadata

  • Download URL: srtm_rs-0.4.0.tar.gz
  • Upload date:
  • Size: 63.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for srtm_rs-0.4.0.tar.gz
Algorithm Hash digest
SHA256 e4c90ff56985f7574f9c0251db1fc4a7169d21573f217ba692f05c97ab2170a9
MD5 57553f9d3e483a7a51f079bbfb1a0180
BLAKE2b-256 1a88e2221732ba3cb32513d4a9d366dad525733da988c3bb06f99d213565a81f

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm_rs-0.4.0.tar.gz:

Publisher: release.yml on pedrosanzmtz/htg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file srtm_rs-0.4.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: srtm_rs-0.4.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 376.0 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for srtm_rs-0.4.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ffbcd68e8e81f6fb5be97189593efd4653817a1858ff5f5adf5cd64b241605b9
MD5 c3f67755664b839724775ff9845ebc71
BLAKE2b-256 e9e8ce29a068c724d7f36ac478ef796382f54844f67d209d14e4b6e59a5b5d8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm_rs-0.4.0-cp313-cp313-win_amd64.whl:

Publisher: release.yml on pedrosanzmtz/htg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file srtm_rs-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for srtm_rs-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8d802e552098da4194f5a1a9e378edcdce1d3bb30061f3e785203a4735dfc9b0
MD5 ca02119ad0b25e07f61f9c6d6eb55448
BLAKE2b-256 3b5e2a722599193b3958ed3e7ac23a98f41fc5bfc5693d74035e2c9422b1d7e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm_rs-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl:

Publisher: release.yml on pedrosanzmtz/htg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file srtm_rs-0.4.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for srtm_rs-0.4.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 aa8b3d73fc8361df0cafab7318c3242ea18a66db5e6947796fdb9f5aa8a53368
MD5 87deab71b30413b185a8a8226ca8bd2b
BLAKE2b-256 e89f8841ea07895f1cb16ed828af6d6e32f2d297b793397150b9653238647f87

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm_rs-0.4.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on pedrosanzmtz/htg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file srtm_rs-0.4.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for srtm_rs-0.4.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9455985961bb724acd8814fc2a079bfe6d0090a78c16855569309d72697e8d9b
MD5 f2746945504a961df27db212df487455
BLAKE2b-256 360da29c0627f08faa6d0e2649c64a343662c1c89fdee673a1a4e1126c0956e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm_rs-0.4.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on pedrosanzmtz/htg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file srtm_rs-0.4.0-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for srtm_rs-0.4.0-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e674ca60f897072b6bee382b17828ee88978df1d44fa5c5f1e7373eacc6c7ad0
MD5 81b20c55f66b8f94199f5b4e177a0840
BLAKE2b-256 7fe80bee1f36a5563dd32b55513e5fc5378a76fac6c38f1564d3c912ff4125bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm_rs-0.4.0-cp313-cp313-macosx_10_12_x86_64.whl:

Publisher: release.yml on pedrosanzmtz/htg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file srtm_rs-0.4.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: srtm_rs-0.4.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 376.2 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for srtm_rs-0.4.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e55b9c0c504086be746baa39954af1ade6379734baef9edbe7729a6350a11e5d
MD5 23f3bd49a544c4922a6c750e4375498b
BLAKE2b-256 5885d5e84eee4857f9429f5bc36e5810f11e924c8a19f89d53c7f325a37e7cd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm_rs-0.4.0-cp312-cp312-win_amd64.whl:

Publisher: release.yml on pedrosanzmtz/htg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file srtm_rs-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for srtm_rs-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 60a4c21bb8acd50368012522a5782e4c5044007dd775ff0bf85279198b26887d
MD5 d65f6fd3cca757af7382052d6ca4b75d
BLAKE2b-256 aedb50e9426cf1e3082c25cfdfa0ce9b40eb90e215565c35b6ca72256925d35c

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm_rs-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: release.yml on pedrosanzmtz/htg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file srtm_rs-0.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for srtm_rs-0.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d5e734881f98ff81e4b699b88470cc0100a38aca982304d26ffa7826350e0bb6
MD5 c795fee6cc02089073e4bbaa67fcb30c
BLAKE2b-256 e1184b4392bfebbd283dded62c4d283ed628d4e61487456914ae224cd3456df7

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm_rs-0.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on pedrosanzmtz/htg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file srtm_rs-0.4.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for srtm_rs-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 622e3e3f0987ada879e6346f5b83ac234f7d2c403bf0059b6eaa108d8aabd968
MD5 bff70f14b35fcdb4a046b6bf04a8c6c0
BLAKE2b-256 3dcad5cdcdeb86c129d2e4a54f005d99be1f300e6d6e29b872099ac188098388

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm_rs-0.4.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on pedrosanzmtz/htg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file srtm_rs-0.4.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for srtm_rs-0.4.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d8c3cb96195e48782fdec2fca2787608fcefc0ad6227364070ae0f33edfeefd2
MD5 41ee26b95f6610f6e5cd1183b219f109
BLAKE2b-256 a53b2197b9143a123d7642d632fd420dae8099f8493af47b73fd94242ef08ce5

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm_rs-0.4.0-cp312-cp312-macosx_10_12_x86_64.whl:

Publisher: release.yml on pedrosanzmtz/htg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page