2013-05-27 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_gis.php: added function "gis_calculate_distance" to calculate the distance between to points, and return in the international metric system, kilometers. * operation/agentes/gis_view.php: added column with the show the distance with the previous point. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8210 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
b442ad8c7a
commit
ab298033f3
|
@ -1,3 +1,12 @@
|
|||
2013-05-27 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* include/functions_gis.php: added function "gis_calculate_distance"
|
||||
to calculate the distance between to points, and return in the
|
||||
international metric system, kilometers.
|
||||
|
||||
* operation/agentes/gis_view.php: added column with the show the
|
||||
distance with the previous point.
|
||||
|
||||
2013-05-27 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* pandoradb.sql: Updated data types to allow 64bit integers to be
|
||||
|
|
|
@ -438,9 +438,9 @@ function gis_get_agents_layer($idLayer, $fields = null) {
|
|||
$agents = db_get_all_rows_sql('SELECT ' . $select . '
|
||||
FROM tagente
|
||||
WHERE id_agente IN (
|
||||
SELECT tagente_id_agente
|
||||
FROM tgis_map_layer_has_tagente
|
||||
WHERE tgis_map_layer_id_tmap_layer = ' . $idLayer . ');');
|
||||
SELECT tagente_id_agente
|
||||
FROM tgis_map_layer_has_tagente
|
||||
WHERE tgis_map_layer_id_tmap_layer = ' . $idLayer . ');');
|
||||
|
||||
if ($agents !== false) {
|
||||
foreach ($agents as $index => $agent) {
|
||||
|
@ -1303,4 +1303,82 @@ function gis_add_layer_list($layer_list) {
|
|||
|
||||
return $returnVar;
|
||||
}
|
||||
|
||||
function gis_calculate_distance($lat_start, $lon_start, $lat_end, $lon_end) {
|
||||
//Use 3958.9=miles, 6371.0=Km;
|
||||
$earthRadius = 6371;
|
||||
|
||||
$distance = 0;
|
||||
$azimuth = 0;
|
||||
$beta = 0;
|
||||
$cosBeta = 0;
|
||||
$cosAzimuth = 0;
|
||||
|
||||
$lat_start = deg2rad($lat_start);
|
||||
$lon_start = deg2rad($lon_start);
|
||||
$lat_end = deg2rad($lat_end);
|
||||
$lon_end = deg2rad($lon_end);
|
||||
|
||||
if (abs($lat_start) < 90.0) {
|
||||
$cosBeta = (sin($lat_start) * sin($lat_end)) +
|
||||
((cos ($lat_start) * cos ($lat_end)) * cos ($lon_end - $lon_start));
|
||||
|
||||
if ($cosBeta >= 1.0) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/*
|
||||
Antipodes (return miles, 0 degrees)
|
||||
*/
|
||||
if ($cosBeta <= -1.0) {
|
||||
return floor($earthRadius * pi() * 100.0) / 100.0;
|
||||
}
|
||||
|
||||
$beta = acos($cosBeta);
|
||||
$distance = $beta * $earthRadius;
|
||||
$cosAzimuth = (sin($lat_end) - sin($lat_start) * cos($beta)) /
|
||||
(cos($lat_start) * sin($beta));
|
||||
|
||||
if ($cosAzimuth >= 1.0) {
|
||||
$azimuth = 0.0;
|
||||
}
|
||||
elseif ($cosAzimuth <= -1.0) {
|
||||
$azimuth = 180.0;
|
||||
}
|
||||
else {
|
||||
$azimuth = rad2deg(acos($cosAzimuth));
|
||||
}
|
||||
|
||||
if (sin($lon_end - $lon_start) < 0.0) {
|
||||
$azimuth = 360.0 - $azimuth;
|
||||
}
|
||||
|
||||
return floor($distance * 100.0) / 100.0;
|
||||
}
|
||||
|
||||
//If P1 Is North Or South Pole, Then Azimuth Is Undefined
|
||||
if (gis_sgn($lat_start) == gis_sgn ($lat_end)) {
|
||||
$distance = $earthRadius * (pi() / 2 - abs($lat_end));
|
||||
}
|
||||
else {
|
||||
$distance = $earthRadius * (pi() / 2 + abs($lat_end));
|
||||
}
|
||||
|
||||
return floor($distance * 100.0) / 100.0;
|
||||
}
|
||||
|
||||
function gis_sgn($number)
|
||||
{
|
||||
if ($number == 0) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
if ($number < 0) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -81,7 +81,8 @@ if ($agentData === false) {
|
|||
echo "<br />";
|
||||
$dataLastPosition = gis_get_data_last_position_agent($agentId);
|
||||
if ($dataLastPosition !== false) {
|
||||
echo "<b>" . __("Last position in ") . $dataLastPosition['start_timestamp'] . ":</b> " .
|
||||
echo "<b>" . __("Last position in ") .
|
||||
$dataLastPosition['start_timestamp'] . ":</b> " .
|
||||
$dataLastPosition['stored_longitude'] . ", " . $dataLastPosition['stored_latitude'] . ", " . $dataLastPosition['stored_altitude'];
|
||||
}
|
||||
echo "<br />";
|
||||
|
@ -118,11 +119,44 @@ if ($result === false) {
|
|||
else {
|
||||
ui_pagination ($countData, false) ;
|
||||
$table->data = array();
|
||||
foreach ($result as $row) {
|
||||
$rowdata = array($row['longitude'], $row['latitude'], $row['altitude'], $row['start_timestamp'], $row['end_timestamp'], $row['description'], $row['number_of_packages'], $row['manual_placement']);
|
||||
foreach ($result as $key => $row) {
|
||||
$distance = 0;
|
||||
if (isset($result[$key - 1])) {
|
||||
$distance = gis_calculate_distance($row['latitude'],
|
||||
$row['longitude'], $result[$key - 1]['latitude'],
|
||||
$result[$key - 1]['longitude']);
|
||||
}
|
||||
else {
|
||||
$dataLastPosition = gis_get_data_last_position_agent($agentId);
|
||||
if ($dataLastPosition !== false) {
|
||||
$distance = gis_calculate_distance($row['latitude'],
|
||||
$row['longitude'], $dataLastPosition['stored_latitude'],
|
||||
$dataLastPosition['stored_longitude']);
|
||||
}
|
||||
}
|
||||
|
||||
$rowdata = array(
|
||||
$row['longitude'],
|
||||
$row['latitude'],
|
||||
$row['altitude'],
|
||||
$row['start_timestamp'],
|
||||
$row['end_timestamp'],
|
||||
$row['description'],
|
||||
sprintf(__('%s Km'), $distance),
|
||||
$row['number_of_packages'],
|
||||
$row['manual_placement']);
|
||||
array_push($table->data, $rowdata);
|
||||
}
|
||||
$table->head = array(__("Longitude"), __("Latitude"), __("Altitude"), __("From"), __("To"), __("Description"), '# '.__("of Packages"), __("Manual placement"));
|
||||
$table->head = array(
|
||||
__("Longitude"),
|
||||
__("Latitude"),
|
||||
__("Altitude"),
|
||||
__("From"),
|
||||
__("To"),
|
||||
__("Description"),
|
||||
__('Distance'),
|
||||
__("# of Packages"),
|
||||
__("Manual placement"));
|
||||
$table->class = 'position_data_table';
|
||||
$table->id = $agent_name.'_position_data_table';
|
||||
$table->title = $agent_name_original . " " . __("positional data");
|
||||
|
|
Loading…
Reference in New Issue