Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

generating garmin waypoint files

  • Loading branch information...
commit ea8d68bf21b55d1063b493fb9819a4a162da3de6 1 parent d2a657e
@akwiatkowski authored
View
1  Gemfile
@@ -2,6 +2,7 @@ source "http://rubygems.org"
gem 'nokogiri'
gem 'mini_exiftool'
+gem 'builder'
group :development do
gem "rspec", "~> 2.3.0"
View
4 Gemfile.lock
@@ -1,6 +1,7 @@
GEM
remote: http://rubygems.org/
specs:
+ builder (3.0.0)
diff-lcs (1.1.3)
git (1.2.5)
jeweler (1.6.4)
@@ -8,7 +9,7 @@ GEM
git (>= 1.2.5)
rake
mini_exiftool (1.3.1)
- multi_json (1.1.0)
+ multi_json (1.2.0)
nokogiri (1.5.2)
rake (0.9.2.2)
rspec (2.3.0)
@@ -28,6 +29,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ builder
bundler (~> 1.0.0)
jeweler (~> 1.6.4)
mini_exiftool
View
22 bin/generate_garmin_waypoints
@@ -0,0 +1,22 @@
+#!/usr/bin/env ruby
+
+require 'rubygems'
+require 'gpx2exif'
+require 'optparse'
+
+options = {}
+OptionParser.new do |opts|
+ opts.banner = "Usage: generate_garmin_waypoints [options]"
+
+ opts.on("-y", "--yaml FILE", "Add points from yaml file") do |v|
+ options[:yaml] = v
+ end
+end.parse!
+
+g = GarminUtils::WaypointListGenerator.new
+if options[:yaml]
+ g.add_yaml_file(options[:yaml])
+end
+
+# result
+puts xml = g.to_xml
View
6 lib/garmin_utils.rb
@@ -0,0 +1,6 @@
+$:.unshift(File.dirname(__FILE__))
+
+require 'garmin_utils/waypoint_list_generator'
+
+module GarminUtils
+end
View
81 lib/garmin_utils/waypoint_list_generator.rb
@@ -0,0 +1,81 @@
+require 'rubygems'
+require 'builder'
+require 'yaml'
+
+$:.unshift(File.dirname(__FILE__))
+
+module GarminUtils
+ class WaypointListGenerator
+
+ def initialize
+ @pois = Array.new
+ @etrex_model = "eTrex 30"
+ end
+
+ def add_yaml_file(y)
+
+ end
+
+ def add(lat, lon, name, cmt = nil, time = nil, ele = nil, sym = nil)
+ @pois << {
+ :lat => lat,
+ :lon => lon,
+ :name => name,
+ :cmt => cmt,
+ :time => time,
+ :ele => ele,
+ :sym => sym
+ }
+ end
+
+ def to_xml
+ xml = Builder::XmlMarkup.new(:indent => 2)
+ xml.instruct! :xml, :encoding => "UTF-8", :standalone => 'no'
+ xml.gpx(
+ 'xmlns' => "http://www.topografix.com/GPX/1/1",
+ 'xmlns:gpxx' => "http://www.garmin.com/xmlschemas/GpxExtensions/v3",
+ 'xmlns:wptx1' => "http://www.garmin.com/xmlschemas/WaypointExtension/v1",
+ 'xmlns:gpxtpx' => "http://www.garmin.com/xmlschemas/TrackPointExtension/v1",
+ 'creator' => @etrex_model,
+ 'version' => "1.1",
+ 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
+ 'xsi:schemaLocation' => "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/WaypointExtension/v1 http://www8.garmin.com/xmlschemas/WaypointExtensionv1.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd"
+
+
+ ) do |g|
+ g.metadata do |meta|
+ meta.link('href' => "http://www.garmin.com")
+ meta.text 'Garmin International'
+ meta.time process_time(Time.now) # 2012-03-24T15:41:34Z
+ end
+
+ # coords
+ # <wpt lat="52.484444" lon="16.893056"><ele>113.286499</ele><time>2012-03-18T16:42:47Z</time><name>GORA MORASKO</name><cmt>DUZY</cmt><sym>Flag, Blue</sym></wpt>
+ @pois.each do |poi|
+ g.wpt('lat' => poi[:lat], 'lon' => poi[:lon]) do |wp|
+ wp.ele poi[:elevation] unless poi[:elevation].nil?
+ wp.ele poi[:ele] unless poi[:ele].nil?
+
+ wp.time process_time(poi[:time])
+ wp.name poi[:name]
+
+ wp.cmt poi[:comment] unless poi[:comment].nil?
+ wp.cmt poi[:cmt] unless poi[:cmt].nil?
+
+ wp.sym poi[:sym] || "Flag, Blue" # default garmin symbol
+ end
+ end
+ end
+
+ return xml.to_s
+
+ end
+
+ attr_reader :pois
+
+ def process_time(time)
+ time.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
+ end
+
+ end
+end
View
2  lib/gpx2exif.rb
@@ -1,5 +1,7 @@
$:.unshift(File.dirname(__FILE__))
+require 'garmin_utils'
+
require 'gpx2exif/gpx_parser'
require 'gpx2exif/exif_editor'
require 'gpx2exif/geo_manager'
View
2  lib/gpx2exif/exif_editor.rb
@@ -14,7 +14,7 @@ def initialize
attr_reader :images
attr_accessor :global_time_offset
- def read_file(path, time_offset)
+ def read_file(path, time_offset = 0)
i = {
:path => path,
:time => get_photo_time(path) + time_offset + @global_time_offset
View
21 spec/waypoint_list_generator_spec.rb
@@ -0,0 +1,21 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe GarminUtils::WaypointListGenerator do
+ it "should create empty xml" do
+ g = GarminUtils::WaypointListGenerator.new
+ xml = g.to_xml
+ xml.should be_kind_of(String)
+
+ #puts xml
+ end
+
+ it "should create xml with 1 poi" do
+ g = GarminUtils::WaypointListGenerator.new
+ # <wpt lat="52.484444" lon="16.893056"><ele>113.286499</ele><time>2012-03-18T16:42:47Z</time><name>GORA MORASKO</name><cmt>DUZY</cmt><sym>Flag, Blue</sym></wpt>
+ g.add(52.384444, 16.193056, 'test', nil, Time.now - 3600, 120, nil)
+
+ xml = g.to_xml
+ xml.should be_kind_of(String)
+ puts xml
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.