Subversion Repositories eFlore/Projets.eflore-projets

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
11
/* Function to compute, phi4, the latitude for the inverse of the
12
  Polyconic projection.
13
  ------------------------------------------------------------ */
14
function phi4z( $eccent, $e0, $e1, $e2, $e3, $a, $b, &$c, $phi ) {
15
    /*
16
    $sinphi;
17
    $sin2ph;
18
    $tanph;
19
    $ml;
20
    $mlp;
21
    $con1;
22
    $con2;
23
    $con3;
24
    $dphi;
25
    $i;
26
    */
27
 
28
    $phi = $a;
29
    for( $i = 1; $i <= 15; $i++ ) {
30
        $sinphi = sin( $phi );
31
        $tanphi = tan( $phi );
32
        $c = $tanphi * sqrt( 1.0 - $eccent * $sinphi * $sinphi );
33
        $sin2ph = sin( 2.0 * $phi );
34
        /*
35
          ml = e0 * *phi - e1 * sin2ph + e2 * sin (4.0 *  *phi);
36
          mlp = e0 - 2.0 * e1 * cos (2.0 *  *phi) + 4.0 * e2 *  cos (4.0 *  *phi);
37
         */
38
        $ml = $e0 * $phi - $e1 * $sin2ph + $e2 * sin( 4.0 * $phi ) - $e3 * sin( 6.0 * $phi );
39
        $mlp = $e0 - 2.0 * $e1 * cos( 2.0 * $phi ) + 4.0 * $e2 * cos( 4.0 * $phi ) - 6.0 * $e3 * cos( 6.0 * $phi );
40
        $con1 = 2.0 * $ml + $c * ($ml * $ml + $b) - 2.0 * $a * ($c * $ml + 1.0);
41
        $con2 = $eccent * $sin2ph * ($ml * $ml + $b - 2.0 * $a * $ml) / (2.0 * $c);
42
        $con3 = 2.0 * ($a - $ml) * ($c * $mlp - 2.0 / $sin2ph) - 2.0 * $mlp;
43
        $dphi = $con1 / ($con2 + $con3);
44
        $phi += $dphi;
45
        if( abs( $dphi ) <= .0000000001 )
46
            return($phi);
47
    }
48
 
49
    Proj4php::reportError( "phi4z: No convergence" );
50
 
51
    return null;
52
}
53
 
54
/* Function to compute the constant e4 from the input of the eccentricity
55
  of the spheroid, x.  This constant is used in the Polar Stereographic
56
  projection.
57
  -------------------------------------------------------------------- */
58
function e4fn( $x ) {
59
    #$con;
60
    #$com;
61
    $con = 1.0 + $x;
62
    $com = 1.0 - $x;
63
    return (sqrt( (pow( $con, $con )) * (pow( $com, $com )) ));
64
}
65
 
66
/* * *****************************************************************************
67
  NAME                             POLYCONIC
68
 
69
  PURPOSE:	Transforms input longitude and latitude to Easting and
70
  Northing for the Polyconic projection.  The
71
  longitude and latitude must be in radians.  The Easting
72
  and Northing values will be returned in meters.
73
 
74
  PROGRAMMER              DATE
75
  ----------              ----
76
  T. Mittan		Mar, 1993
77
 
78
  ALGORITHM REFERENCES
79
 
80
  1.  Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
81
  Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
82
  State Government Printing Office, Washington D.C., 1987.
83
 
84
  2.  Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
85
  U.S. Geological Survey Professional Paper 1453 , United State Government
86
  Printing Office, Washington D.C., 1989.
87
 * ***************************************************************************** */
88
 
