com.oziexplorer
Class LatLon

java.lang.Object
  extended by com.oziexplorer.Position
      extended by com.oziexplorer.LatLon

public class LatLon
extends Position

This class represents (lattitude, longitude coordinates). These are defined by the datum the coordinates are based on plus the lattitude and longitude in decimal degrees.

Implementation notes for the distance and bearing calculations

See http://williams.best.vwh.net/avform.htm for the formulae and http://www.movable-type.co.uk/scripts/LatLong.html for example javascript implementations. This implementation is based on the Javascript versions, Copyright Chris Veness 2002-2010, www.movable-type.co.uk/scripts/latlong.html

Copyright 2011 Alan Burlison, . All rights reserved. Use is subject to license terms, see LICENSE.txt.
SourceForge.net


Field Summary
protected static double DEG_PER_RAD
          Degrees per radian.
protected  double lat
          The lattitude, in decimal degrees.
protected  double lon
          The longitude, in decimal degrees.
protected static double WGS84_RADIUS
          WGS84 average radius, in metres
 
Fields inherited from class com.oziexplorer.Position
comparisonAccuracy, datum
 
Constructor Summary
LatLon(double lat, double lon)
          Create a LatLon object using the currently loaded map's datum.
LatLon(Position pos)
          Create a LatLon by converting the given Position to a LatLon, using the currently loaded map's datum.
LatLon(Position position, String newDatum)
          Create a latLon object by converting the given Position to the specified datum.
LatLon(String datum, double lat, double lon)
          Creates a new LatLon object given the datum, lattitude and longitude.
 
Method Summary
 LatLon addVector(SpatialVector vector)
          Return a new LatLon which is offset from the current position by the given vector, specified as a SpatialVector.
 boolean equals(Object that)
          Test if two lat/lon positions are equal.
 double getLat()
          Return the lattitude of the LatLon.
 double getLon()
          Return the longitude of the LatLon.
 int hashCode()
          Return the hash code for this object.
 String toDMS()
          Return a string representation of the LatLon, of the form dd°mm'ss.ss"[WE] dd°mm'ss.ss"[NS] (datum)
 String toString()
          Return a string representation of the LatLon, of the form decimal lattitude, decimal longitude (datum)
static LatLon toWGS84(Position position)
          Create a LatLon object by converting the given Position to the WGS84 datum.
 SpatialVector vectorBetween(Position position)
          Return the distance between two positions as a SpatialVector.
 
Methods inherited from class com.oziexplorer.Position
getComparisonAccuracy, getDatum, setComparisonAccuracy
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

lat

protected double lat
The lattitude, in decimal degrees.


lon

protected double lon
The longitude, in decimal degrees.


WGS84_RADIUS

protected static final double WGS84_RADIUS
WGS84 average radius, in metres

See Also:
Constant Field Values

DEG_PER_RAD

protected static final double DEG_PER_RAD
Degrees per radian.

See Also:
Constant Field Values
Constructor Detail

LatLon

public LatLon(String datum,
              double lat,
              double lon)
       throws OziException
Creates a new LatLon object given the datum, lattitude and longitude.

Parameters:
datum - OziAPI datum name.
lat - lattitude in decimal degrees.
lon - longitude in decimal degrees.
Throws:
OziException - if OziAPI returns an error.

LatLon

public LatLon(double lat,
              double lon)
       throws OziException
Create a LatLon object using the currently loaded map's datum.

Parameters:
lat - latitude in decimal degrees.
lon - longitude in decimal degrees.
Throws:
OziException - if OziAPI returns an error.

LatLon

public LatLon(Position position,
              String newDatum)
       throws OziException
Create a latLon object by converting the given Position to the specified datum.

Parameters:
position - the source Position.
newDatum - the datum of the new LatLon.
Throws:
OziException - if OziAPI returns an error.

LatLon

public LatLon(Position pos)
       throws OziException
Create a LatLon by converting the given Position to a LatLon, using the currently loaded map's datum.

Parameters:
pos - the Position to be converted.
Throws:
OziException - if OziAPI returns an error.
Method Detail

toWGS84

public static LatLon toWGS84(Position position)
                      throws OziException
Create a LatLon object by converting the given Position to the WGS84 datum.

Parameters:
position - the source Position.
Returns:
the position as a WGS85 LatLon.
Throws:
OziException - if OziAPI returns an error.

vectorBetween

public SpatialVector vectorBetween(Position position)
                            throws OziException
Return the distance between two positions as a SpatialVector. Both positions are normalised to WGS84 before the comparison. The formula used (Haversine) calculates the Great Circle distance assuming the earth is spherical. It is accurate to within 1% or so. If you need high accuracy values you should refer to methods such as the Vincenty formula ( http://www.movable-type.co.uk/scripts/LatLongVincenty.html).

Specified by:
vectorBetween in class Position
Parameters:
position - the position to compare against.
Returns:
the distance between the two positions, in metres.
Throws:
OziException - if OziAPI returns an error.

addVector

public LatLon addVector(SpatialVector vector)
                 throws OziException
Return a new LatLon which is offset from the current position by the given vector, specified as a SpatialVector. The return value is in the same datum as the current lat/lon. The formula used calculates the Great Circle distance assuming the earth is spherical. It is accurate to within 1% or so. If you need high accuracy values you should refer to methods such as the Vincenty formula ( http://www.movable-type.co.uk/scripts/LatLongVincenty.html).

Specified by:
addVector in class Position
Parameters:
vector - the SpatialVector to offset by.
Returns:
the new LatLon.
Throws:
OziException - if OziAPI returns an error.

equals

public boolean equals(Object that)
Test if two lat/lon positions are equal. Both positions are normalised to LatLons in the WGS84 datum before the comparison, and the positions will compare as equal if they are within Position.getComparisonAccuracy() of each other.

Overrides:
equals in class Object
Parameters:
that - the object to compare against.
Returns:
true if the objects are equal, within the specified bounds..

hashCode

public int hashCode()
Return the hash code for this object.

Overrides:
hashCode in class Object
Returns:
the hash code for this object.

getLat

public double getLat()
Return the lattitude of the LatLon.

Returns:
the lattitude of the LatLon.

getLon

public double getLon()
Return the longitude of the LatLon.

Returns:
the longitude of the LatLon.

toString

public String toString()
Return a string representation of the LatLon, of the form decimal lattitude, decimal longitude (datum)

Overrides:
toString in class Object
Returns:
a string representation of the LatLon.

toDMS

public String toDMS()
Return a string representation of the LatLon, of the form dd°mm'ss.ss"[WE] dd°mm'ss.ss"[NS] (datum)

Returns:
a string representation of the LatLon.