module GPX2V900

convert from GPX to V900

Public Class Methods

gpx2v900(file) click to toggle source

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

# 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