Esempio n. 1
0
 public function forward($p)
 {
     $lon = $p->x;
     $lat = $p->y;
     /* Forward equations
       	-----------------*/
     $dlon = Sourcemap_Proj::adjust_lon($lon - $this->long0);
     if (abs($lat) <= Sourcemap_Proj::EPSLN) {
         $x = $this->x0 + $this->R * $dlon;
         $y = $this->y0;
     }
     $theta = Sourcemap_Proj::asinz(2.0 * abs($lat / Sourcemap_Proj::PI));
     if (abs($dlon) <= Sourcemap_Proj::EPSLN || abs(abs(lat) - Sourcemap_Proj::HALF_PI) <= Sourcemap_Proj::EPSLN) {
         $x = $this->x0;
         if ($lat >= 0) {
             $y = $this->y0 + Sourcemap_Proj::PI * $this->R * tan(0.5 * $theta);
         } else {
             $y = $this->y0 + Sourcemap_Proj::PI * $this->R * -tan(0.5 * $theta);
         }
     }
     $al = 0.5 * abs(Sourcemap_Proj::PI / $dlon - $dlon / Sourcemap_Proj::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 = Sourcemap_Proj::PI * $this->R * ($al * ($g - $msq) + sqrt($asq * ($g - $msq) * ($g - $msq) - ($msq + $asq) * ($gsq - $msq))) / ($msq + $asq);
     if ($dlon < 0) {
         $con = -$con;
     }
     $x = $this->x0 + $con;
     $con = abs($con / (Sourcemap_Proj::PI * $this->R));
     if ($lat >= 0) {
         $y = $this->y0 + Sourcemap_Proj::PI * $this->R * sqrt(1.0 - $con * $con - 2.0 * $al * $con);
     } else {
         $y = $this->y0 - Sourcemap_Proj::PI * $this->R * sqrt(1.0 - $con * $con - 2.0 * $al * $con);
     }
     $p->x = $x;
     $p->y = $y;
     return $p;
 }
Esempio n. 2
0
 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 * Sourcemap_Proj::HALF_PI * $this->a) {
         throw new Exception("Data error");
     }
     $z = $rh / $this->a;
     $sinz = sin(z);
     $cosz = cos(z);
     $lon = $this->long0;
     if (abs($rh) <= Sourcemap_Proj::EPSLN) {
         $lat = $this->lat0;
     } else {
         $lat = Sourcemap_Proj::asinz($cosz * $this->sin_p12 + $p->y * $sinz * $this->cos_p12 / $rh);
         $con = abs($this->lat0) - Sourcemap_Proj::HALF_PI;
         if (abs($con) <= Sourcemap_Proj::EPSLN) {
             if ($lat0 >= 0.0) {
                 $lon = Sourcemap_Proj::adjust_lon($this->long0 + atan2($p->x, -$p->y));
             } else {
                 $lon = Sourcemap_Proj::adjust_lon($this->long0 - atan2(-$p->x, $p->y));
             }
         } else {
             $con = $cosz - $this->sin_p12 * sin($lat);
             if (abs($con) < Sourcemap_Proj::EPSLN && abs($p->x) < Sourcemap_Proj::EPSLN) {
                 // pass
             } else {
                 $temp = atan2($p->x * $sinz * $this->cos_p12, $con * $rh);
                 $lon = Sourcemap_Proj::adjust_lon($this->long0 + atan2($p->x * $sinz * $this->cos_p12, $con * $rh));
             }
         }
     }
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }
Esempio n. 3
0
 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 = Sourcemap_Proj::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 = Sourcemap_Proj::adjust_lon($this->long0 + lon);
     } else {
         $lat = $this->phic0;
         $lon = 0.0;
     }
     $p->x = $lon;
     $p->y = $lat;
     return p;
 }
