Class: GPX::MagellanTrackLog

Inherits:
Object
  • Object
show all
Defined in:
lib/gpx/magellan_track_log.rb

Overview

This class will parse the lat/lon and time data from a Magellan track log, which is a NMEA formatted CSV list of points.

Constant Summary collapse

LAT =
1
LAT_HEMI =
2
LON =
3
LON_HEMI =
4
ELE =
5
ELE_UNITS =
6
TIME =
7
INVALID_FLAG =
8
DATE =
10
FEET_TO_METERS =
0.3048

Class Method Summary collapse

Class Method Details

.convert_to_gpx(magellan_filename, gpx_filename) ⇒ Object

Takes the name of a magellan file, converts the contents to GPX, and writes the result to gpx_filename.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/gpx/magellan_track_log.rb', line 63

def  convert_to_gpx(magellan_filename, gpx_filename)

   segment = Segment.new

   CSV.open(magellan_filename, "r") do |row| 
      next if(row.size < 10 or row[INVALID_FLAG] == 'V')

      lat_deg  = row[LAT][0..1]
      lat_min  = row[LAT][2...-1]
      lat_hemi = row[LAT_HEMI]

      lat = lat_deg.to_f + (lat_min.to_f / 60.0)
      lat = (-lat) if(lat_hemi == 'S')

      lon_deg      = row[LON][0..2]
      lon_min  = row[LON][3..-1]
      lon_hemi = row[LON_HEMI]

      lon = lon_deg.to_f + (lon_min.to_f / 60.0)
      lon = (-lon) if(lon_hemi == 'W')


      ele = row[ELE]
      ele_units = row[ELE_UNITS]
      ele = ele.to_f
      if(ele_units == 'F')
         ele *= FEET_TO_METERS
      end

      hrs  = row[TIME][0..1].to_i
      mins = row[TIME][2..3].to_i
      secs = row[TIME][4..5].to_i
      day  = row[DATE][0..1].to_i
      mon  = row[DATE][2..3].to_i
      yr   = 2000 + row[DATE][4..5].to_i

      time = Time.gm(yr, mon, day, hrs, mins, secs)

      #must create point
      pt = TrackPoint.new(:lat => lat, :lon => lon, :time => time, :elevation => ele)
      segment.append_point(pt)

   end 

   trk = Track.new
   trk.append_segment(segment)
   gpx_file = GPXFile.new(:tracks => [trk])
   gpx_file.write(gpx_filename)

end

.is_magellan_file?(filename) ⇒ Boolean

Tests to see if the given file is a magellan NMEA track log.

Returns:

  • (Boolean)


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/gpx/magellan_track_log.rb', line 115

def is_magellan_file?(filename)
   i = 0
   File.open(filename, "r") do |f|
      f.each do |line|
         i +=  1
         if line =~ /^\$PMGNTRK/
            return true 
         elsif line =~ /<\?xml/
            return false
         elsif(i > 10)
            return false 
         end
      end
   end
   return false
end