Search in sources :

Example 6 with Position

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;
}
Also used : Position(net.sf.marineapi.nmea.util.Position)

Example 7 with Position

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);
}
Also used : Position(net.sf.marineapi.nmea.util.Position) CompassPoint(net.sf.marineapi.nmea.util.CompassPoint)

Example 8 with Position

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);
}
Also used : Position(net.sf.marineapi.nmea.util.Position)

Example 9 with Position

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);
}
Also used : Position(net.sf.marineapi.nmea.util.Position)

Example 10 with Position

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);
}
Also used : Position(net.sf.marineapi.nmea.util.Position) Test(org.junit.Test)

Aggregations

Position (net.sf.marineapi.nmea.util.Position)16 Test (org.junit.Test)11 DataNotAvailableException (net.sf.marineapi.nmea.parser.DataNotAvailableException)1 GGASentence (net.sf.marineapi.nmea.sentence.GGASentence)1 GLLSentence (net.sf.marineapi.nmea.sentence.GLLSentence)1 RMCSentence (net.sf.marineapi.nmea.sentence.RMCSentence)1 Sentence (net.sf.marineapi.nmea.sentence.Sentence)1 VTGSentence (net.sf.marineapi.nmea.sentence.VTGSentence)1 CompassPoint (net.sf.marineapi.nmea.util.CompassPoint)1 Date (net.sf.marineapi.nmea.util.Date)1 FaaMode (net.sf.marineapi.nmea.util.FaaMode)1 GpsFixQuality (net.sf.marineapi.nmea.util.GpsFixQuality)1 Time (net.sf.marineapi.nmea.util.Time)1 PositionEvent (net.sf.marineapi.provider.event.PositionEvent)1