Ejemplo n.º 1
0
 public function testAsinz()
 {
     $ret = Common::asinz(10);
     $this->assertEquals(1.5707963267949, $ret, "", 1.0E-6);
     $ret = Common::asinz(-100);
     $this->assertEquals(-1.5707963267949, $ret, "", 1.0E-6);
     $ret = Common::asinz(-240);
     $this->assertEquals(-1.5707963267949, $ret, "", 1.0E-6);
     $ret = Common::asinz(-370);
     $this->assertEquals(-1.5707963267949, $ret, "", 1.0E-6);
     $ret = Common::asinz(310);
     $this->assertEquals(1.5707963267949, $ret, "", 1.0E-6);
 }
Ejemplo n.º 2
0
 /**
  *
  * @param type $p
  * @return type 
  */
 public function forward($p)
 {
     $lon = $p->x;
     $lat = $p->y;
     /* Forward equations
        ----------------- */
     $dlon = Common::adjust_lon($lon - $this->long0);
     $x;
     $y;
     if (abs($lat) <= Common::EPSLN) {
         $x = $this->x0 + $this->R * $dlon;
         $y = $this->y0;
     }
     $theta = Common::asinz(2.0 * abs($lat / Common::PI));
     if (abs($dlon) <= Common::EPSLN || abs(abs($lat) - Common::HALF_PI) <= Common::EPSLN) {
         $x = $this->x0;
         if ($lat >= 0) {
             $y = $this->y0 + Common::PI * $this->R * tan(0.5 * $theta);
         } else {
             $y = $this->y0 + Common::PI * $this->R * -tan(0.5 * $theta);
         }
         //  return(OK);
     }
     $al = 0.5 * abs(Common::PI / $dlon - $dlon / Common::PI);
     $asq = $al * $al;
     $sinth = sin($theta);
     $costh = cos($theta);
     $g = $costh / ($sinth + $costh - 1.0);
     $gsq = $g * $g;
     $m = $g * (2.0 / $sinth - 1.0);
     $msq = $m * $m;
     $con = Common::PI * $this->R * ($al * ($g - $msq) + sqrt($asq * ($g - $sq) * ($g - $msq) - ($msq + $asq) * ($gsq - $msq))) / ($msq + $asq);
     if ($dlon < 0) {
         $con = -$con;
     }
     $x = $this->x0 + $con;
     $con = abs($con / (Common::PI * $this->R));
     if ($lat >= 0) {
         $y = $this->y0 + Common::PI * $this->R * sqrt(1.0 - $con * $con - 2.0 * $al * $con);
     } else {
         $y = $this->y0 - Common::PI * $this->R * sqrt(1.0 - $con * $con - 2.0 * $al * $con);
     }
     $p->x = $x;
     $p->y = $y;
     return $p;
 }
