I'm trying to read and process the 1.9GB GTOPO30+ dataset from
http://topex.ucsd.edu/WWW_html/srtm30_plus.html At this point I've
been trying for several days to read the right altitude for a given
lat/lng value (originating from google maps). And I can't seem to
figure out what I'm doing wrong. I think there is something
fundamentally wrong in my code, and my suspect is that I need to
convert between coordinate systems.

The description of the file is:
"The  subdirectory called topo30 has the data stored in a single large
file of 2-byte integers in MSB format (i.e. big-endian).  The grid
spans 0 to 360 in longitude and -90 to 90 in latitude. The upper left
corner of the upper left grid cell has latitude 90 and longitude 0.
There are 43200 columns and 21600 rows."

What I'm doing is the following (in sortof semi-code-PHP-ish):

function convert($lat, $lng)

$cols = 43200; /* LNG */
$rows = 21600; /* LAT */

/* input spans 90 to -90 lat, and -180 to 180 lng, convert these
values to cover 0 to 180 and 0 to 360 resp. */
if($lng < 0)
        $lng = 360 - abs($lng); /* -180 to 180 becomes 0 to 360 */
$lat = abs($lat - 90); /* -90 to 90 becomes 0 to 180 */

$colpx = $lng / (360 / $cols); /* per LNG GRAD */
$rowpx = $lat / (180 / $rows); /* per LAT GRAD */

/* calculate the file position by taking the col-width in account,
multiply by two because there are 2 bytes of data per 'pixel' */
$file_pos = ( floor(($rowpx * $cols) + ($colpx)) ) * 2;

/* now read from the GTOPO+ single 1.9GB file */
$fp = fopen($file,'r');
$res = fseek($fp, $file_pos);
$h = fread($fp, 2);
fclose($fp);
$src = unpack('n',$h); /* thanks to 
http://groups.google.com/group/geonames/msg/9c976963d21ed13a
*/
$height = $src[1];
if ($height>32767) $height -= 65536;  // make signed
if ($height==-32768) $height = 0;

(I'm aware that this isn't really the right group to post this kind of
questions, but I couldn't find any better groups. Nevertheless I did
found some similar questions from other people who were also trying to
distinguish between land and water by using altitude information. So I
do think an answer to this problem could be valuable for the
community.)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to