PHP code example of tito10047 / hgtreader

1. Go to this page and download the library: Download tito10047/hgtreader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tito10047 / hgtreader example snippets


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";

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

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

// 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);