Esempio n. 1
0
 /**
  * Convert a latitude and longitude to easting and northing using a Transverse Mercator projection
  * Formula for transformation is taken from OS document
  * "A Guide to Coordinate Systems in Great Britain"
  *
  * @param float $scale scale factor on central meridian
  * @param float $originEasting easting of true origin
  * @param float $originNorthing northing of true origin
  * @param float $originLat latitude of true origin
  * @param float $originLong longitude of true origin
  * @return array
  */
 public function toTransverseMercatorEastingNorthing($scale, $originEasting, $originNorthing, $originLat, $originLong)
 {
     $originLat = deg2rad($originLat);
     $originLong = deg2rad($originLong);
     $lat = deg2rad($this->lat);
     $sinLat = sin($lat);
     $cosLat = cos($lat);
     $tanLat = tan($lat);
     $tanLatSq = pow($tanLat, 2);
     $long = deg2rad($this->lng);
     $n = ($this->refEll->getMaj() - $this->refEll->getMin()) / ($this->refEll->getMaj() + $this->refEll->getMin());
     $nSq = pow($n, 2);
     $nCu = pow($n, 3);
     $v = $this->refEll->getMaj() * $scale * pow(1 - $this->refEll->getEcc() * pow($sinLat, 2), -0.5);
     $p = $this->refEll->getMaj() * $scale * (1 - $this->refEll->getEcc()) * pow(1 - $this->refEll->getEcc() * pow($sinLat, 2), -1.5);
     $hSq = $v / $p - 1;
     $latPlusOrigin = $lat + $originLat;
     $latMinusOrigin = $lat - $originLat;
     $longMinusOrigin = $long - $originLong;
     $M = $this->refEll->getMin() * $scale * ((1 + $n + 1.25 * ($nSq + $nCu)) * $latMinusOrigin - (3 * ($n + $nSq) + 2.625 * $nCu) * sin($latMinusOrigin) * cos($latPlusOrigin) + 1.875 * ($nSq + $nCu) * sin(2 * $latMinusOrigin) * cos(2 * $latPlusOrigin) - 35 / 24 * $nCu * sin(3 * $latMinusOrigin) * cos(3 * $latPlusOrigin));
     $I = $M + $originNorthing;
     $II = $v / 2 * $sinLat * $cosLat;
     $III = $v / 24 * $sinLat * pow($cosLat, 3) * (5 - $tanLatSq + 9 * $hSq);
     $IIIA = $v / 720 * $sinLat * pow($cosLat, 5) * (61 - 58 * $tanLatSq + pow($tanLatSq, 2));
     $IV = $v * $cosLat;
     $V = $v / 6 * pow($cosLat, 3) * ($v / $p - $tanLatSq);
     $VI = $v / 120 * pow($cosLat, 5) * (5 - 18 * $tanLatSq + pow($tanLatSq, 2) + 14 * $hSq - 58 * $tanLatSq * $hSq);
     $E = $originEasting + $IV * $longMinusOrigin + $V * pow($longMinusOrigin, 3) + $VI * pow($longMinusOrigin, 5);
     $N = $I + $II * pow($longMinusOrigin, 2) + $III * pow($longMinusOrigin, 4) + $IIIA * pow($longMinusOrigin, 6);
     return array('E' => $E, 'N' => $N);
 }
Esempio n. 2
0
 /**
  * Convert these coordinates into a latitude, longitude
  * Formula for transformation is taken from OS document
  * "A Guide to Coordinate Systems in Great Britain"
  *
  * @return LatLng
  */
 public function toLatitudeLongitude()
 {
     $lambda = rad2deg(atan2($this->y, $this->x));
     $p = sqrt(pow($this->x, 2) + pow($this->y, 2));
     $phi = atan($this->z / ($p * (1 - $this->refEll->getEcc())));
     do {
         $phi1 = $phi;
         $v = $this->refEll->getMaj() / sqrt(1 - $this->refEll->getEcc() * pow(sin($phi), 2));
         $phi = atan(($this->z + $this->refEll->getEcc() * $v * sin($phi)) / $p);
     } while (abs($phi - $phi1) >= 1.0E-5);
     $h = $p / cos($phi) - $v;
     $phi = rad2deg($phi);
     return new LatLng($phi, $lambda, $h, $this->refEll);
 }