Пример #1
0
 function get_elevation($lat, $lon, $round = TRUE)
 {
     $y = $lat;
     $x = $lon;
     $filename = $this->data_path . 'N' . (int) $lat . 'E' . ((int) $lon < 100 ? '0' . (int) $lon : (int) $lon) . '.hgt';
     if ($lat == '' || $lon == '' || !file_exists($filename)) {
         return FALSE;
     }
     $file = fopen($filename, 'r');
     $offset = (int) (($x - (int) $x) * 1200) * 2 + (1200 - (int) (($y - (int) $y) * 1200)) * 2402;
     fseek($file, $offset);
     $h1 = bytes2int(strrev(fread($file, 2)));
     $h2 = bytes2int(strrev(fread($file, 2)));
     fseek($file, $offset - 2402);
     $h3 = bytes2int(strrev(fread($file, 2)));
     $h4 = bytes2int(strrev(fread($file, 2)));
     fclose($file);
     $m = max($h1, $h2, $h3, $h4);
     for ($i = 1; $i <= 4; $i++) {
         $c = 'h' . $i;
         if (${$c} == -32768) {
             ${$c} = $m;
         }
     }
     $fx = ($lon - (int) ($lon * 1200) / 1200) * 1200;
     $fy = ($lat - (int) ($lat * 1200) / 1200) * 1200;
     // normalizing data
     $elevation = ($h1 * (1 - $fx) + $h2 * $fx) * (1 - $fy) + ($h3 * (1 - $fx) + $h4 * $fx) * $fy;
     if ($round) {
         $elevation = round($elevation);
     }
     return $elevation;
 }
Пример #2
0
 function get_elevation($lat, $lon, $round = TRUE)
 {
     $filename = $this->data_path . $this->get_filename($lat, $lon);
     if ($lat === '' || $lon === '' || !file_exists($filename)) {
         return FALSE;
     }
     $file = fopen($filename, 'r');
     $ll = $this->get_lat_long_adjustments($lat, $lon);
     $lat_dir = $ll['lat_dir'];
     $lat_adj = $ll['lat_adj'];
     $lon_dir = $ll['lon_dir'];
     $lon_adj = $ll['lon_adj'];
     $y = $lat;
     $x = $lon;
     $offset = (int) (($x - (int) $x + $lon_adj) * 1200) * 2 + (1200 - (int) (($y - (int) $y + $lat_adj) * 1200)) * 2402;
     fseek($file, $offset);
     $h1 = bytes2int(strrev(fread($file, 2)));
     $h2 = bytes2int(strrev(fread($file, 2)));
     fseek($file, $offset - 2402);
     $h3 = bytes2int(strrev(fread($file, 2)));
     $h4 = bytes2int(strrev(fread($file, 2)));
     fclose($file);
     $m = max($h1, $h2, $h3, $h4);
     for ($i = 1; $i <= 4; $i++) {
         $c = 'h' . $i;
         if (${$c} == -32768) {
             ${$c} = $m;
         }
     }
     $fx = ($lon - (int) ($lon * 1200) / 1200) * 1200;
     $fy = ($lat - (int) ($lat * 1200) / 1200) * 1200;
     // normalizing data
     $elevation = ($h1 * (1 - $fx) + $h2 * $fx) * (1 - $fy) + ($h3 * (1 - $fx) + $h4 * $fx) * $fy;
     if ($round) {
         $elevation = round($elevation);
     }
     return $elevation;
 }
Пример #3
0
 function get_elevation($lat, $lon, $round = TRUE)
 {
     $filename = $this->data_path . $this->get_filename($lat, $lon);
     if ($lat === '' || $lon === '' || !file_exists($filename)) {
         return FALSE;
     }
     $file = fopen($filename, 'r');
     $ll = $this->get_lat_long_adjustments($lat, $lon);
     $lat_dir = $ll['lat_dir'];
     $lat_adj = $ll['lat_adj'];
     $lon_dir = $ll['lon_dir'];
     $lon_adj = $ll['lon_adj'];
     $y = $lat;
     $x = $lon;
     //whole number - full number * lines (1201)
     // * (
     $line = (int) (((int) $lat - $lat) * 1201);
     $pixel = round(($lon - (int) $lon) * 1201);
     //Debug
     if (isset($_SESSION['userdata']['id']) && $_SESSION['userdata']['id'] == "-1") {
         //echo "filename:$filename, lat:$lat, lon:$lon\n";
         //echo "Line:$line, pixel:$pixel, iLine:$iLine,
         //offset $offset_no_adj <br />\n";
     }
     //file naming is from lower left corner.
     //data is stored within the file from the upper left corner.
     $offset = ($line * 1201 + $pixel) * 2;
     fseek($file, $offset);
     //reverse string - file read (handle, length)
     $h1 = bytes2int(strrev(fread($file, 2)));
     if ($h1 == -32768) {
         $h1 = 0;
     }
     fclose($file);
     return $h1;
 }