| 1001 | delphine | 1 | <?php
 | 
        
           |  |  | 2 | /**
 | 
        
           |  |  | 3 |  * Author : Julien Moquet
 | 
        
           |  |  | 4 |  *
 | 
        
           |  |  | 5 |  * Inspired by Proj4php from Mike Adair madairATdmsolutions.ca
 | 
        
           |  |  | 6 |  *                      and Richard Greenwood rich@greenwoodma$p->com
 | 
        
           |  |  | 7 |  * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
 | 
        
           |  |  | 8 |  */
 | 
        
           |  |  | 9 | /* * *****************************************************************************
 | 
        
           |  |  | 10 |   NAME                             ORTHOGRAPHIC
 | 
        
           |  |  | 11 |   | 
        
           |  |  | 12 |   PURPOSE:	Transforms input longitude and latitude to Easting and
 | 
        
           |  |  | 13 |   Northing for the Orthographic projection.  The
 | 
        
           |  |  | 14 |   longitude and latitude must be in radians.  The Easting
 | 
        
           |  |  | 15 |   and Northing values will be returned in meters.
 | 
        
           |  |  | 16 |   | 
        
           |  |  | 17 |   PROGRAMMER              DATE
 | 
        
           |  |  | 18 |   ----------              ----
 | 
        
           |  |  | 19 |   T. Mittan		Mar, 1993
 | 
        
           |  |  | 20 |   | 
        
           |  |  | 21 |   ALGORITHM REFERENCES
 | 
        
           |  |  | 22 |   | 
        
           |  |  | 23 |   1.  Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
 | 
        
           |  |  | 24 |   Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
 | 
        
           |  |  | 25 |   State Government Printing Office, Washington D.C., 1987.
 | 
        
           |  |  | 26 |   | 
        
           |  |  | 27 |   2.  Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
 | 
        
           |  |  | 28 |   U.S. Geological Survey Professional Paper 1453 , United State Government
 | 
        
           |  |  | 29 |   Printing Office, Washington D.C., 1989.
 | 
        
           |  |  | 30 |  * ***************************************************************************** */
 | 
        
           |  |  | 31 |   | 
        
           |  |  | 32 | class Proj4phpProjOrtho {
 | 
        
           |  |  | 33 |   | 
        
           |  |  | 34 |     /* Initialize the Orthographic projection
 | 
        
           |  |  | 35 |       ------------------------------------- */
 | 
        
           |  |  | 36 |     public function init( $def ) {
 | 
        
           |  |  | 37 |         //double temp;			/* temporary variable		*/
 | 
        
           |  |  | 38 |   | 
        
           |  |  | 39 |         /* Place parameters in static storage for common use
 | 
        
           |  |  | 40 |           ------------------------------------------------- */;
 | 
        
           |  |  | 41 |         $this->sin_p14 = sin( $this->lat0 );
 | 
        
           |  |  | 42 |         $this->cos_p14 = cos( $this->lat0 );
 | 
        
           |  |  | 43 |     }
 | 
        
           |  |  | 44 |   | 
        
           |  |  | 45 |     /* Orthographic forward equations--mapping lat,long to x,y
 | 
        
           |  |  | 46 |       --------------------------------------------------- */
 | 
        
           |  |  | 47 |     public function forward( $p ) {
 | 
        
           |  |  | 48 |   | 
        
           |  |  | 49 |         /*
 | 
        
           |  |  | 50 |         $sinphi;
 | 
        
           |  |  | 51 |         $cosphi; // sin and cos value
 | 
        
           |  |  | 52 |         $dlon;  // delta longitude value
 | 
        
           |  |  | 53 |         $coslon;  // cos of longitude
 | 
        
           |  |  | 54 |         $ksp;  // scale factor
 | 
        
           |  |  | 55 |         $g;
 | 
        
           |  |  | 56 |         */
 | 
        
           |  |  | 57 |   | 
        
           |  |  | 58 |         $lon = $p->x;
 | 
        
           |  |  | 59 |         $lat = $p->y;
 | 
        
           |  |  | 60 |   | 
        
           |  |  | 61 |         /* Forward equations
 | 
        
           |  |  | 62 |           ----------------- */
 | 
        
           |  |  | 63 |         $dlon = Proj4php::$common->adjust_lon( $lon - $this->long0 );
 | 
        
           |  |  | 64 |   | 
        
           |  |  | 65 |         $sinphi = sin( $lat );
 | 
        
           |  |  | 66 |         $cosphi = cos( $lat );
 | 
        
           |  |  | 67 |   | 
        
           |  |  | 68 |         $coslon = cos( $dlon );
 | 
        
           |  |  | 69 |         $g = $this->sin_p14 * sinphi + $this->cos_p14 * $cosphi * $coslon;
 | 
        
           |  |  | 70 |         $ksp = 1.0;
 | 
        
           |  |  | 71 |   | 
        
           |  |  | 72 |         if( ($g > 0) || (abs( $g ) <= Proj4php::$common->EPSLN) ) {
 | 
        
           |  |  | 73 |             $x = $this->a * $ksp * $cosphi * sin( $dlon );
 | 
        
           |  |  | 74 |             $y = $this->y0 + $this->a * $ksp * ($this->cos_p14 * $sinphi - $this->sin_p14 * $cosphi * $coslon);
 | 
        
           |  |  | 75 |         } else {
 | 
        
           |  |  | 76 |             Proj4php::reportError( "orthoFwdPointError" );
 | 
        
           |  |  | 77 |         }
 | 
        
           |  |  | 78 |   | 
        
           |  |  | 79 |         $p->x = $x;
 | 
        
           |  |  | 80 |         $p->y = $y;
 | 
        
           |  |  | 81 |   | 
        
           |  |  | 82 |         return $p;
 | 
        
           |  |  | 83 |     }
 | 
        
           |  |  | 84 |   | 
        
           |  |  | 85 |     /**
 | 
        
           |  |  | 86 |      *
 | 
        
           |  |  | 87 |      * @param type $p
 | 
        
           |  |  | 88 |      * @return type
 | 
        
           |  |  | 89 |      */
 | 
        
           |  |  | 90 |     public function inverse( $p ) {
 | 
        
           |  |  | 91 |   | 
        
           |  |  | 92 |         /*
 | 
        
           |  |  | 93 |         $rh;  // height above ellipsoid
 | 
        
           |  |  | 94 |         $z;  // angle
 | 
        
           |  |  | 95 |         $sinz;
 | 
        
           |  |  | 96 |         $cosz; // sin of z and cos of z
 | 
        
           |  |  | 97 |         $temp;
 | 
        
           |  |  | 98 |         $con;
 | 
        
           |  |  | 99 |         $lon;
 | 
        
           |  |  | 100 |         $lat;
 | 
        
           |  |  | 101 |         */
 | 
        
           |  |  | 102 |   | 
        
           |  |  | 103 |         /* Inverse equations
 | 
        
           |  |  | 104 |           ----------------- */
 | 
        
           |  |  | 105 |         $p->x -= $this->x0;
 | 
        
           |  |  | 106 |         $p->y -= $this->y0;
 | 
        
           |  |  | 107 |         $rh = sqrt( $p->x * $p->x + $p->y * $p->y );
 | 
        
           |  |  | 108 |         if( $rh > $this->a + .0000001 ) {
 | 
        
           |  |  | 109 |             Proj4php::reportError( "orthoInvDataError" );
 | 
        
           |  |  | 110 |         }
 | 
        
           |  |  | 111 |         $z = Proj4php::$common . asinz( $rh / $this->a );
 | 
        
           |  |  | 112 |   | 
        
           |  |  | 113 |         $sinz = sin( $z );
 | 
        
           |  |  | 114 |         $cosz = cos( $z );
 | 
        
           |  |  | 115 |   | 
        
           |  |  | 116 |         $lon = $this->long0;
 | 
        
           |  |  | 117 |         if( abs( $rh ) <= Proj4php::$common->EPSLN ) {
 | 
        
           |  |  | 118 |             $lat = $this->lat0;
 | 
        
           |  |  | 119 |         }
 | 
        
           |  |  | 120 |         $lat = Proj4php::$common . asinz( $cosz * $this->sin_p14 + ($p->y * $sinz * $this->cos_p14) / $rh );
 | 
        
           |  |  | 121 |         $con = abs( $this->lat0 ) - Proj4php::$common->HALF_PI;
 | 
        
           |  |  | 122 |         if( abs( con ) <= Proj4php::$common->EPSLN ) {
 | 
        
           |  |  | 123 |             if( $this->lat0 >= 0 ) {
 | 
        
           |  |  | 124 |                 $lon = Proj4php::$common->adjust_lon( $this->long0 + atan2( $p->x, -$p->y ) );
 | 
        
           |  |  | 125 |             } else {
 | 
        
           |  |  | 126 |                 $lon = Proj4php::$common->adjust_lon( $this->long0 - atan2( -$p->x, $p->y ) );
 | 
        
           |  |  | 127 |             }
 | 
        
           |  |  | 128 |         }
 | 
        
           |  |  | 129 |         $con = $cosz - $this->sin_p14 * sin( $lat );
 | 
        
           |  |  | 130 |   | 
        
           |  |  | 131 |         $p->x = $lon;
 | 
        
           |  |  | 132 |         $p->y = $lat;
 | 
        
           |  |  | 133 |   | 
        
           |  |  | 134 |         return $p;
 | 
        
           |  |  | 135 |     }
 | 
        
           |  |  | 136 |   | 
        
           |  |  | 137 | }
 | 
        
           |  |  | 138 |   | 
        
           |  |  | 139 | Proj4php::$proj['ortho'] = new Proj4phpProjOrtho();
 |