Ejemplo n.º 3
0
 /**
  *
  * @param type $p
  * @return type 
  */
 public function inverse($p)
 {
     $p->x -= $this->x0;
     $p->y -= $this->y0;
     $rh = sqrt($p->x * $p->x + $p->y * $p->y);
     if ($rh > 2.0 * Common::HALF_PI * $this->a) {
         Proj4php::reportError("aeqdInvDataError");
         return;
     }
     $z = $rh / $this->a;
     $sinz = sin($z);
     $cosz = cos($z);
     $lon = $this->long0;
     #$lat;
     if (abs($rh) <= Common::EPSLN) {
         $lat = $this->lat0;
     } else {
         $lat = Common::asinz($cosz * $this->sin_p12 + $p->y * $sinz * $this->cos_p12 / $rh);
         $con = abs($this->lat0) - Common::HALF_PI;
         if (abs($con) <= Common::EPSLN) {
             if ($this->lat0 >= 0.0) {
                 $lon = Common::adjust_lon($this->long0 + atan2($p->x, -$p->y));
             } else {
                 $lon = Common::adjust_lon($this->long0 - atan2(-$p->x, $p->y));
             }
         } else {
             $con = $cosz - $this->sin_p12 * sin($lat);
             if (abs($con) < Common::EPSLN && abs($p->x) < Common::EPSLN) {
                 //no-op, just keep the lon value as is
             } else {
                 #$temp = atan2( ($p->x * $sinz * $this->cos_p12 ), ($con * $rh ) ); // $temp is unused !?!
                 $lon = Common::adjust_lon($this->long0 + atan2($p->x * $sinz * $this->cos_p12, $con * $rh));
             }
         }
     }
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }
Ejemplo n.º 4
0
 /**
  *
  * @param type $p
  * @return type 
  */
 public function inverse($p)
 {
     /*
     $rh;  // height above ellipsoid	
     $z;  // angle
     $sinz;
     $cosz; // sin of z and cos of z	
     $temp;
     $con;
     $lon;
     $lat;
     */
     /* Inverse equations
        ----------------- */
     $p->x -= $this->x0;
     $p->y -= $this->y0;
     $rh = sqrt($p->x * $p->x + $p->y * $p->y);
     if ($rh > $this->a + 1.0E-7) {
         Proj4php::reportError("orthoInvDataError");
     }
     $z = Common::asinz($rh / $this->a);
     $sinz = sin($z);
     $cosz = cos($z);
     $lon = $this->long0;
     if (abs($rh) <= Common::EPSLN) {
         $lat = $this->lat0;
     }
     $lat = Common::asinz($cosz * $this->sin_p14 + $p->y * $sinz * $this->cos_p14 / $rh);
     $con = abs($this->lat0) - Common::HALF_PI;
     if (abs(con) <= Common::EPSLN) {
         if ($this->lat0 >= 0) {
             $lon = Common::adjust_lon($this->long0 + atan2($p->x, -$p->y));
         } else {
             $lon = Common::adjust_lon($this->long0 - atan2(-$p->x, $p->y));
         }
     }
     $con = $cosz - $this->sin_p14 * sin($lat);
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }
Ejemplo n.º 5
0
 public function init()
 {
     if (!$this->mode) {
         $this->mode = 0;
     }
     if (!$this->lon1) {
         $this->lon1 = 0;
         $this->mode = 1;
     }
     if (!$this->lon2) {
         $this->lon2 = 0;
     }
     if (!$this->lat2) {
         $this->lat2 = 0;
     }
     /* Place parameters in static storage for common use
        ------------------------------------------------- */
     $temp = $this->b / $this->a;
     $es = 1.0 - pow($temp, 2);
     $e = sqrt($es);
     $this->sin_p20 = sin($this->lat0);
     $this->cos_p20 = cos($this->lat0);
     $this->con = 1.0 - $this->es * $this->sin_p20 * $this->sin_p20;
     $this->com = sqrt(1.0 - $es);
     $this->bl = sqrt(1.0 + $this->es * pow($this->cos_p20, 4.0) / (1.0 - $es));
     $this->al = $this->a * $this->bl * $this->k0 * $this->com / $this->con;
     if (abs($this->lat0) < Common::EPSLN) {
         $this->ts = 1.0;
         $this->d = 1.0;
         $this->el = 1.0;
     } else {
         $this->ts = Common::tsfnz($this->e, $this->lat0, $this->sin_p20);
         $this->con = sqrt($this->con);
         $this->d = $this->bl * $this->com / ($this->cos_p20 * $this->con);
         if ($this->d * $this->d - 1.0 > 0.0) {
             if ($this->lat0 >= 0.0) {
                 $this->f = $this->d + sqrt($this->d * $this->d - 1.0);
             } else {
                 $this->f = $this->d - sqrt($this->d * $this->d - 1.0);
             }
         } else {
             $this->f = $this->d;
         }
         $this->el = $this->f * pow($this->ts, $this->bl);
     }
     //$this->longc=52.60353916666667;
     if ($this->mode != 0) {
         $this->g = 0.5 * ($this->f - 1.0 / $this->f);
         $this->gama = Common::asinz(sin($this->alpha) / $this->d);
         $this->longc = $this->longc - Common::asinz($this->g * tan($this->gama)) / $this->bl;
         /* Report parameters common to format B
            ------------------------------------- */
         //genrpt(azimuth * R2D,"Azimuth of Central Line:    ");
         //cenlon(lon_origin);
         // cenlat(lat_origin);
         $this->con = abs($this->lat0);
         if ($this->con > Common::EPSLN && abs($this->con - Common::HALF_PI) > Common::EPSLN) {
             $this->singam = sin($this->gama);
             $this->cosgam = cos($this->gama);
             $this->sinaz = sin($this->alpha);
             $this->cosaz = cos($this->alpha);
             if ($this->lat0 >= 0) {
                 $this->u = $this->al / $this->bl * atan(sqrt($this->d * $this->d - 1.0) / $this->cosaz);
             } else {
                 $this->u = -($this->al / $this->bl) * atan(sqrt($this->d * $this->d - 1.0) / $this->cosaz);
             }
         } else {
             Proj4php::reportError("omerc:Init:DataError");
         }
     } else {
         $this->sinphi = sin($this->at1);
         $this->ts1 = Common::tsfnz($this->e, $this->lat1, $this->sinphi);
         $this->sinphi = sin($this->lat2);
         $this->ts2 = Common::tsfnz($this->e, $this->lat2, $this->sinphi);
         $this->h = pow($this->ts1, $this->bl);
         $this->l = pow($this->ts2, $this->bl);
         $this->f = $this->el / $this->h;
         $this->g = 0.5 * ($this->f - 1.0 / $this->f);
         $this->j = ($this->el * $this->el - $this->l * $this->h) / ($this->el * $this->el + $this->l * $this->h);
         $this->p = ($this->l - $this->h) / ($this->l + $this->h);
         $this->dlon = $this->lon1 - $this->lon2;
         if ($this->dlon < -Common::PI) {
             $this->lon2 = $this->lon2 - 2.0 * Common::PI;
         }
         if ($this->dlon > Common::PI) {
             $this->lon2 = $this->lon2 + 2.0 * Common::PI;
         }
         $this->dlon = $this->lon1 - $this->lon2;
         $this->longc = 0.5 * ($this->lon1 + $this->lon2) - atan($this->j * tan(0.5 * $this->bl * $this->dlon) / $this->p) / $this->bl;
         $this->dlon = Common::adjust_lon($this->lon1 - $this->longc);
         $this->gama = atan(sin($this->bl * $this->dlon) / $this->g);
         $this->alpha = Common::asinz($this->d * sin($this->gama));
         /* Report parameters common to format A
            ------------------------------------- */
         if (abs($this->lat1 - $this->lat2) <= Common::EPSLN) {
             Proj4php::reportError("omercInitDataError");
             //return(202);
         } else {
             $this->con = abs($this->lat1);
         }
         if ($this->con <= Common::EPSLN || abs($this->con - Common::HALF_PI) <= Common::EPSLN) {
             Proj4php::reportError("omercInitDataError");
             //return(202);
         } else {
             if (abs(abs($this->lat0) - Common::HALF_PI) <= Common::EPSLN) {
                 Proj4php::reportError("omercInitDataError");
                 //return(202);
             }
         }
         $this->singam = sin($this->gam);
         $this->cosgam = cos($this->gam);
         $this->sinaz = sin($this->alpha);
         $this->cosaz = cos($this->alpha);
         if ($this->lat0 >= 0) {
             $this->u = $this->al / $this->bl * atan(sqrt($this->d * $this->d - 1.0) / $this->cosaz);
         } else {
             $this->u = -($this->al / $this->bl) * atan(sqrt($this->d * $this->d - 1.0) / $this->cosaz);
         }
     }
 }
