Giter Club home page Giter Club logo

php-srtm's Introduction

SRTM Elevation Data in PHP

This repo contains PHP code (with a usage demo) to obtain worldwide elevation data from the freely-available 5°x5° 90m v4.1 SRTM GeoTIFF data. It was written around 2010.

The core code is in SRTMGeoTIFFReader.php. The other files are just for the demo, which can also be seen here. My home site uses this code along with JpGraph to make profile graphs of the elevations between two user-chosen locations.

The code determines which data file to read for a given location then uses file pointer arithmetic to read the elevation data from standard GEOTIFF data offsets. It is therefore orders of magnitude faster than ASCII file parsing or reading from a database. For example, my (2020) webserver returns 3378 elevations in around 30ms for the straight line between the two locations of London and Liverpool. This line is around 176 miles in length and the code calculates each elevation for every 90m (approx.) along the line.

Getting the data files

The full set of SRTM elevation data files is downloadable from either CGIAR-CSI or Derek Watkins' SRTM Tile Grabber. I recommend the latter as it's much more responsive and easier to use.

Code features

The code can:

  • return the single elevation in metres closest to the location lat, lon
  • return an array of elevations for the array (lat1, lon1, ... latN, lonN)
  • optionally include elevations for calculated intermediate locations every 90m along the straight line between successive pairs of locations
  • optionally return a bilinear interpolation of the four elevation data points which surround each location
  • return the total linear distance, ascent and descent between two or more locations

The bilinear interpolation option tends to flatten out peaks and troughs. It can make elevation graphs appear smoother over shorter distances (e.g. for hikes or cycle rides) but is arguably less accurate depending on the profile of the terrain.

Running the demo

You will need to:

  • unzip the file GeoData/srtm_36_02.zip into the same directory (the zip can then be discarded)
  • copy all the files to a webserver running any version of PHP
  • browse to index.htm

Code usage

The basic usage is as follows:

<?php 
require_once 'SRTMGeoTIFFReader.php';

$reader = new SRTMGeoTIFFReader("path/to/SRTMdatafiles");

// get the closest single elevation for a given $lat and $lon
$elevation = $reader->getElevation($lat, $lon, $interpolate = false);

// get an array of elevations for every 90m between multiple waypoints
// given an array of lats & lons as (lat1, lon1, ... latN, lonN)
$elevations = $reader->getMultipleElevations(
   $latLons, 
   $addIntermediatelatLons = true, 
   $interpolate = false
);
?>

Usage is described in more detail in the class itself with worked examples in the demo code files.

Be aware that empty data (e.g. over sea areas) is stored as 0x800 and returned as -32678, so such values must be handled accordingly in your code. More details in the SRTM FAQ.

php-srtm's People

Contributors

bobosola avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.