My current pet project involves creating a web service that uses the CGIAR SRTM worldwide elevation data set. Each request to the service will query for elevation data from a small geographic area.

Storing all the data in fashion that can be queried fast turns out to be difficult. My best idea is to keep the data in GeoTIFF files and create an index linking lat/lon coordinates to files. Which leads to my current main problem:

How do I get the elevation values out of a GeoTIFF file? I know the projection, scale and orientation of the GeoTIFF files (i.e. I know what lat/lon values each pixel represents). How can I figure out what elevation that pixel refers to? I have to use PHP and thought I could use the ImageMagick function for reading a pixel's color. Unfortunately, it returns R=2 G=2 B=2 for all pixels.


To answer someone else's question below, here is my solution.

I went with the library by Bob Osola suggested in the accepted answer below and made the following changes to adjust it to SRTMv4.1 file format (the one available from the CGIAR website). Update the constants to:

const NUM_DATA_ROWS = 6000;     // the number of data rows in the file ( = ImageLength tag value) 
const NUM_DATA_COLS = 6000;     // the number of data columns in the file ( = ImageWidth tag value)   
const DEGREES_PER_TILE = 5;     // each tile is 5 x 5 degrees of lat/lon
const PIXEL_DIST = 0.000833333; // the distance represented by one pixel (0 degrees 0 mins 3 secs of arc = 1/1200)
const STRIPOFFSETS = 0x44bbd5c; // the offset address of the 'StripOffsets' tag

In addition there was a bug in the computation of a longitude. To fix it, replace

$topleftLon = 180 - (($tileRefHoriz -1) * self::DEGREES_PER_TILE); 
if ($lon < 0) {
    $topleftLon = -$topleftLon;


$topleftLon = (($tileRefHoriz -1) * self::DEGREES_PER_TILE) - 180; 

That should be it.

2 Answers 2


Download the source code from here


SRTMGeoTIFFReader.php is the clever file the reads the GeoTiff and converts the elevation values (in meters) into Lat/Lng coordinates.

I doubt this is exactly what you want but it does give you a solid base on understanding the process required to accomplish the task from your question.

(There is too much code to post here)

  • 1
    Thanks, this script is indeed very useful! I am surprised to see that the author chose to treat the TIFF file simply as a binary file (functions used for reading data are just fopen/fseek/unpack). My naive assumption was that usage of the TIFF storage format implies that image manipulation libraries can be used.
    – jonemo
    Feb 1, 2012 at 18:28
  • Didn't know that script. very nice, indeed! Thanks
    – simo
    Feb 1, 2012 at 21:34
  • After playing with this for two days, I find that it yields incorrect results for locations east of Greenwich and the parameters are set for the SRTM3 dataset (the current one is SRTM4).
    – jonemo
    Feb 3, 2012 at 19:06
  • Did you ever manage to get SRTMGeoTIFFReader.php working with the SRTM4 data?
    – FigBug
    May 4, 2012 at 2:27
  • 1
    edit: I added my answer to your question as a separate answer as it doesn't fit into a comment.
    – jonemo
    Jan 7, 2013 at 22:52

i worked on SRTMGeoTIFFReader and this is what i give

enter image description here

All i want is the coordinate of 4 corner of my geotiff pic like this :

Corner Coordinates:

Upper Left ( 69.7357061, 29.87658367)

Lower Left ( 69.7357061, 28.19226367)

Upper Right ( 86.6125061, 29.87658367)

Lower Right ( 86.6125061, 28.19226367)

Center ( 781741.061, 2903442.367)

have you any suggestion for me?

  • Consider creating a new question rather than posting it to the Answer section.
    – Nikos
    Jun 2, 2023 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.