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 GNOMONIC
|
|
|
11 |
|
|
|
12 |
PURPOSE: Transforms input longitude and latitude to Easting and
|
|
|
13 |
Northing for the Gnomonic Projection.
|
|
|
14 |
Implementation based on the existing sterea and ortho
|
|
|
15 |
implementations.
|
|
|
16 |
|
|
|
17 |
PROGRAMMER DATE
|
|
|
18 |
---------- ----
|
|
|
19 |
Richard Marsden November 2009
|
|
|
20 |
|
|
|
21 |
ALGORITHM REFERENCES
|
|
|
22 |
|
|
|
23 |
1. Snyder, John P., "Flattening the Earth - Two Thousand Years of Map
|
|
|
24 |
Projections", University of Chicago Press 1993
|
|
|
25 |
|
|
|
26 |
2. Wolfram Mathworld "Gnomonic Projection"
|
|
|
27 |
http://mathworld.wolfram.com/GnomonicProjection.html
|
|
|
28 |
Accessed: 12th November 2009
|
|
|
29 |
******************************************************************************/
|
|
|
30 |
|
|
|
31 |
class Proj4phpProjGnom {
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Initialize the Gnomonic projection
|
|
|
35 |
*
|
|
|
36 |
* @todo $def not used in context...?
|
|
|
37 |
* @param type $def
|
|
|
38 |
*/
|
|
|
39 |
public function init( $def ) {
|
|
|
40 |
|
|
|
41 |
/* Place parameters in static storage for common use
|
|
|
42 |
------------------------------------------------- */
|
|
|
43 |
$this->sin_p14 = sin( $this->lat0 );
|
|
|
44 |
$this->cos_p14 = cos( $this->lat0 );
|
|
|
45 |
|
|
|
46 |
// Approximation for projecting points to the horizon (infinity)
|
|
|
47 |
$this->infinity_dist = 1000 * $this->a;
|
|
|
48 |
$this->rc = 1;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
/* Gnomonic forward equations--mapping lat,long to x,y
|
|
|
52 |
--------------------------------------------------- */
|
|
|
53 |
public function forward( $p ) {
|
|
|
54 |
|
|
|
55 |
/*
|
|
|
56 |
$sinphi;
|
|
|
57 |
$cosphi; // sin and cos value
|
|
|
58 |
$dlon; // delta longitude value
|
|
|
59 |
$coslon; // cos of longitude
|
|
|
60 |
$ksp; // scale factor
|
|
|
61 |
$g;
|
|
|
62 |
*/
|
|
|
63 |
|
|
|
64 |
$lon = $p->x;
|
|
|
65 |
$lat = $p->y;
|
|
|
66 |
/* Forward equations
|
|
|
67 |
----------------- */
|
|
|
68 |
$dlon = Proj4php::$common->adjust_lon( $lon - $this->long0 );
|
|
|
69 |
|
|
|
70 |
$sinphi = sin( $lat );
|
|
|
71 |
$cosphi = cos( $lat );
|
|
|
72 |
|
|
|
73 |
$coslon = cos( $dlon );
|
|
|
74 |
$g = $this->sin_p14 * $sinphi + $this->cos_p14 * $cosphi * $coslon;
|
|
|
75 |
$ksp = 1.0;
|
|
|
76 |
|
|
|
77 |
if( (g > 0) || (abs( g ) <= Proj4php::$common->EPSLN) ) {
|
|
|
78 |
$x = $this->x0 + $this->a * $ksp * $cosphi * sin( $dlon ) / $g;
|
|
|
79 |
$y = $this->y0 + $this->a * $ksp * ($this->cos_p14 * $sinphi - $this->sin_p14 * $cosphi * $coslon) / $g;
|
|
|
80 |
} else {
|
|
|
81 |
Proj4php::reportError( "orthoFwdPointError" );
|
|
|
82 |
|
|
|
83 |
// Point is in the opposing hemisphere and is unprojectable
|
|
|
84 |
// We still need to return a reasonable point, so we project
|
|
|
85 |
// to infinity, on a bearing
|
|
|
86 |
// equivalent to the northern hemisphere equivalent
|
|
|
87 |
// This is a reasonable approximation for short shapes and lines that
|
|
|
88 |
// straddle the horizon.
|
|
|
89 |
|
|
|
90 |
$x = $this->x0 + $this->infinity_dist * $cosphi * sin( $dlon );
|
|
|
91 |
$y = $this->y0 + $this->infinity_dist * ($this->cos_p14 * $sinphi - $this->sin_p14 * $cosphi * $coslon);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
$p->x = $x;
|
|
|
95 |
$p->y = $y;
|
|
|
96 |
|
|
|
97 |
return $p;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
*
|
|
|
102 |
* @param type $p
|
|
|
103 |
* @return type
|
|
|
104 |
*/
|
|
|
105 |
public function inverse( $p ) {
|
|
|
106 |
|
|
|
107 |
/*
|
|
|
108 |
$rh; // Rho
|
|
|
109 |
$z; // angle
|
|
|
110 |
$sinc;
|
|
|
111 |
$cosc;
|
|
|
112 |
$c;
|
|
|
113 |
$lon;
|
|
|
114 |
$lat;
|
|
|
115 |
*/
|
|
|
116 |
|
|
|
117 |
/* Inverse equations
|
|
|
118 |
----------------- */
|
|
|
119 |
$p->x = ($p->x - $this->x0) / $this->a;
|
|
|
120 |
$p->y = ($p->y - $this->y0) / $this->a;
|
|
|
121 |
|
|
|
122 |
$p->x /= $this->k0;
|
|
|
123 |
$p->y /= $this->k0;
|
|
|
124 |
|
|
|
125 |
if( ($rh = sqrt( $p->x * $p->x + $p->y * $p->y ) ) ) {
|
|
|
126 |
$c = atan2( $rh, $this->rc );
|
|
|
127 |
$sinc = sin( $c );
|
|
|
128 |
$cosc = cos( $c );
|
|
|
129 |
|
|
|
130 |
$lat = Proj4php::$common->asinz( $cosc * $this->sin_p14 + ($p->y * $sinc * $this->cos_p14) / $rh );
|
|
|
131 |
$lon = atan2( $p->x * sinc, rh * $this->cos_p14 * $cosc - $p->y * $this->sin_p14 * $sinc );
|
|
|
132 |
$lon = Proj4php::$common->adjust_lon( $this->long0 + $lon );
|
|
|
133 |
} else {
|
|
|
134 |
$lat = $this->phic0;
|
|
|
135 |
$lon = 0.0;
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
$p->x = $lon;
|
|
|
139 |
$p->y = $lat;
|
|
|
140 |
|
|
|
141 |
return $p;
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
Proj4php::$proj['gnom'] = new Proj4phpProjGnom();
|