Package PamUtils

Class LatLong

java.lang.Object
PamUtils.LatLong
All Implemented Interfaces:
Transferable, Serializable, Cloneable, ManagedParameters, PamCoordinate
Direct Known Subclasses:
GpsData, LatLongTime, ReceiverReference

public class LatLong extends Object implements Serializable, Cloneable, Transferable, PamCoordinate, ManagedParameters
Class for handling and formatting latitude and longitude data. Only contains two variables, which are assumed to be in decimal degrees. Also contains a number of other static variables for formatting other lat long data.
Author:
Doug Gillespie
See Also:
  • Field Details

  • Constructor Details

    • LatLong

      public LatLong(double latitude, double longitude)
    • LatLong

      public LatLong(double latitude, double longitude, double height)
    • LatLong

      public LatLong()
    • LatLong

      public LatLong(LatLong locLatLong)
    • LatLong

      public LatLong(String string) throws NullPointerException
      USE WITH CAUTION uses LatLong.valueOfSubstring
      Parameters:
      LatLong -
      Throws:
      NullPointerException
  • Method Details

    • getFormatStyle

      public static int getFormatStyle()
      Returns:
      Returns the formatStyle.
    • getDataFlavor

      public static DataFlavor getDataFlavor()
    • setFormatStyle

      public static void setFormatStyle(int formatStyle)
      Parameters:
      formatStyle - The formatStyle to set.
    • clone

      public LatLong clone()
    • getLatitude

      public double getLatitude()
      Returns:
      Returns the latitude.
    • setLatitude

      public void setLatitude(double latitude)
      Parameters:
      latitude - The latitude to set.
    • getLongitude

      public double getLongitude()
      Returns:
      Returns the longitude.
    • setLongitude

      public void setLongitude(double longitude)
      Parameters:
      longitude - The longitude to set.
    • formatLatitude

      public String formatLatitude()
      formats the latitude string
      Returns:
      formated latitude string
    • formatLatitude

      public static String formatLatitude(double latlong)
      convert a double decimal degrees into a formatted latlong string
      Parameters:
      latlong -
      Returns:
      a string representation of a Latitude
    • valueOfString

      public static LatLong valueOfString(String string)
      must be separated by comma, then see valueOfSubstring
      Parameters:
      string -
      Returns:
      LatLong
    • valueOfSubstring

      public static Double valueOfSubstring(String angleString)
      must contain degree sign � -5� S will produce a north value if neither N, S or - will assume positive 57�19.800' N or 10�48.000' W
      Parameters:
      string -
      Returns:
      the angle
    • formatLongitude

      public String formatLongitude()
      formats the longitude as a string
      Returns:
      formatted longitude string
    • formatLongitude

      public static String formatLongitude(double latlong)
      convert a double decimal degrees into a formatted latlong string
      Parameters:
      latlong -
      Returns:
      a string representation of a Longitude
    • doubleDegrees2StringDegs

      public static String doubleDegrees2StringDegs(double latlong)
    • doubleDegrees2StringMins

      public static String doubleDegrees2StringMins(double latlong)
    • getSignedDegrees

      public static int getSignedDegrees(double latLong)
    • getDecimalMinutes

      public static double getDecimalMinutes(double latLong)
    • shortFormatLatitude

      public String shortFormatLatitude()
    • shortFormatLongitude

      public String shortFormatLongitude()
    • getIntegerMinutes

      public static int getIntegerMinutes(double latLong)
    • getSeconds

      public static double getSeconds(double latLong)
    • latLongArea

      public static net.sf.geographiclib.PolygonResult latLongArea(LatLong[] latLongList)
      Calculate the area of a latitude and longitude polygon in meters squared. Also calculates the perimeter. Geodisic calculations are WGS84.
      Parameters:
      latLongList - - a list of latitude and longitude values. The length of list must be greater than 3.
      Returns:
      PolygonResult which contains multiple measurements, including area, perimeter and number of vertices.
    • travelDistanceMeters

      public LatLong travelDistanceMeters(double trueHeading, double distance)
      Parameters:
      trueHeading - Heading relative to True North -degrees
      distance - Distance to travel in meters.
      Returns:
      New Latlong in decimal degrees
    • travelDistanceMeters

      public LatLong travelDistanceMeters(double trueHeading, double xydistance, double heightDistance)
      Travel a distance and a height in metres.
      Parameters:
      trueHeading - true heading
      xydistance - horizontal distance in metres
      heightDistance - hight distance in metres
      Returns:
      new position
    • TravelDistanceMiles

      public LatLong TravelDistanceMiles(double trueHeading, double distance)
      Parameters:
      trueHeading - Heading relative to True North- degrees
      distance - Distance to travel in nautical miles.
      Returns:
      New Latlong in decimal degrees
    • addDistanceMeters

      public LatLong addDistanceMeters(double addX, double addY)
      Add distances in metres East and metres North to a LatLong
      Note that this assumes a flat earth model away from poles, so it's possible to create stupid values. It's intended for small localised shifts in the vicinity of a single detection.
      Parameters:
      addX - distance to travel East in metres
      addY - distance to travel North in metres
      Returns:
      new LatLong
    • addDistanceMeters

      public LatLong addDistanceMeters(double addX, double addY, double addZ)
      Add distances in metres East and metres North to a LatLong
      Note that this assumes a flat earth model away from poles, so it's possible to create stupid values. It's intended for small localised shifts in the vicinity of a single detection.
      Parameters:
      addX - distance to travel East in metres
      addY - distance to travel North in metres
      addZ - vertical distance to add
      Returns:
      new LatLong
    • addDistanceMeters

      public LatLong addDistanceMeters(PamVector movementVector)
      Add an x,y,z vector to the current location.
      Parameters:
      movementVector - two element x,y or three element x,y,z vector.
      Returns:
      new LatLong.
    • distanceToMiles

      public double distanceToMiles(LatLong destination)
      Calculate the distance from this positions to some other position in miles.
      Parameters:
      destination - destiantion position
      Returns:
      distance in miles
    • distanceToMetres

      public double distanceToMetres(LatLong destination)
      Calculate the distance from this positions to some other position in metres.
      Parameters:
      destination - destination position
      Returns:
      distance in metres
    • distanceToMetres3D

      public double distanceToMetres3D(LatLong destination)
      Calculate the distance from this positions to some other position in three dimensions (i.e. including any height or depth changes) in metres.
      Parameters:
      destination - destination position
      Returns:
      distance in metres
    • distanceToMetresX

      public double distanceToMetresX(LatLong destination)
      Calculate the distance in metres along the X coordinate from the lat long to some other lat long.
      Parameters:
      destination - destination coordinate
      Returns:
      distance in metres
    • distanceToMetresY

      public double distanceToMetresY(LatLong destination)
      Calculate the distance in metres along the Y coordinate from the lat long to some other lat long.
      Parameters:
      destination - destination coordinate
      Returns:
      distance in metres
    • equals

      public boolean equals(LatLong ll)
    • getMean

      public static LatLong getMean(LatLong[] lls)
    • bearingTo

      public double bearingTo(LatLong destination)
      Get the bearing in degree to this latlong to another latlong.
      Does not do a full great circle calculation, but uses rectangular trigonometry.
      Parameters:
      destination - destination lat long
      Returns:
      angle to destination in degrees.
    • getCrossTrackError

      public double getCrossTrackError(LatLong latLong1, LatLong latLong2)
      Clculate the perpendicular distance from this LatLong to a line joining latLong1 and latLong2
      Returns:
      cross track error in metres
    • getHeight

      public double getHeight()
      Returns:
      the height
    • setHeight

      public void setHeight(double height)
      Parameters:
      height - the height to set
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getTransferData

      public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException
      Specified by:
      getTransferData in interface Transferable
      Throws:
      UnsupportedFlavorException
      IOException
    • getTransferDataFlavors

      public DataFlavor[] getTransferDataFlavors()
      Specified by:
      getTransferDataFlavors in interface Transferable
    • isDataFlavorSupported

      public boolean isDataFlavorSupported(DataFlavor flavor)
      Specified by:
      isDataFlavorSupported in interface Transferable
    • getPastedValue

      public static LatLong getPastedValue()
    • getCoordinate

      public double getCoordinate(int iCoordinate)
      Description copied from interface: PamCoordinate
      Get an indexed coordinate.
      Specified by:
      getCoordinate in interface PamCoordinate
      Parameters:
      iCoordinate - coordinate index.
      Returns:
      coordinate value.
    • setCoordinate

      public void setCoordinate(int iCoordinate, double value)
      Description copied from interface: PamCoordinate
      Set a coordinate value
      Specified by:
      setCoordinate in interface PamCoordinate
      Parameters:
      iCoordinate - index of coordinate (0,1,2)
      value - value to set.
    • getNumCoordinates

      public int getNumCoordinates()
      Specified by:
      getNumCoordinates in interface PamCoordinate
      Returns:
      the number of coordinates.
    • distanceTo

      public double[] distanceTo(LatLong other)
      Returns the position of this minus the position of the other Lat Long in metres, i.e. it is the distance you'd have to travel in x,y and x to get from 'other' to this.
      Parameters:
      other - Other lat long.
      Returns:
      distance to travel from this to other (x,y,z).
    • getParameterSet

      public PamParameterSet getParameterSet()
      Get the auto-generated parameter set, and then add in the fields that are not included because they are not public and do not have getters. Note: for each field, we search the current class and (if that fails) the superclass. It's done this way because LatLong might be used directly (and thus the field would be found in the class) and it also might be used as a superclass to something else (e.g. Vessel) in which case the field would only be found in the superclass.
      Specified by:
      getParameterSet in interface ManagedParameters
      Returns:
      description of the parameters in a class.