Jump to content

Calculating Total Route Distance? [SOLVED]


freshJet

Recommended Posts

I am trying to return the total distance of a route, rather than the great circle distance. I have a complicated method, but I'm not convinced with the result:

function getFPDistance(){

$schedule = SchedulesData::getScheduleDetailed($_GET['plan']);
$params->deplat = $schedule->deplat;
$params->deplng = $schedule->deplng;
$params->arrlat = $schedule->arrlat;
$params->arrlng = $schedule->arrlng;
$params->route = $_POST['route'];
$routedata = NavData::parseRoute($params);
$depairport = OperationsData::getAirportInfo($schedule->depicao);
$arrairport = OperationsData::getAirportInfo($schedule->arricao);
$end = (count($routedata) - 1);

$total = 0;
$a = -1;
$b = 0;

# Put lat/lng of each waypoint into array
$lat = array();
$lng = array();

foreach($routedata as $wp){
$lat[] = $wp->lat;
$lng[] = $wp->lng;
}

# Calculate the distance between each waypoint in the array
for($i=0; $i<$end; $i++){

$a++;
$b++;

$dist1 = distance($lat[$a], $lng[$a], $arrairport->lat, $arrairport->lng);
$dist2 = distance($lat[$b], $lng[$b], $arrairport->lat, $arrairport->lng);
$dist = $dist1 - $dist2;

$total = $total + $dist;
}

# Get the distance between the departure airport and the first waypoint
$dep_to_first = distance($depairport->lat, $depairport->lng, $lat[0], $lng[0]);

# Get the distance between the last waypoint and arrival airport
$last_to_arr = distance($lat[$end], $lng[$end], $arrairport->lat, $arrairport->lng);

# Add these to the total
$total = $total + $dep_to_first + $last_to_arr;

return round($total);
}

For EGCC-GCTS, this returns 1650nm, with GC distance being 1648nm, route shown below.

NOKIN UN862 LAMAT UN90 NOTRO UM30 SALCO UN864 MONTO UN857 TERTO

Any ideas?

Link to comment
Share on other sites

I put the route into a mapper and it suggests the route length should be 1780.6nm.

You seem to be calculating the distance between each waypoint and the destination airport, and subtracting the distance of the previous waypoint and the destination airport. Strange method...

Assuming your logic for $end etc is correct this might work better:

function getFPDistance(){

$schedule = SchedulesData::getScheduleDetailed($_GET['plan']);
$params->deplat = $schedule->deplat;
$params->deplng = $schedule->deplng;
$params->arrlat = $schedule->arrlat;
$params->arrlng = $schedule->arrlng;
$params->route = $_POST['route'];
$routedata = NavData::parseRoute($params);
$depairport = OperationsData::getAirportInfo($schedule->depicao);
$arrairport = OperationsData::getAirportInfo($schedule->arricao);
$end = (count($routedata) - 1);

// Put lat/lng of each waypoint into array
$lat = $lng = array();
foreach($routedata as $wp){
$lat[] = $wp->lat;
$lng[] = $wp->lng;
}

// Distance from departure airport to first waypoint
$total = distance($depairport->lat, $depairport->lng, $lat[0], $lng[0]);

// Distance between each waypoint
for($i=1; $i<$end; $i++){
$total += distance($lat[$i], $lng[$i], $lat[$i - 1], $lng[$i - 1]);
}

// Distance from last waypoint to arrival airport
$total += distance($lat[$end], $lng[$end], $arrairport->lat, $arrairport->lng);

return round($total);
}

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...