Added Calculation for Heading, Leg Distance and Total Distnace also added the appropriate functio nto commit these to database.

main
YaFedImYaEatIm 10 years ago
parent 68277cb983
commit 7ffe8dcea8

Binary file not shown.

@ -210,6 +210,7 @@ public class Dataset {
} }
rs.close(); rs.close();
stmt.close(); stmt.close();
flightPaths.get(i).updateFlightPointInfo();
} }
/*//////////////// /*////////////////
//Get all Routes// //Get all Routes//
@ -240,6 +241,10 @@ public class Dataset {
System.err.println( e.getClass().getName() + ": " + e.getMessage() ); System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0); System.exit(0);
} }
//update all flightpaths
for (FlightPath flightPath: flightPaths){
//updateFlightPointInfo(flightPath);
}
createDataLinks(); createDataLinks();
} }
@ -720,9 +725,12 @@ public class Dataset {
} }
if (numOfFlights > 0){ if (numOfFlights > 0){
stmt.execute(insertFlightPointQuery); stmt.execute(insertFlightPointQuery);
stmt.close();
} }
stmt.close();
c.close();
flightPaths.add(flightPathToAdd); flightPaths.add(flightPathToAdd);
updateFlightPointInfo(flightPathToAdd);
flightPathDictionary.put(flightPathToAdd.getID(), flightPathToAdd); flightPathDictionary.put(flightPathToAdd.getID(), flightPathToAdd);
} catch ( Exception e ) { } catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() ); System.err.println( e.getClass().getName() + ": " + e.getMessage() );
@ -1278,6 +1286,7 @@ public class Dataset {
FlightPoint pointToAdd = new FlightPoint(name, pointID+1, id, type, via, headingVal, altitudeVal, legDistVal, FlightPoint pointToAdd = new FlightPoint(name, pointID+1, id, type, via, headingVal, altitudeVal, legDistVal,
totalDistVal,latitudeVal, longitudeVal); totalDistVal,latitudeVal, longitudeVal);
updateFlightPointInfo(flightPathDictionary.get(Integer.valueOf(id)));
flightPathDictionary.get(Integer.valueOf(id)).addFlightPoint(pointToAdd, index); flightPathDictionary.get(Integer.valueOf(id)).addFlightPoint(pointToAdd, index);
} }
@ -1962,7 +1971,7 @@ public class Dataset {
} }
flightPath.setArrivalAirport(flightPoint.getName()); flightPath.setArrivalAirport(flightPoint.getName());
} }
updateFlightPointInfo(flightPath);
createDataLinks(); createDataLinks();
} }
@ -2025,5 +2034,33 @@ public class Dataset {
System.err.println( e.getClass().getName() + ": " + e.getMessage() ); System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0); System.exit(0);
} }
updateFlightPointInfo(flightPath);
}
/**
* Updates the Leg Distance, Total Distance and Bearing(Heading) of the Flight points in the flight path.
* @param flightPath
*/
public void updateFlightPointInfo(FlightPath flightPath){
flightPath.updateFlightPointInfo();
Connection c = null;
Statement stmt;
try {
c = DriverManager.getConnection("jdbc:sqlite:res/userdb.db");
//move all the points after this forward
for (FlightPoint flightPoint: flightPath.getFlightPoints()){
stmt = c.createStatement();
String updatePointQuery = "UPDATE `"+this.name+"_Flight_Points` SET `Heading` = "+flightPoint.getHeading()+", " +
"`Tot_Dist` = "+flightPoint.getTotalDistance()+", `Leg_Dist` = "+flightPoint.getLegDistance()+" WHERE `POINT_ID` = " +
"" + flightPoint.getID();
stmt.execute(updatePointQuery);
stmt.close();
}
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
e.printStackTrace();
System.exit(0);
}
} }
} }

@ -183,4 +183,37 @@ public class FlightPath {
} }
return routePath; return routePath;
} }
public void updateFlightPointInfo(){
if (flightPoints.size() == 0){
return;
}
FlightPoint startPoint = flightPoints.get(0);
startPoint.setLegDistance(0);
startPoint.setTotalDistance(0);
startPoint.setHeading(0);
for (int i = 1; i < flightPoints.size(); i ++){
double distance = 0;
double dLong = flightPoints.get(i - 1).getLongitude() - flightPoints.get(i).getLongitude();
double dLat = flightPoints.get(i - 1).getLatitude() - flightPoints.get(i).getLatitude();
dLong = Math.toRadians(dLong);
dLat = Math.toRadians(dLat);
double a = Math.pow((Math.sin(dLat/2)), 2) + Math.cos(Math.toRadians(flightPoints.get(i).getLatitude())) * Math.cos(Math.toRadians(flightPoints.get(i - 1).getLatitude())) * Math.pow(Math.sin(dLong/2), 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
distance = 6371 * c;
//convert distance from km to nautical mile
distance = distance * 0.53995680345572;
flightPoints.get(i).setLegDistance(distance);
flightPoints.get(i).setTotalDistance(distance + flightPoints.get(i).getTotalDistance());
//calculate bearing
double lat1 = Math.toRadians(flightPoints.get(i - 1).getLatitude());
double lat2 = Math.toRadians(flightPoints.get(i).getLatitude());
double lng1 = Math.toRadians(flightPoints.get(i - 1).getLongitude());
double lng2 = Math.toRadians(flightPoints.get(i).getLongitude());
double y = Math.sin(dLong) * Math.cos(lat2);
double x = Math.cos(lat1) * Math.sin(lat2);
x -= Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLong);
double heading = 360 - Math.toDegrees(Math.atan2(y, x));
flightPoints.get(i).setHeading((int)heading);
}
}
} }

Loading…
Cancel
Save