Python library for parsing and generating NMEA 0183 protocol messages used in GPS and marine navigation systems
77
Navigation and course sentences provide heading, bearing, waypoint, and route information for marine and land navigation systems.
class HDG(TalkerSentence):
"""Heading, Deviation and Variation."""
heading: str # Magnetic heading in degrees
deviation: str # Magnetic deviation in degrees
dev_dir: str # Deviation direction ('E' or 'W')
variation: str # Magnetic variation in degrees
var_dir: str # Variation direction ('E' or 'W')class HDT(TalkerSentence):
"""Heading True."""
heading: str # True heading in degrees
hdg_true: str # Always 'T' for trueclass HDM(TalkerSentence):
"""Heading, Magnetic."""
heading: str # Magnetic heading in degrees
magnetic: str # Always 'M' for magneticclass BWC(TalkerSentence):
"""Bearing & Distance to Waypoint - Great Circle."""
timestamp: datetime.time
lat_next: str # Next waypoint latitude
lat_next_direction: str # 'N' or 'S'
lon_next: str # Next waypoint longitude
lon_next_direction: str # 'E' or 'W'
true_track: str # True bearing to waypoint
true_track_sym: str # 'T' for true
mag_track: str # Magnetic bearing to waypoint
mag_sym: str # 'M' for magnetic
range_next: str # Distance to waypoint
range_unit: str # Distance unit ('N' for nautical miles)
waypoint_name: str # Waypoint identifierclass WPL(TalkerSentence):
"""Waypoint Location."""
lat: str # Waypoint latitude
lat_dir: str # 'N' or 'S'
lon: str # Waypoint longitude
lon_dir: str # 'E' or 'W'
waypoint_id: str # Waypoint identifierclass RTE(TalkerSentence):
"""Routes."""
num_in_seq: str # Total number of sentences in sequence
sen_num: str # Sentence number
start_type: str # Message type ('c' = complete route, 'w' = working route)
active_route_id: str # Active route identifier
@property
def waypoint_list(self) -> List[str]:
"""List of waypoint identifiers in the route."""
@waypoint_list.setter
def waypoint_list(self, waypoints: List[str]):
"""Set the waypoint list."""import pynmea2
# Parse heading sentence
msg = pynmea2.parse("$HCHDG,98.3,0.6,E,12.6,W*57")
print(f"Magnetic heading: {msg.heading}°") # 98.3°
print(f"Deviation: {msg.deviation}°{msg.dev_dir}") # 0.6°E
print(f"Variation: {msg.variation}°{msg.var_dir}") # 12.6°W
# Parse waypoint bearing sentence
msg = pynmea2.parse("$GPBWC,220516,5130.02,N,00046.34,W,213.8,T,218.0,M,0004.6,N,EGLM*11")
print(f"Next waypoint: {msg.waypoint_name}") # EGLM
print(f"Distance: {msg.range_next} {msg.range_unit}") # 0004.6 N
print(f"True bearing: {msg.true_track}°{msg.true_track_sym}") # 213.8°T
# Parse route sentence
msg = pynmea2.parse("$GPRTE,2,1,c,0,PBRCPK,PBRTO,PTELGR,PPLAND,PYAMBU,PPFAIR,PWARRN,PMORTL,PLISMR*73")
print(f"Route sentence {msg.sen_num} of {msg.num_in_seq}") # 1 of 2
print(f"Route type: {msg.start_type}") # c (complete)
print(f"Waypoints: {msg.waypoint_list}") # ['PBRCPK', 'PBRTO', ...]Install with Tessl CLI
npx tessl i tessl/pypi-pynmea2docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10