Exemplo n.º 1
0
 public function inverse($p)
 {
     /* Inverse equations
        -----------------*/
     $p->x -= $this->x0;
     //~ $p->y -= $this->y0;
     $arg = $p->y / (1.4142135623731 * $this->a);
     /* Because of division by zero problems, 'arg' can not be 1.0.  Therefore
        a number very close to one is used instead.
        -------------------------------------------------------------------*/
     if (abs($arg) > 0.999999999999) {
         $arg = 0.999999999999;
     }
     $theta = asin($arg);
     $lon = Sourcemap_Proj::adjust_lon($this->long0 + $p->x / (0.900316316158 * $this->a * cos($theta)));
     if ($lon < -Sourcemap_Proj::PI) {
         $lon = -Sourcemap_Proj::PI;
     }
     if ($lon > Sourcemap_Proj::PI) {
         $lon = Sourcemap_Proj::PI;
     }
     $arg = (2.0 * $theta + sin(2.0 * $theta)) / Sourcemap_Proj::PI;
     if (abs($arg) > 1.0) {
         $arg = 1.0;
     }
     $lat = asin($arg);
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }
Exemplo n.º 2
0
 public function action_get()
 {
     $get = Validate::factory($_GET);
     $get->rule('latitude', 'numeric')->rule('longitude', 'numeric')->rule('placename', 'max_length', array(128))->rule('placename', 'not_empty')->rule('supplychain_id', 'numeric')->rule('projection', 'regex', array('/epsg:[\\w\\d]+/i'))->filter(true, 'trim');
     if ($get->check()) {
         $get = $get->as_array();
         $proj = 'EPSG:4326';
         // wgs84, by default
         if (isset($_GET['projection'])) {
             $proj = $get['projection'];
         }
         if (isset($_GET['latitude'], $_GET['longitude'])) {
             $pt = new Sourcemap_Proj_Point($get['latitude'], $get['longitude']);
         } elseif (isset($_GET['placename'])) {
             $results = Sourcemap_Geocoder::geocode($get['placename']);
             if ($results) {
                 $r = $results[0];
                 $pt = new Sourcemap_Proj_Point($r->longitude, $r->latitude);
             } else {
                 return $this->_internal_server_error('Could not geocode placename.');
             }
         } else {
             return $this->_bad_request('Coordinates or placename required.');
         }
         $pt = Sourcemap_Proj::transform($proj, 'EPSG:900913', $pt);
     } else {
         return $this->_bad_request('Invalid parameters.');
     }
     $this->response = ORM::factory('stop')->nearby($pt);
 }
Exemplo n.º 3
0
 public function inverse($p)
 {
     $x = $p->x;
     $y = $p->y;
     $p->x = Sourcemap_Proj::adjust_lon($this->long0 + ($x - $this->x0) / ($this->a * $this->rc));
     $p->y = Sourcemap_Proj::adjust_lat($this->lat0 + ($y - $this->y0) / $this->a);
     return $p;
 }
Exemplo n.º 4
0
 public function inverse($p)
 {
     $p->x -= $this->x0;
     $p->y -= $this->y0;
     $lon = Sourcemap_Proj::adjust_lon($this->long0 + $p->x / $this->a);
     $lat = 2.5 * (atan(exp(0.8 * $p->y / $this->a)) - Sourcemap_Proj::PI / 4.0);
     $p->x = $lon;
     $p->y = $lat;
     return p;
 }
Exemplo n.º 5
0
 public function inverse($p)
 {
     $p->x -= $this->x0;
     $p->y -= $this->y0;
     $lon = Sourcemap_Proj::adjust_lon($this->long0 + $p->x / $this->a / cos($this->lat_ts));
     $lat = asin($p->y / $this->a * cos($this->lat_ts));
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }
Exemplo n.º 6
0
 public function inverse($p)
 {
     $x = $p->x;
     $y = $p->y;
     $L = atan(Sourcemap_Proj::sinh(($x - $this->xs) / $this->n2) / cos(($y - $this->ys) / $this->n2));
     $lat1 = asin(sin(($y - $this->ys) / $this->n2) / Sourcemap_Proj::cosh(($x - $this->xs) / $this->n2));
     $LC = Sourcemap_Proj::latiso(0.0, $lat1, sin($lat1));
     $p->x = $this->lc + $L / $this->rs;
     $p->y = Sourcemap_Proj::invlatiso($this->e, ($LC - $this->cp) / $this->rs);
     return $p;
 }
