コード例 #1
0
ファイル: Velo.class.php プロジェクト: Tjoosten/BikesResource
 public function read()
 {
     $data = TDT::HttpRequest("http://*****:*****@m.velo-antwerpen.be/data/stations.json");
     $decoded = json_decode($data->data);
     //todo: convert to wished format
     $result = array();
     $gpoint = new gPoint();
     foreach ($decoded as $sourceStation) {
         $station = new Object();
         $station->name = $sourceStation->name;
         $station->freebikes = $sourceStation->bikes;
         $station->freespots = $sourceStation->slots;
         $station->state = $sourceStation->status;
         $station->latitude = $sourceStation->latitude;
         $station->longitude = $sourceStation->longitude;
         $gpoint->setLongLat($station->longitude, $station->latitude);
         if ($this->lat != null && $this->long != null) {
             $station->distance = $gpoint->distanceFrom($this->long, $this->lat);
         }
         array_push($result, $station);
     }
     function compare($a, $b)
     {
         if ($a->distance == $b->distance) {
             return 0;
         }
         return $a->distance < $b->distance ? -1 : 1;
     }
     if ($this->lat != null && $this->long != null) {
         usort($result, "compare");
     }
     return array_slice($result, $this->offset, $this->rowcount);
 }
コード例 #2
0
 public function read()
 {
     $data = TDT::HttpRequest("http://www.mobielbrussel.irisnet.be/villo/json/");
     $decoded = json_decode($data->data);
     //todo: convert to wished format
     $result = array();
     $gpoint = new gPoint();
     foreach ($decoded->features as $feature) {
         $station = new Object();
         $station->name = $feature->properties->NAME;
         $station->freebikes = $feature->properties->FREEBK;
         $station->freespots = $feature->properties->FREEBS;
         $station->state = $feature->properties->STATE;
         // Configure the gPoint library to use the Lambert Projection for Belgium
         $gpoint->configLambertProjection(150000.013, 5400088.438, 4.367487, 90, 49.833333, 51.166666);
         $x = $feature->geometry->coordinates[0];
         $y = $feature->geometry->coordinates[1];
         $gpoint->setLambert($x, $y);
         // Convert the Lambert Coordinates to Latitude and Longitude (using the gPoint Library)
         $gpoint->convertLCCtoLL();
         $station->latitude = $gpoint->lat;
         $station->longitude = $gpoint->long;
         if ($this->lat != null && $this->long != null) {
             $station->distance = $gpoint->distanceFrom($this->long, $this->lat);
         }
         array_push($result, $station);
     }
     function compare($a, $b)
     {
         if ($a->distance == $b->distance) {
             return 0;
         }
         return $a->distance < $b->distance ? -1 : 1;
     }
     if ($this->lat != null && $this->long != null) {
         usort($result, "compare");
     }
     return array_slice($result, $this->offset, $this->rowcount);
 }
コード例 #3
0
/**
 * Converts $ps_value from UTM format to decimal latitude and longitude
 *
 * @param string $ps_value The UTM expression in the format <zone><hemisphere> <easting> <northing>. Example:  17N 630084 4833438
 * @return array Array with 'latitude' and 'longitude' keys and decimal values. Return null if value cannot be converted. 
 */
function caGISUTMToSignedDecimals($ps_value)
{
    $ps_value = trim($ps_value);
    if (preg_match('!^([0-9]{1,2}[NSns]{1})[ ]+([0-9]{1,9})[ ]+([0-9]{1,9})$!', $ps_value, $va_matches)) {
        $o_gpoint = new gPoint();
        $o_gpoint->setUTM($va_matches[2], $va_matches[3], $va_matches[1]);
        $o_gpoint->convertTMtoLL();
        return array('latitude' => $o_gpoint->Lat(), 'longitude' => $o_gpoint->Long());
    }
    return null;
}
コード例 #4
0
 public function update_infrastruktur($id)
 {
     require 'source/php/gPoint.php';
     $gpoint = new gPoint();
     $gpoint->setUTM(Input::get('easting'), Input::get('northing'), Input::get('primer'));
     $gpoint->convertTMtoLL();
     $long = $gpoint->Long();
     $lat = $gpoint->Lat();
     DB::table('infrastruktur')->where('id', '=', $id)->update(array('id_ruas_jalan' => Input::get('id_ruas_jalan'), 'nama_infrastruktur' => Input::get('nama_infrastruktur'), 'jenis_infrastruktur' => Input::get('jenis_infrastruktur'), 'kondisi' => Input::get('kondisi'), 'no_gps' => Input::get('no_gps'), 'koordinat_gps' => Input::get('primer') . " " . Input::get('easting') . " " . Input::get('northing'), 'long' => $long, 'lat' => $lat, 'kecamatan_id' => Input::get('kecamatan')));
     return Redirect::to('admin/data_infrastruktur/infrastruktur');
 }
コード例 #5
0
ファイル: BusStops.php プロジェクト: nervetattoo/rutetid
 /**
  * Import bus stops from a csv file fmor eiendomsprofil data
  *
  * @return int
  * @param string $file
  */
 public function import($file)
 {
     $db = Config::getDb();
     // Lat/long limits, should be converted
     $top = 60.60108;
     //lat
     $bottom = 59.90108;
     //lat
     $left = 5.005268;
     //long
     $right = 5.725268;
     //long
     $gPoint = new gPoint();
     $gPoint->setLongLat($left, $top);
     $gPoint->convertLLtoTM();
     $utmTop = (int) $gPoint->N();
     $utmLeft = (int) $gPoint->E();
     $gPoint->setLongLat($right, $bottom);
     $gPoint->convertLLtoTM();
     $utmBottom = (int) $gPoint->N();
     $utmRight = (int) $gPoint->E();
     $utmTop = 6800000;
     $utmBottom = 6600000;
     $utmRight = -15000;
     $utmLeft = -46000;
     $handle = fopen($file, "r");
     $i = 0;
     $db->stops->ensureIndex(array('location' => '2d'));
     if ($handle) {
         echo "Top: {$utmTop} Bottom: {$utmBottom} Left: {$utmLeft} Right: {$utmRight}<br>\n";
         fgets($handle, 4096);
         while (!feof($handle)) {
             $line = fgets($handle);
             if (strlen($line) > 10) {
                 $fields = explode(",", $line);
                 $name = substr($fields[3], 1, -1);
                 $x = (int) substr($fields[8], 1, -1);
                 $y = (int) substr($fields[9], 1, -1);
                 if ($x < $utmRight && $x > $utmLeft && $y < $utmTop && $y > $utmBottom) {
                     $i++;
                     $gPoint->setUTM($x, $y, "33V");
                     $gPoint->convertTMtoLL();
                     $lat = $gPoint->Lat();
                     $long = $gPoint->Long();
                     $location = array((double) $lat, (double) $long);
                     $stop = $db->stops->findOne(array('location' => $location));
                     if ($stop === null) {
                         $db->stops->insert(array('name' => $name, 'location' => $location, 'aliases' => array($name), 'search' => array(toLower($name)), 'connectsFrom' => array(), 'connectsTo' => array()));
                     } else {
                         if (array_key_exists('aliases', $stop)) {
                             $aliases = $stop['aliases'];
                         } else {
                             $aliases = array();
                         }
                         $aliases[] = $name;
                         $res = $db->stops->update(array("_id" => $stop['_id']), array('$set' => array('aliases' => $aliases)));
                     }
                     unset($stop);
                     //echo "$name lies as $lat,$long\n";
                 }
             }
         }
         fclose($handle);
         return $i;
     }
     return false;
 }
コード例 #6
0
ファイル: distance.php プロジェクト: runand/stog
<?php

/*

$lat1 = 55.66157579999999;
$lon1 = 12.4049744;
*/
$lat1 = $_POST['lat'];
$lon1 = $_POST['lon'];
require 'gPoint.php';
include 'stations.inc';
$stations = array();
foreach ($stationlist as $uic => $stationinfo) {
    $utm_parts = explode(';', $stationinfo['utm']);
    $station = new gPoint();
    $station->setUTM($utm_parts[0], $utm_parts[1], '32N');
    $station->convertTMtoLL();
    $stations[] = array('uic' => $uic - 8600000, 'name' => $stationinfo['station'], 'distance' => $station->distanceFrom($lon1, $lat1));
}
usort($stations, 'distancesort');
print json_encode($stations);
function distancesort($a, $b)
{
    if ($a['distance'] == $b['distance']) {
        return 0;
    }
    return $a['distance'] < $b['distance'] ? -1 : 1;
}