package seng302.Model; import org.geotools.referencing.Console; import org.geotools.referencing.GeodeticCalculator; import seng302.Constants; import seng302.GPSCoordinate; import seng302.GraphCoordinate; /** * Created by cbt24 on 6/03/17. */ public class Leg { private String name; //nautical miles private double distance; private int legNumber; private GPSCoordinate startGPSCoordinate; private GPSCoordinate endGPSCoordinate; /** * Leg Initialiser * @param name Name of the Leg */ public Leg(String name, GPSCoordinate start, GPSCoordinate end, int number) { this.name = name; this.startGPSCoordinate = start; this.endGPSCoordinate = end; this.legNumber = number; this.distance = calculateDistance(); } public Leg(String name) { this.name = name; } /** * * @return the name of the Leg */ public String getName() { return name; } /** * * @return the total distance of the leg. */ public double getDistance() { return distance; } /** * * @return the name of the Leg */ public String toString() { return name; } /** * * @return the coordinate of the start of the leg ) */ public GPSCoordinate getStartGraphCoordinate() { return startGPSCoordinate; } /** * * @return the coordinate of the end of the leg */ public GPSCoordinate getEndGraphCoordinate() { return endGPSCoordinate; } public int getLegNumber() { return legNumber; } private double calculateDistance() { GeodeticCalculator calc = new GeodeticCalculator(); calc.setStartingGeographicPoint(startGPSCoordinate.getLatitude(), startGPSCoordinate.getLongitude()); calc.setDestinationGeographicPoint(endGPSCoordinate.getLatitude(), endGPSCoordinate.getLongitude()); return calc.getOrthodromicDistance() / Constants.NMToMetersConversion; } }