Exemplo n.º 7
0
 public function inverse($p)
 {
     $p->x -= $this->x0;
     $p->y -= $this->y0;
     $lat = $p->y / $this->a;
     if (abs($lat) > Sourcemap_Proj::HALF_PI) {
         throw new Exception("Data error: lat out of range.");
     }
     $lon = Sourcemap_Proj::adjust_lon($this->long0 + $p->x / ($this->a * cos($this->lat0)));
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }
Exemplo n.º 8
0
 public function action_get()
 {
     header('Content-Type: text/plain');
     #print_r(new Sourcemap_Proj_Projection('EPSG:900913'));
     #print_r(new Sourcemap_Proj_Projection('EPSG:4326'));
     #print_r(Sourcemap_Proj_Point::parse_coords('x=1,y=2'));
     $x = isset($_GET['x']) ? $_GET['x'] : null;
     $y = isset($_GET['y']) ? $_GET['y'] : null;
     $src = isset($_GET['src']) ? $_GET['src'] : 'WGS84';
     $dest = isset($_GET['dest']) ? $_GET['dest'] : 'WGS84';
     if ($x == null || $y == null) {
         return $this->_bad_request('Invalid x/y combination.');
     }
     #$this->response = Sourcemap_Proj::transform('WGS84', 'EPSG:900913', new Sourcemap_Proj_Point(-76.640625, 49.921875));
     $this->response = Sourcemap_Proj::transform($src, $dest, new Sourcemap_Proj_Point($x, $y));
 }
Exemplo n.º 9
0
 public function inverse($p)
 {
     /* Inverse equations
        -----------------*/
     $p->x -= $this->x0;
     $p->y -= $this->y0;
     $lat = $p->y / $this->R;
     if (abs($lat) > Sourcemap_Proj::HALF_PI) {
         throw new Exception("Data error.");
     }
     $temp = abs($lat) - Sourcemap_Proj::HALF_PI;
     if (abs($temp) > Sourcemap_Proj::EPSLN) {
         $temp = $this->long0 + $p->x / ($this->R * cos($lat));
         $lon = Sourcemap_Proj::adjust_lon($temp);
     } else {
         $lon = $this->long0;
     }
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }
Exemplo n.º 10
0
 public function inverse($p)
 {
     $DEL_TOL = 1.0E-14;
     $lon = $p->x / $this->C;
     $lat = $p->y;
     $num = pow(tan(0.5 * $lat + Sourcemap_Proj::FORTPI) / $this->K, 1.0 / $this->C);
     for ($i = Sourcemap_Proj::MAX_ITER; $i > 0; --$i) {
         $lat = 2.0 * atan($num * Sourcemap_Proj::srat($this->e * sin($p->y), -0.5 * $this->e)) - Sourcemap_Proj::HALF_PI;
         if (abs($lat - $p->y) < $DEL_TOL) {
             break;
         }
         $p->y = $lat;
     }
     /* convergence failed */
     if (!$i) {
         throw new Exception("Convergence failed.");
     }
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }
Exemplo n.º 11
0
 public static function get_sc_bbox($raw_sc)
 {
     $min_lat = $max_lat = $min_lon = $max_lon = null;
     foreach ($raw_sc->stops as $i => $stop) {
         if ($pt = Sourcemap_Proj_Point::fromGeometry($stop->geometry)) {
             $pt = Sourcemap_Proj::transform('EPSG:900913', 'WGS84', $pt);
             if ($min_lat === null || $pt->y < $min_lat) {
                 $min_lat = $pt->y;
             }
             if ($max_lat === null || $pt->y > $max_lat) {
                 $max_lat = $pt->y;
             }
             if ($min_lon === null || $pt->x < $min_lon) {
                 $min_lon = $pt->x;
             }
             if ($max_lon === null || $pt->x > $max_lon) {
                 $max_lon = $pt->x;
             }
         }
     }
     $bbox = array($min_lat, $min_lon, $max_lat, $max_lon);
     return $bbox;
 }
Exemplo n.º 12
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;
 }
Exemplo n.º 13
0
 public static function make($supplychain)
 {
     $geojson = array("type" => "FeatureCollection", "features" => array());
     foreach ($supplychain->attributes as $k => $v) {
         $geojson["properties"][$k] = $v;
     }
     foreach (array_merge($supplychain->stops, $supplychain->hops) as $item) {
         $geom = Sourcemap_Wkt::read($item->geometry);
         switch ($geom[0]) {
             case "point":
                 $pt = new Sourcemap_Proj_Point($geom[1][0], $geom[1][1]);
                 $pt = Sourcemap_Proj::transform('EPSG:900913 ', 'WGS84', $pt);
                 $geometry = array("type" => "Point", "coordinates" => array($pt->x, $pt->y));
                 break;
             case "multilinestring":
                 $return = array();
                 array_walk_recursive($geom[1], function ($a) use(&$return) {
                     $return[] = $a;
                 });
                 $pt1 = new Sourcemap_Proj_Point($return[2], $return[3]);
                 $pt2 = new Sourcemap_Proj_Point($return[5], $return[6]);
                 $pt1 = Sourcemap_Proj::transform('EPSG:900913 ', 'WGS84', $pt1);
                 $pt2 = Sourcemap_Proj::transform('EPSG:900913 ', 'WGS84', $pt2);
                 $geometry = array("type" => "LineString", "coordinates" => array(array($pt1->x, $pt1->y), array($pt2->x, $pt2->y)));
                 break;
             default:
                 break;
         }
         $props = array();
         foreach ($item->attributes as $k => $v) {
             $props[$k] = $v;
         }
         array_push($geojson["features"], array("type" => "Feature", "geometry" => $geometry, "properties" => $props));
     }
     return json_encode($geojson);
 }
