Skip to content
tito10047Public

About

High-precision SRTM (HGT) elevation reader for PHP 8.2+. Low memory footprint (fseek), bilinear interpolation, and SOLID architecture. Short Version (Tagline) πŸš€ Fast, memory-efficient HGT elevation reader for PHP. πŸ”οΈ

Topics

Resources

Stars

3 stars

Watchers

3 watching

Forks

Latest commit

Β 

History

33 Commits

Folders and files

Repository files navigation

HGT Elevation Reader

PHP Tests License

Professional PHP library for reading SRTM (HGT) files with high precision and minimal memory footprint. Designed for modern PHP 8.2+ with an emphasis on SOLID principles and flexibility.

πŸš€ Key Features

  • Extremely low memory footprint: Uses fseek for direct data access without loading entire files into RAM.
  • High precision: Implements bilinear interpolation for accurate elevation calculation between measurement points.
  • Flexible architecture: Abstraction of data sources (DataSource) and tile providers (TileProvider).
  • Resolution support: Full support for both SRTM-1 (1 arc-second) and SRTM-3 (3 arc-seconds).

πŸ“¦ Installation

You can install the library via Composer:

composer require tito10047/hgtreader

πŸ› οΈ Quick Start (Modern API)

use Tito10047\HgtReader\HgtReader;
use Tito10047\HgtReader\Resolution;
use Tito10047\HgtReader\TileProvider\LocalFileSystemTileProvider;

// 1. Set the path to the folder containing .hgt files
$hgtPath = __DIR__ . '/data/hgt';

// 2. Create a tile provider (TileProvider)
$provider = new LocalFileSystemTileProvider($hgtPath);

// 3. Initialize the reader (Resolution is auto-detected from file size)
$reader = new HgtReader($provider);

// 4. Get precise elevation for coordinates
$lat = 49.38628;
$lon = 19.37702;
$elevation = $reader->getElevation($lat, $lon);

echo "Elevation: {$elevation} m";

πŸ–ΌοΈ Purpose and Usage

The library is ideal for generating elevation profiles of tracks, terrain analysis, or visualizing geographical data.

Elevation profile 1 Example of track elevation profile rendering.

Elevation profile 2 Detailed visualization of terrain changes.

🧩 Advanced Features

Custom DataSources

If you need to read data from memory (e.g., during network transfers), you can use MemoryDataSource:

use Tito10047\HgtReader\DataSource\MemoryDataSource;
// ...
$content = file_get_contents('path/to/file.hgt');
$dataSource = new MemoryDataSource($content);

SRTM-1 Support

For more detailed data (3601x3601 points), simply change the resolution:

$reader = new HgtReader($provider, Resolution::Arc1);

πŸ‘΄ Legacy Support (Backward Compatibility)

The original static interface is available for existing projects:

// The old way of calling is still functional via a wrapper
HgtReader::init(__DIR__ . '/data/hgt', 3); // 3 for SRTM-3
$elevation = HgtReader::getElevation(49.38, 19.37);

πŸ“‚ Where to download HGT data?

You can obtain data in .hgt format from various sources, for example:

πŸ§ͺ Testing

The project is fully covered by tests using PHPUnit:

./vendor/bin/phpunit tests

πŸ“„ License

This project is licensed under the Apache-2.0 License - see the LICENSE file for details.


Author: Jozef MΓ΄stka

About

High-precision SRTM (HGT) elevation reader for PHP 8.2+. Low memory footprint (fseek), bilinear interpolation, and SOLID architecture. Short Version (Tagline) πŸš€ Fast, memory-efficient HGT elevation reader for PHP. πŸ”οΈ

Topics

Resources

Stars

3 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages