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 EQUIDISTANT CONIC
|
|
|
11 |
|
|
|
12 |
PURPOSE: Transforms input longitude and latitude to Easting and Northing
|
|
|
13 |
for the Equidistant Conic projection. The longitude and
|
|
|
14 |
latitude must be in radians. The Easting and Northing values
|
|
|
15 |
will be returned in meters.
|
|
|
16 |
|
|
|
17 |
PROGRAMMER DATE
|
|
|
18 |
---------- ----
|
|
|
19 |
T. Mittan Mar, 1993
|
|
|
20 |
|
|
|
21 |
ALGORITHM REFERENCES
|
|
|
22 |
|
|
|
23 |
1. Snyder, John $p->, "Map Projections--A Working Manual", U.S. Geological
|
|
|
24 |
Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
|
|
|
25 |
State Government Printing Office, Washington D.C., 1987.
|
|
|
26 |
|
|
|
27 |
2. Snyder, John $p-> and Voxland, Philip M., "An Album of Map Projections",
|
|
|
28 |
U.S. Geological Survey Professional Paper 1453 , United State Government
|
|
|
29 |
Printing Office, Washington D.C., 1989.
|
|
|
30 |
*******************************************************************************/
|
|
|
31 |
|
|
|
32 |
/* Variables common to all subroutines in this code file
|
|
|
33 |
-----------------------------------------------------*/
|
|
|
34 |
|
|
|
35 |
class Proj4phpProjEqdc {
|
|
|
36 |
|
|
|
37 |
/* Initialize the Equidistant Conic projection
|
|
|
38 |
------------------------------------------ */
|
|
|
39 |
public function init() {
|
|
|
40 |
|
|
|
41 |
/* Place parameters in static storage for common use
|
|
|
42 |
------------------------------------------------- */
|
|
|
43 |
if( !$this->mode )
|
|
|
44 |
$this->mode = 0; //chosen default mode
|
|
|
45 |
$this->temp = $this->b / $this->a;
|
|
|
46 |
$this->es = 1.0 - pow( $this->temp, 2 );
|
|
|
47 |
$this->e = sqrt( $this->es );
|
|
|
48 |
$this->e0 = Proj4php::$common->e0fn( $this->es );
|
|
|
49 |
$this->e1 = Proj4php::$common->e1fn( $this->es );
|
|
|
50 |
$this->e2 = Proj4php::$common->e2fn( $this->es );
|
|
|
51 |
$this->e3 = Proj4php::$common->e3fn( $this->es );
|
|
|
52 |
|
|
|
53 |
$this->sinphi = sin( $this->lat1 );
|
|
|
54 |
$this->cosphi = cos( $this->lat1 );
|
|
|
55 |
|
|
|
56 |
$this->ms1 = Proj4php::$common->msfnz( $this->e, $this->sinphi, $this->cosphi );
|
|
|
57 |
$this->ml1 = Proj4php::$common->mlfn( $this->e0, $this->e1, $this->e2, $this->e3, $this->lat1 );
|
|
|
58 |
|
|
|
59 |
/* format B
|
|
|
60 |
--------- */
|
|
|
61 |
if( $this->mode != 0 ) {
|
|
|
62 |
if( abs( $this->lat1 + $this->lat2 ) < Proj4php::$common->EPSLN ) {
|
|
|
63 |
Proj4php::reportError( "eqdc:Init:EqualLatitudes" );
|
|
|
64 |
//return(81);
|
|
|
65 |
}
|
|
|
66 |
$this->sinphi = sin( $this->lat2 );
|
|
|
67 |
$this->cosphi = cos( $this->lat2 );
|
|
|
68 |
|
|
|
69 |
$this->ms2 = Proj4php::$common->msfnz( $this->e, $this->sinphi, $this->cosphi );
|
|
|
70 |
$this->ml2 = Proj4php::$common->mlfn( $this->e0, $this->e1, $this->e2, $this->e3, $this->lat2 );
|
|
|
71 |
if( abs( $this->lat1 - $this->lat2 ) >= Proj4php::$common->EPSLN ) {
|
|
|
72 |
$this->ns = ($this->ms1 - $this->ms2) / ($this->ml2 - $this->ml1);
|
|
|
73 |
} else {
|
|
|
74 |
$this->ns = $this->sinphi;
|
|
|
75 |
}
|
|
|
76 |
} else {
|
|
|
77 |
$this->ns = $this->sinphi;
|
|
|
78 |
}
|
|
|
79 |
$this->g = $this->ml1 + $this->ms1 / $this->ns;
|
|
|
80 |
$this->ml0 = Proj4php::$common->mlfn( $this->e0, $this->e1, $this->e2, $this->e3, $this->lat0 );
|
|
|
81 |
$this->rh = $this->a * ($this->g - $this->ml0);
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
/* Equidistant Conic forward equations--mapping lat,long to x,y
|
|
|
85 |
----------------------------------------------------------- */
|
|
|
86 |
public function forward( $p ) {
|
|
|
87 |
$lon = $p->x;
|
|
|
88 |
$lat = $p->y;
|
|
|
89 |
|
|
|
90 |
/* Forward equations
|
|
|
91 |
----------------- */
|
|
|
92 |
$ml = Proj4php::$common->mlfn( $this->e0, $this->e1, $this->e2, $this->e3, $lat );
|
|
|
93 |
$rh1 = $this->a * ($this->g - $ml);
|
|
|
94 |
$theta = $this->ns * Proj4php::$common->adjust_lon( $lon - $this->long0 );
|
|
|
95 |
|
|
|
96 |
$x = $this->x0 + $rh1 * sin( $theta );
|
|
|
97 |
$y = $this->y0 + $this->rh - $rh1 * cos( $theta );
|
|
|
98 |
$p->x = $x;
|
|
|
99 |
$p->y = $y;
|
|
|
100 |
|
|
|
101 |
return $p;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
/* Inverse equations
|
|
|
105 |
----------------- */
|
|
|
106 |
public function inverse( $p ) {
|
|
|
107 |
|
|
|
108 |
$p->x -= $this->x0;
|
|
|
109 |
$p->y = $this->rh - $p->y + $this->y0;
|
|
|
110 |
|
|
|
111 |
if( $this->ns >= 0 ) {
|
|
|
112 |
$rh1 = sqrt( $p->x * $p->x + $p->y * $p->y );
|
|
|
113 |
$con = 1.0;
|
|
|
114 |
} else {
|
|
|
115 |
$rh1 = -sqrt( $p->x * $p->x + $p->y * $p->y );
|
|
|
116 |
$con = -1.0;
|
|
|
117 |
}
|
|
|
118 |
$theta = 0.0;
|
|
|
119 |
if( $rh1 != 0.0 )
|
|
|
120 |
$theta = atan2( $con * $p->x, $con * $p->y );
|
|
|
121 |
$ml = $this->g - $rh1 / $this->a;
|
|
|
122 |
$lat = $this->phi3z( $ml, $this->e0, $this->e1, $this->e2, $this->e3 );
|
|
|
123 |
$lon = Proj4php::$common->adjust_lon( $this->long0 + $theta / $this->ns );
|
|
|
124 |
|
|
|
125 |
$p->x = $lon;
|
|
|
126 |
$p->y = $lat;
|
|
|
127 |
|
|
|
128 |
return $p;
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
/* Function to compute latitude, phi3, for the inverse of the Equidistant
|
|
|
132 |
Conic projection.
|
|
|
133 |
----------------------------------------------------------------- */
|
|
|
134 |
|
|
|
135 |
public function phi3z( $ml, $e0, $e1, $e2, $e3 ) {
|
|
|
136 |
|
|
|
137 |
$phi = $ml;
|
|
|
138 |
for( $i = 0; $i < 15; $i++ ) {
|
|
|
139 |
$dphi = ($ml + $e1 * sin( 2.0 * $phi ) - $e2 * sin( 4.0 * $phi ) + $e3 * sin( 6.0 * $phi )) / $e0 - $phi;
|
|
|
140 |
$phi += $dphi;
|
|
|
141 |
if( abs( $dphi ) <= .0000000001 ) {
|
|
|
142 |
return $phi;
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
Proj4php::reportError( "PHI3Z-CONV:Latitude failed to converge after 15 iterations" );
|
|
|
147 |
|
|
|
148 |
return null;
|
|
|
149 |
}
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
Proj4php::$proj['eqdc'] = new Proj4phpProjEqdc();
|