Subversion Repositories eFlore/Projets.eflore-projets

Rev

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
  NAME                            LAMBERT CONFORMAL CONIC
11
 
12
  PURPOSE:	Transforms input longitude and latitude to Easting and
13
  Northing for the Lambert Conformal Conic projection.  The
14
  longitude and latitude must be in radians.  The Easting
15
  and Northing values will be returned in meters.
16
 
17
 
18
  ALGORITHM REFERENCES
19
 
20
  1.  Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
21
  Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
22
  State Government Printing Office, Washington D.C., 1987.
23
 
24
  2.  Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
25
  U.S. Geological Survey Professional Paper 1453 , United State Government
26
 *******************************************************************************/
27
 
28
 
29
//<2104> +proj=lcc +lat_1=10.16666666666667 +lat_0=10.16666666666667 +lon_0=-71.60561777777777 +k_0=1 +x0=-17044 +x0=-23139.97 +ellps=intl +units=m +no_defs  no_defs
30
// Initialize the Lambert Conformal conic projection
31
// -----------------------------------------------------------------
32
//class Proj4phpProjlcc = Class.create();
33
class Proj4phpProjLcc {
34
 
35
    public function init() {
36
        // array of:  r_maj,r_min,lat1,lat2,c_lon,c_lat,false_east,false_north
37
        //double c_lat;                   /* center latitude                      */
38
        //double c_lon;                   /* center longitude                     */
39
        //double lat1;                    /* first standard parallel              */
40
        //double lat2;                    /* second standard parallel             */
41
        //double r_maj;                   /* major axis                           */
42
        //double r_min;                   /* minor axis                           */
43
        //double false_east;              /* x offset in meters                   */
44
        //double false_north;             /* y offset in meters                   */
45
 
46
        //if lat2 is not defined
47
        if( !isset($this->lat2) ) {
48
            $this->lat2 = $this->lat0;
49
        }
50
 
51
        //if k0 is not defined
52
        if( !isset($this->k0) )
53
            $this->k0 = 1.0;
54
 
55
        // Standard Parallels cannot be equal and on opposite sides of the equator
56
        if( abs( $this->lat1 + $this->lat2 ) < Proj4php::$common->EPSLN ) {
57
            Proj4php::reportError( "lcc:init: Equal Latitudes" );
58
            return;
59
        }
60
 
61
        $temp = $this->b / $this->a;
62
        $this->e = sqrt( 1.0 - $temp * $temp );
63
 
64
        $sin1 = sin( $this->lat1 );
65
        $cos1 = cos( $this->lat1 );
66
        $ms1 = Proj4php::$common->msfnz( $this->e, $sin1, $cos1 );
67
        $ts1 = Proj4php::$common->tsfnz( $this->e, $this->lat1, $sin1 );
68
 
69
        $sin2 = sin( $this->lat2 );
70
        $cos2 = cos( $this->lat2 );
71
        $ms2 = Proj4php::$common->msfnz( $this->e, $sin2, $cos2 );
72
        $ts2 = Proj4php::$common->tsfnz( $this->e, $this->lat2, $sin2 );
73
 
74
        $ts0 = Proj4php::$common->tsfnz( $this->e, $this->lat0, sin( $this->lat0 ) );
75
 
76
        if( abs( $this->lat1 - $this->lat2 ) > Proj4php::$common->EPSLN ) {
77
            $this->ns = log( $ms1 / $ms2 ) / log( $ts1 / $ts2 );
78
        } else {
79
            $this->ns = $sin1;
80
        }
81
        $this->f0 = $ms1 / ($this->ns * pow( $ts1, $this->ns ));
82
        $this->rh = $this->a * $this->f0 * pow( $ts0, $this->ns );
83
 
84
        if( !isset($this->title) )
85
            $this->title = "Lambert Conformal Conic";
86
    }
87
 
88
    // Lambert Conformal conic forward equations--mapping lat,long to x,y
89
    // -----------------------------------------------------------------
90
    public function forward( $p ) {
91
 
92
        $lon = $p->x;
93
        $lat = $p->y;
94
 
95
        // convert to radians
96
        if( $lat <= 90.0 && $lat >= -90.0 && $lon <= 180.0 && $lon >= -180.0 ) {
97
            //lon = lon * Proj4php::$common.D2R;
98
            //lat = lat * Proj4php::$common.D2R;
99
        } else {
100
            Proj4php::reportError( "lcc:forward: llInputOutOfRange: " . $lon . " : " . $lat );
101
            return null;
102
        }
103
 
104
        $con = abs( abs( $lat ) - Proj4php::$common->HALF_PI );
105
 
106
        if( $con > Proj4php::$common->EPSLN ) {
107
            $ts = Proj4php::$common->tsfnz( $this->e, $lat, sin( $lat ) );
108
            $rh1 = $this->a * $this->f0 * pow( $ts, $this->ns );
109
        } else {
110
            $con = $lat * $this->ns;
111
            if( $con <= 0 ) {
112
                Proj4php::reportError( "lcc:forward: No Projection" );
113
                return null;
114
            }
115
            $rh1 = 0;
116
        }
117
 
118
        $theta = $this->ns * Proj4php::$common->adjust_lon( $lon - $this->long0 );
119
        $p->x = $this->k0 * ($rh1 * sin( $theta )) + $this->x0;
120
        $p->y = $this->k0 * ($this->rh - $rh1 * cos( $theta )) + $this->y0;
121
 
122
        return $p;
123
    }
124
 
125
    /**
126
     * Lambert Conformal Conic inverse equations--mapping x,y to lat/long
127
     *
128
     * @param type $p
129
     * @return null
130
     */
131
    public function inverse( $p ) {
132
 
133
        $x = ($p->x - $this->x0) / $this->k0;
134
        $y = ($this->rh - ($p->y - $this->y0) / $this->k0);
135
        if( $this->ns > 0 ) {
136
            $rh1 = sqrt( $x * $x + $y * $y );
137
            $con = 1.0;
138
        } else {
139
            $rh1 = -sqrt( $x * $x + $y * $y );
140
            $con = -1.0;
141
        }
142
        $theta = 0.0;
143
        if( $rh1 != 0 ) {
144
            $theta = atan2( ($con * $x ), ($con * $y ) );
145
        }
146
        if( ($rh1 != 0) || ($this->ns > 0.0) ) {
147
            $con = 1.0 / $this->ns;
148
            $ts = pow( ($rh1 / ($this->a * $this->f0) ), $con );
149
            $lat = Proj4php::$common->phi2z( $this->e, $ts );
150
            if( $lat == -9999 )
151
                return null;
152
        } else {
153
            $lat = -Proj4php::$common->HALF_PI;
154
        }
155
        $lon = Proj4php::$common->adjust_lon( $theta / $this->ns + $this->long0 );
156
 
157
        $p->x = $lon;
158
        $p->y = $lat;
159
 
160
        return $p;
161
    }
162
}
163
 
164
Proj4php::$proj['lcc'] = new Proj4phpProjLcc();
165
 
166