Example #1
0
function utm($lon, $lat)
{
    /* Convert lon/lat to UTM x/y */
    global $NORTH;
    global $workingUTMzone;
    // compute UTMzone
    list($UTMzone, $UTMlatZone) = getUTMzone($lon, $lat);
    //echo "$".$UTMzone."$";
    if ($UTMzone != $workingUTMzone) {
        initUTM($UTMzone);
    }
    if ($lon < 0.0) {
        $lon += 360.0;
    }
    list($x, $y) = tm($lon, $lat);
    $x += 500000.0;
    if ($lat < 0) {
        $y += 10000000.0;
    }
    /* For S hemisphere, add 10^6 m */
    return array($x, $y, $UTMzone, $UTMlatZone);
}
Example #2
0
 function findThisPointMap($pointX, $pointY, $pointUTMzone, $pointUTMlatZone)
 {
     global $db, $mapsTable;
     global $minMrSidResolution;
     $requiredMetersPerPixel = $this->requiredMetersPerPixel();
     // echo "requiredMetersPerPixel=$requiredMetersPerPixel <BR>";
     //		while ($requiredMetersPerPixel <= $minMrSidResolution )  {
     //		while ($requiredMetersPerPixel == $minMrSidResolution )  {
     // FIND THE MAP THAT includes the given point
     $query = "select * FROM {$mapsTable} WHERE  ( " . $requiredMetersPerPixel . "= metersPerPixel ) AND ( UTMzone=" . $pointUTMzone . "  OR UTMzone=" . ($pointUTMzone + 1) . " ) ";
     DEBUG("MAP", 8, "query: {$query}<BR>");
     $res = $db->sql_query($query);
     # Error checking
     $foundMap = 0;
     //echo  " FLIGHT ## $this->UTMzoneUpLeft , $this->MAP_TOP , $this->MAP_LEFT , $this->MAP_BOTTOM , $this->MAP_RIGHT <BR>" ;
     if ($res <= 0) {
         echo "<H3> Error in getting maps query! </H3>\n";
     }
     while ($row = $db->sql_fetchrow($res)) {
         $filename = $row["filename"];
         $leftX = $row["leftX"];
         $topY = $row["topY"];
         $rightX = $row["rightX"];
         $bottomY = $row["bottomY"];
         $UTMzone = $row["UTMzone"];
         $pixelHeight = $row["pixelHeight"];
         $pixelWidth = $row["pixelWidth"];
         $filename = ltrim($filename, "\\/");
         $filenameParts = explode("/", $filename);
         $lon = 0;
         $lat = substr($filenameParts[2], 0, 2);
         if (strtolower(substr($filenameParts[2], 2, 1)) == 's') {
             $lat = -$lat;
         }
         // 28_5/UTM34/35n/N-34-35_009_011.jpg
         list($UTMzone2, $UTMlatZone) = getUTMzone($lon, $lat);
         //DEBUG("MAP",8,"Tile UTMlatZone=$UTMlatZone, looking for $pointUTMlatZone #$filename ");
         //echo " GOT ------> $UTMzone  , $UTMlatZone , $topY , $leftX, $bottomY , $rightX , $filename <br>";
         // echo " LOOKING --> $pointUTMzone $pointX , $pointY<br>";
         $lz1 = getInvLatUTMzone($UTMlatZone);
         $lz2 = getInvLatUTMzone($pointUTMlatZone);
         // DEBUG("MAP",8,"lz1=$lz1 , lz2=$lz2 <BR>");
         if ($lz1 != $lz2 && $lz1 != $lz2 + 1 && $lz1 != $lz2 - 1) {
             //DEBUG("MAP",64,"NOT equal<br>");
             continue;
         } else {
             DEBUG("MAP", 8, "Tile UTMlatZone={$UTMlatZone}, ({$lz1},{$lz2}) looking for {$pointUTMlatZone} #{$filename} <br>");
             //DEBUG("MAP",8,"Correct UTMlatZone<br>");
         }
         //	find the map that has the upper left corner of the flight's rectangle
         if ($UTMzone == $pointUTMzone) {
             if ($leftX <= $pointX && $rightX >= $pointX && $topY >= $pointY && $bottomY <= $pointY) {
                 $foundMap = 1;
                 DEBUG("MAP", 8, "FOUND map 1::");
             }
         } else {
             if ($pointUTMzone + 1 == $UTMzone) {
                 // echo "pointUTMzone = $pointUTMzone , UTMzone = $UTMzone <br>";
                 list($this_lon_top, $this_lat_top) = iutm($rightX, min($topY, $this->MAP_TOP), $UTMzone, $UTMlatZone);
                 list($this_lon_bottom, $this_lat_bottom) = iutm($rightX, max($bottomY, $this->MAP_BOTTOM), $UTMzone, $UTMlatZone);
                 // get the middle lat of the tile
                 $this_lat = $this_lat_bottom + ($this_lat_top - $this_lat_bottom) / 2;
                 $zoneWidth = getUTMZoneWidth($this_lat);
                 $leftX += $zoneWidth;
                 $rightX += $zoneWidth;
                 if ($leftX <= $pointX && $rightX >= $pointX && $topY >= $pointY && $bottomY <= $pointY) {
                     DEBUG("MAP", 8, "FOUND map 2::");
                     $UTMzone--;
                     $foundMap = 1;
                 }
             }
         }
         if ($foundMap) {
             DEBUG("MAP", 8, "Found MAP --> ZONE: {$UTMzone} , {$UTMlatZone} ( {$lat} ) , TOP: {$topY} , LEFT: {$leftX}, BOTOM: {$bottomY} , RIGHT: {$rightX} , {$filename} <br>");
             // flush();
             // A UTM map has always the same $UTMzone for its corners
             $jpegMap = new rasterUTM_Map($UTMzone, $UTMlatZone, $topY, $leftX, $UTMzone, $UTMlatZone, $bottomY, $rightX, $filename);
             if ($jpegMap->pixelWidth) {
                 return $jpegMap;
             } else {
                 DEBUG("MAP", 2, "Could not Read Map {$filename} <br>");
                 $jpegMap->destroy();
                 return new rasterUTM_Map(0, "", 0, 0, 0, "", 0, 0, "", 0, 0);
             }
             // break;
         }
     }
     // havent found anything so we look for less good maps
     // echo $requiredMetersPerPixel."<BR>";
     $requiredMetersPerPixel = $requiredMetersPerPixel * 2;
     //		} //end of while
     $jpegMap = new rasterUTM_Map(0, "", 0, 0, 0, "", 0, 0, "", 0, 0);
     return $jpegMap;
 }