89
class Proj4phpProjPoly {
90
 
91
    /* Initialize the POLYCONIC projection
92
      ---------------------------------- */
93
    public function init() {
94
        #$temp;   /* temporary variable		 */
95
        if( $this->lat0 == 0 )
96
            $this->lat0 = 90; //$this->lat0 ca
97
 
98
        /* Place parameters in static storage for common use
99
          ------------------------------------------------- */
100
        $this->temp = $this->b / $this->a;
101
        $this->es = 1.0 - pow( $this->temp, 2 ); // devait etre dans tmerc.js mais n y est pas donc je commente sinon retour de valeurs nulles
102
        $this->e = sqrt( $this->es );
103
        $this->e0 = Proj4php::$common->e0fn( $this->es );
104
        $this->e1 = Proj4php::$common->e1fn( $this->es );
105
        $this->e2 = Proj4php::$common->e2fn( $this->es );
106
        $this->e3 = Proj4php::$common->e3fn( $this->es );
107
        $this->ml0 = Proj4php::$common->mlfn( $this->e0, $this->e1, $this->e2, $this->e3, $this->lat0 ); //si que des zeros le calcul ne se fait pas
108
        //if (!$this->ml0) {$this->ml0=0;}
109
    }
110
 
111
    /* Polyconic forward equations--mapping lat,long to x,y
112
      --------------------------------------------------- */
113
    public function forward( $p ) {
114
 
115
        /*
116
        $sinphi;
117
        $cosphi; // sin and cos value
118
        $al;    // temporary values
119
        $c;    // temporary values
120
        $con;
121
        $ml;  // cone constant, small m
122
        $ms;    // small m
123
        $x;
124
        $y;
125
        */
126
 
127
        $lon = $p->x;
128
        $lat = $p->y;
129
 
130
        $con = Proj4php::$common->adjust_lon( $lon - $this->long0 );
131
 
132
        if( abs( $lat ) <= .0000001 ) {
133
            $x = $this->x0 + $this->a * $con;
134
            $y = $this->y0 - $this->a * $this->ml0;
135
        } else {
136
            $sinphi = sin( $lat );
137
            $cosphi = cos( $lat );
138
 
139
            $ml = Proj4php::$common->mlfn( $this->e0, $this->e1, $this->e2, $this->e3, $lat );
140
            $ms = Proj4php::$common->msfnz( $this->e, $sinphi, $cosphi );
141
 
142
            $x = $this->x0 + $this->a * $ms * sin( $sinphi ) / $sinphi;
143
            $y = $this->y0 + $this->a * ($ml - $this->ml0 + $ms * (1.0 - cos( $sinphi )) / $sinphi);
144
        }
145
 
146
        $p->x = $x;
147
        $p->y = $y;
148
 
149
        return $p;
150
    }
151
 
152
    /* Inverse equations
153
      ----------------- */
154
    public function inverse( $p ) {
155
 
156
        /*
157
        $sin_phi;
158
        $cos_phi; // sin and cos values
159
        $al;     // temporary values
160
        $b;     // temporary values
161
        $c;     // temporary values
162
        $con;
163
        $ml;   // cone constant, small m
164
        $iflg;    // error flag
165
        $lon;
166
        $lat;
167
        */
168
 
169
        $p->x -= $this->x0;
170
        $p->y -= $this->y0;
171
        $al = $this->ml0 + $p->y / $this->a;
172
        $iflg = 0;
173
 
174
        if( abs( $al ) <= .0000001 ) {
175
            $lon = $p->x / $this->a + $this->long0;
176
            $lat = 0.0;
177
        } else {
178
            $b = $al * $al + ($p->x / $this->a) * ($p->x / $this->a);
179
            $iflg = phi4z( $this->es, $this->e0, $this->e1, $this->e2, $this->e3, $this->al, $b, $c, $lat );
180
            if( $iflg != 1 )
181
                return($iflg);
182
            $lon = Proj4php::$common->adjust_lon( (Proj4php::$common->asinz( $p->x * $c / $this->a ) / sin( $lat )) + $this->long0 );
183
        }
184
 
185
        $p->x = $lon;
186
        $p->y = $lat;
187
        return $p;
188
    }
189
 
190
}
191
 
192
Proj4php::$proj['poly'] = new Proj4phpProjPoly();