diff --git a/src/Common.php b/src/Common.php
index 23a8405..e26f25e 100644
--- a/src/Common.php
+++ b/src/Common.php
@@ -4,10 +4,10 @@
/**
* Author : Julien Moquet, Jason Judge
- *
+ *
* Inspired by Proj4js from Mike Adair madairATdmsolutions.ca
- * and Richard Greenwood rich@greenwoodmap.com
- * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
+ * and Richard Greenwood rich@greenwoodmap.com
+ * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
*/
class Common {
public $PI = M_PI; #3.141592653589793238; //Math.PI,
@@ -63,79 +63,75 @@ class Common {
/**
* Function to compute the constant small m which is the radius of
* a parallel of latitude, phi, divided by the semimajor axis.
- *
+ *
* @param type $eccent
* @param type $sinphi
* @param type $cosphi
* @return type
*/
- public function msfnz($eccent, $sinphi, $cosphi)
- {
+ public function msfnz($eccent, $sinphi, $cosphi) {
$con = $eccent * $sinphi;
-
- return $cosphi / (sqrt( 1.0 - $con * $con ));
+
+ return $cosphi / (sqrt(1.0 - $con * $con));
}
/**
* Function to compute the constant small t for use in the forward
* computations in the Lambert Conformal Conic and the Polar
* Stereographic projections.
- *
+ *
* @param type $eccent
* @param type $phi
* @param type $sinphi
* @return type
*/
- public function tsfnz($eccent, $phi, $sinphi)
- {
+ public function tsfnz($eccent, $phi, $sinphi) {
$con = $eccent * $sinphi;
$com = 0.5 * $eccent;
- $con = pow( ((1.0 - $con) / (1.0 + $con) ), $com );
+ $con = pow(((1.0 - $con) / (1.0 + $con)), $com);
- return (tan( .5 * (M_PI_2 - $phi) ) / $con);
+ return (tan(.5 * (M_PI_2 - $phi)) / $con);
}
/**
* Function to compute the latitude angle, phi2, for the inverse of the
* Lambert Conformal Conic and Polar Stereographic projections.
- *
+ *
* rise up an assertion if there is no convergence.
- *
+ *
* @param type $eccent
* @param type $ts
* @return type
*/
- public function phi2z($eccent, $ts)
- {
+ public function phi2z($eccent, $ts) {
$eccnth = .5 * $eccent;
- $phi = M_PI_2 - 2 * atan( $ts );
+ $phi = M_PI_2 - 2 * atan($ts);
- for( $i = 0; $i <= 15; $i++ ) {
- $con = $eccent * sin( $phi );
- $dphi = M_PI_2 - 2 * atan( $ts * (pow( ((1.0 - $con) / (1.0 + $con) ), $eccnth )) ) - $phi;
+ for ($i = 0; $i <= 15; $i++) {
+ $con = $eccent * sin($phi);
+ $dphi = M_PI_2 - 2 * atan($ts * (pow(((1.0 - $con) / (1.0 + $con)), $eccnth))) - $phi;
$phi += $dphi;
- if( abs( $dphi ) <= .0000000001 )
+ if (abs($dphi) <= .0000000001)
return $phi;
}
- assert( "false; /* phi2z has NoConvergence */" );
+ assert("false; /* phi2z has NoConvergence */");
return (-9999);
}
/**
- * Function to compute constant small q which is the radius of a
+ * Function to compute constant small q which is the radius of a
* parallel of latitude, phi, divided by the semimajor axis.
- *
+ *
* @param type $eccent
* @param type $sinphi
* @return type
*/
- public function qsfnz($eccent, $sinphi)
- {
- if( $eccent > 1.0e-7 ) {
+ public function qsfnz($eccent, $sinphi) {
+ if ($eccent > 1.0e-7) {
$con = $eccent * $sinphi;
- return (( 1.0 - $eccent * $eccent) * ($sinphi / (1.0 - $con * $con) - (.5 / $eccent) * log( (1.0 - $con) / (1.0 + $con) )));
+ return ((1.0 - $eccent * $eccent) * ($sinphi / (1.0 - $con * $con) - (.5 / $eccent) * log((1.0 - $con) / (1.0 + $con))));
}
return (2.0 * $sinphi);
@@ -143,14 +139,13 @@ public function qsfnz($eccent, $sinphi)
/**
* Function to eliminate roundoff errors in asin
- *
+ *
* @param type $x
* @return type
*/
- public function asinz($x)
- {
- return asin(
- abs( $x ) > 1.0 ? ($x > 1.0 ? 1.0 : -1.0) : $x
+ public function asinz($x) {
+ return asin(
+ abs($x) > 1.0 ? ($x > 1.0 ? 1.0 : -1.0) : $x
);
#if( abs( $x ) > 1.0 ) {
@@ -161,47 +156,43 @@ public function asinz($x)
/**
* following functions from gctpc cproj.c for transverse mercator projections
- *
+ *
* @param type $x
* @return type
*/
- public function e0fn($x)
- {
+ public function e0fn($x) {
return (1.0 - 0.25 * $x * (1.0 + $x / 16.0 * (3.0 + 1.25 * $x)));
}
/**
- *
+ *
* @param type $x
* @return type
*/
- public function e1fn($x)
- {
+ public function e1fn($x) {
return (0.375 * $x * (1.0 + 0.25 * $x * (1.0 + 0.46875 * $x)));
}
/**
- *
+ *
* @param type $x
* @return type
*/
- public function e2fn($x)
- {
+ public function e2fn($x) {
return (0.05859375 * $x * $x * (1.0 + 0.75 * $x));
}
/**
- *
+ *
* @param type $x
* @return type
*/
- public function e3fn($x)
- {
+ public function e3fn($x) {
return ($x * $x * $x * (35.0 / 3072.0));
}
/**
- *
+ *
* @param type $e0
* @param type $e1
* @param type $e2
@@ -209,136 +200,126 @@ public function e3fn($x)
* @param type $phi
* @return type
*/
- public function mlfn($e0, $e1, $e2, $e3, $phi)
- {
- return ($e0 * $phi - $e1 * sin( 2.0 * $phi ) + $e2 * sin( 4.0 * $phi ) - $e3 * sin( 6.0 * $phi ));
+ public function mlfn($e0, $e1, $e2, $e3, $phi) {
+ return ($e0 * $phi - $e1 * sin(2.0 * $phi) + $e2 * sin(4.0 * $phi) - $e3 * sin(6.0 * $phi));
}
/**
- *
+ *
* @param type $esinp
* @param type $exp
* @return type
*/
- public function srat($esinp, $exp)
- {
- return (pow( (1.0 - $esinp) / (1.0 + $esinp), $exp ));
+ public function srat($esinp, $exp) {
+ return (pow((1.0 - $esinp) / (1.0 + $esinp), $exp));
}
/**
* Function to return the sign of an argument
- *
+ *
* @param type $x
* @return type
*/
- public function sign($x)
- {
+ public function sign($x) {
return $x < 0.0 ? -1 : 1;
}
/**
* Function to adjust longitude to -180 to 180; input in radians
- *
+ *
* @param type $x
* @return type
*/
- public function adjust_lon($x)
- {
- return (abs( $x ) < M_PI) ? $x : ($x - ($this->sign( $x ) * $this->TWO_PI) );
+ public function adjust_lon($x) {
+ return (abs($x) < M_PI) ? $x : ($x - ($this->sign($x) * $this->TWO_PI));
}
/**
* IGNF - DGR : algorithms used by IGN France
* Function to adjust latitude to -90 to 90; input in radians
- *
+ *
* @param type $x
* @return type
*/
- public function adjust_lat($x)
- {
- $x = (abs( $x ) < M_PI_2) ? $x : ($x - ($this->sign( $x ) * M_PI) );
+ public function adjust_lat($x) {
+ $x = (abs($x) < M_PI_2) ? $x : ($x - ($this->sign($x) * M_PI));
return $x;
}
/**
* Latitude Isometrique - close to tsfnz ...
- *
+ *
* @param type $eccent
* @param float $phi
* @param type $sinphi
* @return string
*/
- public function latiso($eccent, $phi, $sinphi)
- {
- if( abs( $phi ) > M_PI_2 )
+ public function latiso($eccent, $phi, $sinphi) {
+ if (abs($phi) > M_PI_2)
return +NaN;
- if( $phi == M_PI_2 )
+ if ($phi == M_PI_2)
return INF;
- if( $phi == -1.0 * M_PI_2 )
+ if ($phi == -1.0 * M_PI_2)
return -1.0 * INF;
$con = $eccent * $sinphi;
- return log( tan( (M_PI_2 + $phi) / 2.0 ) ) + $eccent * log( (1.0 - $con) / (1.0 + $con) ) / 2.0;
+ return log(tan((M_PI_2 + $phi) / 2.0)) + $eccent * log((1.0 - $con) / (1.0 + $con)) / 2.0;
}
/**
- *
+ *
* @param type $x
* @param type $L
* @return type
*/
- public function fL($x, $L)
- {
- return 2.0 * atan( $x * exp( $L ) ) - M_PI_2;
+ public function fL($x, $L) {
+ return 2.0 * atan($x * exp($L)) - M_PI_2;
}
/**
* Inverse Latitude Isometrique - close to ph2z
- *
+ *
* @param type $eccent
* @param type $ts
* @return type
*/
- public function invlatiso($eccent, $ts)
- {
- $phi = $this->fL( 1.0, $ts );
+ public function invlatiso($eccent, $ts) {
+ $phi = $this->fL(1.0, $ts);
$Iphi = 0.0;
$con = 0.0;
do {
$Iphi = $phi;
- $con = $eccent * sin( $Iphi );
- $phi = $this->fL( exp( $eccent * log( (1.0 + $con) / (1.0 - $con) ) / 2.0 ), $ts );
- } while( abs( $phi - $Iphi ) > 1.0e-12 );
+ $con = $eccent * sin($Iphi);
+ $phi = $this->fL(exp($eccent * log((1.0 + $con) / (1.0 - $con)) / 2.0), $ts);
+ } while (abs($phi - $Iphi) > 1.0e-12);
return $phi;
}
/**
* Grande Normale
- *
+ *
* @param type $a
* @param type $e
* @param type $sinphi
* @return type
*/
- public function gN($a, $e, $sinphi)
- {
+ public function gN($a, $e, $sinphi) {
$temp = $e * $sinphi;
- return $a / sqrt( 1.0 - $temp * $temp );
+ return $a / sqrt(1.0 - $temp * $temp);
}
/**
* code from the PROJ.4 pj_mlfn.c file; this may be useful for other projections
- *
+ *
* @param type $es
* @return type
*/
- public function pj_enfn($es)
- {
- $en = array( );
+ public function pj_enfn($es) {
+ $en = array();
$en[0] = $this->C00 - $es * ($this->C02 + $es * ($this->C04 + $es * ($this->C06 + $es * $this->C08)));
$en[1] = es * ($this->C22 - $es * ($this->C04 + $es * ($this->C06 + $es * $this->C08)));
$t = $es * $es;
@@ -351,15 +332,14 @@ public function pj_enfn($es)
}
/**
- *
+ *
* @param type $phi
* @param type $sphi
* @param type $cphi
* @param type $en
* @return type
*/
- public function pj_mlfn($phi, $sphi, $cphi, $en)
- {
+ public function pj_mlfn($phi, $sphi, $cphi, $en) {
$cphi *= $sphi;
$sphi *= $sphi;
@@ -367,29 +347,28 @@ public function pj_mlfn($phi, $sphi, $cphi, $en)
}
/**
- *
+ *
* @param type $arg
* @param type $es
* @param type $en
* @return type
*/
- public function pj_inv_mlfn($arg, $es, $en)
- {
- $k = (float) 1 / (1 - $es);
+ public function pj_inv_mlfn($arg, $es, $en) {
+ $k = (float)1 / (1 - $es);
$phi = $arg;
- for( $i = Proj4php::$common->MAX_ITER; $i; --$i ) { /* rarely goes over 2 iterations */
- $s = sin( $phi );
+ for ($i = Proj4php::$common->MAX_ITER; $i; --$i) { /* rarely goes over 2 iterations */
+ $s = sin($phi);
$t = 1. - $es * $s * $s;
//$t = $this->pj_mlfn($phi, $s, cos($phi), $en) - $arg;
//$phi -= $t * ($t * sqrt($t)) * $k;
- $t = ($this->pj_mlfn( $phi, $s, cos( $phi ), $en ) - $arg) * ($t * sqrt( $t )) * $k;
+ $t = ($this->pj_mlfn($phi, $s, cos($phi), $en) - $arg) * ($t * sqrt($t)) * $k;
$phi -= $t;
- if( abs( $t ) < Proj4php::$common->EPSLN )
+ if (abs($t) < Proj4php::$common->EPSLN)
return $phi;
}
- Proj4php::reportError( "cass:pj_inv_mlfn: Convergence error" );
+ Proj4php::reportError("cass:pj_inv_mlfn: Convergence error");
return $phi;
}
diff --git a/src/Datum.php b/src/Datum.php
index ef9aae1..fb69d28 100644
--- a/src/Datum.php
+++ b/src/Datum.php
@@ -4,10 +4,10 @@
/**
* Author : Julien Moquet, Jason Judge
- *
+ *
* Inspired by Proj4js from Mike Adair madairATdmsolutions.ca
- * and Richard Greenwood rich@greenwoodma$p->com
- * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
+ * and Richard Greenwood rich@greenwoodma$p->com
+ * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
*/
use Academe\Proj4Php\Proj4 as Proj4Php;
@@ -20,28 +20,28 @@ class Datum {
public $datum_params;
/**
- * @param type $proj
+ * @param type $proj
*/
- public function __construct($proj)
- {
+ public function __construct($proj) {
$this->datum_type = Proj4php::$common->PJD_WGS84; //default setting
- if( isset($proj->datumCode) && $proj->datumCode == 'none' ) {
+ if (isset($proj->datumCode) && $proj->datumCode == 'none') {
$this->datum_type = Proj4Php::$common->PJD_NODATUM;
}
- if( isset( $proj->datum_params ) ) {
- for( $i = 0; $i < sizeof( $proj->datum_params ); $i++ ) {
- $proj->datum_params[$i] = floatval( $proj->datum_params[$i] );
+ if (isset($proj->datum_params)) {
+ for ($i = 0; $i < sizeof($proj->datum_params); $i++) {
+ $proj->datum_params[$i] = floatval($proj->datum_params[$i]);
}
- if( $proj->datum_params[0] != 0 || $proj->datum_params[1] != 0 || $proj->datum_params[2] != 0 ) {
+ if ($proj->datum_params[0] != 0 || $proj->datum_params[1] != 0 || $proj->datum_params[2] != 0) {
$this->datum_type = Proj4php::$common->PJD_3PARAM;
}
- if( sizeof( $proj->datum_params ) > 3 ) {
- if( $proj->datum_params[3] != 0 || $proj->datum_params[4] != 0 ||
- $proj->datum_params[5] != 0 || $proj->datum_params[6] != 0 ) {
+ if (sizeof($proj->datum_params) > 3) {
+ if ($proj->datum_params[3] != 0 || $proj->datum_params[4] != 0 ||
+ $proj->datum_params[5] != 0 || $proj->datum_params[6] != 0
+ ) {
$this->datum_type = Proj4php::$common->PJD_7PARAM;
$proj->datum_params[3] *= Proj4php::$common->SEC_TO_RAD;
@@ -66,12 +66,12 @@ public function __construct($proj)
/**
* @param type $dest
* @return boolean Returns TRUE if the two datums match, otherwise FALSE.
- * @throws type
+ * @throws type
*/
- public function compare_datums( $dest ) {
+ public function compare_datums($dest) {
if ($this->datum_type != $dest->datum_type) {
return false; // false, datums are not equal
- } else if ($this->a != $dest->a || abs( $this->es - $dest->es ) > 0.000000000050) {
+ } else if ($this->a != $dest->a || abs($this->es - $dest->es) > 0.000000000050) {
// the tolerence for es is to ensure that GRS80 and WGS84
// are considered identical
return false;
@@ -112,11 +112,10 @@ public function compare_datums( $dest ) {
* Z : Calculated Geocentric Z coordinate, in meters (output)
*
*/
- public function geodetic_to_geocentric($p)
- {
+ public function geodetic_to_geocentric($p) {
$Longitude = $p->x;
$Latitude = $p->y;
- $Height = isset( $p->z ) ? $p->z : 0; //Z value not always supplied
+ $Height = isset($p->z) ? $p->z : 0; //Z value not always supplied
$Error_Code = 0; // GEOCENT_NO_ERROR;
/*
@@ -138,12 +137,12 @@ public function geodetic_to_geocentric($p)
$Longitude -= (2 * Proj4php::$common->PI);
}
- $Sin_Lat = sin( $Latitude ); /* sin(Latitude) */
- $Cos_Lat = cos( $Latitude ); /* cos(Latitude) */
+ $Sin_Lat = sin($Latitude); /* sin(Latitude) */
+ $Cos_Lat = cos($Latitude); /* cos(Latitude) */
$Sin2_Lat = $Sin_Lat * $Sin_Lat; /* Square of sin(Latitude) */
- $Rn = $this->a / (sqrt( 1.0e0 - $this->es * $Sin2_Lat )); /* Earth radius at location */
- $p->x = ($Rn + $Height) * $Cos_Lat * cos( $Longitude );
- $p->y = ($Rn + $Height) * $Cos_Lat * sin( $Longitude );
+ $Rn = $this->a / (sqrt(1.0e0 - $this->es * $Sin2_Lat)); /* Earth radius at location */
+ $p->x = ($Rn + $Height) * $Cos_Lat * cos($Longitude);
+ $p->y = ($Rn + $Height) * $Cos_Lat * sin($Longitude);
$p->z = (($Rn * (1 - $this->es)) + $Height) * $Sin_Lat;
return $Error_Code;
@@ -152,10 +151,9 @@ public function geodetic_to_geocentric($p)
/**
*
* @param object $p
- * @return type
+ * @return type
*/
- public function geocentric_to_geodetic($p)
- {
+ public function geocentric_to_geodetic($p) {
// local defintions and variables
// end-criterium of loop, accuracy of sin(Latitude)
$genau = 1.E-12;
@@ -166,28 +164,28 @@ public function geocentric_to_geodetic($p)
$Z = $p->z ? $p->z : 0.0; //Z value not always supplied
/*
- $P; // distance between semi-minor axis and location
+ $P; // distance between semi-minor axis and location
$RR; // distance between center and location
- $CT; // sin of geocentric latitude
- $ST; // cos of geocentric latitude
+ $CT; // sin of geocentric latitude
+ $ST; // cos of geocentric latitude
$RX;
$RK;
- $RN; // Earth radius at location
- $CPHI0; // cos of start or old geodetic latitude in iterations
- $SPHI0; // sin of start or old geodetic latitude in iterations
+ $RN; // Earth radius at location
+ $CPHI0; // cos of start or old geodetic latitude in iterations
+ $SPHI0; // sin of start or old geodetic latitude in iterations
$CPHI; // cos of searched geodetic latitude
- $SPHI; // sin of searched geodetic latitude
- $SDPHI; // end-criterium: addition-theorem of sin(Latitude(iter)-Latitude(iter-1))
- $At_Pole; // indicates location is in polar region
- $iter; // of continous iteration, max. 30 is always enough (s.a.)
+ $SPHI; // sin of searched geodetic latitude
+ $SDPHI; // end-criterium: addition-theorem of sin(Latitude(iter)-Latitude(iter-1))
+ $At_Pole; // indicates location is in polar region
+ $iter; // of continous iteration, max. 30 is always enough (s.a.)
$Longitude;
$Latitude;
$Height;
*/
$At_Pole = false;
- $P = sqrt( $X * $X + $Y * $Y );
- $RR = sqrt( $X * $X + $Y * $Y + $Z * $Z );
+ $P = sqrt($X * $X + $Y * $Y);
+ $RR = sqrt($X * $X + $Y * $Y + $Z * $Z);
// special cases for latitude and longitude
if ($P / $this->a < $genau) {
@@ -197,7 +195,7 @@ public function geocentric_to_geodetic($p)
// if (X,Y,Z)=(0.,0.,0.) then Height becomes semi-minor axis
// of ellipsoid (=center of mass), Latitude becomes PI/2
- if ( $RR / $this->a < $genau) {
+ if ($RR / $this->a < $genau) {
$Latitude = Proj4php::$common->HALF_PI;
$Height = -$this->b;
return;
@@ -205,7 +203,7 @@ public function geocentric_to_geodetic($p)
} else {
/* ellipsoidal (geodetic) longitude
* interval: -PI < Longitude <= +PI */
- $Longitude = atan2( $Y, $X );
+ $Longitude = atan2($Y, $X);
}
/* --------------------------------------------------------------
@@ -219,7 +217,7 @@ public function geocentric_to_geodetic($p)
*/
$CT = $Z / $RR;
$ST = $P / $RR;
- $RX = 1.0 / sqrt( 1.0 - $this->es * (2.0 - $this->es) * $ST * $ST );
+ $RX = 1.0 / sqrt(1.0 - $this->es * (2.0 - $this->es) * $ST * $ST);
$CPHI0 = $ST * (1.0 - $this->es) * $RX;
$SPHI0 = $CT * $RX;
$iter = 0;
@@ -228,13 +226,13 @@ public function geocentric_to_geodetic($p)
// until |sin(Latitude(iter)-Latitude(iter-1))| < genau
do {
++$iter;
- $RN = $this->a / sqrt( 1.0 - $this->es * $SPHI0 * $SPHI0 );
+ $RN = $this->a / sqrt(1.0 - $this->es * $SPHI0 * $SPHI0);
/* ellipsoidal (geodetic) height */
$Height = $P * $CPHI0 + $Z * $SPHI0 - $RN * (1.0 - $this->es * $SPHI0 * $SPHI0);
$RK = $this->es * $RN / ($RN + $Height);
- $RX = 1.0 / sqrt( 1.0 - $RK * (2.0 - $RK) * $ST * $ST );
+ $RX = 1.0 / sqrt(1.0 - $RK * (2.0 - $RK) * $ST * $ST);
$CPHI = $ST * (1.0 - $RK) * $RX;
$SPHI = $CT * $RX;
$SDPHI = $SPHI * $CPHI0 - $CPHI * $SPHI0;
@@ -243,44 +241,43 @@ public function geocentric_to_geodetic($p)
} while ($SDPHI * $SDPHI > $genau2 && $iter < $maxiter);
// ellipsoidal (geodetic) latitude
- $Latitude = atan( $SPHI / abs( $CPHI ) );
+ $Latitude = atan($SPHI / abs($CPHI));
$p->x = $Longitude;
$p->y = $Latitude;
$p->z = $Height;
-
+
return $p;
}
- /**
+ /**
* Convert_Geocentric_To_Geodetic
* The method used here is derived from 'An Improved Algorithm for
* Geocentric to Geodetic Coordinate Conversion', by Ralph Toms, Feb 1996
- *
+ *
* @param object Point $p
* @return object Point $p
*/
- public function geocentric_to_geodetic_noniter($p)
- {
+ public function geocentric_to_geodetic_noniter($p) {
/*
$Longitude;
$Latitude;
$Height;
-
- $W; // distance from Z axis
- $W2; // square of distance from Z axis
- $T0; // initial estimate of vertical component
- $T1; // corrected estimate of vertical component
- $S0; // initial estimate of horizontal component
+
+ $W; // distance from Z axis
+ $W2; // square of distance from Z axis
+ $T0; // initial estimate of vertical component
+ $T1; // corrected estimate of vertical component
+ $S0; // initial estimate of horizontal component
$S1; // corrected estimate of horizontal component
- $Sin_B0; // sin(B0), B0 is estimate of Bowring aux variable
- $Sin3_B0; // cube of sin(B0)
+ $Sin_B0; // sin(B0), B0 is estimate of Bowring aux variable
+ $Sin3_B0; // cube of sin(B0)
$Cos_B0; // cos(B0)
- $Sin_p1; // sin(phi1), phi1 is estimated latitude
- $Cos_p1; // cos(phi1)
- $Rn; // Earth radius at location
- $Sum; // numerator of cos(phi1)
- $At_Pole; // indicates location is in polar region
+ $Sin_p1; // sin(phi1), phi1 is estimated latitude
+ $Cos_p1; // cos(phi1)
+ $Rn; // Earth radius at location
+ $Sum; // numerator of cos(phi1)
+ $At_Pole; // indicates location is in polar region
*/
// cast from string to float
@@ -311,18 +308,18 @@ public function geocentric_to_geodetic_noniter($p)
}
}
$W2 = $X * $X + $Y * $Y;
- $W = sqrt( $W2 );
+ $W = sqrt($W2);
$T0 = $Z * Proj4php::$common->AD_C;
- $S0 = sqrt( $T0 * $T0 + $W2 );
+ $S0 = sqrt($T0 * $T0 + $W2);
$Sin_B0 = $T0 / $S0;
$Cos_B0 = $W / $S0;
$Sin3_B0 = $Sin_B0 * $Sin_B0 * $Sin_B0;
$T1 = $Z + $this->b * $this->ep2 * $Sin3_B0;
$Sum = $W - $this->a * $this->es * $Cos_B0 * $Cos_B0 * $Cos_B0;
- $S1 = sqrt( $T1 * $T1 + $Sum * $Sum );
+ $S1 = sqrt($T1 * $T1 + $Sum * $Sum);
$Sin_p1 = $T1 / $S1;
$Cos_p1 = $Sum / $S1;
- $Rn = $this->a / sqrt( 1.0 - $this->es * $Sin_p1 * $Sin_p1 );
+ $Rn = $this->a / sqrt(1.0 - $this->es * $Sin_p1 * $Sin_p1);
if ($Cos_p1 >= Proj4php::$common->COS_67P5) {
$Height = $W / $Cos_p1 - $Rn;
} else if ($Cos_p1 <= -Proj4php::$common->COS_67P5) {
@@ -331,21 +328,20 @@ public function geocentric_to_geodetic_noniter($p)
$Height = $Z / $Sin_p1 + $Rn * ($this->es - 1.0);
}
if ($At_Pole == false) {
- $Latitude = atan( $Sin_p1 / $Cos_p1 );
+ $Latitude = atan($Sin_p1 / $Cos_p1);
}
-
+
$p->x = $Longitude;
$p->y = $Latitude;
$p->z = $Height;
-
+
return $p;
}
/************************************************************** */
// pj_geocentic_to_wgs84( p )
// p = point to transform in geocentric coordinates (x,y,z)
- public function geocentric_to_wgs84 ($p)
- {
+ public function geocentric_to_wgs84($p) {
if ($this->datum_type == Proj4php::$common->PJD_3PARAM) {
// if( x[io] == HUGE_VAL )
// continue;
@@ -362,8 +358,8 @@ public function geocentric_to_wgs84 ($p)
$M_BF = $this->datum_params[6];
// if( x[io] == HUGE_VAL )
// continue;
- $p->x = $M_BF * ( $p->x - $Rz_BF * $p->y + $Ry_BF * $p->z) + $Dx_BF;
- $p->y = $M_BF * ( $Rz_BF * $p->x + $p->y - $Rx_BF * $p->z) + $Dy_BF;
+ $p->x = $M_BF * ($p->x - $Rz_BF * $p->y + $Ry_BF * $p->z) + $Dx_BF;
+ $p->y = $M_BF * ($Rz_BF * $p->x + $p->y - $Rx_BF * $p->z) + $Dy_BF;
$p->z = $M_BF * (-$Ry_BF * $p->x + $Rx_BF * $p->y + $p->z) + $Dz_BF;
}
}
@@ -373,8 +369,7 @@ public function geocentric_to_wgs84 ($p)
// pj_geocentic_from_wgs84()
// coordinate system definition,
// point to transform in geocentric coordinates (x,y,z)
- public function geocentric_from_wgs84($p)
- {
+ public function geocentric_from_wgs84($p) {
if ($this->datum_type == Proj4php::$common->PJD_3PARAM) {
//if( x[io] == HUGE_VAL )
// continue;
diff --git a/src/Defs/Epsg27700.php b/src/Defs/Epsg27700.php
index a86b3e2..552ced7 100644
--- a/src/Defs/Epsg27700.php
+++ b/src/Defs/Epsg27700.php
@@ -4,10 +4,8 @@
use Academe\Proj4Php\Proj4;
-class Epsg27700
-{
- public function init()
- {
+class Epsg27700 {
+ public function init() {
// Add this entry to the static global. Not a good way to handle it when this is essentially just a
// lumnp of string data.
diff --git a/src/Defs/Epsg900913.php b/src/Defs/Epsg900913.php
index 450e9e3..b01a3c6 100644
--- a/src/Defs/Epsg900913.php
+++ b/src/Defs/Epsg900913.php
@@ -4,10 +4,8 @@
use Academe\Proj4Php\Proj4;
-class Epsg900913
-{
- public function init()
- {
+class Epsg900913 {
+ public function init() {
// Add this entry to the static global. Not a good way to handle it when this is essentially just a
// lumnp of string data.
diff --git a/src/LongLat.php b/src/LongLat.php
index 1c04387..c3f2074 100644
--- a/src/LongLat.php
+++ b/src/LongLat.php
@@ -4,24 +4,21 @@
/**
* Author : Julien Moquet, Jason Judge
- *
+ *
* Inspired by Proj4js from Mike Adair madairATdmsolutions.ca
- * and Richard Greenwood rich@greenwoodmap.com
- * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
+ * and Richard Greenwood rich@greenwoodmap.com
+ * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
*/
class LongLat {
- public function init()
- {
+ public function init() {
}
- public function forward($pt)
- {
+ public function forward($pt) {
return $pt;
}
- public function inverse($pt)
- {
+ public function inverse($pt) {
return $pt;
}
}
diff --git a/src/Mgrs/LatLong.php b/src/Mgrs/LatLong.php
index c3acd91..baca59c 100644
--- a/src/Mgrs/LatLong.php
+++ b/src/Mgrs/LatLong.php
@@ -6,8 +6,7 @@
* Lat/long concrete.
*/
-class LatLong implements LatLongInterface
-{
+class LatLong implements LatLongInterface {
/**
* The latitude of the coordinate.
*
@@ -28,17 +27,15 @@ class LatLong implements LatLongInterface
* {@inheritDoc}
*/
- public function normalizeLatitude($latitude)
- {
- return (double) max(-90, min(90, $latitude));
+ public function normalizeLatitude($latitude) {
+ return (double)max(-90, min(90, $latitude));
}
/**
* {@inheritDoc}
*/
- public function normalizeLongitude($longitude)
- {
+ public function normalizeLongitude($longitude) {
if (180 === $longitude % 360) {
return 180.0;
}
@@ -46,15 +43,14 @@ public function normalizeLongitude($longitude)
$mod = fmod($longitude, 360);
$longitude = $mod < -180 ? $mod + 360 : ($mod > 180 ? $mod - 360 : $mod);
- return (double) $longitude;
+ return (double)$longitude;
}
/**
* {@inheritDoc}
*/
- public function setLatitude($latitude)
- {
+ public function setLatitude($latitude) {
$this->latitude = $this->normalizeLatitude($latitude);
}
@@ -62,8 +58,7 @@ public function setLatitude($latitude)
* {@inheritDoc}
*/
- public function getLatitude()
- {
+ public function getLatitude() {
return $this->latitude;
}
@@ -71,8 +66,7 @@ public function getLatitude()
* {@inheritDoc}
*/
- public function setLongitude($longitude)
- {
+ public function setLongitude($longitude) {
$this->longitude = $this->normalizeLongitude($longitude);
}
@@ -80,8 +74,7 @@ public function setLongitude($longitude)
* {@inheritDoc}
*/
- public function getLongitude()
- {
+ public function getLongitude() {
return $this->longitude;
}
@@ -89,9 +82,8 @@ public function getLongitude()
* Constructor to set values.
* @todo Do we want to support named element keys, e.g. 'lat' and 'lon'?
*/
- public function __construct($latitude, $longitude = null)
- {
- if ( ! isset($longitude) && is_array($latitude) && count($latitude) == 2) {
+ public function __construct($latitude, $longitude = null) {
+ if (!isset($longitude) && is_array($latitude) && count($latitude) == 2) {
// The order of the elements is latitude then longitude.
list($lat, $long) = array_values($latitude);
$this->setLatitude($lat);
diff --git a/src/Mgrs/LatLongInterface.php b/src/Mgrs/LatLongInterface.php
index e5ca49f..5e47f40 100644
--- a/src/Mgrs/LatLongInterface.php
+++ b/src/Mgrs/LatLongInterface.php
@@ -6,8 +6,7 @@
* Interface for setting and getting lat/long values.
*/
-interface LatLongInterface
-{
+interface LatLongInterface {
/**
* Set the latitude.
*
diff --git a/src/Mgrs/Merc.php b/src/Mgrs/Merc.php
index 6bd4251..84afe3d 100644
--- a/src/Mgrs/Merc.php
+++ b/src/Mgrs/Merc.php
@@ -7,8 +7,7 @@
* Provides conversion to and from Lat/Long, using the WGS84 ellipsoid.
*/
-class Merc
-{
+class Merc {
// TODO
}
diff --git a/src/Mgrs/Mgrs.php b/src/Mgrs/Mgrs.php
index faf2038..7ce409d 100644
--- a/src/Mgrs/Mgrs.php
+++ b/src/Mgrs/Mgrs.php
@@ -9,8 +9,7 @@
* something is amiss here.
*/
-class Mgrs extends Utm
-{
+class Mgrs extends Utm {
/**
* UTM zones are grouped, and assigned to one of a group of 6
* sets.
@@ -94,8 +93,7 @@ class Mgrs extends Utm
* 100 m, 4 for 1000 m or 5 for 10000 m). Optional, default is 5.
* @return {string} the MGRS string for the given location and accuracy.
*/
- public static function forward($lat_long, $accuracy = null)
- {
+ public static function forward($lat_long, $accuracy = null) {
// This handles $lat_long being in any of a number of different formats.
$mgrs = static::fromLatLong($lat_long);
@@ -112,8 +110,7 @@ public static function forward($lat_long, $accuracy = null)
* bounding box for the provided MGRS reference.
* We actually want to return a Square.
*/
- public static function inverse($mgrs_grid_reference)
- {
+ public static function inverse($mgrs_grid_reference) {
$mgrs = static::fromGridReference($mgrs_grid_reference);
return $mgrs->toSquare();
@@ -124,8 +121,7 @@ public static function inverse($mgrs_grid_reference)
* The point is the centre of the square, according to the accuracy that the
* reference carries (the number of digits it uses).
*/
- public function toPoint($accuracy = null)
- {
+ public function toPoint($accuracy = null) {
// Get the bounding box.
$lat_long_bounding_box = $this->toSquare($accuracy);
@@ -150,13 +146,12 @@ public function toPoint($accuracy = null)
* CHECKME: the method interface has been overridden from the parent. We may need to drop $accuracy
* to get them consistent again.
*/
- public function toGridReference($template = null, $accuracy = null)
- {
- if ( ! isset($template)) {
+ public function toGridReference($template = null, $accuracy = null) {
+ if (!isset($template)) {
$template = '%z%l%k%e%n';
}
- if ( ! isset($accuracy)) {
+ if (!isset($accuracy)) {
$accuracy = $this->getAccuracy();
}
@@ -184,8 +179,7 @@ public function toGridReference($template = null, $accuracy = null)
/**
* Return as the square bounded by the current, or the given accuracy.
*/
- public function toSquare($accuracy = null)
- {
+ public function toSquare($accuracy = null) {
// The top-right of the square is the bottom left with an appropriate number
// of metres added.
@@ -209,10 +203,9 @@ public function toSquare($accuracy = null)
/**
* Get the size of the square in metres.
*/
- public function getSize($accuracy = null)
- {
+ public function getSize($accuracy = null) {
// Use the current accuracy, if not provided.
- if ( ! isset($accuracy)) {
+ if (!isset($accuracy)) {
$accuracy = $this->accuracy;
}
@@ -224,10 +217,9 @@ public function getSize($accuracy = null)
* Set the number of digits to be used by default for output (0 to 5).
*/
- public function setAccuracy($accuracy)
- {
+ public function setAccuracy($accuracy) {
// Must be an integer.
- if ( ! is_int($accuracy)) {
+ if (!is_int($accuracy)) {
throw new \InvalidArgumentException(
sprintf('Accuracy must be an integer; %s passed in', gettype($accuracy))
);
@@ -240,8 +232,7 @@ public function setAccuracy($accuracy)
$this->accuracy = $accuracy;
}
- public function getAccuracy()
- {
+ public function getAccuracy() {
return $this->accuracy;
}
@@ -255,8 +246,7 @@ public function getAccuracy()
* @param {number} zoneNumber
* @return the two letter 100k designator for the given UTM location.
*/
- protected static function get100kId($easting, $northing, $zone_number)
- {
+ protected static function get100kId($easting, $northing, $zone_number) {
$set_parm = static::get100kSetForZone($zone_number);
$set_column = floor($easting / 100000);
$set_row = floor($northing / 100000) % 20;
@@ -270,8 +260,7 @@ protected static function get100kId($easting, $northing, $zone_number)
* @param {number} i An UTM zone number.
* @return {number} the 100k set the UTM zone is in.
*/
- protected static function get100kSetForZone($i)
- {
+ protected static function get100kSetForZone($i) {
$set_parm = $i % static::NUM_100K_SETS;
if ($set_parm === 0) {
@@ -297,8 +286,7 @@ protected static function get100kSetForZone($i)
* 1-60.
* @return two letter MGRS 100k code.
*/
- protected function getLetter100kId($column, $row, $parm)
- {
+ protected function getLetter100kId($column, $row, $parm) {
// colOrigin and rowOrigin are the letters at the origin of the set
$index = $parm - 1;
$colOrigin = ord(substr(static::SET_ORIGIN_COLUMN_LETTERS, $index, 1));
@@ -379,8 +367,7 @@ protected function getLetter100kId($column, $row, $parm)
* @param string mgrs_reference a MGRS coordinate reference string.
* @return object An Mgrs object.
*/
- public static function fromGridReference($mgrs_reference)
- {
+ public static function fromGridReference($mgrs_reference) {
// Make sure upper-case letters are used.
$mgrs_reference = strtoupper($mgrs_reference);
@@ -388,7 +375,7 @@ public static function fromGridReference($mgrs_reference)
$mgrs_reference = str_replace(array(" ", "\t"), "", $mgrs_reference);
// Validate it as a string.
- if ( ! is_string($mgrs_reference)) {
+ if (!is_string($mgrs_reference)) {
throw new \Exception("MGRS reference must be a string; $s supplied", gettype($mgrs_reference));
}
@@ -410,7 +397,7 @@ public static function fromGridReference($mgrs_reference)
// If there are less than two digits, then it seems to be happy (though
// en exception is raised later if there are no digits).
- while ( ! preg_match('/[A-Z]/', substr($mgrs_reference, $i, 1))) {
+ while (!preg_match('/[A-Z]/', substr($mgrs_reference, $i, 1))) {
if ($i >= 2) {
throw new \Exception("MGRSPoint bad conversion from: " . $mgrs_reference);
}
@@ -513,8 +500,7 @@ public static function fromGridReference($mgrs_reference)
* looking at the first letter.
*/
- protected static function getEastingFromChar($e, $set)
- {
+ protected static function getEastingFromChar($e, $set) {
// colOrigin is the letter at the origin of the set for the column.
$curCol = substr(static::SET_ORIGIN_COLUMN_LETTERS, $set - 1, 1);
$eastingValue = 100000.0;
@@ -565,8 +551,7 @@ protected static function getEastingFromChar($e, $set)
* @todo Better name: use "letter" rather than "char" and show this is just the second letter.
*/
- protected function getNorthingFromChar($n, $set)
- {
+ protected function getNorthingFromChar($n, $set) {
if ($n > 'V') {
throw new \Exception("MGRSPoint given invalid Northing " . $n);
}
@@ -614,8 +599,7 @@ protected function getNorthingFromChar($n, $set)
* @return {number}
*/
- protected static function getMinNorthing($zone_letter)
- {
+ protected static function getMinNorthing($zone_letter) {
if (isset(static::$zone_min_northing[$zone_letter])) {
return static::$zone_min_northing[$zone_letter];
}
diff --git a/src/Mgrs/Square.php b/src/Mgrs/Square.php
index 6a1327c..aa65b4a 100644
--- a/src/Mgrs/Square.php
+++ b/src/Mgrs/Square.php
@@ -6,8 +6,7 @@
* Square concrete.
*/
-class Square implements SquareInterface
-{
+class Square implements SquareInterface {
/**
* The square is defined by two lat/long points - bottom left and top right.
*/
@@ -18,40 +17,35 @@ class Square implements SquareInterface
/**
* Set the bottom left coordinate of the square.
*/
- public function setBottomLeft(LatLongInterface $coordinate)
- {
+ public function setBottomLeft(LatLongInterface $coordinate) {
$this->bottom_left = $coordinate;
}
/**
* Get the bottom left coordinate of the square.
*/
- public function getBottomLeft()
- {
+ public function getBottomLeft() {
return $this->bottom_left;
}
/**
* Set the top right coordinate of the square.
*/
- public function setTopRight(LatLongInterface $coordinate)
- {
+ public function setTopRight(LatLongInterface $coordinate) {
$this->top_right = $coordinate;
}
/**
* Get the top right coordinate of the square.
*/
- public function getTopRight()
- {
+ public function getTopRight() {
return $this->top_right;
}
/**
* You must construct with a pair of LatLong objects.
*/
- public function __construct(LatLongInterface $lat_long_bottom_left, LatLongInterface $lat_long_top_right)
- {
+ public function __construct(LatLongInterface $lat_long_bottom_left, LatLongInterface $lat_long_top_right) {
$this->setBottomLeft($lat_long_bottom_left);
$this->setTopRight($lat_long_top_right);
}
diff --git a/src/Mgrs/SquareInterface.php b/src/Mgrs/SquareInterface.php
index ec6f424..f188098 100644
--- a/src/Mgrs/SquareInterface.php
+++ b/src/Mgrs/SquareInterface.php
@@ -6,8 +6,7 @@
* Square interface.
*/
-interface SquareInterface
-{
+interface SquareInterface {
/**
* Set the bottom left coordinate of the square.
*/
diff --git a/src/Mgrs/Utm.php b/src/Mgrs/Utm.php
index 05c30c2..c21c11e 100644
--- a/src/Mgrs/Utm.php
+++ b/src/Mgrs/Utm.php
@@ -14,8 +14,7 @@
* their own grid reference formats and rules) can be applied.
*/
-class Utm
-{
+class Utm {
/**
* The parts of a UTM coordinate.
*/
@@ -50,8 +49,7 @@ class Utm
* Constructor.
* @todo Validate values.
*/
- public function __construct($northing, $easting, $zone_number, $zone_letter)
- {
+ public function __construct($northing, $easting, $zone_number, $zone_letter) {
$this->northing = $northing;
$this->easting = $easting;
$this->zone_number = $zone_number;
@@ -62,23 +60,19 @@ public function __construct($northing, $easting, $zone_number, $zone_letter)
* Get the current value elements.
*/
- public function getNorthing()
- {
+ public function getNorthing() {
return $this->northing;
}
- public function getEasting()
- {
+ public function getEasting() {
return $this->easting;
}
- public function getZoneNumber()
- {
+ public function getZoneNumber() {
return $this->zone_number;
}
- public function getZoneLetter()
- {
+ public function getZoneLetter() {
return $this->zone_letter;
}
@@ -86,15 +80,14 @@ public function getZoneLetter()
* Instantiate a Utm onject from Lat/Long coordinates or a LatLong object.
* Returns a new Utm object.
*/
- public static function fromLatLong($latitude, $longitude = null)
- {
+ public static function fromLatLong($latitude, $longitude = null) {
// Accept various inputs.
- if ( ! isset($longitude)) {
+ if (!isset($longitude)) {
// One parameter only supplied. If this is not already a LatLong object,
// then convert it into one.
- if ( ! is_a($latitude, 'Academe\\Proj4Php\\Mgrs\\LatLongInterface')) {
+ if (!is_a($latitude, 'Academe\\Proj4Php\\Mgrs\\LatLongInterface')) {
// If some form of array, then let LatLong work out how to interpret it.
$latitude = new LatLong($latitude);
}
@@ -137,11 +130,11 @@ public static function fromLatLong($latitude, $longitude = null)
$A = cos($lat_rad) * ($long_rad - $long_origin_rad);
$M = static::$a * (
- (1 - static::$ecc_squared / 4 - 3 * pow(static::$ecc_squared, 2) / 64 - 5 * pow(static::$ecc_squared, 3) / 256) * $lat_rad
- - (3 * static::$ecc_squared / 8 + 3 * pow(static::$ecc_squared, 2) / 32 + 45 * pow(static::$ecc_squared, 3) / 1024) * sin(2 * $lat_rad)
- + (15 * pow(static::$ecc_squared, 2) / 256 + 45 * pow(static::$ecc_squared, 3) / 1024) * sin(4 * $lat_rad)
- - (35 * pow(static::$ecc_squared, 3) / 3072) * sin(6 * $lat_rad)
- );
+ (1 - static::$ecc_squared / 4 - 3 * pow(static::$ecc_squared, 2) / 64 - 5 * pow(static::$ecc_squared, 3) / 256) * $lat_rad
+ - (3 * static::$ecc_squared / 8 + 3 * pow(static::$ecc_squared, 2) / 32 + 45 * pow(static::$ecc_squared, 3) / 1024) * sin(2 * $lat_rad)
+ + (15 * pow(static::$ecc_squared, 2) / 256 + 45 * pow(static::$ecc_squared, 3) / 1024) * sin(4 * $lat_rad)
+ - (35 * pow(static::$ecc_squared, 3) / 3072) * sin(6 * $lat_rad)
+ );
$utm_easting = (static::$k0 * $N * ($A + (1 - $T + $C) * pow($A, 3) / 6.0 + (5 - 18 * pow($T, 3) + 72 * $C - 58 * $ecc_prime_squared) * pow($A, 5) / 120.0) + 500000.0);
@@ -172,8 +165,7 @@ public static function fromLatLong($latitude, $longitude = null)
* The zone number largely identifies the longitude, in 6 degree increments, but
* has some exceptions at certain latitudes.
*/
- public static function calcZoneNumber($latitude, $longitude)
- {
+ public static function calcZoneNumber($latitude, $longitude) {
// Convert 0 to 360 to -180 to +180
// Might just replace this with an if-statement, as that would be clearer.
$longitude = ($longitude + 180) - floor(($longitude + 180) / 360) * 360 - 180;
@@ -215,8 +207,7 @@ public static function calcZoneNumber($latitude, $longitude)
* @param number latitude The latitude in WGS84 to get the letter designator for.
* @return char The letter designator.
*/
- protected static function calcLetterDesignator($latitude)
- {
+ protected static function calcLetterDesignator($latitude) {
// I'm sure we can turn this into a simple formula, perhaps with a string lookup.
// It basically splits the latitudes into 8 degree bands, and leaves out O and I in
// the lettering sequence.
@@ -278,8 +269,7 @@ protected static function calcLetterDesignator($latitude)
/**
* Get the hemisphere indicator - N or S.
*/
- protected static function calcHemisphereLetter($northing)
- {
+ protected static function calcHemisphereLetter($northing) {
return (ord($northing) >= ord('N') ? 'N' : 'S');
}
@@ -294,8 +284,7 @@ protected static function calcHemisphereLetter($northing)
* @return {object} An object literal containing either lat and lon values
* Returns null if the conversion failed.
*/
- public function toLatLong()
- {
+ public function toLatLong() {
$zone_letter = $this->getZoneLetter();
$zone_number = $this->getZoneNumber();
@@ -324,7 +313,7 @@ public function toLatLong()
// There are 60 zones with zone 1 being at West -180 to -174
// +3 puts origin in middle of zone.
- $long_origin = ($zone_number - 1) * 6 - 180 + 3;
+ $long_origin = ($zone_number - 1) * 6 - 180 + 3;
$ecc_prime_squared = (static::$ecc_squared) / (1 - static::$ecc_squared);
@@ -357,10 +346,9 @@ public function toLatLong()
* Format the coordinate as a UTM string.
* @param string format Optional template to format the reference.
*/
- public function toGridReference($template = null)
- {
+ public function toGridReference($template = null) {
// Set the default format if not overridden.
- if ( ! isset($template)) {
+ if (!isset($template)) {
$template = '%z%l %e %n';
}
@@ -387,8 +375,7 @@ public function toGridReference($template = null)
/**
* Default cast to string.
*/
- public function __toString()
- {
+ public function __toString() {
return $this->toGridReference();
}
}
diff --git a/src/Point.php b/src/Point.php
index b1f0c4d..ca720f9 100644
--- a/src/Point.php
+++ b/src/Point.php
@@ -2,20 +2,20 @@
namespace Academe\Proj4Php;
-/**
- * Author : Julien Moquet, Jason Judge
- *
- * Inspired by Proj4js from Mike Adair madairATdmsolutions.ca
- * and Richard Greenwood rich@greenwoodmap.com
- * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
- */
+ /**
+ * Author : Julien Moquet, Jason Judge
+ *
+ * Inspired by Proj4js from Mike Adair madairATdmsolutions.ca
+ * and Richard Greenwood rich@greenwoodmap.com
+ * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
+ */
-/**
+/**
* point object, nothing fancy, just allows values to be
* passed back and forth by reference rather than by value.
* Other point classes may be used as long as they have
* x and y properties, which will get modified in the transform method.
-*/
+ */
class Point {
public $x;
@@ -31,17 +31,16 @@ class Point {
* - y {float} the second component
* - z {float} the third component, optional.
*/
- public function __construct($x = null, $y = null, $z = null)
- {
- if( is_array( $x ) ) {
+ public function __construct($x = null, $y = null, $z = null) {
+ if (is_array($x)) {
$this->x = $x[0];
$this->y = $x[1];
$this->z = isset($x[2]) ? $x[2] : 0.0;#(count( $x ) > 2) ? $x[2] : 0.0;
- } else if( is_string( $x ) && !is_numeric( $y ) ) {
- $coord = explode( ' ', $x );
- $this->x = floatval( $coord[0] );
- $this->y = floatval( $coord[1] );
- $this->z = (count( $coord ) > 2) ? floatval( $coord[2] ) : 0.0;
+ } else if (is_string($x) && !is_numeric($y)) {
+ $coord = explode(' ', $x);
+ $this->x = floatval($coord[0]);
+ $this->y = floatval($coord[1]);
+ $this->z = (count($coord) > 2) ? floatval($coord[2]) : 0.0;
} else {
$this->x = $x !== null ? $x : 0.0;
$this->y = $y !== null ? $y : 0.0;
@@ -54,12 +53,11 @@ public function __construct($x = null, $y = null, $z = null)
* Build a copy of a Proj4js.Point object.
*
* renamed because of PHP keyword.
- *
+ *
* Return:
* {Proj4js}.Point the cloned point.
*/
- public function _clone()
- {
+ public function _clone() {
return new Point($this->x, $this->y, $this->z);
}
@@ -68,11 +66,10 @@ public function _clone()
* Return a readable string version of the point
*
* Return:
- * {String} String representation of Proj4js.Point object.
+ * {String} String representation of Proj4js.Point object.
* (ex. "x=5,y=42")
*/
- public function toString()
- {
+ public function toString() {
return "x=" . $this->x . ",y=" . $this->y;
}
@@ -81,11 +78,10 @@ public function toString()
* Return a short string version of the point.
*
* Return:
- * {String} Shortened String representation of Proj4js.Point object.
+ * {String} Shortened String representation of Proj4js.Point object.
* (ex. "5, 42")
*/
- public function toShortString()
- {
+ public function toShortString() {
return $this->x . " " . $this->y;
}
}
diff --git a/src/Proj4.php b/src/Proj4.php
index f0bfca6..048f4f9 100644
--- a/src/Proj4.php
+++ b/src/Proj4.php
@@ -4,11 +4,11 @@
/**
* Author : Julien Moquet, Jason Judge
- *
+ *
* Simple conversion from javascript to PHP of Proj4Js by Mike Adair madairATdmsolutions.ca
* and Richard Greenwood rich@greenwoodmap.com
*
- * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
+ * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
*/
use \Academe\Proj4Php\Proj4 as Proj4Php;
@@ -50,8 +50,7 @@ class Proj4 {
* +lat0=somenumber
* +long=somenumber
*/
- protected function initDefs()
- {
+ protected function initDefs() {
// These are so widely used, we'll go ahead and throw them in
// without requiring a separate file
@@ -63,7 +62,7 @@ protected function initDefs()
self::$defs['EPSG:4269'] = "+title=long/lat:NAD83 +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees";
// CHECKME: does the title need to be quoted? Probably not, as the defs are exploded at "+" and "=" to
- // separate the parts, rather than parsed in a stateful way. However, finding a definition of the
+ // separate the parts, rather than parsed in a stateful way. However, finding a definition of the
// syntax for the Proj.4 def string is not easy.
// In here: ftp://ftp.remotesensing.org/proj/OF90-284.pdf under "Cartographic Parameters"
// +title does not seem to be mentioned in any of the Proj.4 documentation, except as unimplemented
@@ -85,8 +84,7 @@ protected function initDefs()
// build this out as required.
// TODO: pick these up from a data file.
- protected function initWKTProjections()
- {
+ protected function initWKTProjections() {
self::$wktProjections["Lambert Tangential Conformal Conic Projection"] = "lcc";
self::$wktProjections["Mercator"] = "merc";
self::$wktProjections["Mercator_1SP"] = "merc";
@@ -98,72 +96,69 @@ protected function initWKTProjections()
// TODO: pick these up from the data file.
- protected function initDatum()
- {
- self::$datum["WGS84"] = array( 'towgs84' => "0,0,0", 'ellipse' => "WGS84", 'datumName' => "WGS84" );
- self::$datum["GGRS87"] = array( 'towgs84' => "-199.87,74.79,246.62", 'ellipse' => "GRS80", 'datumName' => "Greek_Geodetic_Reference_System_1987" );
- self::$datum["NAD83"] = array( 'towgs84' => "0,0,0", 'ellipse' => "GRS80", 'datumName' => "North_American_Datum_1983" );
- self::$datum["NAD27"] = array( 'nadgrids' => "@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat", 'ellipse' => "clrk66", 'datumName' => "North_American_Datum_1927" );
- self::$datum["potsdam"] = array( 'towgs84' => "606.0,23.0,413.0", 'ellipse' => "bessel", 'datumName' => "Potsdam Rauenberg 1950 DHDN" );
- self::$datum["carthage"] = array( 'towgs84' => "-263.0,6.0,431.0", 'ellipse' => "clark80", 'datumName' => "Carthage 1934 Tunisia" );
- self::$datum["hermannskogel"] = array( 'towgs84' => "653.0,-212.0,449.0", 'ellipse' => "bessel", 'datumName' => "Hermannskogel" );
- self::$datum["ire65"] = array( 'towgs84' => "482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15", 'ellipse' => "mod_airy", 'datumName' => "Ireland 1965" );
- self::$datum["nzgd49"] = array( 'towgs84' => "59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993", 'ellipse' => "intl", 'datumName' => "New Zealand Geodetic Datum 1949" );
- self::$datum["OSGB36"] = array( 'towgs84' => "446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894", 'ellipse' => "airy", 'datumName' => "Airy 1830" );
+ protected function initDatum() {
+ self::$datum["WGS84"] = array('towgs84' => "0,0,0", 'ellipse' => "WGS84", 'datumName' => "WGS84");
+ self::$datum["GGRS87"] = array('towgs84' => "-199.87,74.79,246.62", 'ellipse' => "GRS80", 'datumName' => "Greek_Geodetic_Reference_System_1987");
+ self::$datum["NAD83"] = array('towgs84' => "0,0,0", 'ellipse' => "GRS80", 'datumName' => "North_American_Datum_1983");
+ self::$datum["NAD27"] = array('nadgrids' => "@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat", 'ellipse' => "clrk66", 'datumName' => "North_American_Datum_1927");
+ self::$datum["potsdam"] = array('towgs84' => "606.0,23.0,413.0", 'ellipse' => "bessel", 'datumName' => "Potsdam Rauenberg 1950 DHDN");
+ self::$datum["carthage"] = array('towgs84' => "-263.0,6.0,431.0", 'ellipse' => "clark80", 'datumName' => "Carthage 1934 Tunisia");
+ self::$datum["hermannskogel"] = array('towgs84' => "653.0,-212.0,449.0", 'ellipse' => "bessel", 'datumName' => "Hermannskogel");
+ self::$datum["ire65"] = array('towgs84' => "482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15", 'ellipse' => "mod_airy", 'datumName' => "Ireland 1965");
+ self::$datum["nzgd49"] = array('towgs84' => "59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993", 'ellipse' => "intl", 'datumName' => "New Zealand Geodetic Datum 1949");
+ self::$datum["OSGB36"] = array('towgs84' => "446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894", 'ellipse' => "airy", 'datumName' => "Airy 1830");
}
// TODO: read this from the data file.
- protected function initEllipsoid()
- {
- self::$ellipsoid["MERIT"] = array( 'a' => 6378137.0, 'rf' => 298.257, 'ellipseName' => "MERIT 1983" );
- self::$ellipsoid["SGS85"] = array( 'a' => 6378136.0, 'rf' => 298.257, 'ellipseName' => "Soviet Geodetic System 85" );
- self::$ellipsoid["GRS80"] = array( 'a' => 6378137.0, 'rf' => 298.257222101, 'ellipseName' => "GRS 1980(IUGG, 1980)" );
- self::$ellipsoid["IAU76"] = array( 'a' => 6378140.0, 'rf' => 298.257, 'ellipseName' => "IAU 1976" );
- self::$ellipsoid["airy"] = array( 'a' => 6377563.396, 'b' => 6356256.910, 'ellipseName' => "Airy 1830" );
- self::$ellipsoid["APL4."] = array( 'a' => 6378137, 'rf' => 298.25, 'ellipseName' => "Appl. Physics. 1965" );
- self::$ellipsoid["NWL9D"] = array( 'a' => 6378145.0, 'rf' => 298.25, 'ellipseName' => "Naval Weapons Lab., 1965" );
- self::$ellipsoid["mod_airy"] = array( 'a' => 6377340.189, 'b' => 6356034.446, 'ellipseName' => "Modified Airy" );
- self::$ellipsoid["andrae"] = array( 'a' => 6377104.43, 'rf' => 300.0, 'ellipseName' => "Andrae 1876 (Den., Iclnd.)" );
- self::$ellipsoid["aust_SA"] = array( 'a' => 6378160.0, 'rf' => 298.25, 'ellipseName' => "Australian Natl & S. Amer. 1969" );
- self::$ellipsoid["GRS67"] = array( 'a' => 6378160.0, 'rf' => 298.2471674270, 'ellipseName' => "GRS 67(IUGG 1967)" );
- self::$ellipsoid["bessel"] = array( 'a' => 6377397.155, 'rf' => 299.1528128, 'ellipseName' => "Bessel 1841" );
- self::$ellipsoid["bess_nam"] = array( 'a' => 6377483.865, 'rf' => 299.1528128, 'ellipseName' => "Bessel 1841 (Namibia)" );
- self::$ellipsoid["clrk66"] = array( 'a' => 6378206.4, 'b' => 6356583.8, 'ellipseName' => "Clarke 1866" );
- self::$ellipsoid["clrk80"] = array( 'a' => 6378249.145, 'rf' => 293.4663, 'ellipseName' => "Clarke 1880 mod." );
- self::$ellipsoid["CPM"] = array( 'a' => 6375738.7, 'rf' => 334.29, 'ellipseName' => "Comm. des Poids et Mesures 1799" );
- self::$ellipsoid["delmbr"] = array( 'a' => 6376428.0, 'rf' => 311.5, 'ellipseName' => "Delambre 1810 (Belgium)" );
- self::$ellipsoid["engelis"] = array( 'a' => 6378136.05, 'rf' => 298.2566, 'ellipseName' => "Engelis 1985" );
- self::$ellipsoid["evrst30"] = array( 'a' => 6377276.345, 'rf' => 300.8017, 'ellipseName' => "Everest 1830" );
- self::$ellipsoid["evrst48"] = array( 'a' => 6377304.063, 'rf' => 300.8017, 'ellipseName' => "Everest 1948" );
- self::$ellipsoid["evrst56"] = array( 'a' => 6377301.243, 'rf' => 300.8017, 'ellipseName' => "Everest 1956" );
- self::$ellipsoid["evrst69"] = array( 'a' => 6377295.664, 'rf' => 300.8017, 'ellipseName' => "Everest 1969" );
- self::$ellipsoid["evrstSS"] = array( 'a' => 6377298.556, 'rf' => 300.8017, 'ellipseName' => "Everest (Sabah & Sarawak)" );
- self::$ellipsoid["fschr60"] = array( 'a' => 6378166.0, 'rf' => 298.3, 'ellipseName' => "Fischer (Mercury Datum) 1960" );
- self::$ellipsoid["fschr60m"] = array( 'a' => 6378155.0, 'rf' => 298.3, 'ellipseName' => "Fischer 1960" );
- self::$ellipsoid["fschr68"] = array( 'a' => 6378150.0, 'rf' => 298.3, 'ellipseName' => "Fischer 1968" );
- self::$ellipsoid["helmert"] = array( 'a' => 6378200.0, 'rf' => 298.3, 'ellipseName' => "Helmert 1906" );
- self::$ellipsoid["hough"] = array( 'a' => 6378270.0, 'rf' => 297.0, 'ellipseName' => "Hough" );
- self::$ellipsoid["intl"] = array( 'a' => 6378388.0, 'rf' => 297.0, 'ellipseName' => "International 1909 (Hayford)" );
- self::$ellipsoid["kaula"] = array( 'a' => 6378163.0, 'rf' => 298.24, 'ellipseName' => "Kaula 1961" );
- self::$ellipsoid["lerch"] = array( 'a' => 6378139.0, 'rf' => 298.257, 'ellipseName' => "Lerch 1979" );
- self::$ellipsoid["mprts"] = array( 'a' => 6397300.0, 'rf' => 191.0, 'ellipseName' => "Maupertius 1738" );
- self::$ellipsoid["new_intl"] = array( 'a' => 6378157.5, 'b' => 6356772.2, 'ellipseName' => "New International 1967" );
- self::$ellipsoid["plessis"] = array( 'a' => 6376523.0, 'rf' => 6355863.0, 'ellipseName' => "Plessis 1817 (France)" );
- self::$ellipsoid["krass"] = array( 'a' => 6378245.0, 'rf' => 298.3, 'ellipseName' => "Krassovsky, 1942" );
- self::$ellipsoid["SEasia"] = array( 'a' => 6378155.0, 'b' => 6356773.3205, 'ellipseName' => "Southeast Asia" );
- self::$ellipsoid["walbeck"] = array( 'a' => 6376896.0, 'b' => 6355834.8467, 'ellipseName' => "Walbeck" );
- self::$ellipsoid["WGS60"] = array( 'a' => 6378165.0, 'rf' => 298.3, 'ellipseName' => "WGS 60" );
- self::$ellipsoid["WGS66"] = array( 'a' => 6378145.0, 'rf' => 298.25, 'ellipseName' => "WGS 66" );
- self::$ellipsoid["WGS72"] = array( 'a' => 6378135.0, 'rf' => 298.26, 'ellipseName' => "WGS 72" );
- self::$ellipsoid["WGS84"] = array( 'a' => 6378137.0, 'rf' => 298.257223563, 'ellipseName' => "WGS 84" );
- self::$ellipsoid["sphere"] = array( 'a' => 6370997.0, 'b' => 6370997.0, 'ellipseName' => "Normal Sphere (r=6370997)" );
+ protected function initEllipsoid() {
+ self::$ellipsoid["MERIT"] = array('a' => 6378137.0, 'rf' => 298.257, 'ellipseName' => "MERIT 1983");
+ self::$ellipsoid["SGS85"] = array('a' => 6378136.0, 'rf' => 298.257, 'ellipseName' => "Soviet Geodetic System 85");
+ self::$ellipsoid["GRS80"] = array('a' => 6378137.0, 'rf' => 298.257222101, 'ellipseName' => "GRS 1980(IUGG, 1980)");
+ self::$ellipsoid["IAU76"] = array('a' => 6378140.0, 'rf' => 298.257, 'ellipseName' => "IAU 1976");
+ self::$ellipsoid["airy"] = array('a' => 6377563.396, 'b' => 6356256.910, 'ellipseName' => "Airy 1830");
+ self::$ellipsoid["APL4."] = array('a' => 6378137, 'rf' => 298.25, 'ellipseName' => "Appl. Physics. 1965");
+ self::$ellipsoid["NWL9D"] = array('a' => 6378145.0, 'rf' => 298.25, 'ellipseName' => "Naval Weapons Lab., 1965");
+ self::$ellipsoid["mod_airy"] = array('a' => 6377340.189, 'b' => 6356034.446, 'ellipseName' => "Modified Airy");
+ self::$ellipsoid["andrae"] = array('a' => 6377104.43, 'rf' => 300.0, 'ellipseName' => "Andrae 1876 (Den., Iclnd.)");
+ self::$ellipsoid["aust_SA"] = array('a' => 6378160.0, 'rf' => 298.25, 'ellipseName' => "Australian Natl & S. Amer. 1969");
+ self::$ellipsoid["GRS67"] = array('a' => 6378160.0, 'rf' => 298.2471674270, 'ellipseName' => "GRS 67(IUGG 1967)");
+ self::$ellipsoid["bessel"] = array('a' => 6377397.155, 'rf' => 299.1528128, 'ellipseName' => "Bessel 1841");
+ self::$ellipsoid["bess_nam"] = array('a' => 6377483.865, 'rf' => 299.1528128, 'ellipseName' => "Bessel 1841 (Namibia)");
+ self::$ellipsoid["clrk66"] = array('a' => 6378206.4, 'b' => 6356583.8, 'ellipseName' => "Clarke 1866");
+ self::$ellipsoid["clrk80"] = array('a' => 6378249.145, 'rf' => 293.4663, 'ellipseName' => "Clarke 1880 mod.");
+ self::$ellipsoid["CPM"] = array('a' => 6375738.7, 'rf' => 334.29, 'ellipseName' => "Comm. des Poids et Mesures 1799");
+ self::$ellipsoid["delmbr"] = array('a' => 6376428.0, 'rf' => 311.5, 'ellipseName' => "Delambre 1810 (Belgium)");
+ self::$ellipsoid["engelis"] = array('a' => 6378136.05, 'rf' => 298.2566, 'ellipseName' => "Engelis 1985");
+ self::$ellipsoid["evrst30"] = array('a' => 6377276.345, 'rf' => 300.8017, 'ellipseName' => "Everest 1830");
+ self::$ellipsoid["evrst48"] = array('a' => 6377304.063, 'rf' => 300.8017, 'ellipseName' => "Everest 1948");
+ self::$ellipsoid["evrst56"] = array('a' => 6377301.243, 'rf' => 300.8017, 'ellipseName' => "Everest 1956");
+ self::$ellipsoid["evrst69"] = array('a' => 6377295.664, 'rf' => 300.8017, 'ellipseName' => "Everest 1969");
+ self::$ellipsoid["evrstSS"] = array('a' => 6377298.556, 'rf' => 300.8017, 'ellipseName' => "Everest (Sabah & Sarawak)");
+ self::$ellipsoid["fschr60"] = array('a' => 6378166.0, 'rf' => 298.3, 'ellipseName' => "Fischer (Mercury Datum) 1960");
+ self::$ellipsoid["fschr60m"] = array('a' => 6378155.0, 'rf' => 298.3, 'ellipseName' => "Fischer 1960");
+ self::$ellipsoid["fschr68"] = array('a' => 6378150.0, 'rf' => 298.3, 'ellipseName' => "Fischer 1968");
+ self::$ellipsoid["helmert"] = array('a' => 6378200.0, 'rf' => 298.3, 'ellipseName' => "Helmert 1906");
+ self::$ellipsoid["hough"] = array('a' => 6378270.0, 'rf' => 297.0, 'ellipseName' => "Hough");
+ self::$ellipsoid["intl"] = array('a' => 6378388.0, 'rf' => 297.0, 'ellipseName' => "International 1909 (Hayford)");
+ self::$ellipsoid["kaula"] = array('a' => 6378163.0, 'rf' => 298.24, 'ellipseName' => "Kaula 1961");
+ self::$ellipsoid["lerch"] = array('a' => 6378139.0, 'rf' => 298.257, 'ellipseName' => "Lerch 1979");
+ self::$ellipsoid["mprts"] = array('a' => 6397300.0, 'rf' => 191.0, 'ellipseName' => "Maupertius 1738");
+ self::$ellipsoid["new_intl"] = array('a' => 6378157.5, 'b' => 6356772.2, 'ellipseName' => "New International 1967");
+ self::$ellipsoid["plessis"] = array('a' => 6376523.0, 'rf' => 6355863.0, 'ellipseName' => "Plessis 1817 (France)");
+ self::$ellipsoid["krass"] = array('a' => 6378245.0, 'rf' => 298.3, 'ellipseName' => "Krassovsky, 1942");
+ self::$ellipsoid["SEasia"] = array('a' => 6378155.0, 'b' => 6356773.3205, 'ellipseName' => "Southeast Asia");
+ self::$ellipsoid["walbeck"] = array('a' => 6376896.0, 'b' => 6355834.8467, 'ellipseName' => "Walbeck");
+ self::$ellipsoid["WGS60"] = array('a' => 6378165.0, 'rf' => 298.3, 'ellipseName' => "WGS 60");
+ self::$ellipsoid["WGS66"] = array('a' => 6378145.0, 'rf' => 298.25, 'ellipseName' => "WGS 66");
+ self::$ellipsoid["WGS72"] = array('a' => 6378135.0, 'rf' => 298.26, 'ellipseName' => "WGS 72");
+ self::$ellipsoid["WGS84"] = array('a' => 6378137.0, 'rf' => 298.257223563, 'ellipseName' => "WGS 84");
+ self::$ellipsoid["sphere"] = array('a' => 6370997.0, 'b' => 6370997.0, 'ellipseName' => "Normal Sphere (r=6370997)");
}
// TODO: read from data files.
- protected function initPrimeMeridian()
- {
+ protected function initPrimeMeridian() {
self::$primeMeridian["greenwich"] = '0.0'; //"0dE",
self::$primeMeridian["lisbon"] = -9.131906111111; //"9d07'54.862\"W",
self::$primeMeridian["paris"] = 2.337229166667; //"2d20'14.025\"E",
@@ -182,8 +177,7 @@ protected function initPrimeMeridian()
/**
*
*/
- public function __construct()
- {
+ public function __construct() {
// Initialise the data.
// Most of this can be read from data files.
@@ -212,20 +206,19 @@ public function __construct()
* point - {Object} point to transform, may be geodetic (long, lat) or
* projected Cartesian (x,y), but should always have x,y properties.
*/
- public function transform(Projection $source, Projection $dest, Point $point)
- {
- if ( ! $source->readyToUse) {
+ public function transform(Projection $source, Projection $dest, Point $point) {
+ if (!$source->readyToUse) {
self::reportError("Proj4php initialization for:" . $source->srsCode . " not yet complete");
return $point;
}
- if ( ! $dest->readyToUse) {
+ if (!$dest->readyToUse) {
self::reportError("Proj4php initialization for:" . $dest->srsCode . " not yet complete");
return $point;
}
// Workaround for datum shifts towgs84, if either source or destination projection is not wgs84
- // WS, 2014/03/26 changed from recursive call of function transform to seperate function doTransform
+ // WS, 2014/03/26 changed from recursive call of function transform to seperate function doTransform
if (
isset($source->datum) && isset($dest->datum)
@@ -249,15 +242,14 @@ public function transform(Projection $source, Projection $dest, Point $point)
return $point;
}
- public function doTransform(Projection $source, Projection $dest, Point $point)
- {
+ public function doTransform(Projection $source, Projection $dest, Point $point) {
// DGR, 2010/11/12
if ($source->axis != 'enu') {
$this->adjust_axis($source, false, $point);
}
// Transform source points to long/lat, if they aren't already.
- if ($source->projName == 'longlat' ) {
+ if ($source->projName == 'longlat') {
// Convert degrees to radians.
$point->x *= Proj4::$common->D2R;
$point->y *= Proj4::$common->D2R;
@@ -280,7 +272,7 @@ public function doTransform(Projection $source, Projection $dest, Point $point)
$point = $this->datum_transform($source->datum, $dest->datum, $point);
// Adjust for the prime meridian if necessary.
- if(isset($dest->from_greenwich)) {
+ if (isset($dest->from_greenwich)) {
$point->x -= $dest->from_greenwich;
}
@@ -313,8 +305,7 @@ public function doTransform(Projection $source, Projection $dest, Point $point)
* destination coordinate system definition,
* point to transform in geodetic coordinates (long, lat, height)
*/
- public function datum_transform($source, $dest, Point $point)
- {
+ public function datum_transform($source, $dest, Point $point) {
// Short cut if the datums are identical.
if ($source->compare_datums($dest)) {
// in this case, zero is sucess,
@@ -361,7 +352,7 @@ public function datum_transform($source, $dest, Point $point)
}
if ($dest->datum_type == Proj4::$common->PJD_3PARAM || $dest->datum_type == Proj4::$common->PJD_7PARAM) {
- $dest->geocentric_from_wgs84( $point );
+ $dest->geocentric_from_wgs84($point);
// CHECK_RETURN;
}
@@ -391,8 +382,7 @@ public function datum_transform($source, $dest, Point $point)
* denorm {Boolean} when false, normalize
* point {Object} the coordinates to adjust
*/
- public function adjust_axis($crs, $denorm, Point $point)
- {
+ public function adjust_axis($crs, $denorm, Point $point) {
$xin = $point->x;
$yin = $point->y;
$zin = isset($point->z) ? $point->z : 0.0;
@@ -413,7 +403,7 @@ public function adjust_axis($crs, $denorm, Point $point)
$t = 'z';
}
- switch($crs->axis[$i]) {
+ switch ($crs->axis[$i]) {
case 'e':
$point[$t] = $v;
break;
@@ -447,11 +437,10 @@ public function adjust_axis($crs, $denorm, Point $point)
/**
* Function: reportError
- * An internal method to report errors back to user.
+ * An internal method to report errors back to user.
* Override this in applications to report error messages or throw exceptions.
*/
- public static function reportError($msg)
- {
+ public static function reportError($msg) {
//console.log(msg);
echo $msg . "
\n";
}
@@ -460,8 +449,7 @@ public static function reportError($msg)
* Function : loadScript
* adapted from original. PHP is simplier.
*/
- public static function loadScript($filename, $onload = null, $onfail = null, $loadCheck = null)
- {
+ public static function loadScript($filename, $onload = null, $onfail = null, $loadCheck = null) {
if (stripos($filename, 'http://') !== false) {
return @file_get_contents($filename);
} elseif (file_exists($filename)) {
@@ -486,10 +474,9 @@ public static function loadScript($filename, $onload = null, $onfail = null, $lo
* Returns:
* {Object} The destination object.
*/
- public static function extend($destination, $source)
- {
+ public static function extend($destination, $source) {
if ($source != null) {
- foreach($source as $key => $value) {
+ foreach ($source as $key => $value) {
$destination->$key = $value;
}
}
diff --git a/src/Projection.php b/src/Projection.php
index 77058dd..b918f54 100644
--- a/src/Projection.php
+++ b/src/Projection.php
@@ -4,10 +4,10 @@
/**
* Author : Julien Moquet, Jason Judge
- *
+ *
* Inspired by Proj4js from Mike Adair madairATdmsolutions.ca
- * and Richard Greenwood rich@greenwoodmap.com
- * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
+ * and Richard Greenwood rich@greenwoodmap.com
+ * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
*/
class Projection {
@@ -26,11 +26,11 @@ class Projection {
/**
* Property: projName
* The projection class for $this projection, e.g. lcc (lambert conformal conic,
- * or merc for mercator). These are exactly equivalent to their Proj4
+ * or merc for mercator). These are exactly equivalent to their Proj4
* counterparts.
*/
public $projName = null;
-
+
/**
* Property: projection
* The projection object for $this projection. */
@@ -69,7 +69,7 @@ class Projection {
/**
*
- * @var type
+ * @var type
*/
protected $wktRE = '/^(\w+)\[(.*)\]$/';
@@ -82,16 +82,15 @@ class Projection {
* (but not always) EPSG codes.
* TODO: also support the raw def string being passed in and parsed here.
*/
- public function __construct($srsCode)
- {
+ public function __construct($srsCode) {
$this->srsCodeInput = $srsCode;
//check to see if $this is a WKT string
if (
- (strpos( $srsCode, 'GEOGCS' ) !== false)
- || (strpos( $srsCode, 'GEOCCS' ) !== false)
- || (strpos( $srsCode, 'PROJCS' ) !== false)
- || (strpos( $srsCode, 'LOCAL_CS' ) !== false)
+ (strpos($srsCode, 'GEOGCS') !== false)
+ || (strpos($srsCode, 'GEOCCS') !== false)
+ || (strpos($srsCode, 'PROJCS') !== false)
+ || (strpos($srsCode, 'LOCAL_CS') !== false)
) {
$this->parseWKT($srsCode);
$this->deriveConstants();
@@ -108,7 +107,7 @@ public function __construct($srsCode)
&& ($urn[2] == 'def')
&& ($urn[3] == 'crs')
) {
- $srsCode = $urn[4] . ':' . $urn[strlen( $urn ) - 1];
+ $srsCode = $urn[4] . ':' . $urn[strlen($urn) - 1];
}
} elseif (strpos($srsCode, 'http://') === 0) {
//url#ID
@@ -150,7 +149,7 @@ public function __construct($srsCode)
/**
* Function: loadProjDefinition
* Loads the coordinate system initialization string if required.
- * Note that dynamic loading happens asynchronously so an application must
+ * Note that dynamic loading happens asynchronously so an application must
* wait for the readyToUse property is set to true.
* To prevent dynamic loading, include the defs through a script tag in
* your application.
@@ -158,8 +157,7 @@ public function __construct($srsCode)
* sources and not having to create a class for each one.
*
*/
- public function loadProjDefinition()
- {
+ public function loadProjDefinition() {
// Check if in memory.
if (array_key_exists($this->srsCode, Proj4::$defs)) {
$this->defsLoaded();
@@ -174,26 +172,25 @@ public function loadProjDefinition()
//Proj4::loadScript($filename);
$classname::init();
$this->defsLoaded(); // success
- } catch ( Exception $e ) {
+ } catch (Exception $e) {
$this->loadFromService(); // fail
}
}
/**
* Function: loadFromService
- * Creates the REST URL for loading the definition from a web service and
+ * Creates the REST URL for loading the definition from a web service and
* loads it.
*
* DO IT AGAIN. : SHOULD PHP CODE BE GET BY WEBSERVICES?
*/
- public function loadFromService()
- {
+ public function loadFromService() {
//else load from web service
$url = Proj4::$defsLookupService . '/' . $this->srsAuth . '/' . $this->srsProjNumber . '/proj4/';
try {
Proj4::$defs[strtoupper($this->srsAuth) . ":" . $this->srsProjNumber] = Proj4::loadScript($url);
- } catch ( Exception $e ) {
+ } catch (Exception $e) {
$this->defsFailed();
}
}
@@ -203,8 +200,7 @@ public function loadFromService()
* Continues the Proj object initilization once the def file is loaded
*
*/
- public function defsLoaded()
- {
+ public function defsLoaded() {
$this->parseDefs();
$this->loadProjCode($this->projName);
}
@@ -214,8 +210,7 @@ public function defsLoaded()
* $this is the loadCheck method to see if the def object exists
*
*/
- public function checkDefsLoaded()
- {
+ public function checkDefsLoaded() {
return isset(Proj4::$defs[$this->srsCode]) && !empty(Proj4::$defs[$this->srsCode]);
}
@@ -224,9 +219,8 @@ public function checkDefsLoaded()
* Report an error in loading the defs file, but continue on using WGS84
*
*/
- public function defsFailed()
- {
- Proj4::reportError( 'failed to load projection definition for: ' . $this->srsCode );
+ public function defsFailed() {
+ Proj4::reportError('failed to load projection definition for: ' . $this->srsCode);
// set it to something so it can at least continue
Proj4::$defs[$this->srsCode] = Proj4::$defs['WGS84'];
$this->defsLoaded();
@@ -240,9 +234,8 @@ public function defsFailed()
*
* An exception occurs if the projection is not found.
*/
- public function loadProjCode($projName)
- {
- if (array_key_exists( $projName, Proj4::$proj)) {
+ public function loadProjCode($projName) {
+ if (array_key_exists($projName, Proj4::$proj)) {
$this->initTransforms();
return;
}
@@ -251,7 +244,7 @@ public function loadProjCode($projName)
$class = __NAMESPACE__ . '\\Projections\\' . ucfirst($projName);
if (class_exists($class)) {
- Proj4::$proj['merc'] = new $class();
+ Proj4::$proj[$projName] = new $class();
$this->loadProjCodeSuccess($projName);
return;
}
@@ -262,7 +255,7 @@ public function loadProjCode($projName)
try {
Proj4::loadScript($filename);
$this->loadProjCodeSuccess($projName);
- } catch ( Exception $e ) {
+ } catch (Exception $e) {
$this->loadProjCodeFailure($projName);
}
}
@@ -272,10 +265,9 @@ public function loadProjCode($projName)
* Loads any proj dependencies or continue on to final initialization.
*
*/
- public function loadProjCodeSuccess($projName)
- {
+ public function loadProjCodeSuccess($projName) {
if (isset(Proj4::$proj[$projName]->dependsOn) && !empty(Proj4::$proj[$projName]->dependsOn)) {
- $this->loadProjCode( Proj4::$proj[$projName]->dependsOn );
+ $this->loadProjCode(Proj4::$proj[$projName]->dependsOn);
} else {
$this->initTransforms();
}
@@ -287,8 +279,7 @@ public function loadProjCodeSuccess($projName)
* object has failed and the readyToUse flag will never be set.
*
*/
- public function loadProjCodeFailure($projName)
- {
+ public function loadProjCodeFailure($projName) {
Proj4::reportError("failed to find projection file for: " . $projName);
//TBD initialize with identity transforms so proj will still work?
}
@@ -298,8 +289,7 @@ public function loadProjCodeFailure($projName)
* $this is the loadCheck method to see if the projection code is loaded
*
*/
- public function checkCodeLoaded($projName)
- {
+ public function checkCodeLoaded($projName) {
return isset(Proj4::$proj[$projName]) && !empty(Proj4::$proj[$projName]);
}
@@ -308,53 +298,49 @@ public function checkCodeLoaded($projName)
* Finalize the initialization of the Proj object
*
*/
- public function initTransforms()
- {
+ public function initTransforms() {
$this->projection = clone(Proj4::$proj[$this->projName]);
- Proj4::extend( $this->projection, $this );
+ Proj4::extend($this->projection, $this);
$this->init();
// initiate depending class
if (
false !== (
- $dependsOn = isset($this->projection->dependsOn) && !empty($this->projection->dependsOn)
+ $dependsOn = isset($this->projection->dependsOn) && !empty($this->projection->dependsOn)
? $this->projection->dependsOn
: false
)
) {
- Proj4::extend( Proj4::$proj[$dependsOn], $this->projection) &&
+ Proj4::extend(Proj4::$proj[$dependsOn], $this->projection) &&
Proj4::$proj[$dependsOn]->init() &&
- Proj4::extend( $this->projection, Proj4::$proj[$dependsOn] );
+ Proj4::extend($this->projection, Proj4::$proj[$dependsOn]);
}
$this->readyToUse = true;
}
/**
- *
+ *
*/
- public function init()
- {
+ public function init() {
$this->projection->init();
}
/**
*
* @param type $pt
- * @return type
+ * @return type
*/
- public function forward($pt)
- {
+ public function forward($pt) {
return $this->projection->forward($pt);
}
/**
*
* @param type $pt
- * @return type
+ * @return type
*/
- public function inverse($pt)
- {
+ public function inverse($pt) {
return $this->projection->inverse($pt);
}
@@ -363,19 +349,18 @@ public function inverse($pt)
* Parses a WKT string to get initialization parameters
*
*/
- public function parseWKT($wkt)
- {
+ public function parseWKT($wkt) {
if (false === ($match = preg_match($this->wktRE, $wkt, $wktMatch))) {
return;
}
$wktObject = $wktMatch[1];
$wktContent = $wktMatch[2];
- $wktTemp = explode( ",", $wktContent );
-
- $wktName = (strtoupper($wktObject) == "TOWGS84") ? "TOWGS84" : array_shift( $wktTemp );
- $wktName = preg_replace( '/^\"/', "", $wktName );
- $wktName = preg_replace( '/\"$/', "", $wktName );
+ $wktTemp = explode(",", $wktContent);
+
+ $wktName = (strtoupper($wktObject) == "TOWGS84") ? "TOWGS84" : array_shift($wktTemp);
+ $wktName = preg_replace('/^\"/', "", $wktName);
+ $wktName = preg_replace('/\"$/', "", $wktName);
/*
$wktContent = implode(",",$wktTemp);
@@ -452,7 +437,7 @@ public function parseWKT($wkt)
//there may be many variations on the wktName values, add in case
//statements as required
- switch($name) {
+ switch ($name) {
case 'false_easting':
$this->x0 = $value;
break;
@@ -481,36 +466,47 @@ public function parseWKT($wkt)
case 'AXIS':
$name = strtolower($wktName);
$value = array_shift($wktArray);
- switch( $value ) {
- case 'EAST' : $value = 'e';
+ switch ($value) {
+ case 'EAST' :
+ $value = 'e';
break;
- case 'WEST' : $value = 'w';
+ case 'WEST' :
+ $value = 'w';
break;
- case 'NORTH': $value = 'n';
+ case 'NORTH':
+ $value = 'n';
break;
- case 'SOUTH': $value = 's';
+ case 'SOUTH':
+ $value = 's';
break;
- case 'UP' : $value = 'u';
+ case 'UP' :
+ $value = 'u';
break;
- case 'DOWN' : $value = 'd';
+ case 'DOWN' :
+ $value = 'd';
break;
case 'OTHER':
- default : $value = ' ';
+ default :
+ $value = ' ';
break; //FIXME
}
- if ( ! $this->axis) {
+ if (!$this->axis) {
$this->axis = 'enu';
}
- switch( $name ) {
- case 'X': $this->axis = $value . substr($this->axis, 1, 2);
+ switch ($name) {
+ case 'X':
+ $this->axis = $value . substr($this->axis, 1, 2);
+ break;
+ case 'Y':
+ $this->axis = substr($this->axis, 0, 1) . $value . substr($this->axis, 2, 1);
break;
- case 'Y': $this->axis = substr($this->axis, 0, 1) . $value . substr($this->axis, 2, 1);
+ case 'Z':
+ $this->axis = substr($this->axis, 0, 2) . $value;
break;
- case 'Z': $this->axis = substr($this->axis, 0, 2) . $value;
+ default :
break;
- default : break;
}
case 'MORE_HERE':
break;
@@ -528,27 +524,26 @@ public function parseWKT($wkt)
* Parses the PROJ.4 initialization string and sets the associated properties.
*
*/
- public function parseDefs()
- {
+ public function parseDefs() {
$this->defData = Proj4::$defs[$this->srsCode];
#$paramName;
#$paramVal;
- if( !$this->defData ) {
+ if (!$this->defData) {
return;
}
$paramArray = explode('+', $this->defData);
- for ($prop = 0; $prop < sizeof( $paramArray ); $prop++) {
- if (strlen( $paramArray[$prop] ) == 0) {
+ for ($prop = 0; $prop < sizeof($paramArray); $prop++) {
+ if (strlen($paramArray[$prop]) == 0) {
continue;
}
$property = explode("=", $paramArray[$prop]);
$paramName = strtolower($property[0]);
- if (sizeof( $property ) >= 2) {
+ if (sizeof($property) >= 2) {
$paramVal = $property[1];
}
@@ -617,19 +612,19 @@ public function parseDefs()
break;
case 'x_0':
// false easting
- $this->x0 = floatval( $paramVal );
+ $this->x0 = floatval($paramVal);
break;
case 'y_0':
// false northing
- $this->y0 = floatval( $paramVal );
+ $this->y0 = floatval($paramVal);
break;
case 'k_0':
// projection scale factor
- $this->k0 = floatval( $paramVal );
+ $this->k0 = floatval($paramVal);
break;
case 'k':
// both forms returned
- $this->k0 = floatval( $paramVal );
+ $this->k0 = floatval($paramVal);
break;
case 'r_a':
// sphere--area of ellipsoid
@@ -637,7 +632,7 @@ public function parseDefs()
break;
case 'zone':
// UTM Zone
- $this->zone = intval( $paramVal, 10 );
+ $this->zone = intval($paramVal, 10);
break;
case 'south':
// UTM north/south
@@ -653,23 +648,23 @@ public function parseDefs()
case 'from_greenwich':
$this->from_greenwich = $paramVal * Proj4::$common->D2R;
break;
- // DGR 2008-07-09 : if pm is not a well-known prime meridian take
- // the value instead of 0.0, then convert to radians
+ // DGR 2008-07-09 : if pm is not a well-known prime meridian take
+ // the value instead of 0.0, then convert to radians
case 'pm':
$paramVal = trim($paramVal);
$this->from_greenwich = Proj4::$primeMeridian[$paramVal] ? Proj4::$primeMeridian[$paramVal] : floatval($paramVal);
$this->from_greenwich *= Proj4::$common->D2R;
break;
- // DGR 2010-11-12: axis
+ // DGR 2010-11-12: axis
case 'axis':
$paramVal = trim($paramVal);
$legalAxis = "ewnsud";
if (
- strlen( paramVal ) == 3
- && strpos( $legalAxis, substr( $paramVal, 0, 1 ) ) !== false
- && strpos( $legalAxis, substr( $paramVal, 1, 1 ) ) !== false
- && strpos( $legalAxis, substr( $paramVal, 2, 1 ) ) !== false
+ strlen(paramVal) == 3
+ && strpos($legalAxis, substr($paramVal, 0, 1)) !== false
+ && strpos($legalAxis, substr($paramVal, 1, 1)) !== false
+ && strpos($legalAxis, substr($paramVal, 2, 1)) !== false
) {
$this->axis = $paramVal;
} //FIXME: be silent ?
@@ -690,8 +685,7 @@ public function parseDefs()
* Sets several derived constant values and initialization of datum and ellipse parameters.
*
*/
- public function deriveConstants()
- {
+ public function deriveConstants() {
if (isset($this->nagrids) && $this->nagrids == '@null') {
$this->datumCode = 'none';
}
@@ -707,8 +701,8 @@ public function deriveConstants()
}
// do we have an ellipsoid?
- if ( ! isset($this->a)) {
- if ( ! isset($this->ellps) || strlen($this->ellps) == 0 || ! array_key_exists($this->ellps, Proj4::$ellipsoid)) {
+ if (!isset($this->a)) {
+ if (!isset($this->ellps) || strlen($this->ellps) == 0 || !array_key_exists($this->ellps, Proj4::$ellipsoid)) {
$ellipse = Proj4::$ellipsoid['WGS84'];
} else {
$ellipse = Proj4::$ellipsoid[$this->ellps];
@@ -717,7 +711,7 @@ public function deriveConstants()
Proj4::extend($this, $ellipse);
}
- if (isset($this->rf) && ! isset($this->b)) {
+ if (isset($this->rf) && !isset($this->b)) {
$this->b = (1.0 - 1.0 / $this->rf) * $this->a;
}
@@ -748,13 +742,13 @@ public function deriveConstants()
// used in geocentric
$this->ep2 = ($this->a2 - $this->b2) / $this->b2;
- if ( ! isset($this->k0)) {
+ if (!isset($this->k0)) {
//default value
$this->k0 = 1.0;
}
//DGR 2010-11-12: axis
- if ( ! isset($this->axis)) {
+ if (!isset($this->axis)) {
$this->axis = 'enu';
}
diff --git a/src/Projections/Aea.php b/src/Projections/Aea.php
index 25c258f..54229bc 100644
--- a/src/Projections/Aea.php
+++ b/src/Projections/Aea.php
@@ -2,104 +2,102 @@
namespace Academe\Proj4Php\Projections;
-use Academe\Proj4Php\Proj4Php;
+use Academe\Proj4Php\Proj4 as Proj4Php;
/*******************************************************************************
- NAME ALBERS CONICAL EQUAL AREA
-
- PURPOSE: Transforms input longitude and latitude to Easting and Northing
- for the Albers Conical Equal Area projection. The longitude
- and latitude must be in radians. The Easting and Northing
- values will be returned in meters.
-
- PROGRAMMER DATE
- ---------- ----
- T. Mittan, Feb, 1992
-
- ALGORITHM REFERENCES
-
- 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
- Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
- State Government Printing Office, Washington D.C., 1987.
-
- 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
- U.S. Geological Survey Professional Paper 1453 , United State Government
- Printing Office, Washington D.C., 1989.
+ * NAME ALBERS CONICAL EQUAL AREA
+ *
+ * PURPOSE: Transforms input longitude and latitude to Easting and Northing
+ * for the Albers Conical Equal Area projection. The longitude
+ * and latitude must be in radians. The Easting and Northing
+ * values will be returned in meters.
+ *
+ * PROGRAMMER DATE
+ * ---------- ----
+ * T. Mittan, Feb, 1992
+ *
+ * ALGORITHM REFERENCES
+ *
+ * 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
+ * Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
+ * State Government Printing Office, Washington D.C., 1987.
+ *
+ * 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
+ * U.S. Geological Survey Professional Paper 1453 , United State Government
+ * Printing Office, Washington D.C., 1989.
*******************************************************************************/
/**
* Author : Julien Moquet
- *
+ *
* Inspired by Proj4php from Mike Adair madairATdmsolutions.ca
- * and Richard Greenwood rich@greenwoodma$p->com
- * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
+ * and Richard Greenwood rich@greenwoodma$p->com
+ * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
*/
class Aea {
/**
*
- * @return void
+ * @return void
*/
- public function init()
- {
- if( abs( $this->lat1 + $this->lat2 ) < Proj4php::$common->EPSLN ) {
- Proj4php::reportError( "aeaInitEqualLatitudes" );
+ public function init() {
+ if (abs($this->lat1 + $this->lat2) < Proj4php::$common->EPSLN) {
+ Proj4php::reportError("aeaInitEqualLatitudes");
return;
}
$this->temp = $this->b / $this->a;
- $this->es = 1.0 - pow( $this->temp, 2 );
- $this->e3 = sqrt( $this->es );
+ $this->es = 1.0 - pow($this->temp, 2);
+ $this->e3 = sqrt($this->es);
- $this->sin_po = sin( $this->lat1 );
- $this->cos_po = cos( $this->lat1 );
+ $this->sin_po = sin($this->lat1);
+ $this->cos_po = cos($this->lat1);
$this->t1 = $this->sin_po;
$this->con = $this->sin_po;
- $this->ms1 = Proj4php::$common->msfnz( $this->e3, $this->sin_po, $this->cos_po );
- $this->qs1 = Proj4php::$common->qsfnz( $this->e3, $this->sin_po, $this->cos_po );
+ $this->ms1 = Proj4php::$common->msfnz($this->e3, $this->sin_po, $this->cos_po);
+ $this->qs1 = Proj4php::$common->qsfnz($this->e3, $this->sin_po, $this->cos_po);
- $this->sin_po = sin( $this->lat2 );
- $this->cos_po = cos( $this->lat2 );
+ $this->sin_po = sin($this->lat2);
+ $this->cos_po = cos($this->lat2);
$this->t2 = $this->sin_po;
- $this->ms2 = Proj4php::$common->msfnz( $this->e3, $this->sin_po, $this->cos_po );
- $this->qs2 = Proj4php::$common->qsfnz( $this->e3, $this->sin_po, $this->cos_po );
+ $this->ms2 = Proj4php::$common->msfnz($this->e3, $this->sin_po, $this->cos_po);
+ $this->qs2 = Proj4php::$common->qsfnz($this->e3, $this->sin_po, $this->cos_po);
- $this->sin_po = sin( $this->lat0 );
- $this->cos_po = cos( $this->lat0 );
+ $this->sin_po = sin($this->lat0);
+ $this->cos_po = cos($this->lat0);
$this->t3 = $this->sin_po;
- $this->qs0 = Proj4php::$common->qsfnz( $this->e3, $this->sin_po, $this->cos_po );
+ $this->qs0 = Proj4php::$common->qsfnz($this->e3, $this->sin_po, $this->cos_po);
- if( abs( $this->lat1 - $this->lat2 ) > Proj4php::$common->EPSLN ) {
+ if (abs($this->lat1 - $this->lat2) > Proj4php::$common->EPSLN) {
$this->ns0 = ($this->ms1 * $this->ms1 - $this->ms2 * $this->ms2) / ($this->qs2 - $this->qs1);
} else {
$this->ns0 = $this->con;
}
-
+
$this->c = $this->ms1 * $this->ms1 + $this->ns0 * $this->qs1;
- $this->rh = $this->a * sqrt( $this->c - $this->ns0 * $this->qs0 ) / $this->ns0;
+ $this->rh = $this->a * sqrt($this->c - $this->ns0 * $this->qs0) / $this->ns0;
}
/**
* Albers Conical Equal Area forward equations--mapping lat,long to x,y
*
* @param Point $p
- * @return Point $p
+ * @return Point $p
*/
- public function forward($p)
- {
+ public function forward($p) {
$lon = $p->x;
$lat = $p->y;
- $this->sin_phi = sin( $lat );
- $this->cos_phi = cos( $lat );
+ $this->sin_phi = sin($lat);
+ $this->cos_phi = cos($lat);
- $qs = Proj4php::$common->qsfnz( $this->e3, $this->sin_phi, $this->cos_phi );
- $rh1 = $this->a * sqrt( $this->c - $this->ns0 * $qs ) / $this->ns0;
- $theta = $this->ns0 * Proj4php::$common->adjust_lon( $lon - $this->long0 );
- $x = rh1 * sin( $theta ) + $this->x0;
- $y = $this->rh - $rh1 * cos( $theta ) + $this->y0;
+ $qs = Proj4php::$common->qsfnz($this->e3, $this->sin_phi, $this->cos_phi);
+ $rh1 = $this->a * sqrt($this->c - $this->ns0 * $qs) / $this->ns0;
+ $theta = $this->ns0 * Proj4php::$common->adjust_lon($lon - $this->long0);
+ $x = rh1 * sin($theta) + $this->x0;
+ $y = $this->rh - $rh1 * cos($theta) + $this->y0;
$p->x = $x;
$p->y = $y;
-
+
return $p;
}
@@ -108,47 +106,46 @@ public function forward($p)
* @param Point $p
* @return Point $p
*/
- public function inverse($p)
- {
+ public function inverse($p) {
$p->x -= $this->x0;
$p->y = $this->rh - $p->y + $this->y0;
-
- if( $this->ns0 >= 0 ) {
- $rh1 = sqrt( $p->x * $p->x + $p->y * $p->y );
+
+ if ($this->ns0 >= 0) {
+ $rh1 = sqrt($p->x * $p->x + $p->y * $p->y);
$con = 1.0;
} else {
- $rh1 = -sqrt( $p->x * $p->x + $p->y * $p->y );
+ $rh1 = -sqrt($p->x * $p->x + $p->y * $p->y);
$con = -1.0;
}
-
+
$theta = 0.0;
- if( $rh1 != 0.0 ) {
- $theta = atan2( $con * $p->x, $con * $p->y );
+ if ($rh1 != 0.0) {
+ $theta = atan2($con * $p->x, $con * $p->y);
}
-
+
$con = $rh1 * $this->ns0 / $this->a;
$qs = ($this->c - $con * $con) / $this->ns0;
-
- if( $this->e3 >= 1e-10 ) {
- $con = 1 - .5 * (1.0 - $this->es) * log( (1.0 - $this->e3) / (1.0 + $this->e3) ) / $this->e3;
- if( abs( abs( $con ) - abs( $qs ) ) > .0000000001 ) {
- $lat = $this->phi1z( $this->e3, $qs );
+
+ if ($this->e3 >= 1e-10) {
+ $con = 1 - .5 * (1.0 - $this->es) * log((1.0 - $this->e3) / (1.0 + $this->e3)) / $this->e3;
+ if (abs(abs($con) - abs($qs)) > .0000000001) {
+ $lat = $this->phi1z($this->e3, $qs);
} else {
- if( $qs >= 0 ) {
+ if ($qs >= 0) {
$lat = .5 * Proj4php::$Common->PI;
} else {
$lat = -.5 * Proj4php::$Common->PI;
}
}
} else {
- $lat = $this->phi1z( $this->e3, $qs );
+ $lat = $this->phi1z($this->e3, $qs);
}
- $lon = Proj4php::$common->adjust_lon( $theta / $this->ns0 + $this->long0 );
-
+ $lon = Proj4php::$common->adjust_lon($theta / $this->ns0 + $this->long0);
+
$p->x = $lon;
$p->y = $lat;
-
+
return $p;
}
@@ -159,26 +156,25 @@ public function inverse($p)
* @param type $qs
* @return $phi or null on Convergence error
*/
- public function phi1z($eccent, $qs)
- {
- $phi = Proj4php::$common->asinz( .5 * $qs );
+ public function phi1z($eccent, $qs) {
+ $phi = Proj4php::$common->asinz(.5 * $qs);
- if( $eccent < Proj4php::$common->EPSLN )
+ if ($eccent < Proj4php::$common->EPSLN)
return $phi;
$eccnts = $eccent * $eccent;
- for( $i = 1; $i <= 25; ++$i ) {
- $sinphi = sin( $phi );
- $cosphi = cos( $phi );
+ for ($i = 1; $i <= 25; ++$i) {
+ $sinphi = sin($phi);
+ $cosphi = cos($phi);
$con = $eccent * $sinphi;
$com = 1.0 - $con * $con;
- $dphi = .5 * $com * $com / $cosphi * ($qs / (1.0 - $eccnts) - $sinphi / $com + .5 / $eccent * log( (1.0 - $con) / (1.0 + $con) ));
+ $dphi = .5 * $com * $com / $cosphi * ($qs / (1.0 - $eccnts) - $sinphi / $com + .5 / $eccent * log((1.0 - $con) / (1.0 + $con)));
$phi = $phi + $dphi;
- if( abs( $dphi ) <= 1e-7 )
+ if (abs($dphi) <= 1e-7)
return $phi;
}
- Proj4php::reportError( "aea:phi1z:Convergence error" );
+ Proj4php::reportError("aea:phi1z:Convergence error");
return null;
}
diff --git a/src/Projections/Merc.php b/src/Projections/Merc.php
index 9ee9f70..4864716 100644
--- a/src/Projections/Merc.php
+++ b/src/Projections/Merc.php
@@ -2,14 +2,14 @@
namespace Academe\Proj4Php\Projections;
-use \Academe\Proj4Php\Proj4 as Proj4Php;
+use Academe\Proj4Php\Proj4 as Proj4Php;
/**
* Author : Julien Moquet
- *
+ *
* Inspired by Proj4php from Mike Adair madairATdmsolutions.ca
- * and Richard Greenwood rich@greenwoodma$p->com
- * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
+ * and Richard Greenwood rich@greenwoodma$p->com
+ * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
*/
/* * *****************************************************************************
NAME MERCATOR
@@ -43,22 +43,21 @@
//static double m1; /* small value m */
//static double false_northing = y0; /* y offset in meters */
//static double false_easting = x0; /* x offset in meters */
-//scale_fact = k0
+//scale_fact = k0
class Merc {
- public function init()
- {
+ public function init() {
//?$this->temp = $this->r_minor / $this->r_major;
//$this->temp = $this->b / $this->a;
//$this->es = 1.0 - sqrt($this->temp);
//$this->e = sqrt( $this->es );
//?$this->m1 = cos($this->lat_origin) / (sqrt( 1.0 - $this->es * sin($this->lat_origin) * sin($this->lat_origin)));
//$this->m1 = cos(0.0) / (sqrt( 1.0 - $this->es * sin(0.0) * sin(0.0)));
- if( $this->lat_ts ) {
- if( $this->sphere ) {
- $this->k0 = cos( $this->lat_ts );
+ if ($this->lat_ts) {
+ if ($this->sphere) {
+ $this->k0 = cos($this->lat_ts);
} else {
- $this->k0 = Proj4php::$common->msfnz( $this->es, sin( $this->lat_ts ), cos( $this->lat_ts ) );
+ $this->k0 = Proj4php::$common->msfnz($this->es, sin($this->lat_ts), cos($this->lat_ts));
}
}
}
@@ -66,8 +65,7 @@ public function init()
/* Mercator forward equations--mapping lat,long to x,y
-------------------------------------------------- */
- public function forward($p)
- {
+ public function forward($p) {
//alert("ll2m coords : ".coords);
$lon = $p->x;
$lat = $p->y;
@@ -79,22 +77,22 @@ public function forward($p)
$lon * Proj4Php::$common->R2D > 180.0 &&
$lon * Proj4Php::$common->R2D < -180.0
) {
- Proj4Php::reportError( "merc:forward: llInputOutOfRange: " . $lon . " : " . $lat );
+ Proj4Php::reportError("merc:forward: llInputOutOfRange: " . $lon . " : " . $lat);
return null;
}
- if (abs( abs( $lat ) - Proj4php::$common->HALF_PI ) <= Proj4Php::$common->EPSLN) {
- Proj4php::reportError( "merc:forward: ll2mAtPoles" );
+ if (abs(abs($lat) - Proj4php::$common->HALF_PI) <= Proj4Php::$common->EPSLN) {
+ Proj4php::reportError("merc:forward: ll2mAtPoles");
return null;
} else {
if ($this->sphere) {
- $x = $this->x0 + $this->a * $this->k0 * Proj4Php::$common->adjust_lon( $lon - $this->long0 );
- $y = $this->y0 + $this->a * $this->k0 * log( tan( Proj4Php::$common->FORTPI + 0.5 * $lat ) );
+ $x = $this->x0 + $this->a * $this->k0 * Proj4Php::$common->adjust_lon($lon - $this->long0);
+ $y = $this->y0 + $this->a * $this->k0 * log(tan(Proj4Php::$common->FORTPI + 0.5 * $lat));
} else {
- $sinphi = sin( $lat );
- $ts = Proj4Php::$common . tsfnz( $this->e, $lat, $sinphi );
- $x = $this->x0 + $this->a * $this->k0 * Proj4Php::$common->adjust_lon( $lon - $this->long0 );
- $y = $this->y0 - $this->a * $this->k0 * log( $ts );
+ $sinphi = sin($lat);
+ $ts = Proj4Php::$common . tsfnz($this->e, $lat, $sinphi);
+ $x = $this->x0 + $this->a * $this->k0 * Proj4Php::$common->adjust_lon($lon - $this->long0);
+ $y = $this->y0 - $this->a * $this->k0 * log($ts);
}
$p->x = $x;
@@ -107,22 +105,21 @@ public function forward($p)
/* Mercator inverse equations--mapping x,y to lat/long
-------------------------------------------------- */
- public function inverse($p)
- {
+ public function inverse($p) {
$x = $p->x - $this->x0;
$y = $p->y - $this->y0;
if ($this->sphere) {
- $lat = Proj4Php::$common->HALF_PI - 2.0 * atan( exp( -$y / $this->a * $this->k0 ) );
+ $lat = Proj4Php::$common->HALF_PI - 2.0 * atan(exp(-$y / $this->a * $this->k0));
} else {
- $ts = exp( -$y / ($this->a * $this->k0) );
- $lat = Proj4php::$common->phi2z( $this->e, $ts );
+ $ts = exp(-$y / ($this->a * $this->k0));
+ $lat = Proj4php::$common->phi2z($this->e, $ts);
if ($lat == -9999) {
- Proj4Php::reportError( "merc:inverse: lat = -9999" );
+ Proj4Php::reportError("merc:inverse: lat = -9999");
return null;
}
}
- $lon = Proj4Php::$common->adjust_lon( $this->long0 + $x / ($this->a * $this->k0) );
+ $lon = Proj4Php::$common->adjust_lon($this->long0 + $x / ($this->a * $this->k0));
$p->x = $lon;
$p->y = $lat;
diff --git a/src/Projections/Tmerc.php b/src/Projections/Tmerc.php
index 8c05b81..c227607 100644
--- a/src/Projections/Tmerc.php
+++ b/src/Projections/Tmerc.php
@@ -2,94 +2,94 @@
namespace Academe\Proj4Php\Projections;
-use Academe\Proj4Php\Proj4Php;
+use Academe\Proj4Php\Proj4 as Proj4Php;
/**
* Author : Julien Moquet
- *
+ *
* Inspired by Proj4php from Mike Adair madairATdmsolutions.ca
- * and Richard Greenwood rich@greenwoodma$p->com
- * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
+ * and Richard Greenwood rich@greenwoodma$p->com
+ * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
*/
/*******************************************************************************
- NAME TRANSVERSE MERCATOR
-
- PURPOSE: Transforms input longitude and latitude to Easting and
- Northing for the Transverse Mercator projection. The
- longitude and latitude must be in radians. The Easting
- and Northing values will be returned in meters.
-
- ALGORITHM REFERENCES
-
- 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
- Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
- State Government Printing Office, Washington D.C., 1987.
-
- 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
- U.S. Geological Survey Professional Paper 1453 , United State Government
- Printing Office, Washington D.C., 1989.
-*******************************************************************************/
+ * NAME TRANSVERSE MERCATOR
+ *
+ * PURPOSE: Transforms input longitude and latitude to Easting and
+ * Northing for the Transverse Mercator projection. The
+ * longitude and latitude must be in radians. The Easting
+ * and Northing values will be returned in meters.
+ *
+ * ALGORITHM REFERENCES
+ *
+ * 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
+ * Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
+ * State Government Printing Office, Washington D.C., 1987.
+ *
+ * 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
+ * U.S. Geological Survey Professional Paper 1453 , United State Government
+ * Printing Office, Washington D.C., 1989.
+ *******************************************************************************/
/**
- Initialize Transverse Mercator projection
+ * Initialize Transverse Mercator projection
*/
class Tmerc {
private $e0, $e1, $e2, $e3, $ml0;
/**
- *
+ *
*/
public function init() {
-
- $this->e0 = Proj4php::$common->e0fn( $this->es );
- $this->e1 = Proj4php::$common->e1fn( $this->es );
- $this->e2 = Proj4php::$common->e2fn( $this->es );
- $this->e3 = Proj4php::$common->e3fn( $this->es );
- $this->ml0 = $this->a * Proj4php::$common->mlfn( $this->e0, $this->e1, $this->e2, $this->e3, $this->lat0 );
+
+ $this->e0 = Proj4php::$common->e0fn($this->es);
+ $this->e1 = Proj4php::$common->e1fn($this->es);
+ $this->e2 = Proj4php::$common->e2fn($this->es);
+ $this->e3 = Proj4php::$common->e3fn($this->es);
+ $this->ml0 = $this->a * Proj4php::$common->mlfn($this->e0, $this->e1, $this->e2, $this->e3, $this->lat0);
}
/**
- Transverse Mercator Forward - long/lat to x/y
- long/lat in radians
+ * Transverse Mercator Forward - long/lat to x/y
+ * long/lat in radians
*/
- public function forward( $p ) {
+ public function forward($p) {
$lon = $p->x;
$lat = $p->y;
- $delta_lon = Proj4php::$common->adjust_lon( $lon - $this->long0 ); // Delta longitude
+ $delta_lon = Proj4php::$common->adjust_lon($lon - $this->long0); // Delta longitude
#$con = 0; // cone constant
#$x = 0;
#$y = 0;
- $sin_phi = sin( $lat );
- $cos_phi = cos( $lat );
-
- if( isset($this->sphere) && $this->sphere === true ) { /* spherical form */
- $b = $cos_phi * sin( $delta_lon );
- if( (abs( abs( $b ) - 1.0 )) < .0000000001 ) {
- Proj4php::reportError( "tmerc:forward: Point projects into infinity" );
- return(93);
+ $sin_phi = sin($lat);
+ $cos_phi = cos($lat);
+
+ if (isset($this->sphere) && $this->sphere === true) { /* spherical form */
+ $b = $cos_phi * sin($delta_lon);
+ if ((abs(abs($b) - 1.0)) < .0000000001) {
+ Proj4php::reportError("tmerc:forward: Point projects into infinity");
+ return (93);
} else {
- $x = .5 * $this->a * $this->k0 * log( (1.0 + $b) / (1.0 - $b) );
- $con = acos( $cos_phi * cos( $delta_lon ) / sqrt( 1.0 - $b * $b ) );
- if( $lat < 0 )
- $con = - $con;
+ $x = .5 * $this->a * $this->k0 * log((1.0 + $b) / (1.0 - $b));
+ $con = acos($cos_phi * cos($delta_lon) / sqrt(1.0 - $b * $b));
+ if ($lat < 0)
+ $con = -$con;
$y = $this->a * $this->k0 * ($con - $this->lat0);
}
} else {
$al = $cos_phi * $delta_lon;
- $als = pow( $al, 2 );
- $c = $this->ep2 * pow( $cos_phi, 2 );
- $tq = tan( $lat );
- $t = pow( $tq, 2 );
- $con = 1.0 - $this->es * pow( $sin_phi, 2 );
- $n = $this->a / sqrt( $con );
+ $als = pow($al, 2);
+ $c = $this->ep2 * pow($cos_phi, 2);
+ $tq = tan($lat);
+ $t = pow($tq, 2);
+ $con = 1.0 - $this->es * pow($sin_phi, 2);
+ $n = $this->a / sqrt($con);
- $ml = $this->a * Proj4php::$common->mlfn( $this->e0, $this->e1, $this->e2, $this->e3, $lat );
+ $ml = $this->a * Proj4php::$common->mlfn($this->e0, $this->e1, $this->e2, $this->e3, $lat);
- $x = $this->k0 * $n * $al * (1.0 + $als / 6.0 * (1.0 - $t + $c + $als / 20.0 * (5.0 - 18.0 * $t + pow( $t, 2 ) + 72.0 * $c - 58.0 * $this->ep2))) + $this->x0;
- $y = $this->k0 * ($ml - $this->ml0 + $n * $tq * ($als * (0.5 + $als / 24.0 * (5.0 - $t + 9.0 * $c + 4.0 * pow( $c, 2 ) + $als / 30.0 * (61.0 - 58.0 * $t + pow( $t, 2 ) + 600.0 * $c - 330.0 * $this->ep2))))) + $this->y0;
+ $x = $this->k0 * $n * $al * (1.0 + $als / 6.0 * (1.0 - $t + $c + $als / 20.0 * (5.0 - 18.0 * $t + pow($t, 2) + 72.0 * $c - 58.0 * $this->ep2))) + $this->x0;
+ $y = $this->k0 * ($ml - $this->ml0 + $n * $tq * ($als * (0.5 + $als / 24.0 * (5.0 - $t + 9.0 * $c + 4.0 * pow($c, 2) + $als / 30.0 * (61.0 - 58.0 * $t + pow($t, 2) + 600.0 * $c - 330.0 * $this->ep2))))) + $this->y0;
}
$p->x = $x;
@@ -99,27 +99,27 @@ public function forward( $p ) {
}
/**
- Transverse Mercator Inverse - x/y to long/lat
+ * Transverse Mercator Inverse - x/y to long/lat
*/
- public function inverse( $p ) {
+ public function inverse($p) {
#$phi; /* temporary angles */
#$delta_phi; /* difference between longitudes */
$max_iter = 6; /* maximun number of iterations */
- if( isset($this->sphere) && $this->sphere === true ) { /* spherical form */
- $f = exp( $p->x / ($this->a * $this->k0) );
+ if (isset($this->sphere) && $this->sphere === true) { /* spherical form */
+ $f = exp($p->x / ($this->a * $this->k0));
$g = .5 * ($f - 1 / $f);
$temp = $this->lat0 + $p->y / ($this->a * $this->k0);
- $h = cos( $temp );
- $con = sqrt( (1.0 - $h * $h) / (1.0 + $g * $g) );
- $lat = Proj4php::$common->asinz( $con );
- if( $temp < 0 )
+ $h = cos($temp);
+ $con = sqrt((1.0 - $h * $h) / (1.0 + $g * $g));
+ $lat = Proj4php::$common->asinz($con);
+ if ($temp < 0)
$lat = -$lat;
- if( ($g == 0) && ($h == 0) ) {
+ if (($g == 0) && ($h == 0)) {
$lon = $this->long0;
} else {
- $lon = Proj4php::$common->adjust_lon( atan2( $g, $h ) + $this->long0 );
+ $lon = Proj4php::$common->adjust_lon(atan2($g, $h) + $this->long0);
}
} else { // ellipsoidal form
$x = $p->x - $this->x0;
@@ -128,41 +128,41 @@ public function inverse( $p ) {
$con = ($this->ml0 + $y / $this->k0) / $this->a;
$phi = $con;
- for( $i = 0; true; $i++ ) {
- $delta_phi = (($con + $this->e1 * sin( 2.0 * $phi ) - $this->e2 * sin( 4.0 * $phi ) + $this->e3 * sin( 6.0 * $phi )) / $this->e0) - $phi;
+ for ($i = 0; true; $i++) {
+ $delta_phi = (($con + $this->e1 * sin(2.0 * $phi) - $this->e2 * sin(4.0 * $phi) + $this->e3 * sin(6.0 * $phi)) / $this->e0) - $phi;
$phi += $delta_phi;
- if( abs( $delta_phi ) <= Proj4php::$common->EPSLN )
+ if (abs($delta_phi) <= Proj4php::$common->EPSLN)
break;
- if( $i >= $max_iter ) {
- Proj4php::reportError( "tmerc:inverse: Latitude failed to converge" );
- return(95);
+ if ($i >= $max_iter) {
+ Proj4php::reportError("tmerc:inverse: Latitude failed to converge");
+ return (95);
}
} // for()
- if( abs( $phi ) < Proj4php::$common->HALF_PI ) {
+ if (abs($phi) < Proj4php::$common->HALF_PI) {
// sincos(phi, &sin_phi, &cos_phi);
- $sin_phi = sin( $phi );
- $cos_phi = cos( $phi );
- $tan_phi = tan( $phi );
- $c = $this->ep2 * pow( $cos_phi, 2 );
- $cs = pow( $c, 2 );
- $t = pow( $tan_phi, 2 );
- $ts = pow( $t, 2 );
- $con = 1.0 - $this->es * pow( $sin_phi, 2 );
- $n = $this->a / sqrt( $con );
+ $sin_phi = sin($phi);
+ $cos_phi = cos($phi);
+ $tan_phi = tan($phi);
+ $c = $this->ep2 * pow($cos_phi, 2);
+ $cs = pow($c, 2);
+ $t = pow($tan_phi, 2);
+ $ts = pow($t, 2);
+ $con = 1.0 - $this->es * pow($sin_phi, 2);
+ $n = $this->a / sqrt($con);
$r = $n * (1.0 - $this->es) / $con;
$d = $x / ($n * $this->k0);
- $ds = pow( $d, 2 );
+ $ds = pow($d, 2);
$lat = $phi - ($n * $tan_phi * $ds / $r) * (0.5 - $ds / 24.0 * (5.0 + 3.0 * $t + 10.0 * $c - 4.0 * $cs - 9.0 * $this->ep2 - $ds / 30.0 * (61.0 + 90.0 * $t + 298.0 * $c + 45.0 * $ts - 252.0 * $this->ep2 - 3.0 * $cs)));
- $lon = Proj4php::$common->adjust_lon( $this->long0 + ($d * (1.0 - $ds / 6.0 * (1.0 + 2.0 * $t + $c - $ds / 20.0 * (5.0 - 2.0 * $c + 28.0 * $t - 3.0 * $cs + 8.0 * $this->ep2 + 24.0 * $ts))) / $cos_phi) );
+ $lon = Proj4php::$common->adjust_lon($this->long0 + ($d * (1.0 - $ds / 6.0 * (1.0 + 2.0 * $t + $c - $ds / 20.0 * (5.0 - 2.0 * $c + 28.0 * $t - 3.0 * $cs + 8.0 * $this->ep2 + 24.0 * $ts))) / $cos_phi));
} else {
- $lat = Proj4php::$common->HALF_PI * Proj4php::$common->sign( $y );
+ $lat = Proj4php::$common->HALF_PI * Proj4php::$common->sign($y);
$lon = $this->long0;
}
}
-
+
$p->x = $lon;
$p->y = $lat;
-
+
return $p;
}
}
diff --git a/src/Projections/Utm.php b/src/Projections/Utm.php
index a12caf7..1f62b49 100644
--- a/src/Projections/Utm.php
+++ b/src/Projections/Utm.php
@@ -2,36 +2,36 @@
namespace Academe\Proj4Php\Projections;
-use Academe\Proj4Php\Proj4Php;
+use Academe\Proj4Php\Proj4 as Proj4Php;
/**
* Author : Julien Moquet
- *
+ *
* Inspired by Proj4php from Mike Adair madairATdmsolutions.ca
- * and Richard Greenwood rich@greenwoodma$p->com
- * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
+ * and Richard Greenwood rich@greenwoodma$p->com
+ * License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
*/
/*******************************************************************************
- NAME TRANSVERSE MERCATOR
-
- PURPOSE: Transforms input longitude and latitude to Easting and
- Northing for the Transverse Mercator projection. The
- longitude and latitude must be in radians. The Easting
- and Northing values will be returned in meters.
-
- ALGORITHM REFERENCES
-
- 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
- Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
- State Government Printing Office, Washington D.C., 1987.
-
- 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
- U.S. Geological Survey Professional Paper 1453 , United State Government
- Printing Office, Washington D.C., 1989.
-*******************************************************************************/
+ * NAME TRANSVERSE MERCATOR
+ *
+ * PURPOSE: Transforms input longitude and latitude to Easting and
+ * Northing for the Transverse Mercator projection. The
+ * longitude and latitude must be in radians. The Easting
+ * and Northing values will be returned in meters.
+ *
+ * ALGORITHM REFERENCES
+ *
+ * 1. Snyder, John P., "Map Projections--A Working Manual", U.S. Geological
+ * Survey Professional Paper 1395 (Supersedes USGS Bulletin 1532), United
+ * State Government Printing Office, Washington D.C., 1987.
+ *
+ * 2. Snyder, John P. and Voxland, Philip M., "An Album of Map Projections",
+ * U.S. Geological Survey Professional Paper 1453 , United State Government
+ * Printing Office, Washington D.C., 1989.
+ *******************************************************************************/
/**
- Initialize Transverse Mercator projection
+ * Initialize Transverse Mercator projection
*/
class Utm {
@@ -41,16 +41,17 @@ class Utm {
/**
*
- * @return void
+ * @return void
*/
public function init() {
- if( !isset($this->zone) ) {
- Proj4php::reportError( "utm:init: zone must be specified for UTM" );
+ if (!isset($this->zone)) {
+ Proj4php::reportError("utm:init: zone must be specified for UTM");
+
return;
}
$this->lat0 = 0.0;
- $this->long0 = ((6 * abs( $this->zone )) - 183) * Proj4php::$common->D2R;
+ $this->long0 = ((6 * abs($this->zone)) - 183) * Proj4php::$common->D2R;
$this->x0 = 500000.0;
$this->y0 = $this->utmSouth ? 10000000.0 : 0.0;
$this->k0 = 0.9996;
@@ -59,19 +60,21 @@ public function init() {
/**
*
* @param type $p
- * @return type
+ *
+ * @return type
*/
- public function forward( $p ) {
- return Proj4php::$proj['tmerc']->forward( $p );
+ public function forward($p) {
+ return Proj4php::$proj['tmerc']->forward($p);
}
/**
*
* @param type $p
- * @return type
+ *
+ * @return type
*/
- public function inverse( $p ) {
- return Proj4php::$proj['tmerc']->inverse( $p );
+ public function inverse($p) {
+ return Proj4php::$proj['tmerc']->inverse($p);
}
}