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
/**
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
class Proj4phpProjAeqd {
11
 
12
    public function init() {
13
        $this->sin_p12 = sin( $this->lat0 );
14
        $this->cos_p12 = cos( $this->lat0 );
15
    }
16
 
17
    /**
18
     *
19
     * @param type $p
20
     * @return type
21
     */
22
    public function forward( $p ) {
23
 
24
        #$lon = $p->x;
25
        #$lat = $p->y;
26
        #$ksp;
27
 
28
        $sinphi = sin( $p->y );
29
        $cosphi = cos( $p->y );
30
        $dlon = Proj4php::$common->adjust_lon( lon - $this->long0 );
31
        $coslon = cos( $dlon );
32
        $g = $this->sin_p12 * $sinphi + $this->cos_p12 * $cosphi * $coslon;
33
        if( abs( abs( $g ) - 1.0 ) < Proj4php::$common->EPSLN ) {
34
            $ksp = 1.0;
35
            if( $g < 0.0 ) {
36
                Proj4php::reportError( "aeqd:Fwd:PointError" );
37
                return;
38
            }
39
        } else {
40
            $z = acos( $g );
41
            $ksp = $z / sin( $z );
42
        }
43
        $p->x = $this->x0 + $this->a * $ksp * $cosphi * sin( $dlon );
44
        $p->y = $this->y0 + $this->a * $ksp * ($this->cos_p12 * $sinphi - $this->sin_p12 * $cosphi * $coslon);
45
 
46
        return $p;
47
    }
48
 
49
    /**
50
     *
51
     * @param type $p
52
     * @return type
53
     */
54
    public function inverse( $p ) {
55
 
56
        $p->x -= $this->x0;
57
        $p->y -= $this->y0;
58
 
59
        $rh = sqrt( $p->x * $p->x + $p->y * $p->y );
60
        if( $rh > (2.0 * Proj4php::$common->HALF_PI * $this->a) ) {
61
            Proj4php::reportError( "aeqdInvDataError" );
62
            return;
63
        }
64
        $z = $rh / $this->a;
65
 
66
        $sinz = sin( $z );
67
        $cosz = cos( $z );
68
 
69
        $lon = $this->long0;
70
        #$lat;
71
        if( abs( $rh ) <= Proj4php::$common->EPSLN ) {
72
            $lat = $this->lat0;
73
        } else {
74
            $lat = Proj4php::$common->asinz( $cosz * $this->sin_p12 + ($p->y * $sinz * $this->cos_p12) / $rh );
75
            $con = abs( $this->lat0 ) - Proj4php::$common->HALF_PI;
76
            if( abs( $con ) <= Proj4php::$common->EPSLN ) {
77
                if( $this->lat0 >= 0.0 ) {
78
                    $lon = Proj4php::$common->adjust_lon( $this->long0 + atan2( $p->x, -$p->y ) );
79
                } else {
80
                    $lon = Proj4php::$common->adjust_lon( $this->long0 - atan2( -$p->x, $p->y ) );
81
                }
82
            } else {
83
                $con = $cosz - $this->sin_p12 * sin( $lat );
84
                if( (abs( $con ) < Proj4php::$common->EPSLN) && (abs( $p->x ) < Proj4php::$common->EPSLN) ) {
85
                    //no-op, just keep the lon value as is
86
                } else {
87
                    #$temp = atan2( ($p->x * $sinz * $this->cos_p12 ), ($con * $rh ) ); // $temp is unused !?!
88
                    $lon = Proj4php::$common->adjust_lon( $this->long0 + atan2( ($p->x * $sinz * $this->cos_p12 ), ($con * $rh ) ) );
89
                }
90
            }
91
        }
92
 
93
        $p->x = $lon;
94
        $p->y = $lat;
95
 
96
        return $p;
97
    }
98
 
99
}
100
 
101
Proj4php::$proj['aeqd'] = new Proj4phpProjAeqd();