| 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                  		SINUSOIDAL
 | 
        
           |  |  | 11 |   | 
        
           |  |  | 12 |   PURPOSE:	Transforms input longitude and latitude to Easting and
 | 
        
           |  |  | 13 |   Northing for the Sinusoidal 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 |   D. Steinwand, EROS      May, 1991
 | 
        
           |  |  | 20 |   | 
        
           |  |  | 21 |   This function was adapted from the Sinusoidal projection code (FORTRAN) in the
 | 
        
           |  |  | 22 |   General Cartographic Transformation Package software which is available from
 | 
        
           |  |  | 23 |   the U.S. Geological Survey National Mapping Division.
 | 
        
           |  |  | 24 |   | 
        
           |  |  | 25 |   ALGORITHM REFERENCES
 | 
        
           |  |  | 26 |   | 
        
           |  |  | 27 |   1.  Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
 | 
        
           |  |  | 28 |   Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
 | 
        
           |  |  | 29 |   State Government Printing Office, Washington D.C., 1987.
 | 
        
           |  |  | 30 |   | 
        
           |  |  | 31 |   2.  "Software Documentation for GCTP General Cartographic Transformation
 | 
        
           |  |  | 32 |   Package", U.S. Geological Survey National Mapping Division, May 1982.
 | 
        
           |  |  | 33 |  * ***************************************************************************** */
 | 
        
           |  |  | 34 |   | 
        
           |  |  | 35 | class Proj4phpProjSinu {
 | 
        
           |  |  | 36 |   | 
        
           |  |  | 37 |     /* Initialize the Sinusoidal projection
 | 
        
           |  |  | 38 |       ------------------------------------ */
 | 
        
           |  |  | 39 |     public function init() {
 | 
        
           |  |  | 40 |         /* Place parameters in static storage for common use
 | 
        
           |  |  | 41 |           ------------------------------------------------- */
 | 
        
           |  |  | 42 |         #$this->R = 6370997.0; //Radius of earth
 | 
        
           |  |  | 43 |   | 
        
           |  |  | 44 |         if( !$this->sphere ) {
 | 
        
           |  |  | 45 |             $this->en = Proj4php::$common->pj_enfn( $this->es );
 | 
        
           |  |  | 46 |         } else {
 | 
        
           |  |  | 47 |             $this->n = 1.;
 | 
        
           |  |  | 48 |             $this->m = 0.;
 | 
        
           |  |  | 49 |             $this->es = 0;
 | 
        
           |  |  | 50 |             $this->C_y = sqrt( ($this->m + 1.) / $this->n );
 | 
        
           |  |  | 51 |             $this->C_x = $this->C_y / ($this->m + 1.);
 | 
        
           |  |  | 52 |         }
 | 
        
           |  |  | 53 |     }
 | 
        
           |  |  | 54 |   | 
        
           |  |  | 55 |     /* Sinusoidal forward equations--mapping lat,long to x,y
 | 
        
           |  |  | 56 |       ----------------------------------------------------- */
 | 
        
           |  |  | 57 |     public function forward( $p ) {
 | 
        
           |  |  | 58 |   | 
        
           |  |  | 59 |         #$x,y,delta_lon;
 | 
        
           |  |  | 60 |         $lon = $p->x;
 | 
        
           |  |  | 61 |         $lat = $p->y;
 | 
        
           |  |  | 62 |   | 
        
           |  |  | 63 |         /* Forward equations
 | 
        
           |  |  | 64 |           ----------------- */
 | 
        
           |  |  | 65 |         $lon = Proj4php::$common->adjust_lon( $lon - $this->long0 );
 | 
        
           |  |  | 66 |   | 
        
           |  |  | 67 |         if( isset($this->sphere) ) {
 | 
        
           |  |  | 68 |             if( !$this->m ) {
 | 
        
           |  |  | 69 |                 $lat = $this->n != 1. ? asin( $this->n * sin( $lat ) ) : $lat;
 | 
        
           |  |  | 70 |             } else {
 | 
        
           |  |  | 71 |                 $k = $this->n * sin( $lat );
 | 
        
           |  |  | 72 |                 for( $i = Proj4php::$common->MAX_ITER; $i; --$i ) {
 | 
        
           |  |  | 73 |                     $V = ($this->m * $lat + sin( $lat ) - $k) / ($this->m + cos( $lat ));
 | 
        
           |  |  | 74 |                     $lat -= $V;
 | 
        
           |  |  | 75 |                     if( abs( $V ) < Proj4php::$common->EPSLN )
 | 
        
           |  |  | 76 |                         break;
 | 
        
           |  |  | 77 |                 }
 | 
        
           |  |  | 78 |             }
 | 
        
           |  |  | 79 |             $x = $this->a * $this->C_x * $lon * ($this->m + cos( $lat ));
 | 
        
           |  |  | 80 |             $y = $this->a * $this->C_y * $lat;
 | 
        
           |  |  | 81 |         } else {
 | 
        
           |  |  | 82 |   | 
        
           |  |  | 83 |             $s = sin( $lat );
 | 
        
           |  |  | 84 |             $c = cos( $lat );
 | 
        
           |  |  | 85 |             $y = $this->a * Proj4php::$common->pj_mlfn( $lat, $s, $c, $this->en );
 | 
        
           |  |  | 86 |             $x = $this->a * $lon * $c / sqrt( 1. - $this->es * $s * $s );
 | 
        
           |  |  | 87 |         }
 | 
        
           |  |  | 88 |   | 
        
           |  |  | 89 |         $p->x = $x;
 | 
        
           |  |  | 90 |         $p->y = $y;
 | 
        
           |  |  | 91 |   | 
        
           |  |  | 92 |         return $p;
 | 
        
           |  |  | 93 |     }
 | 
        
           |  |  | 94 |   | 
        
           |  |  | 95 |     /**
 | 
        
           |  |  | 96 |      *
 | 
        
           |  |  | 97 |      * @param type $p
 | 
        
           |  |  | 98 |      * @return type
 | 
        
           |  |  | 99 |      */
 | 
        
           |  |  | 100 |     public function inverse( $p ) {
 | 
        
           |  |  | 101 |         #$lat;
 | 
        
           |  |  | 102 |         #$temp;
 | 
        
           |  |  | 103 |         #$lon;
 | 
        
           |  |  | 104 |   | 
        
           |  |  | 105 |         /* Inverse equations
 | 
        
           |  |  | 106 |           ----------------- */
 | 
        
           |  |  | 107 |         $p->x -= $this->x0;
 | 
        
           |  |  | 108 |         $p->y -= $this->y0;
 | 
        
           |  |  | 109 |         $lat = $p->y / $this->a;
 | 
        
           |  |  | 110 |   | 
        
           |  |  | 111 |         if( isset($this->sphere) ) {
 | 
        
           |  |  | 112 |   | 
        
           |  |  | 113 |             $p->y /= $this->C_y;
 | 
        
           |  |  | 114 |             $lat = $this->m ? asin( ($this->m * $p->y + sin( $p->y )) / $this->n ) : ( $this->n != 1. ? asin( sin( $p->y ) / $this->n ) : $p->y );
 | 
        
           |  |  | 115 |             $lon = $p->x / ($this->C_x * ($this->m + cos( $p->y )));
 | 
        
           |  |  | 116 |         }
 | 
        
           |  |  | 117 |         else {
 | 
        
           |  |  | 118 |             $lat = Proj4php::$common->pj_inv_mlfn( $p->y / $this->a, $this->es, $this->en );
 | 
        
           |  |  | 119 |             $s = abs( $lat );
 | 
        
           |  |  | 120 |   | 
        
           |  |  | 121 |             if( $s < Proj4php::$common->HALF_PI ) {
 | 
        
           |  |  | 122 |                 $s = sin( $lat );
 | 
        
           |  |  | 123 |                 $temp = $this->long0 + $p->x * sqrt( 1. - $this->es * $s * $s ) / ($this->a * cos( $lat ));
 | 
        
           |  |  | 124 |                 //temp = $this->long0 + $p->x / ($this->a * cos($lat));
 | 
        
           |  |  | 125 |                 $lon = Proj4php::$common->adjust_lon( $temp );
 | 
        
           |  |  | 126 |             } else if( ($s - Proj4php::$common->EPSLN) < Proj4php::$common->HALF_PI ) {
 | 
        
           |  |  | 127 |                 $lon = $this->long0;
 | 
        
           |  |  | 128 |             }
 | 
        
           |  |  | 129 |         }
 | 
        
           |  |  | 130 |   | 
        
           |  |  | 131 |         $p->x = $lon;
 | 
        
           |  |  | 132 |         $p->y = $lat;
 | 
        
           |  |  | 133 |   | 
        
           |  |  | 134 |         return $p;
 | 
        
           |  |  | 135 |     }
 | 
        
           |  |  | 136 |   | 
        
           |  |  | 137 | }
 | 
        
           |  |  | 138 |   | 
        
           |  |  | 139 | Proj4php::$proj['sinu'] = new Proj4phpProjSinu();
 |