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 Summary
Modifier and TypeFieldDescriptionstatic final String
static final int
static final int
static final int
static final double
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddDistanceMeters
(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.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.addDistanceMeters
(PamVector movementVector) Add an x,y,z vector to the current location.double
Get the bearing in degree to this latlong to another latlong.clone()
double[]
distanceTo
(LatLong other) Returns the position of this minus the position of the other Lat Long in metres, i.e.double
distanceToMetres
(LatLong destination) Calculate the distance from this positions to some other position in metres.double
distanceToMetres3D
(LatLong destination) Calculate the distance from this positions to some other position in three dimensions (i.e.double
distanceToMetresX
(LatLong destination) Calculate the distance in metres along the X coordinate from the lat long to some other lat long.double
distanceToMetresY
(LatLong destination) Calculate the distance in metres along the Y coordinate from the lat long to some other lat long.double
distanceToMiles
(LatLong destination) Calculate the distance from this positions to some other position in miles.static String
doubleDegrees2StringDegs
(double latlong) static String
doubleDegrees2StringMins
(double latlong) boolean
formats the latitude stringstatic String
formatLatitude
(double latlong) convert a double decimal degrees into a formatted latlong stringformats the longitude as a stringstatic String
formatLongitude
(double latlong) convert a double decimal degrees into a formatted latlong stringdouble
getCoordinate
(int iCoordinate) Get an indexed coordinate.double
getCrossTrackError
(LatLong latLong1, LatLong latLong2) Clculate the perpendicular distance from this LatLong to a line joining latLong1 and latLong2static DataFlavor
static double
getDecimalMinutes
(double latLong) static int
double
static int
getIntegerMinutes
(double latLong) double
double
static LatLong
int
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.static LatLong
static double
getSeconds
(double latLong) static int
getSignedDegrees
(double latLong) getTransferData
(DataFlavor flavor) boolean
isDataFlavorSupported
(DataFlavor flavor) static net.sf.geographiclib.PolygonResult
latLongArea
(LatLong[] latLongList) Calculate the area of a latitude and longitude polygon in meters squared.void
setCoordinate
(int iCoordinate, double value) Set a coordinate valuestatic void
setFormatStyle
(int formatStyle) void
setHeight
(double height) void
setLatitude
(double latitude) void
setLongitude
(double longitude) toString()
travelDistanceMeters
(double trueHeading, double distance) travelDistanceMeters
(double trueHeading, double xydistance, double heightDistance) Travel a distance and a height in metres.TravelDistanceMiles
(double trueHeading, double distance) static LatLong
valueOfString
(String string) must be separated by comma, then see valueOfSubstringstatic 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
-
Field Details
-
deg
- See Also:
-
MetersPerMile
public static final transient double MetersPerMile- See Also:
-
FORMAT_DECIMALMINUTES
public static final int FORMAT_DECIMALMINUTES- See Also:
-
FORMAT_MINUTESSECONDS
public static final int FORMAT_MINUTESSECONDS- See Also:
-
FORMAT_DECIMAL
public static final int FORMAT_DECIMAL- See Also:
-
-
Constructor Details
-
LatLong
public LatLong(double latitude, double longitude) -
LatLong
public LatLong(double latitude, double longitude, double height) -
LatLong
public LatLong() -
LatLong
-
LatLong
USE WITH CAUTION uses LatLong.valueOfSubstring- Parameters:
LatLong
-- Throws:
NullPointerException
-
-
Method Details
-
getFormatStyle
public static int getFormatStyle()- Returns:
- Returns the formatStyle.
-
getDataFlavor
-
setFormatStyle
public static void setFormatStyle(int formatStyle) - Parameters:
formatStyle
- The formatStyle to set.
-
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
formats the latitude string- Returns:
- formated latitude string
-
formatLatitude
convert a double decimal degrees into a formatted latlong string- Parameters:
latlong
-- Returns:
- a string representation of a Latitude
-
valueOfString
must be separated by comma, then see valueOfSubstring- Parameters:
string
-- Returns:
- LatLong
-
valueOfSubstring
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
formats the longitude as a string- Returns:
- formatted longitude string
-
formatLongitude
convert a double decimal degrees into a formatted latlong string- Parameters:
latlong
-- Returns:
- a string representation of a Longitude
-
doubleDegrees2StringDegs
-
doubleDegrees2StringMins
-
getSignedDegrees
public static int getSignedDegrees(double latLong) -
getDecimalMinutes
public static double getDecimalMinutes(double latLong) -
shortFormatLatitude
-
shortFormatLongitude
-
getIntegerMinutes
public static int getIntegerMinutes(double latLong) -
getSeconds
public static double getSeconds(double latLong) -
latLongArea
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
- Parameters:
trueHeading
- Heading relative to True North -degreesdistance
- Distance to travel in meters.- Returns:
- New Latlong in decimal degrees
-
travelDistanceMeters
Travel a distance and a height in metres.- Parameters:
trueHeading
- true headingxydistance
- horizontal distance in metresheightDistance
- hight distance in metres- Returns:
- new position
-
TravelDistanceMiles
- Parameters:
trueHeading
- Heading relative to True North- degreesdistance
- Distance to travel in nautical miles.- Returns:
- New Latlong in decimal degrees
-
addDistanceMeters
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 metresaddY
- distance to travel North in metres- Returns:
- new LatLong
-
addDistanceMeters
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 metresaddY
- distance to travel North in metresaddZ
- vertical distance to add- Returns:
- new LatLong
-
addDistanceMeters
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
Calculate the distance from this positions to some other position in miles.- Parameters:
destination
- destiantion position- Returns:
- distance in miles
-
distanceToMetres
Calculate the distance from this positions to some other position in metres.- Parameters:
destination
- destination position- Returns:
- distance in metres
-
distanceToMetres3D
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
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
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
-
getMean
-
bearingTo
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
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
-
getTransferData
- Specified by:
getTransferData
in interfaceTransferable
- Throws:
UnsupportedFlavorException
IOException
-
getTransferDataFlavors
- Specified by:
getTransferDataFlavors
in interfaceTransferable
-
isDataFlavorSupported
- Specified by:
isDataFlavorSupported
in interfaceTransferable
-
getPastedValue
-
getCoordinate
public double getCoordinate(int iCoordinate) Description copied from interface:PamCoordinate
Get an indexed coordinate.- Specified by:
getCoordinate
in interfacePamCoordinate
- 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 interfacePamCoordinate
- Parameters:
iCoordinate
- index of coordinate (0,1,2)value
- value to set.
-
getNumCoordinates
public int getNumCoordinates()- Specified by:
getNumCoordinates
in interfacePamCoordinate
- Returns:
- the number of coordinates.
-
distanceTo
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
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 interfaceManagedParameters
- Returns:
- description of the parameters in a class.
-