net.sf.marineapi.nmea.util
Class Position

java.lang.Object
  extended by net.sf.marineapi.nmea.util.Position
Direct Known Subclasses:
Waypoint

public class Position
extends Object

Represents a geographic position. The default datum is WGS84, unless some other datum is explicitly specified.

Version:
$Revision: 104 $
Author:
Kimmo Tuukkanen

Constructor Summary
Position(double lat, CompassPoint lath, double lon, CompassPoint lonh)
          Creates a new instance of Position.
Position(double lat, CompassPoint lath, double lon, CompassPoint lonh, Datum datum)
          Creates new instance of Position.
 
Method Summary
 double distanceTo(Position pos)
          Calculates the distance to specified Position.
 double getAltitude()
          Gets the position altitude from mean sea level.
 Datum getDatum()
          Gets the datum, i.e. the coordinate system used to define geographic position.
 CompassPoint getLatHemisphere()
          Get the hemisphere of latitude (North/South).
 double getLatitude()
          Get latitude value of Position
 double getLongitude()
          Get longitude value of Position
 CompassPoint getLonHemisphere()
          Get the hemisphere of longitude (East/West).
 void setAltitude(double altitude)
          Sets the altitude of position above mean sea level.
 void setLatHemisphere(CompassPoint lathem)
          Set the hemisphere of latitude (North/South).
 void setLatitude(double latitude)
          Set the latitude degrees of Position
 void setLongitude(double longitude)
          Set the longitude degrees of Position
 void setLonHemisphere(CompassPoint lonhem)
          Set the hemisphere of longitude (East/West).
 String toString()
           
 Waypoint toWaypoint(String id)
          Convenience method for creating a waypoint based in the Position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Position

public Position(double lat,
                CompassPoint lath,
                double lon,
                CompassPoint lonh)
Creates a new instance of Position. Notice that altitude defaults to 0.0, unless set with setAltitude(double) method.

Parameters:
lat - Latitude degrees
lath - Hemisphere of latitude
lon - Longitude degrees
lonh - Hemisphere of longitude

Position

public Position(double lat,
                CompassPoint lath,
                double lon,
                CompassPoint lonh,
                Datum datum)
Creates new instance of Position. Notice that altitude defaults to 0.0, unless set with setAltitude(double) method.

Parameters:
lat - Latitude degrees
lath - Hemisphere of latitude
lon - Longitude degrees
lonh - Hemisphere of longitude
datum - Datum
Method Detail

distanceTo

public double distanceTo(Position pos)
Calculates the distance to specified Position.

Calculation is done by using the Haversine formula. The mean earth radius used in calculation is 6371.009 km.

The implementation is based on example found at codecodex.com.

Parameters:
pos - Position to which the distance is calculated.
Returns:
Distance to popos in meters.

getAltitude

public double getAltitude()
Gets the position altitude from mean sea level.

Returns:
Altitude value in meters

getDatum

public Datum getDatum()
Gets the datum, i.e. the coordinate system used to define geographic position. Default is Datum.WGS84, unless datum is specified in the constructor. Notice also that datum cannot be set afterwards.

Returns:
Datum enum

getLatHemisphere

public CompassPoint getLatHemisphere()
Get the hemisphere of latitude (North/South).

Returns:
Direction.NORTH or Direction.SOUTH

getLatitude

public double getLatitude()
Get latitude value of Position

Returns:
latitude degrees

getLongitude

public double getLongitude()
Get longitude value of Position

Returns:
longitude degrees

getLonHemisphere

public CompassPoint getLonHemisphere()
Get the hemisphere of longitude (East/West).

Returns:
CompassPoint.E or CompassPoint.W

setAltitude

public void setAltitude(double altitude)
Sets the altitude of position above mean sea level. Defaults to zero.

Parameters:
altitude - Altitude value to set, in meters.

setLatHemisphere

public void setLatHemisphere(CompassPoint lathem)
Set the hemisphere of latitude (North/South).

Parameters:
lathem - The hemisphere to set
Throws:
IllegalArgumentException - If specified hemisphere is other than NORTH or SOUTH.

setLatitude

public void setLatitude(double latitude)
Set the latitude degrees of Position

Parameters:
latitude - the latitude to set
Throws:
IllegalArgumentException - If specified latitude value is out of range 0..90 degrees.

setLongitude

public void setLongitude(double longitude)
Set the longitude degrees of Position

Parameters:
longitude - the longitude to set
Throws:
IllegalArgumentException - If specified longitude value is out of range 0..180 degrees.

setLonHemisphere

public void setLonHemisphere(CompassPoint lonhem)
Set the hemisphere of longitude (East/West).

Parameters:
lonhem - The hemisphere to set
Throws:
IllegalArgumentException - If specified hemisphere is other than EAST or WEST.

toString

public String toString()
Overrides:
toString in class Object

toWaypoint

public Waypoint toWaypoint(String id)
Convenience method for creating a waypoint based in the Position.

Parameters:
id - Waypoint ID or name
Returns:
the created Waypoint


Copyright (C) 2010-2011 Java Marine API author(s). All Rights Reserved.