Ejemplo n.º 6
0
 /**
  Transverse Mercator Inverse  -  x/y to long/lat
 */
 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));
         $g = 0.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 = Common::asinz($con);
         if ($temp < 0) {
             $lat = -$lat;
         }
         if ($g == 0 && $h == 0) {
             $lon = $this->long0;
         } else {
             $lon = Common::adjust_lon(atan2($g, $h) + $this->long0);
         }
     } else {
         // ellipsoidal form
         $x = $p->x - $this->x0;
         $y = $p->y - $this->y0;
         $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;
             $phi += $delta_phi;
             if (abs($delta_phi) <= Common::EPSLN) {
                 break;
             }
             if ($i >= $max_iter) {
                 Proj4php::reportError("tmerc:inverse: Latitude failed to converge");
                 return 95;
             }
         }
         // for()
         if (abs($phi) < 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);
             $r = $n * (1.0 - $this->es) / $con;
             $d = $x / ($n * $this->k0);
             $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 = 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 = Common::HALF_PI * Common::sign($y);
             $lon = $this->long0;
         }
     }
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }
Ejemplo n.º 7
0
 /**
  *
  * @param type $p
  * @return type 
  */
 public function inverse($p)
 {
     /*
     $rh;  // Rho 
     $z;  // angle 
     $sinc;
     $cosc;
     $c;
     $lon;
     $lat;
     */
     /* Inverse equations
        ----------------- */
     $p->x = ($p->x - $this->x0) / $this->a;
     $p->y = ($p->y - $this->y0) / $this->a;
     $p->x /= $this->k0;
     $p->y /= $this->k0;
     if ($rh = sqrt($p->x * $p->x + $p->y * $p->y)) {
         $c = atan2($rh, $this->rc);
         $sinc = sin($c);
         $cosc = cos($c);
         $lat = Common::asinz($cosc * $this->sin_p14 + $p->y * $sinc * $this->cos_p14 / $rh);
         $lon = atan2($p->x * sinc, rh * $this->cos_p14 * $cosc - $p->y * $this->sin_p14 * $sinc);
         $lon = Common::adjust_lon($this->long0 + $lon);
     } else {
         $lat = $this->phic0;
         $lon = 0.0;
     }
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }
Ejemplo n.º 8
0
 /**
  * Function to compute phi1, the latitude for the inverse of the Albers Conical Equal-Area projection.
  *
  * @param type $eccent
  * @param type $qs
  * @return $phi or null on Convergence error
  */
 public function phi1z($eccent, $qs)
 {
     $phi = Common::asinz(0.5 * $qs);
     if ($eccent < Common::EPSLN) {
         return $phi;
     }
     $eccnts = $eccent * $eccent;
     for ($i = 1; $i <= 25; ++$i) {
         $sinphi = sin($phi);
         $cosphi = cos($phi);
         $con = $eccent * $sinphi;
         $com = 1.0 - $con * $con;
         $dphi = 0.5 * $com * $com / $cosphi * ($qs / (1.0 - $eccnts) - $sinphi / $com + 0.5 / $eccent * log((1.0 - $con) / (1.0 + $con)));
         $phi = $phi + $dphi;
         if (abs($dphi) <= 1.0E-7) {
             return $phi;
         }
     }
     Proj4php::reportError("aea:phi1z:Convergence error");
     return null;
 }
Ejemplo n.º 9
0
 public function inverse($p)
 {
     /*
     $sin_phi;
     $cos_phi; // sin and cos values
     $al;     // temporary values
     $b;     // temporary values
     $c;     // temporary values
     $con;
     $ml;   // cone constant, small m
     $iflg;    // error flag	
     $lon;
     $lat;
     */
     $p->x -= $this->x0;
     $p->y -= $this->y0;
     $al = $this->ml0 + $p->y / $this->a;
     $iflg = 0;
     if (abs($al) <= 1.0E-7) {
         $lon = $p->x / $this->a + $this->long0;
         $lat = 0.0;
     } else {
         $b = $al * $al + $p->x / $this->a * ($p->x / $this->a);
         $iflg = phi4z($this->es, $this->e0, $this->e1, $this->e2, $this->e3, $this->al, $b, $c, $lat);
         if ($iflg != 1) {
             return $iflg;
         }
         $lon = Common::adjust_lon(Common::asinz($p->x * $c / $this->a) / sin($lat) + $this->long0);
     }
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }