/** * 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; }
/** * 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; }
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'); }
<?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; }