Esempio n. 4
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) < Sourcemap_Proj::EPSLN) {
         $this->ts = 1.0;
         $this->d = 1.0;
         $this->el = 1.0;
     } else {
         $this->ts = Sourcemap_Proj::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 = Sourcemap_Proj::asinz(sin($this->alpha) / $this->d);
         $this->longc = $this->longc - Sourcemap_Proj::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 > Sourcemap_Proj::EPSLN && abs($this->con - Sourcemap_Proj::HALF_PI) > Sourcemap_Proj::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 {
             throw new Exception("Data error.");
         }
     } else {
         $this->sinphi = sin($this->at1);
         $this->ts1 = Sourcemap_Proj::tsfnz($this->e, $this->lat1, $this->sinphi);
         $this->sinphi = sin($this->lat2);
         $this->ts2 = Sourcemap_Proj::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 < -Sourcemap_Proj::PI) {
             $this->lon2 = $this->lon2 - 2.0 * Sourcemap_Proj::PI;
         }
         if ($this->dlon > Sourcemap_Proj::PI) {
             $this->lon2 = $this->lon2 + 2.0 * Sourcemap_Proj::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 = Sourcemap_Proj::adjust_lon($this->lon1 - $this->longc);
         $this->gama = atan(sin($this->bl * $this->dlon) / $this->g);
         $this->alpha = Sourcemap_Proj::asinz($this->d * sin($this->gama));
         /* Report parameters common to format A
            -------------------------------------*/
         if (abs($this->lat1 - $this->lat2) <= Sourcemap_Proj::EPSLN) {
             throw new Exception("Data error.");
         } else {
             $this->con = abs($this->lat1);
         }
         if ($this->con <= Sourcemap_Proj::EPSLN || abs($this->con - Sourcemap_Proj::HALF_PI) <= Sourcemap_Proj::EPSLN) {
             throw new Exception("Data error.");
         } else {
             if (abs(abs($this->lat0) - Sourcemap_Proj::HALF_PI) <= Sourcemap_Proj::EPSLN) {
                 throw new Exception("Data error.");
             }
         }
         $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);
         }
     }
 }
Esempio n. 5
0
 public function inverse($p)
 {
     #        $sin_phi, $cos_phi;    /* sin and cos value				*/
     #        $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 = $this->phi4z($this->es, $this->e0, $this->e1, $this->e2, $this->e3, $this->al, $b, $c, $lat);
         if ($iflg != 1) {
             return $iflg;
         }
         $lon = Sourcemap_Proj::adjust_lon(Sourcemap_Proj::asinz($p->x * $c / $this->a) / sin($lat) + $this->long0);
     }
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }
Esempio n. 6
0
 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) {
         throw new Exception("orthoInvDataError");
     }
     $z = Sourcemap_Proj::asinz($rh / $this->a);
     $sinz = sin($z);
     $cosz = cos($z);
     $lon = $this->long0;
     if (abs($rh) <= Sourcemap_Proj::EPSLN) {
         $lat = $this->lat0;
     }
     $lat = Sourcemap_Proj::asinz($cosz * $this->sin_p14 + $p->y * $sinz * $this->cos_p14 / $rh);
     $con = abs($lat0) - Sourcemap_Proj::HALF_PI;
     if (abs($con) <= Sourcemap_Proj::EPSLN) {
         if ($this->lat0 >= 0) {
             $lon = Sourcemap_Proj::adjust_lon($this->long0 + atan2($p->x, -$p->y));
         } else {
             $lon = Sourcemap_Proj::adjust_lon($this->long0 - atan2(-$p->x, $p->y));
         }
     }
     $con = $cosz - $this->sin_p14 * sin($lat);
     if (abs($con) >= Sourcemap_Proj::EPSLN || abs($x) >= Sourcemap_Proj::EPSLN) {
         $lon = Sourcemap_Proj::adjust_lon($this->long0 + atan2($p->x * $sinz * $this->cos_p14, $con * $rh));
     }
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }
Esempio n. 7
0
 public function phi1z($eccent, $qs)
 {
     $phi = Sourcemap_Proj::asinz(0.5 * $qs);
     if (eccent < Sourcemap_Proj::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;
         }
     }
     throw new Exception("Convergence error.");
 }
Esempio n. 8
0
 public function inverse($p)
 {
     #$con, $phi;  /* temporary angles       */
     #$delta_phi; /* difference between longitudes    */
     $max_iter = 6;
     /* maximun number of iterations */
     if ($this->sphere) {
         /* 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 = Sourcemap_Proj::asinz($con);
         if ($temp < 0) {
             $lat = -$lat;
         }
         if ($g == 0 && $h == 0) {
             $lon = $this->long0;
         } else {
             $lon = Sourcemap_Proj::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) <= Sourcemap_Proj::EPSLN) {
                 break;
             }
             if ($i >= $max_iter) {
                 throw new Exception("Latitude failed to converge.");
                 #return(95);
             }
         }
         if (abs($phi) < Sourcemap_Proj::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 = Sourcemap_Proj::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 = Sourcemap_Proj::HALF_PI * Sourcemap_Proj::sign($y);
             $lon = $this->long0;
         }
     }
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }