| 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 Proj4phpProjSterea {
|
|
|
10 |
|
|
|
11 |
protected $dependsOn = 'gauss';
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
*
|
|
|
15 |
* @return void
|
|
|
16 |
*/
|
|
|
17 |
public function init() {
|
|
|
18 |
|
|
|
19 |
if( !$this->rc ) {
|
|
|
20 |
Proj4php::reportError( "sterea:init:E_ERROR_0" );
|
|
|
21 |
return;
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
$this->sinc0 = sin( $this->phic0 );
|
|
|
25 |
$this->cosc0 = cos( $this->phic0 );
|
|
|
26 |
$this->R2 = 2.0 * $this->rc;
|
|
|
27 |
|
|
|
28 |
if( !$this->title )
|
|
|
29 |
$this->title = "Oblique Stereographic Alternative";
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
*
|
|
|
34 |
* @param type $p
|
|
|
35 |
* @return type
|
|
|
36 |
*/
|
|
|
37 |
public function forward( $p ) {
|
|
|
38 |
|
|
|
39 |
$p->x = Proj4php::$common->adjust_lon( $p->x - $this->long0 ); /* adjust del longitude */
|
|
|
40 |
$p = Proj4php::$proj['gauss']->forward( $p );
|
|
|
41 |
$sinc = sin( $p->y );
|
|
|
42 |
$cosc = cos( $p->y );
|
|
|
43 |
$cosl = cos( $p->x );
|
|
|
44 |
$k = $this->k0 * $this->R2 / (1.0 + $this->sinc0 * $sinc + $this->cosc0 * $cosc * $cosl);
|
|
|
45 |
|
|
|
46 |
$p->x = $k * $cosc * sin( $p->x );
|
|
|
47 |
$p->y = $k * ($this->cosc0 * sinc - $this->sinc0 * $cosc * $cosl);
|
|
|
48 |
|
|
|
49 |
$p->x = $this->a * $p->x + $this->x0;
|
|
|
50 |
$p->y = $this->a * $p->y + $this->y0;
|
|
|
51 |
|
|
|
52 |
return $p;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
*
|
|
|
57 |
* @param type $p
|
|
|
58 |
* @return type
|
|
|
59 |
*/
|
|
|
60 |
public function inverse( $p ) {
|
|
|
61 |
|
|
|
62 |
#$lon;
|
|
|
63 |
#$lat;
|
|
|
64 |
$p->x = ($p->x - $this->x0) / $this->a; /* descale and de-offset */
|
|
|
65 |
$p->y = ($p->y - $this->y0) / $this->a;
|
|
|
66 |
|
|
|
67 |
$p->x /= $this->k0;
|
|
|
68 |
$p->y /= $this->k0;
|
|
|
69 |
|
|
|
70 |
if( ($rho = sqrt( $p->x * $p->x + $p->y * $p->y ) ) ) {
|
|
|
71 |
$c = 2.0 * atan2( $rho, $this->R2 );
|
|
|
72 |
$sinc = sin( $c );
|
|
|
73 |
$cosc = cos( $c );
|
|
|
74 |
$lat = asin( $cosc * $this->sinc0 + $p->y * $sinc * $this->cosc0 / $rho );
|
|
|
75 |
$lon = atan2( $p->x * $sinc, $rho * $this->cosc0 * $cosc - $p->y * $this->sinc0 * $sinc );
|
|
|
76 |
} else {
|
|
|
77 |
$lat = $this->phic0;
|
|
|
78 |
$lon = 0.;
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
$p->x = $lon;
|
|
|
82 |
$p->y = $lat;
|
|
|
83 |
$p = Proj4php::$proj['gauss']->inverse( $p );
|
|
|
84 |
$p->x = Proj4php::$common->adjust_lon( $p->x + $this->long0 ); /* adjust longitude to CM */
|
|
|
85 |
|
|
|
86 |
return $p;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
Proj4php::$proj['sterea'] = new Proj4phpProjSterea();
|