Module: GPX2V900

Defined in:
lib/columbus3/v900track/gpx2v900.rb

Overview

convert from GPX to V900

Class Method Summary collapse

Class Method Details

.gpx2v900(file) ⇒ Object

read a GPX file and make it into an array of V900 CSV files (one per GPX track)



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/columbus3/v900track/gpx2v900.rb', line 7

def self.gpx2v900 file
  input = GPX::GPXFile.new(gpx_file: file)
  v900_files = Array.new

  input.tracks.each_with_index do |track, track_index|
    v900_file = V900Track.new filename: file.gsub(/\.[^.]+$/, "") + (input.tracks.size > 1 ? "-#{track_index}" : "") + ".csv", empty: true
    track.points.each_with_index do |waypoint, index|

      row = {"INDEX" => index,
             "DATE"  => waypoint.time.strftime("%y%m%d"),
             "TIME"  =>  waypoint.time.strftime("%H%M%S"),
             "LONGITUDE E/W" => waypoint.lon.abs.to_s + (waypoint.lon > 0 ? "E" : ""),
             "LATITUDE N/S"  => waypoint.lat.abs.to_s + (waypoint.lat > 0 ? "N" : ""),
             "HEIGHT"  =>  waypoint.elevation.to_i,
             "SPEED"   => waypoint.speed.to_i,
             "HEADING" => -1}
      v900_file.add V900Waypoint.new(row)
    end
    v900_files << v900_file
  end

  v900_files
end