Exemplo n.º 14
0
 public function inverse($p)
 {
     $p->x = ($p->x - $this->x0) / $this->a;
     /* descale and de-offset */
     $p->y = ($p->y - $this->y0) / $this->a;
     $p->x /= $this->k0;
     $p->y /= $this->k0;
     if ($rho = sqrt($p->x * $p->x + $p->y * $p->y)) {
         $c = 2.0 * atan2($rho, $this->R2);
         $sinc = sin($c);
         $cosc = cos($c);
         $lat = asin($cosc * $this->sinc0 + $p->y * $sinc * $this->cosc0 / $rho);
         $lon = atan2($p->x * $sinc, $rho * $this->cosc0 * $cosc - $p->y * $this->sinc0 * $sinc);
     } else {
         $lat = $this->phic0;
         $lon = 0.0;
     }
     $p->x = $lon;
     $p->y = $lat;
     $p = parent::inverse($p);
     $p->x = Sourcemap_Proj::adjust_lon($p->x + $this->long0);
     /* adjust longitude to CM */
     return $p;
 }
Exemplo n.º 15
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;
 }
Exemplo n.º 16
0
 public static function get_image($raw_sc)
 {
     $params = array('size' => '1024x768', 'styleid' => 4993, 'format' => 'png32');
     $markers = array();
     $paths = array();
     $stop_dict = array();
     $min_lat = $max_lat = $min_lon = $max_lon = null;
     foreach ($raw_sc->stops as $i => $stop) {
         # TODO: address hard limit of 100 stops.
         if ($pt = Sourcemap_Proj_Point::fromGeometry($stop->geometry)) {
             $pt = Sourcemap_Proj::transform('EPSG:900913', 'WGS84', $pt);
             if ($min_lat === null || $pt->y < $min_lat) {
                 $min_lat = $pt->y;
             }
             if ($max_lat === null || $pt->y > $max_lat) {
                 $max_lat = $pt->y;
             }
             if ($min_lon === null || $pt->x < $min_lon) {
                 $min_lon = $pt->x;
             }
             if ($max_lon === null || $pt->x > $max_lon) {
                 $max_lon = $pt->x;
             }
             $color = '008000';
             if (isset($stop->attributes, $stop->attributes->color)) {
                 $stcolor = $stop->attributes->color;
                 if (preg_match('/^#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})$/', $stcolor)) {
                     $color = ltrim($stcolor, '#');
                 }
             }
             $sz = 16;
             if (isset($stop->attributes, $stop->attributes->size) && is_numeric($stop->attributes->size)) {
                 $sz = (int) $stop->attributes->size;
                 $sz += 16;
             }
             #$markerimg = "http://chart.apis.google.com/chart?cht=it&chs={$sz}x{$sz}&chco=$color&chx=ffffff,8&chf=bg,s,00000000&ext=.png";
             $markerimg = "http://chart.apis.google.com/chart?cht=it&chs={$sz}x{$sz}&chco={$color}&chx=ffffff,8&chf=bg,s,00000000&ext=.png";
             $markers[] = 'url:' . urlencode($markerimg) . '|opacity:0.85|' . $pt->y . ',' . $pt->x;
         }
         $stop_dict[$stop->local_stop_id] = $stop;
     }
     $bbox = array($min_lat, $min_lon, $max_lat, $max_lon);
     foreach ($raw_sc->hops as $i => $hop) {
         $geom = Sourcemap_Wkt::read($hop->geometry);
         $fromst = Sourcemap_Proj_Point::fromGeometry($stop_dict[$hop->from_stop_id]->geometry);
         $fromst = Sourcemap_Proj::transform('EPSG:900913', 'WGS84', $fromst);
         $tost = Sourcemap_Proj_Point::fromGeometry($stop_dict[$hop->to_stop_id]->geometry);
         $tost = Sourcemap_Proj::transform('EPSG:900913', 'WGS84', $tost);
         $bentpts = self::make_bent_line($fromst, $tost);
         $pts = array();
         foreach ($bentpts as $bpi => $bp) {
             $pts[] = sprintf("%f,%f", $bp->y, $bp->x);
         }
         $paths[] = 'color:green|weight:3|opacity:1|' . join('|', $pts);
     }
     $ps = array();
     foreach ($params as $k => $v) {
         $ps[] = "{$k}={$v}";
     }
     foreach ($markers as $i => $m) {
         $ps[] = 'marker=' . $m;
     }
     foreach ($paths as $i => $p) {
         $ps[] = 'path=' . $p;
     }
     if ($bbox[0] || $bbox[1] || $bbox[2]) {
         $ps[] = sprintf("bbox=%s", join(',', $bbox));
     } else {
         $ps[] = 'center=0,0';
         $ps[] = 'zoom=2';
     }
     $ps = join($ps, '&');
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, self::get_base_url());
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $ps);
     return curl_exec($ch);
 }
Exemplo n.º 17
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.");
 }
Exemplo n.º 18
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;
 }
Exemplo n.º 19
0
 public function inverse($p)
 {
     #        $delta_lon;	/* Delta longitude (Given longitude - center 	*/
     #        $theta;		/* angle					*/
     #        $delta_theta;	/* adjusted longitude				*/
     #        $sin_phi, $cos_phi;/* sin and cos value				*/
     #        $b;		/* temporary values				*/
     #        $c, $t, $tq;	/* temporary values				*/
     #        $con, $n, $ml;	/* cone constant, small m			*/
     #        $vs, $us, $q, $s, $ts1;
     #        $vl, $ul, $bs;
     #        $dlon;
     #        $flag;
     /* Inverse equations
        -----------------*/
     $p->x -= $this->x0;
     $p->y -= $this->y0;
     $flag = 0;
     $vs = $p->x * $this->cosaz - $p->y * $this->sinaz;
     $us = $p->y * $this->cosaz + $p->x * $this->sinaz;
     $us = $us + $this->u;
     $q = exp(-$this->bl * $vs / $this->al);
     $s = 0.5 * ($q - 1.0 / $q);
     $t = 0.5 * ($q + 1.0 / $q);
     $vl = sin($this->bl * $us / $this->al);
     $ul = ($vl * $this->cosgam + $s * $this->singam) / $t;
     if (abs(abs($ul) - 1.0) <= Sourcemap_Proj::EPSLN) {
         $lon = $this->longc;
         if ($ul >= 0.0) {
             $lat = Sourcemap_Proj::HALF_PI;
         } else {
             $lat = -Sourcemap_Proj::HALF_PI;
         }
     } else {
         $con = 1.0 / $this->bl;
         $ts1 = pow($this->el / sqrt((1.0 + $ul) / (1.0 - $ul)), $con);
         $lat = Sourcemap_Proj::phi2z($this->e, $ts1);
         //if (flag != 0)
         //return(flag);
         //~ con = cos($this->bl * us /al);
         $theta = $this->longc - atan2($s * $this->cosgam - $vl * $this->singam, $con) / $this->bl;
         $lon = Sourcemap_Proj::adjust_lon($theta);
     }
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }
Exemplo n.º 20
0
 public static function csv2stops($csv, $o = array())
 {
     $options = array();
     foreach (self::$default_options as $k => $v) {
         $options[$k] = isset($o[$k]) ? $o[$k] : $v;
     }
     extract($options);
     $csv = Sourcemap_Csv::parse($csv);
     $data = array();
     $raw_headers = array();
     if ($headers) {
         $raw_headers = array_shift($csv);
         $headers = array();
     }
     for ($i = 0; $i < count($raw_headers); $i++) {
         if (strlen(trim($raw_headers[$i]))) {
             $headers[] = strtolower($raw_headers[$i]);
         }
     }
     foreach ($csv as $ri => $row) {
         if ($headers && is_array($headers)) {
             $record = array();
             foreach ($headers as $hi => $k) {
                 if (isset($row[$hi])) {
                     $record[$k] = $row[$hi];
                 }
             }
         } else {
             $record = $row;
         }
         if ($record) {
             $data[] = $record;
         }
     }
     if ($headers) {
         if (is_null($latcol) || is_null($loncol)) {
             foreach ($headers as $i => $h) {
                 if (is_null($latcol) && preg_match('/^lat(itude)?$/i', $h)) {
                     $latcol = $h;
                 } elseif (is_null($loncol) && preg_match('/^(lng)|(lon(g(itude)?)?)$/i', $h)) {
                     $loncol = $h;
                 } elseif (is_null($addresscol) && preg_match('/place ?name/i', $h) || preg_match('/address/i', $h)) {
                     $addresscol = $h;
                 }
             }
             if (is_null($latcol) || is_null($loncol)) {
                 $latcol = $loncol = null;
                 if (is_null($addresscol)) {
                     return $this->_bad_request('Missing lat/lon or address column index.');
                 }
             }
         }
         if (is_null($idcol)) {
             foreach ($headers as $i => $h) {
                 if (preg_match('/^id$/i', $h)) {
                     $idcol = $h;
                     break;
                 }
             }
         }
     }
     $stops = array();
     foreach ($data as $i => $record) {
         if (is_null($addresscol)) {
             if (!isset($record[$latcol], $record[$loncol])) {
                 throw new Exception('Missing lat/lon field (record #' . ($i + 1) . ').');
             }
         } else {
             if (!isset($record[$addresscol])) {
                 throw new Exception('Missing address field (record #' . ($i + 1) . ').');
             }
         }
         if ($idcol && !isset($record[$idcol])) {
             throw new Exception('Missing id field (record #' . ($i + 1) . ').');
         } elseif ($idcol && !is_numeric($record[$idcol])) {
             throw new Exception('Id value must be an integer.');
         }
         $new_stop = array('local_stop_id' => $idcol ? (int) $record[$idcol] : $i + 1, 'attributes' => array());
         $lat = null;
         $lon = null;
         foreach ($record as $k => $v) {
             if ($k == $latcol || $k == $loncol) {
                 if ($k == $latcol) {
                     $lat = $v;
                 } else {
                     $lon = $v;
                 }
                 continue;
             } elseif ($k == $addresscol) {
                 if ($results = Sourcemap_Geocoder::geocode($v)) {
                     $result = $results[0];
                     $lat = (double) $result->lat;
                     $lon = (double) $result->lng;
                     if (!isset($record['placename'])) {
                         $new_stop['attributes']['placename'] = $result->placename;
                     }
                 } else {
                     throw new Exception('Could not geocode: "' . $v . '".');
                 }
             }
             $new_stop['attributes'][$k] = $v;
         }
         if (!isset($new_stop['attributes']['placename']) && $lat && $lon) {
             $results = Sourcemap_Geocoder::geocode(new Sourcemap_Proj_Point($lon, $lat));
             if ($results) {
                 $result = $results[0];
                 //$lat = $result->lat;
                 //$lon = $result->lng;
                 if (!isset($record['placename'])) {
                     $new_stop['attributes']['placename'] = $result->placename;
                 }
             }
         }
         if (is_null($lon) || is_null($lat)) {
             throw new Exception('No lat/lon.');
         }
         $from_pt = new Sourcemap_Proj_Point($lon, $lat);
         $new_stop['geometry'] = Sourcemap_Proj::transform('WGS84', 'EPSG:900913', $from_pt)->toGeometry();
         $stops[] = (object) $new_stop;
     }
     return $stops;
 }
Exemplo n.º 21
0
 public function render()
 {
     $this->stitch_tiles();
     list($nwxt, $nwyt, $throwaway) = $this->tile_numbers[0][0];
     #$se = new Sourcemap_Proj_Point($this->tiles_bounds[3], $this->tiles_bounds[2]);
     #list($sext,$seyt) = Cloudmade_Tiles::get_tile_number($se->y, $se->x, $this->zoom);
     $stops = array();
     foreach ($this->raw_sc->stops as $stop) {
         $pt = Sourcemap_Proj_Point::fromGeometry($stop->geometry);
         $pt = Sourcemap_Proj::transform('EPSG:900913', 'WGS84', $pt);
         $lon = $pt->x;
         $lat = $pt->y;
         list($xt, $yt) = Cloudmade_Tiles::get_tile_number($lat, $lon, $this->zoom);
         list($xto, $yto) = Cloudmade_Tiles::get_tile_offset($lat, $lon, $this->zoom);
         $x = ($xt - $nwxt) * 256 + $xto;
         $y = ($yt - $nwyt) * 256 + $yto;
         $stops[$stop->local_stop_id] = (object) array('stop' => $stop, 'x' => $x, 'y' => $y);
     }
     foreach ($this->raw_sc->hops as $i => $hop) {
         $from = $stops[$hop->from_stop_id];
         $to = $stops[$hop->to_stop_id];
         $this->draw_hop2($hop, $from, $to);
         //$this->draw_hop($hop, $from, $to);
     }
     foreach ($stops as $sid => $st) {
         $this->draw_stop($st->stop, $st->x, $st->y);
     }
     /*ob_start();
       imagepng($this->tiles_img);
       $imgdata = ob_get_contents();
       ob_end_clean();
       return $imgdata;*/
     return $this->tiles_img;
 }
Exemplo n.º 22
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;
 }
Exemplo n.º 23
0
 public function inverse($pt)
 {
     $x = ($pt->x - $this->_proj->x0) / $this->_proj->k0;
     $y = $this->_proj->rh - ($pt->y - $this->_proj->y0) / $this->_proj->k0;
     if ($this->_proj->ns > 0) {
         $rh1 = sqrt($x * $x + $y * $y);
         $con = 1.0;
     } else {
         $rh1 = -sqrt(x * x + y * y);
         $con = -1.0;
     }
     $theta = 0.0;
     if ($rh1 != 0) {
         $theta = atan2($con * $x, $con * $y);
     }
     if ($rh1 != 0 || $this->_proj->ns > 0.0) {
         $con = 1.0 / $this->_proj->ns;
         $ts = pow($rh1 / ($this->_proj->a * $this->_proj->f0), $con);
         $lat = Sourcemap_Proj::phi2z($this->_proj->e, $ts);
         if ($lat == -9999) {
             return null;
         }
     } else {
         $lat = -Sourcemap_Proj::HALF_PI;
     }
     $lon = Sourcemap_Proj::adjust_lon($theta / $this->_proj->ns + $this->_proj->long0);
     $pt->x = $lon;
     $pt->y = $lat;
     return $pt;
 }
Exemplo n.º 24
0
 public function inverse($p)
 {
     /* inverse equations
       	-----------------*/
     $p->x -= $this->x0;
     $p->y -= $this->y0;
     $con = Sourcemap_Proj::PI * $this->R;
     $xx = $p->x / $con;
     $yy = $p->y / $con;
     $xys = $xx * $xx + $yy * $yy;
     $c1 = -abs($yy) * (1.0 + $xys);
     $c2 = $c1 - 2.0 * $yy * $yy + $xx * $xx;
     $c3 = -2.0 * $c1 + 1.0 + 2.0 * $yy * $yy + $xys * $xys;
     $d = $yy * $yy / $c3 + (2.0 * $c2 * $c2 * $c2 / $c3 / $c3 / $c3 - 9.0 * $c1 * $c2 / $c3 / $c3) / 27.0;
     // seriously?
     $a1 = ($c1 - $c2 * $c2 / 3.0 / $c3) / $c3;
     $m1 = 2.0 * sqrt(-$a1 / 3.0);
     $con = 3.0 * $d / $a1 / $m1;
     if (abs($con) > 1.0) {
         if ($con >= 0.0) {
             $con = 1.0;
         } else {
             $con = -1.0;
         }
     }
     $th1 = acos($con) / 3.0;
     if ($p->y >= 0) {
         $lat = (-$m1 * cos($th1 + Sourcemap_Proj::PI / 3.0) - $c2 / 3.0 / $c3) * Sourcemap_Proj::PI;
     } else {
         $lat = -(-$m1 * cos($th1 + PI / 3.0) - $c2 / 3.0 / $c3) * Sourcemap_Proj::PI;
     }
     if (abs($xx) < Sourcemap_Proj::EPSLN) {
         $lon = $this->long0;
     }
     $lon = Sourcemap_Proj::adjust_lon($this->long0 + Sourcemap_Proj::PI * ($xys - 1.0 + sqrt(1.0 + 2.0 * ($xx * $xx - $yy * $yy) + $xys * $xys)) / 2.0 / $xx);
     $p->x = $lon;
     $p->y = $lat;
     return $p;
 }
Exemplo n.º 25
0
function geo_proj_transform($pt, $from, $to)
{
    $src_pt = new Sourcemap_Proj_Point($pt['longitude'], $pt['latitude']);
    $new_pt = Sourcemap_Proj::transform($from, $to, $src_pt);
    return array('latitude' => $new_pt->y, 'longitude' => $new_pt->x);
}
Exemplo n.º 26
0
 public function inverse($p)
 {
     $x = ($p->x - $this->x0) / $this->a;
     /* descale and de-offset */
     $y = ($p->y - $this->y0) / $this->a;
     $tp = 0.0;
     $phi_l = 0.0;
     $halfe = 0.0;
     $pi2 = 0.0;
     if ($this->sphere) {
         $rh = sqrt($x * $x + $y * $y);
         $c = 2.0 * atan($rh / $this->akm1);
         $sinc = sin($c);
         $cosc = cos($c);
         $lon = 0.0;
         switch ($this->mode) {
             case $this->EQUIT:
                 if (abs($rh) <= Sourcemap_Proj::EPSLN) {
                     $lat = 0.0;
                 } else {
                     $lat = asin($y * $sinc / $rh);
                 }
                 if ($cosc != 0.0 || $x != 0.0) {
                     $lon = atan2($x * $sinc, $cosc * $rh);
                 }
                 break;
             case $this->OBLIQ:
                 if (abs($rh) <= Sourcemap_Proj::EPSLN) {
                     $lat = $this->phi0;
                 } else {
                     $lat = asin($cosc * $sinph0 + $y * $sinc * $cosph0 / $rh);
                 }
                 $c = $cosc - $sinph0 * sin($lat);
                 if ($c != 0.0 || $x != 0.0) {
                     $lon = atan2($x * $sinc * $cosph0, $c * $rh);
                 }
                 break;
             case $this->N_POLE:
                 $y = -$y;
             case $this->S_POLE:
                 if (abs($rh) <= Sourcemap_Proj::EPSLN) {
                     $lat = $this->phi0;
                 } else {
                     $lat = asin($this->mode == $this->S_POLE ? -$cosc : $cosc);
                 }
                 $lon = $x == 0.0 && $y == 0.0 ? 0.0 : atan2($x, $y);
                 break;
         }
     } else {
         $rho = sqrt($x * $x + $y * $y);
         switch ($this->mode) {
             case $this->OBLIQ:
             case $this->EQUIT:
                 $tp = 2.0 * atan2($rho * $this->cosX1, $this->akm1);
                 $cosphi = cos($tp);
                 $sinphi = sin($tp);
                 if ($rho == 0.0) {
                     $phi_l = asin($cosphi * $this->sinX1);
                 } else {
                     $phi_l = asin($cosphi * $this->sinX1 + $y * $sinphi * $this->cosX1 / $rho);
                 }
                 $tp = tan(0.5 * (Sourcemap_Proj::HALF_PI + $phi_l));
                 $x *= $sinphi;
                 $y = $rho * $this->cosX1 * $cosphi - $y * $this->sinX1 * $sinphi;
                 $pi2 = Sourcemap_Proj::HALF_PI;
                 $halfe = 0.5 * $this->e;
                 break;
             case $this->N_POLE:
                 $y = -$y;
             case $this->S_POLE:
                 $tp = -$rho / $this->akm1;
                 $phi_l = Sourcemap_Proj::HALF_PI - 2.0 * atan($tp);
                 $pi2 = -Sourcemap_Proj::HALF_PI;
                 $halfe = -0.5 * $this->e;
                 break;
         }
         for ($i = $this->NITER; $i--; $phi_l = $lat) {
             //check this
             $sinphi = $this->e * sin($phi_l);
             $lat = 2.0 * atan($tp * pow((1.0 + $sinphi) / (1.0 - $sinphi), $halfe)) - $pi2;
             if (abs($phi_l - $lat) < $this->CONV) {
                 if ($this->mode == $this->S_POLE) {
                     $lat = -$lat;
                 }
                 $lon = $x == 0.0 && $y == 0.0 ? 0.0 : atan2($x, $y);
                 $p->x = Sourcemap_Proj::adjust_lon($lon + $this->long0);
                 $p->y = $lat;
                 return $p;
             }
         }
     }
 }
Exemplo n.º 27
0
 public function inverse($p)
 {
     $p->x -= $this->x0;
     $p->y -= $this->y0;
     $x = $p->x / $this->a;
     $y = $p->y / $this->a;
     if ($this->sphere) {
         $cosz = 0.0;
         $sinz = 0.0;
         $rh = sqrt($x * $x + $y * $y);
         $phi = $rh * 0.5;
         if ($phi > 1.0) {
             throw new Exception("Data error.");
         }
         $phi = 2.0 * asin($phi);
         if ($this->mode == $this->OBLIQ || $this->mode == $this->EQUIT) {
             $sinz = sin($phi);
             $cosz = cos($phi);
         }
         switch ($this->mode) {
             case $this->EQUIT:
                 $phi = abs($rh) <= Sourcemap_Proj::EPSLN ? 0.0 : asin($y * $sinz / $rh);
                 $x *= $sinz;
                 $y = $cosz * $rh;
                 break;
             case $this->OBLIQ:
                 $phi = abs($rh) <= Sourcemap_Proj::EPSLN ? $this->phi0 : asin($cosz * $sinph0 + $y * $sinz * $cosph0 / $rh);
                 $x *= $sinz * $cosph0;
                 $y = ($cosz - sin($phi) * $sinph0) * $rh;
                 break;
             case $this->N_POLE:
                 $y = -$y;
                 $phi = Sourcemap_Proj::HALF_PI - $phi;
                 break;
             case $this->S_POLE:
                 $phi -= Sourcemap_Proj::HALF_PI;
                 break;
         }
         $lam = $y == 0.0 && ($this->mode == $this->EQUIT || $this->mode == $this->OBLIQ) ? 0.0 : atan2($x, $y);
     } else {
         $ab = 0.0;
         switch ($this->mode) {
             case $this->EQUIT:
             case $this->OBLIQ:
                 $x /= $this->dd;
                 $y *= $this->dd;
                 $rho = sqrt($x * $x + $y * $y);
                 if ($rho < Sourcemap_Proj::EPSLN) {
                     $p->x = 0.0;
                     $p->y = $this->phi0;
                     return $p;
                 }
                 $sCe = 2.0 * asin(0.5 * $rho / $this->rq);
                 $cCe = cos($sCe);
                 $x *= $sCe = sin($sCe);
                 if ($this->mode == $this->OBLIQ) {
                     $ab = $cCe * $this->sinb1 + $y * $sCe * $this->cosb1 / $rho;
                     $q = $this->qp * $ab;
                     $y = $rho * $this->cosb1 * $cCe - $y * $this->sinb1 * $sCe;
                 } else {
                     $ab = $y * $sCe / $rho;
                     $q = $this->qp * $ab;
                     $y = $rho * $cCe;
                 }
                 break;
             case $this->N_POLE:
                 $y = -$y;
             case $this->S_POLE:
                 $q = $x * $x + $y * $y;
                 if (!$q) {
                     $p->x = 0.0;
                     $p->y = $this->phi0;
                     return $p;
                 }
                 /*
                   q = $this->qp - q;
                 */
                 $ab = 1.0 - $q / $this->qp;
                 if ($this->mode == $this->S_POLE) {
                     $ab = -$ab;
                 }
                 break;
         }
         $lam = atan2($x, $y);
         $phi = $this->authlat(asin($ab), $this->apa);
     }
     /*
       $Rh = sqrt($p->x *$p->x +$p->y * $p->y);
       $temp = Rh / (2.0 * $this->a);
     
       if(temp > 1) {
       Proj4js.reportError("laea:Inv:DataError");
       return null;
       }
     
       $z = 2.0 * Sourcemap_Proj::asinz(temp);
       $sin_z=sin(z);
       $cos_z=cos(z);
     
       $lon =$this->long0;
       if(abs(Rh) > Sourcemap_Proj::EPSLN) {
       $lat = Sourcemap_Proj::asinz($this->sin_lat_o * cos_z +$this-> cos_lat_o * sin_z *$p->y / Rh);
       $temp =abs($this->lat0) - Sourcemap_Proj::HALF_PI;
       if(abs(temp) > Sourcemap_Proj::EPSLN) {
       temp = cos_z -$this->sin_lat_o * sin(lat);
       if(temp!=0.0) lon=Sourcemap_Proj::adjust_lon($this->long0+atan2($p->x*sin_z*$this->cos_lat_o,temp*Rh));
       } else if($this->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 {
       lat = $this->lat0;
       }
     */
     //return(OK);
     $p->x = Sourcemap_Proj::adjust_lon($this->long0 + $lam);
     $p->y = $phi;
     return $p;
 }
Exemplo n.º 28
0
 public function inverse($pt)
 {
     $x = $pt->x - $this->_proj->x0;
     $y = $pt->y - $this->_proj->y0;
     if ($this->_proj->sphere) {
         $lat = Sourcemap_Proj::HALF_PI - 2.0 * atan(exp(-$y / $this->_proj->a * $this->_proj->k0));
     } else {
         $ts = exp(-$y / ($this->_proj->a * $this->_proj->k0));
         $lat = Sourcemap_Proj::phi2z($this->_proj->e, $ts);
         if ($lat == -9999) {
             throw new Exception("Lat = -9999");
         }
     }
     $lon = Sourcemap_Proj::adjust_lon($this->_proj->long0 + $x / ($this->_proj->a * $this->_proj->k0));
     $pt->x = $lon;
     $pt->y = $lat;
     return $pt;
 }
Exemplo n.º 29
0
 public function inverse($p)
 {
     $p->x -= $this->x0;
     $p->y = $this->rh - $p->y + $this->y0;
     if ($this->ns >= 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);
         $con = -1.0;
     }
     $theta = 0.0;
     if ($rh1 != 0.0) {
         $theta = atan2($con * $p->x, $con * $p->y);
     }
     $ml = $this->g - $rh1 / $this->a;
     $lat = $this->phi3z($this->ml, $this->e0, $this->e1, $this->e2, $this->e3);
     $lon = Sourcemap_Proj::adjust_lon($this->long0 + $theta / $this->ns);
     $p->x = lon;
     $p->y = lat;
     return $p;
 }
Exemplo n.º 30
0
 public function inverse($p)
 {
     $p->x -= $this->x0;
     $p->y -= $this->y0;
     $x = $p->x / $this->a;
     $y = $p->y / $this->a;
     if ($this->sphere) {
         $this->dd = $y + $this->lat0;
         $phi = asin(sin($this->dd) * cos($x));
         $lam = atan2(tan($x), cos($this->dd));
     } else {
         /* ellipsoid */
         $ph1 = $this->pj_inv_mlfn($this->m0 + $y, $this->es, $this->en);
         $this->tn = tan($ph1);
         $this->t = $this->tn * $this->tn;
         $this->n = sin($ph1);
         $this->r = 1.0 / (1.0 - $this->es * $this->n * $this->n);
         $this->n = sqrt($this->r);
         $this->r *= (1.0 - $this->es) * $this->n;
         $this->dd = $x / $this->n;
         $this->d2 = $this->dd * $this->dd;
         $phi = $ph1 - $this->n * $this->tn / $this->r * $this->d2 * (0.5 - (1.0 + 3.0 * $this->t) * $this->d2 * $this->C3);
         $lam = $this->dd * (1.0 + $this->t * $this->d2 * (-$this->C4 + (1.0 + 3.0 * $this->t) * $this->d2 * $this->C5)) / cos($ph1);
     }
     $p->x = Sourcemap_Proj::adjust_lon($this->long0 + $lam);
     $p->y = $phi;
     return $p;
 }