use of net.sf.marineapi.nmea.util.Position in project marine-api by ktuukkan.
the class GGAParser method getPosition.
/*
* (non-Javadoc)
* @see net.sf.marineapi.nmea.sentence.PositionSentence#getPosition()
*/
public Position getPosition() {
Position pos = parsePosition(LATITUDE, LAT_HEMISPHERE, LONGITUDE, LON_HEMISPHERE);
if (hasValue(ALTITUDE) && hasValue(ALTITUDE_UNITS)) {
double alt = getAltitude();
if (getAltitudeUnits().equals(Units.FEET)) {
alt = (alt / 0.3048);
}
pos.setAltitude(alt);
}
return pos;
}
use of net.sf.marineapi.nmea.util.Position in project marine-api by ktuukkan.
the class PositionParser method parsePosition.
/**
* Parses a <code>Position</code> from specified fields.
*
* @param latIndex Latitude field index
* @param latHemIndex Latitude hemisphere field index
* @param lonIndex Longitude field index
* @param lonHemIndex Longitude hemisphere field index
* @return Position object
*/
protected Position parsePosition(int latIndex, int latHemIndex, int lonIndex, int lonHemIndex) {
double lat = parseLatitude(latIndex);
double lon = parseLongitude(lonIndex);
CompassPoint lath = parseHemisphereLat(latHemIndex);
CompassPoint lonh = parseHemisphereLon(lonHemIndex);
if (lath.equals(CompassPoint.SOUTH)) {
lat = -lat;
}
if (lonh.equals(CompassPoint.WEST)) {
lon = -lon;
}
return new Position(lat, lon);
}
use of net.sf.marineapi.nmea.util.Position in project marine-api by ktuukkan.
the class RMBParser method getDestination.
/*
* (non-Javadoc)
* @see net.sf.marineapi.nmea.sentence.RMBSentence#getDestination()
*/
public Waypoint getDestination() {
String id = getStringValue(DEST_WPT);
Position p = parsePosition(DEST_LAT, DEST_LAT_HEM, DEST_LON, DEST_LON_HEM);
return p.toWaypoint(id);
}
use of net.sf.marineapi.nmea.util.Position in project marine-api by ktuukkan.
the class WPLParser method getWaypoint.
/*
* (non-Javadoc)
* @see net.sf.marineapi.nmea.sentence.WPLSentence#getWaypoint()
*/
public Waypoint getWaypoint() {
String id = getStringValue(WAYPOINT_ID);
Position p = parsePosition(LATITUDE, LAT_HEMISPHERE, LONGITUDE, LON_HEMISPHERE);
return p.toWaypoint(id);
}
use of net.sf.marineapi.nmea.util.Position in project marine-api by ktuukkan.
the class GLLTest method testSetPositionWithZeroValues.
/**
* Test method for
* {@link net.sf.marineapi.nmea.parser.GLLParser#setPosition(Position)}.
*/
@Test
public void testSetPositionWithZeroValues() {
Position p1 = new Position(0.0, 0.0);
instance.setPosition(p1);
String s1 = instance.toString();
Position p = instance.getPosition();
assertTrue(s1.contains(",0000.000,N,"));
assertTrue(s1.contains(",00000.000,E,"));
assertNotNull(p);
assertEquals(0.0, p.getLatitude(), 0.0000001);
assertEquals(0.0, p.getLongitude(), 0.0000001);
}
Aggregations