| 1001 | delphine | 1 | <?php
 | 
        
           |  |  | 2 |   | 
        
           |  |  | 3 | /**
 | 
        
           |  |  | 4 |  * Author : Julien Moquet
 | 
        
           |  |  | 5 |  *
 | 
        
           |  |  | 6 |  * Inspired by Proj4php from Mike Adair madairATdmsolutions.ca
 | 
        
           |  |  | 7 |  *                      and Richard Greenwood rich@greenwoodma$p->com
 | 
        
           |  |  | 8 |  * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
 | 
        
           |  |  | 9 |  */
 | 
        
           |  |  | 10 | /* * *****************************************************************************
 | 
        
           |  |  | 11 |   NAME                            MERCATOR
 | 
        
           |  |  | 12 |   | 
        
           |  |  | 13 |   PURPOSE:	Transforms input longitude and latitude to Easting and
 | 
        
           |  |  | 14 |   Northing for the Mercator projection.  The
 | 
        
           |  |  | 15 |   longitude and latitude must be in radians.  The Easting
 | 
        
           |  |  | 16 |   and Northing values will be returned in meters.
 | 
        
           |  |  | 17 |   | 
        
           |  |  | 18 |   PROGRAMMER              DATE
 | 
        
           |  |  | 19 |   ----------              ----
 | 
        
           |  |  | 20 |   D. Steinwand, EROS      Nov, 1991
 | 
        
           |  |  | 21 |   T. Mittan		Mar, 1993
 | 
        
           |  |  | 22 |   | 
        
           |  |  | 23 |   ALGORITHM REFERENCES
 | 
        
           |  |  | 24 |   | 
        
           |  |  | 25 |   1.  Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
 | 
        
           |  |  | 26 |   Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
 | 
        
           |  |  | 27 |   State Government Printing Office, Washington D.C., 1987.
 | 
        
           |  |  | 28 |   | 
        
           |  |  | 29 |   2.  Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
 | 
        
           |  |  | 30 |   U.S. Geological Survey Professional Paper 1453 , United State Government
 | 
        
           |  |  | 31 |   Printing Office, Washington D.C., 1989.
 | 
        
           |  |  | 32 |  * ***************************************************************************** */
 | 
        
           |  |  | 33 |   | 
        
           |  |  | 34 | //static double r_major = a;		   /* major axis 				*/
 | 
        
           |  |  | 35 | //static double r_minor = b;		   /* minor axis 				*/
 | 
        
           |  |  | 36 | //static double lon_center = long0;	   /* Center longitude (projection center) */
 | 
        
           |  |  | 37 | //static double lat_origin =  lat0;	   /* center latitude			*/
 | 
        
           |  |  | 38 | //static double e,es;		           /* eccentricity constants		*/
 | 
        
           |  |  | 39 | //static double m1;		               /* small value m			*/
 | 
        
           |  |  | 40 | //static double false_northing = y0;   /* y offset in meters			*/
 | 
        
           |  |  | 41 | //static double false_easting = x0;	   /* x offset in meters			*/
 | 
        
           |  |  | 42 | //scale_fact = k0
 | 
        
           |  |  | 43 |   | 
        
           |  |  | 44 | class Proj4phpProjMerc {
 | 
        
           |  |  | 45 |   | 
        
           |  |  | 46 |     public function init() {
 | 
        
           |  |  | 47 |         //?$this->temp = $this->r_minor / $this->r_major;
 | 
        
           |  |  | 48 |         //$this->temp = $this->b / $this->a;
 | 
        
           |  |  | 49 |         //$this->es = 1.0 - sqrt($this->temp);
 | 
        
           |  |  | 50 |         //$this->e = sqrt( $this->es );
 | 
        
           |  |  | 51 |         //?$this->m1 = cos($this->lat_origin) / (sqrt( 1.0 - $this->es * sin($this->lat_origin) * sin($this->lat_origin)));
 | 
        
           |  |  | 52 |         //$this->m1 = cos(0.0) / (sqrt( 1.0 - $this->es * sin(0.0) * sin(0.0)));
 | 
        
           |  |  | 53 |         if( $this->lat_ts ) {
 | 
        
           |  |  | 54 |             if( $this->sphere ) {
 | 
        
           |  |  | 55 |                 $this->k0 = cos( $this->lat_ts );
 | 
        
           |  |  | 56 |             } else {
 | 
        
           |  |  | 57 |                 $this->k0 = Proj4php::$common->msfnz( $this->es, sin( $this->lat_ts ), cos( $this->lat_ts ) );
 | 
        
           |  |  | 58 |             }
 | 
        
           |  |  | 59 |         }
 | 
        
           |  |  | 60 |     }
 | 
        
           |  |  | 61 |   | 
        
           |  |  | 62 |     /* Mercator forward equations--mapping lat,long to x,y
 | 
        
           |  |  | 63 |       -------------------------------------------------- */
 | 
        
           |  |  | 64 |   | 
        
           |  |  | 65 |     public function forward( $p ) {
 | 
        
           |  |  | 66 |   | 
        
           |  |  | 67 |         //alert("ll2m coords : ".coords);
 | 
        
           |  |  | 68 |         $lon = $p->x;
 | 
        
           |  |  | 69 |         $lat = $p->y;
 | 
        
           |  |  | 70 |         // convert to radians
 | 
        
           |  |  | 71 |         if( $lat * Proj4php::$common->R2D > 90.0 &&
 | 
        
           |  |  | 72 |                   $lat * Proj4php::$common->R2D < -90.0 &&
 | 
        
           |  |  | 73 |                   $lon * Proj4php::$common->R2D > 180.0 &&
 | 
        
           |  |  | 74 |                   $lon * Proj4php::$common->R2D < -180.0 ) {
 | 
        
           |  |  | 75 |             Proj4php::reportError( "merc:forward: llInputOutOfRange: " . $lon . " : " . $lat );
 | 
        
           |  |  | 76 |             return null;
 | 
        
           |  |  | 77 |         }
 | 
        
           |  |  | 78 |   | 
        
           |  |  | 79 |         if( abs( abs( $lat ) - Proj4php::$common->HALF_PI ) <= Proj4php::$common->EPSLN ) {
 | 
        
           |  |  | 80 |             Proj4php::reportError( "merc:forward: ll2mAtPoles" );
 | 
        
           |  |  | 81 |             return null;
 | 
        
           |  |  | 82 |         } else {
 | 
        
           |  |  | 83 |             if( $this->sphere ) {
 | 
        
           |  |  | 84 |                 $x = $this->x0 + $this->a * $this->k0 * Proj4php::$common->adjust_lon( $lon - $this->long0 );
 | 
        
           |  |  | 85 |                 $y = $this->y0 + $this->a * $this->k0 * log( tan( Proj4php::$common->FORTPI + 0.5 * $lat ) );
 | 
        
           |  |  | 86 |             } else {
 | 
        
           |  |  | 87 |                 $sinphi = sin( lat );
 | 
        
           |  |  | 88 |                 $ts = Proj4php::$common . tsfnz( $this->e, $lat, $sinphi );
 | 
        
           |  |  | 89 |                 $x = $this->x0 + $this->a * $this->k0 * Proj4php::$common->adjust_lon( $lon - $this->long0 );
 | 
        
           |  |  | 90 |                 $y = $this->y0 - $this->a * $this->k0 * log( $ts );
 | 
        
           |  |  | 91 |             }
 | 
        
           |  |  | 92 |   | 
        
           |  |  | 93 |             $p->x = $x;
 | 
        
           |  |  | 94 |             $p->y = $y;
 | 
        
           |  |  | 95 |   | 
        
           |  |  | 96 |             return $p;
 | 
        
           |  |  | 97 |         }
 | 
        
           |  |  | 98 |     }
 | 
        
           |  |  | 99 |   | 
        
           |  |  | 100 |     /* Mercator inverse equations--mapping x,y to lat/long
 | 
        
           |  |  | 101 |       -------------------------------------------------- */
 | 
        
           |  |  | 102 |   | 
        
           |  |  | 103 |     public function inverse( $p ) {
 | 
        
           |  |  | 104 |   | 
        
           |  |  | 105 |         $x = $p->x - $this->x0;
 | 
        
           |  |  | 106 |         $y = $p->y - $this->y0;
 | 
        
           |  |  | 107 |   | 
        
           |  |  | 108 |         if( $this->sphere ) {
 | 
        
           |  |  | 109 |             $lat = Proj4php::$common->HALF_PI - 2.0 * atan( exp( -$y / $this->a * $this->k0 ) );
 | 
        
           |  |  | 110 |         } else {
 | 
        
           |  |  | 111 |             $ts = exp( -$y / ($this->a * $this->k0) );
 | 
        
           |  |  | 112 |             $lat = Proj4php::$common->phi2z( $this->e, $ts );
 | 
        
           |  |  | 113 |             if( $lat == -9999 ) {
 | 
        
           |  |  | 114 |                 Proj4php::reportError( "merc:inverse: lat = -9999" );
 | 
        
           |  |  | 115 |                 return null;
 | 
        
           |  |  | 116 |             }
 | 
        
           |  |  | 117 |         }
 | 
        
           |  |  | 118 |         $lon = Proj4php::$common->adjust_lon( $this->long0 + $x / ($this->a * $this->k0) );
 | 
        
           |  |  | 119 |   | 
        
           |  |  | 120 |         $p->x = $lon;
 | 
        
           |  |  | 121 |         $p->y = $lat;
 | 
        
           |  |  | 122 |         return $p;
 | 
        
           |  |  | 123 |     }
 | 
        
           |  |  | 124 |   | 
        
           |  |  | 125 | }
 | 
        
           |  |  | 126 |   | 
        
           |  |  | 127 | Proj4php::$proj['merc'] = new Proj4phpProjMerc();
 | 
        
           |  |  | 128 |   | 
        
           |  |  | 129 |   |