Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 1001 | Details | Compare with Previous | 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
class Proj4phpProjGauss {
10
 
11
    /**
12
     *
13
     */
14
    public function init() {
15
 
16
        $sphi = sin( $this->lat0 );
17
        $cphi = cos( $this->lat0 );
18
        $cphi *= $cphi;
19
        $this->rc = sqrt( 1.0 - $this->es ) / (1.0 - $this->es * $sphi * $sphi);
20
        $this->C = sqrt( 1.0 + $this->es * $cphi * $cphi / (1.0 - $this->es) );
21
        $this->phic0 = asin( $sphi / $this->C );
22
        $this->ratexp = 0.5 * $this->C * $this->e;
23
        $this->K = tan( 0.5 * $this->phic0 + Proj4php::$common->FORTPI ) / (pow( tan( 0.5 * $this->lat0 + Proj4php::$common->FORTPI ), $this->C ) * Proj4php::$common->srat( $this->e * $sphi, $this->ratexp ));
24
    }
25
 
26
    /**
27
     *
28
     * @param type $p
29
     * @return type
30
     */
31
    public function forward( $p ) {
32
        $lon = $p->x;
33
        $lat = $p->y;
34
 
35
        $p->y = 2.0 * atan( $this->K * pow( tan( 0.5 * $lat + Proj4php::$common->FORTPI ), $this->C ) * Proj4php::$common->srat( $this->e * sin( $lat ), $this->ratexp ) ) - Proj4php::$common->HALF_PI;
36
        $p->x = $this->C * $lon;
37
 
38
        return $p;
39
    }
40
 
41
    /**
42
     *
43
     * @param type $p
44
     * @return null
45
     */
46
    public function inverse( $p ) {
47
 
48
        $DEL_TOL = 1e-14;
49
        $lon = $p->x / $this->C;
50
        $lat = $p->y;
51
        $num = pow( tan( 0.5 * $lat + Proj4php::$common . FORTPI ) / $this->K, 1. / $this->C );
52
 
53
        for( $i = Proj4php::$common . MAX_ITER; $i > 0; --$i ) {
54
            $lat = 2.0 * atan( $num * Proj4php::$common->srat( $this->e * sin( $p->y ), -0.5 * $this->e ) ) - Proj4php::$common->HALF_PI;
55
            if( abs( $lat - $p->y ) < $DEL_TOL )
56
                break;
57
            $p->y = $lat;
58
        }
59
 
60
        /* convergence failed */
61
        if( !$i ) {
62
            Proj4php::reportError( "gauss:inverse:convergence failed" );
63
            return null;
64
        }
65
 
66
        $p->x = $lon;
67
        $p->y = $lat;
68
 
69
        return $p;
70
    }
71
 
72
}
73
 
74
Proj4php::$proj['gauss'] = new Proj4phpProjGauss();