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. Default datum is WGS84 as generally in NMEA 0183. Notice that datum is only informative and it does not affect calculations or handling of other values.

Author:
Kimmo Tuukkanen

Constructor Summary
Position(double lat, double lon)
          Creates a new instance of Position.
Position(double lat, double lon, Datum datum)
          Creates new instance of Position with latitude, longitude and datum.
Position(double lat, double lon, double alt)
          Creates a new instance of position with latitude, longitude and altitude.
Position(double lat, double lon, double alt, Datum datum)
          Creates new instance of Position with latitude, longitude, altitude and datum.
 
Method Summary
 double distanceTo(Position pos)
          Calculates 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.
 double getLatitude()
          Get latitude value of Position
 CompassPoint getLatitudeHemisphere()
          Get the hemisphere of latitude, North or South.
 double getLongitude()
          Get longitude value of Position
 CompassPoint getLongitudeHemisphere()
          Get the hemisphere of longitude, East or West.
 boolean isLatitudeNorth()
          Tells if the latitude is on northern hemisphere.
 boolean isLongitudeEast()
          Tells if the longitude is on eastern hemisphere.
 void setAltitude(double altitude)
          Sets the altitude of position above or below mean sea level.
 void setLatitude(double latitude)
          Set the latitude degrees of Position
 void setLongitude(double longitude)
          Set the longitude degrees of Position
 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,
                double lon)
Creates a new instance of Position. Notice that altitude defaults to -0.0 and may be set later.

Parameters:
lat - Latitude degrees
lon - Longitude degrees
See Also:
setAltitude(double)

Position

public Position(double lat,
                double lon,
                double alt)
Creates a new instance of position with latitude, longitude and altitude.

Parameters:
lat - Latitude degrees
lon - Longitude degrees
alt - Altitude value, in meters.

Position

public Position(double lat,
                double lon,
                Datum datum)
Creates new instance of Position with latitude, longitude and datum. Notice that altitude defaults to -0.0 and may be set later.

Parameters:
lat - Latitude degrees
lon - Longitude degrees
datum - Datum to set
See Also:
setAltitude(double)

Position

public Position(double lat,
                double lon,
                double alt,
                Datum datum)
Creates new instance of Position with latitude, longitude, altitude and datum.

Parameters:
lat - Latitude degrees
lon - Longitude degrees
datum - Datum to set
Method Detail

distanceTo

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

The Distance is calculated using the Haversine formula. Implementation is based on example found at codecodex.com.

Earth radius earth radius used in calculation is 6366.70702 km, based on the assumption that 1 degrees is exactly 60 NM.

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. Notice that most sentences with position don't provide this value. When missing, the default value in Position is 0.0.

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

getLatitude

public double getLatitude()
Get latitude value of Position

Returns:
latitude degrees

getLatitudeHemisphere

public CompassPoint getLatitudeHemisphere()
Get the hemisphere of latitude, North or South.

Returns:
CompassPoint.NORTH or CompassPoint.SOUTH

getLongitude

public double getLongitude()
Get longitude value of Position

Returns:
longitude degrees

getLongitudeHemisphere

public CompassPoint getLongitudeHemisphere()
Get the hemisphere of longitude, East or West.

Returns:
CompassPoint.EAST or CompassPoint.WEST

isLatitudeNorth

public boolean isLatitudeNorth()
Tells if the latitude is on northern hemisphere.

Returns:
true if northern, otherwise false (south).

isLongitudeEast

public boolean isLongitudeEast()
Tells if the longitude is on eastern hemisphere.

Returns:
true if eastern, otherwise false (west).

setAltitude

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

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

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.

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-2014 Java Marine API authors. All Rights Reserved.