Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Magnus Persson http://www.derelik.net

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Python: NMEA GPGGA parser

Not tested extensivly, use with caution! I used an LD-1W and it seems to work alright with this parser.

   1  
   2  class GPGGAParser(object):
   3  	import logging
   4  	
   5  	def __init__(self, sentance):
   6  		import time, logging
   7  		
   8  		logging.debug("GPPGAParser started")
   9  		logging.debug("Trying to parse: "+sentance)
  10  		(self.format,
  11  		 self.utc,
  12  		 self.latitude, 
  13  		 self.northsouth, 
  14  		 self.longitude, 
  15  		 self.eastwest, 
  16  		 self.quality, 
  17  		 self.number_of_satellites_in_use, 
  18  		 self.horizontal_dilution, 
  19  		 self.altitude, 
  20  		 self.above_sea_unit, 
  21  		 self.geoidal_separation, 
  22  		 self.geoidal_separation_unit, 
  23  		 self.data_age, 
  24  		 self.diff_ref_stationID) = sentance.split(",")
  25  
  26  		latitude_in=float(self.latitude)
  27  		longitude_in=float(self.longitude)
  28  		if self.northsouth == 'S':
  29  			latitude_in = -latitude_in
  30  		if self.eastwest == 'W':
  31  			longitude_in = -longitude_in
  32  
  33  		latitude_degrees = int(latitude_in/100)
  34  		latitude_minutes = latitude_in - latitude_degrees*100
  35  		
  36  		longitude_degrees = int(longitude_in/100)
  37  		longitude_minutes = longitude_in - longitude_degrees*100
  38  		
  39  		self.latitude = latitude_degrees + (latitude_minutes/60)
  40  		self.longitude = longitude_degrees + (longitude_minutes/60)
  41  		
  42  		self.timeOfFix = time.strftime("%H:%M:%S", time.strptime(self.utc.split(".")[0],"%H%M%S"))
  43  		self.altitude = float(self.altitude)
  44  		logging.debug("GPPGAParser finished")
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS