Sha256: fc5971973c02a7ad48c5a4f23669b95ec802ab27be910a946a3ab61960a61039

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

require 'gpx'

# convert from GPX to V900
module GPX2V900
  
  # read a GPX file and make it into an array of V900 CSV files (one per GPX track)
  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

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
columbus3-0.5.1 lib/columbus3/v900track/gpx2v900.rb
columbus3-0.6.0 lib/columbus3/v900track/gpx2v900.rb
columbus3-0.5.0 lib/columbus3/v900track/gpx2v900.rb