Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

update

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

by

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

That should be it.

share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

Download the source code from here

http://www.osola.org.uk/elevations/index.htm

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)

share|improve this answer
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 '12 at 18:28
    
Didn't know that script. very nice, indeed! Thanks –  simo Feb 1 '12 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 '12 at 19:06
    
Did you ever manage to get SRTMGeoTIFFReader.php working with the SRTM4 data? –  FigBug May 4 '12 at 2:27
    
edit: I added my answer to your question as a separate answer as it doesn't fit into a comment. –  jonemo Jan 7 '13 at 22:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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