Ejemplo n.º 1
0
 /**
  * Convert this LatLng object into an OSGB grid reference. Note that this
  * function does not take into account the bounds of the OSGB grid -
  * beyond the bounds of the OSGB grid, the resulting OSRef object has no
  * meaning
  *
  * @return the converted OSGB grid reference
  */
 public function toOSRef()
 {
     $airy1830 = new ReferenceEllipsoid();
     $OSGB_F0 = 0.9996012717;
     $N0 = -100000.0;
     $E0 = 400000.0;
     $phi0 = deg2rad(49.0);
     $lambda0 = deg2rad(-2.0);
     $a = $airy1830->maj;
     $b = $airy1830->min;
     $eSquared = $airy1830->ecc;
     $phi = deg2rad($this->lat);
     $lambda = deg2rad($this->lng);
     $phiSinSquared = Trig::sinSquared($phi);
     $phiTanSquared = Trig::tanSquared($phi);
     $E = 0.0;
     $N = 0.0;
     $n = ($a - $b) / ($a + $b);
     $v = $a * $OSGB_F0 * pow(1.0 - $eSquared * $phiSinSquared, -0.5);
     $rho = $a * $OSGB_F0 * (1.0 - $eSquared) * pow(1.0 - $eSquared * $phiSinSquared, -1.5);
     $etaSquared = $v / $rho - 1.0;
     $M = $b * $OSGB_F0 * ((1 + $n + 5.0 / 4.0 * $n * $n + 5.0 / 4.0 * $n * $n * $n) * ($phi - $phi0) - (3 * $n + 3 * $n * $n + 21.0 / 8.0 * $n * $n * $n) * sin($phi - $phi0) * cos($phi + $phi0) + (15.0 / 8.0 * $n * $n + 15.0 / 8.0 * $n * $n * $n) * sin(2.0 * ($phi - $phi0)) * cos(2.0 * ($phi + $phi0)) - 35.0 / 24.0 * $n * $n * $n * sin(3.0 * ($phi - $phi0)) * cos(3.0 * ($phi + $phi0)));
     $I = $M + $N0;
     $II = $v / 2.0 * sin($phi) * cos($phi);
     $III = $v / 24.0 * sin($phi) * pow(cos($phi), 3.0) * (5.0 - $phiTanSquared + 9.0 * $etaSquared);
     $IIIA = $v / 720.0 * sin($phi) * pow(cos($phi), 5.0) * (61.0 - 58.0 * $phiTanSquared + pow(tan($phi), 4.0));
     $IV = $v * cos($phi);
     $V = $v / 6.0 * pow(cos($phi), 3.0) * ($v / $rho - $phiTanSquared);
     $VI = $v / 120.0 * pow(cos($phi), 5.0) * (5.0 - 18.0 * $phiTanSquared + pow(tan($phi), 4.0) + 14 * $etaSquared - 58 * $phiTanSquared * $etaSquared);
     $N = $I + $II * pow($lambda - $lambda0, 2.0) + $III * pow($lambda - $lambda0, 4.0) + $IIIA * pow($lambda - $lambda0, 6.0);
     $E = $E0 + $IV * ($lambda - $lambda0) + $V * pow($lambda - $lambda0, 3.0) + $VI * pow($lambda - $lambda0, 5.0);
     return OSRef::create($E, $N);
 }
Ejemplo n.º 2
0
 /**
  * Convert this grid reference into a latitude and longitude
  *
  * @return
  */
 function toLatLng()
 {
     $airy1830 = new ReferenceEllipsoid();
     $OSGB_F0 = 0.9996012717;
     $N0 = -100000.0;
     $E0 = 400000.0;
     $phi0 = deg2rad(49.0);
     $lambda0 = deg2rad(-2.0);
     $a = $airy1830->maj;
     $b = $airy1830->min;
     $eSquared = $airy1830->ecc;
     $phi = 0.0;
     $lambda = 0.0;
     $E = $this->easting;
     $N = $this->northing;
     $n = ($a - $b) / ($a + $b);
     $M = 0.0;
     $phiPrime = ($N - $N0) / ($a * $OSGB_F0) + $phi0;
     $phiPrimeSecant = Trig::sec($phiPrime);
     $phiPrimeSinSquared = Trig::sinSquared($phiPrime);
     $phiPrimeTanSquared = Trig::tanSquared($phiPrime);
     do {
         $M = $b * $OSGB_F0 * ((1 + $n + 5.0 / 4.0 * $n * $n + 5.0 / 4.0 * $n * $n * $n) * ($phiPrime - $phi0) - (3 * $n + 3 * $n * $n + 21.0 / 8.0 * $n * $n * $n) * sin($phiPrime - $phi0) * cos($phiPrime + $phi0) + (15.0 / 8.0 * $n * $n + 15.0 / 8.0 * $n * $n * $n) * sin(2.0 * ($phiPrime - $phi0)) * cos(2.0 * ($phiPrime + $phi0)) - 35.0 / 24.0 * $n * $n * $n * sin(3.0 * ($phiPrime - $phi0)) * cos(3.0 * ($phiPrime + $phi0)));
         $phiPrime += ($N - $N0 - $M) / ($a * $OSGB_F0);
     } while ($N - $N0 - $M >= 0.001);
     $v = $a * $OSGB_F0 * pow(1.0 - $eSquared * $phiPrimeSinSquared, -0.5);
     $rho = $a * $OSGB_F0 * (1.0 - $eSquared) * pow(1.0 - $eSquared * $phiPrimeSinSquared, -1.5);
     $etaSquared = $v / $rho - 1.0;
     $VII = tan($phiPrime) / (2 * $rho * $v);
     $VIII = tan($phiPrime) / (24.0 * $rho * pow($v, 3.0)) * (5.0 + 3.0 * $phiPrimeTanSquared + $etaSquared - 9.0 * $phiPrimeTanSquared * $etaSquared);
     $IX = tan($phiPrime) / (720.0 * $rho * pow($v, 5.0)) * (61.0 + 90.0 * $phiPrimeTanSquared + 45.0 * $phiPrimeTanSquared * $phiPrimeTanSquared);
     $X = $phiPrimeSecant / $v;
     $XI = $phiPrimeSecant / (6.0 * $v * $v * $v) * ($v / $rho + 2 * $phiPrimeTanSquared);
     $XII = $phiPrimeSecant / (120.0 * pow($v, 5.0)) * (5.0 + 28.0 * $phiPrimeTanSquared + 24.0 * $phiPrimeTanSquared * $phiPrimeTanSquared);
     $XIIA = $phiPrimeSecant / (5040.0 * pow($v, 7.0)) * (61.0 + 662.0 * $phiPrimeTanSquared + 1320.0 * $phiPrimeTanSquared * $phiPrimeTanSquared + 720.0 * $phiPrimeTanSquared * $phiPrimeTanSquared * $phiPrimeTanSquared);
     $phi = $phiPrime - $VII * pow($E - $E0, 2.0) + $VIII * pow($E - $E0, 4.0) - $IX * pow($E - $E0, 6.0);
     $lambda = $lambda0 + $X * ($E - $E0) - $XI * pow($E - $E0, 3.0) + $XII * pow($E - $E0, 5.0) - $XIIA * pow($E - $E0, 7.0);
     return new LatLng(rad2deg($phi), rad2deg($lambda));
 }