gpx_utils 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'nokogiri'
4
+ gem 'builder'
5
+
6
+ group :development do
7
+ gem "rspec"
8
+ gem "bundler"
9
+ gem "jeweler"
10
+ gem "simplecov"
11
+ end
@@ -0,0 +1,40 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ builder (3.2.0)
5
+ diff-lcs (1.2.1)
6
+ git (1.2.5)
7
+ jeweler (1.8.4)
8
+ bundler (~> 1.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ rdoc
12
+ json (1.7.7)
13
+ multi_json (1.6.1)
14
+ nokogiri (1.5.6)
15
+ rake (10.0.3)
16
+ rdoc (4.0.0)
17
+ json (~> 1.4)
18
+ rspec (2.13.0)
19
+ rspec-core (~> 2.13.0)
20
+ rspec-expectations (~> 2.13.0)
21
+ rspec-mocks (~> 2.13.0)
22
+ rspec-core (2.13.0)
23
+ rspec-expectations (2.13.0)
24
+ diff-lcs (>= 1.1.3, < 2.0)
25
+ rspec-mocks (2.13.0)
26
+ simplecov (0.7.1)
27
+ multi_json (~> 1.0)
28
+ simplecov-html (~> 0.7.1)
29
+ simplecov-html (0.7.1)
30
+
31
+ PLATFORMS
32
+ ruby
33
+
34
+ DEPENDENCIES
35
+ builder
36
+ bundler
37
+ jeweler
38
+ nokogiri
39
+ rspec
40
+ simplecov
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,92 @@
1
+ gpx_utils
2
+ =======
3
+
4
+ Import track file
5
+ -----------------
6
+
7
+ g = GpxUtils::TrackImporter.new
8
+ g.add_file('track_file.gpx')
9
+ g.coords
10
+ => [{:lat=>52.4606258981, :lon=>16.9213317242, :time=>2012-03-24 18:48:22 +0100, :alt=>83.77}, ...]
11
+
12
+
13
+ Import waypoints file
14
+ ---------------------
15
+
16
+ g = GpxUtils::WaypointsImporter.new
17
+ g.add_file('waypoints.gpx')
18
+ g.pois
19
+ => [{:lat=>49.461531, :lon=>21.160355, :time=>2012-04-30 09:10:48 +0200, :alt=>492.629486, :name=>"PKS", :sym=>"Trail Head"}, ...]
20
+
21
+
22
+ Export waypoints to GPX file
23
+ ------------------------
24
+
25
+ g = GpxUtils::WaypointsExporter.new
26
+ lat = 52.384444
27
+ lon = 16.193056
28
+ name = "point"
29
+ cmt = "comment" # optional
30
+ time = "created_at" # optional
31
+ ele = 200 # 200m above sea level, optional
32
+ sym = "Trail Head" # Garmin icon string, optional
33
+ g.addg.add(lat, lon, name, cmt, time, ele, sym)
34
+ #g.addg.add(lat, lon, name) # w/o optional parameters
35
+ xml = g.to_xml
36
+ xmp # GPX file content
37
+
38
+
39
+ Create waypoint files
40
+ ---------------------
41
+
42
+ You can prepare your own list of waypoints and then store into Garmin eTrex device using a GPX file. At this moment there is
43
+ only possible to convert data from YAML file to GPX. It is also possible to integrate with other (web)apps.
44
+
45
+ How to use it
46
+ -------------
47
+
48
+ 1. Check samples/sample_yaml_pois.yml as a template.
49
+
50
+ 2. Modify it, add yours POIs.
51
+
52
+ 3. Run command
53
+
54
+ generate_garmin_waypoints -y input_file.yml > output.gpx
55
+
56
+ 4. You can check inter-POI distances using
57
+
58
+ generate_garmin_waypoints -y input_file.yml -C
59
+
60
+ Distance conflict does not mean something is wrong. POIs can be close to each other so it
61
+ is a good idea to have your brain turned on ;)
62
+
63
+ 5. You can change inter-POI distances using 'latlon something' distance for distance checking
64
+ explained line before.
65
+
66
+ generate_garmin_waypoints -y samples/sample_yaml_pois.yml -C -t 1
67
+
68
+ 6. You can specify output file if you don't like using >> 'file.gpx'.
69
+
70
+ generate_garmin_waypoints -y samples/sample_yaml_pois.yml -o file.gpx
71
+
72
+
73
+ Contributing to gpx_utils
74
+ -------------------------------
75
+
76
+ [![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=bobik314&url=https://github.com/akwiatkowski/gpx_utils&title=gpx_utils&language=en_GB&tags=github&category=software)
77
+
78
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
79
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
80
+ * Fork the project
81
+ * Start a feature/bugfix branch
82
+ * Commit and push until you are happy with your contribution
83
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
84
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
85
+
86
+
87
+ Copyright
88
+ ---------
89
+
90
+ Copyright (c) 2012-2013 Aleksander Kwiatkowski. See LICENSE.txt for
91
+ further details.
92
+
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "gpx_utils"
18
+ gem.homepage = "http://github.com/akwiatkowski/gpx_utils"
19
+ gem.license = "LGPLv3"
20
+ gem.summary = %Q{GPX file utilities}
21
+ gem.description = %Q{GPX file utilities. Import track file, import/export waypoints file.}
22
+ gem.email = "bobikx@poczta.fm"
23
+ gem.authors = ["Aleksander Kwiatkowski"]
24
+ # dependencies defined in Gemfile
25
+ gem.executables = ['generate_garmin_waypoints']
26
+
27
+ gem.files = FileList[
28
+ "[A-Z]*", "{bin,generators,lib,test}/**/*"
29
+ ]
30
+ end
31
+ Jeweler::RubygemsDotOrgTasks.new
32
+
33
+ require 'rspec/core'
34
+ require 'rspec/core/rake_task'
35
+ RSpec::Core::RakeTask.new(:spec) do |spec|
36
+ spec.pattern = FileList['spec/**/*_spec.rb']
37
+ end
38
+
39
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
40
+ spec.pattern = 'spec/**/*_spec.rb'
41
+ spec.rcov = true
42
+ end
43
+
44
+ task :default => :spec
45
+
46
+ require 'rdoc/task'
47
+
48
+ desc "Run RSpec with code coverage"
49
+ task :coverage do
50
+ `rake spec COVERAGE=true`
51
+ #`open coverage/index.html`
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'gpx_utils'
5
+ require 'optparse'
6
+
7
+ options = { }
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: generate_garmin_waypoints [options]"
10
+
11
+ opts.on("-y", "--yaml FILE", "Add points from yaml file") do |v|
12
+ options[:yaml] = v
13
+ end
14
+ opts.on("-C", "--check", "Check distance of waypoints") do
15
+ options[:check] = true
16
+ end
17
+ opts.on("-t", "--check_threshold DISTANCE", "Min distance of waypoints") do |v|
18
+ options[:check_threshold] = v
19
+ end
20
+ opts.on("-o", "--output FILE", "Save output to file") do |v|
21
+ options[:output_file] = v
22
+ end
23
+ end.parse!
24
+
25
+ g = GpxUtils::WaypointsExporter.new
26
+ if options[:yaml]
27
+ g.add_yaml_file(options[:yaml])
28
+ end
29
+ if options[:check_threshold]
30
+ g.check_min_threshold = options[:check_threshold].to_f
31
+ end
32
+
33
+ # result
34
+ if options[:check]
35
+ g.check
36
+ else
37
+ xml = g.to_xml
38
+ if options[:output_file]
39
+ f = File.open(options[:output_file], 'w')
40
+ f.puts xml
41
+ f.close
42
+ else
43
+ puts xml
44
+ end
45
+
46
+ end
@@ -0,0 +1,9 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'gpx_utils/waypoints_exporter'
4
+ require 'gpx_utils/waypoints_importer'
5
+
6
+ require 'gpx_utils/track_importer'
7
+
8
+ module GpxUtils
9
+ end
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+
4
+ #$:.unshift(File.dirname(__FILE__))
5
+
6
+ # Simple parsing GPX file
7
+ module GpxUtils
8
+ class TrackImporter
9
+
10
+ def initialize
11
+ @coords = Array.new
12
+ end
13
+
14
+ attr_reader :coords
15
+
16
+ def add_file(path)
17
+ f = File.new(path)
18
+ doc = Nokogiri::XML(f)
19
+ doc.remove_namespaces!
20
+ a = Array.new
21
+ error_count = 0
22
+
23
+ trackpoints = doc.xpath('//gpx/trk/trkseg/trkpt')
24
+ trackpoints.each do |wpt|
25
+ w = {
26
+ :lat => wpt.xpath('@lat').to_s.to_f,
27
+ :lon => wpt.xpath('@lon').to_s.to_f,
28
+ :time => proc_time(wpt.xpath('time').children.first.to_s),
29
+ :alt => wpt.xpath('ele').children.first.to_s.to_f
30
+ }
31
+
32
+ if self.class.coord_valid?(w[:lat], w[:lon], w[:alt], w[:time])
33
+ a << w
34
+ else
35
+ error_count += 1
36
+ end
37
+
38
+ end
39
+
40
+ f.close
41
+
42
+ @coords += a
43
+ @coords = @coords.sort { |b, c| b[:time] <=> c[:time] }
44
+ end
45
+
46
+ # Only import valid coords
47
+ def self.coord_valid?(lat, lon, elevation, time)
48
+ return true if lat and lon
49
+ return false
50
+ end
51
+
52
+ def self.proc_time(ts)
53
+ if ts =~ /(\d{4})-(\d{2})-(\d{2})T(\d{1,2}):(\d{2}):(\d{2})Z/
54
+ return Time.gm($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i).localtime
55
+ end
56
+ end
57
+
58
+ def proc_time(ts)
59
+ self.class.proc_time(ts)
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,133 @@
1
+ require 'rubygems'
2
+ require 'builder'
3
+ require 'yaml'
4
+
5
+ $:.unshift(File.dirname(__FILE__))
6
+
7
+ module GpxUtils
8
+ class WaypointsExporter
9
+
10
+ def initialize
11
+ @pois = Array.new
12
+ @etrex_model = "eTrex 30"
13
+ @check_min_threshold = 0.01
14
+ end
15
+
16
+ attr_accessor :check_min_threshold
17
+ attr_accessor :etrex_model
18
+
19
+ def add_yaml_file(y)
20
+ @pois += YAML::load_file(y)
21
+ end
22
+
23
+ def add(lat, lon, name, cmt = nil, time = nil, ele = nil, sym = nil)
24
+ @pois << {
25
+ :lat => lat,
26
+ :lon => lon,
27
+ :name => name,
28
+ :cmt => cmt,
29
+ :time => time,
30
+ :ele => ele,
31
+ :sym => sym
32
+ }
33
+ end
34
+
35
+ def check
36
+ puts "Distance conflicts:"
37
+
38
+ sorted = @pois.sort { |p, q| p[:lat] <=> q[:lat] }
39
+ (1...sorted.size).each do |i|
40
+ l = (sorted[i-1][:lat] - sorted[i][:lat]) ** 2 +
41
+ (sorted[i-1][:lon] - sorted[i][:lon]) ** 2
42
+ l = Math.sqrt(l)
43
+
44
+ if l < @check_min_threshold
45
+ puts "* #{sorted[i-1][:name]} - #{sorted[i][:name]} = #{l}"
46
+ end
47
+ end
48
+ end
49
+
50
+ def to_xml
51
+ #xml = Builder::XmlMarkup.new(:indent => 2)
52
+ string = ""
53
+ xml = Builder::XmlMarkup.new(:target => string, :indent => 0)
54
+ xml.instruct! :xml, :encoding => "UTF-8", :standalone => 'no'
55
+ xml.gpx(
56
+ 'xmlns' => "http://www.topografix.com/GPX/1/1",
57
+ 'xmlns:gpxx' => "http://www.garmin.com/xmlschemas/GpxExtensions/v3",
58
+ 'xmlns:wptx1' => "http://www.garmin.com/xmlschemas/WaypointExtension/v1",
59
+ 'xmlns:gpxtpx' => "http://www.garmin.com/xmlschemas/TrackPointExtension/v1",
60
+ 'creator' => @etrex_model,
61
+ 'version' => "1.1",
62
+ 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
63
+ '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"
64
+
65
+
66
+ ) do |g|
67
+ g.metadata do |meta|
68
+ meta.link('href' => "http://www.garmin.com") do |link|
69
+ link.text 'Garmin International'
70
+ end
71
+ meta.time process_time(Time.now) # 2012-03-24T15:41:34Z
72
+ end
73
+
74
+ # coords
75
+ # <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>
76
+ @pois.each do |poi|
77
+ g.wpt('lat' => poi[:lat], 'lon' => poi[:lon]) do |wp|
78
+ wp.ele poi[:elevation] unless poi[:elevation].nil?
79
+ wp.ele poi[:ele] unless poi[:ele].nil?
80
+
81
+ unless poi[:time].nil?
82
+ wp.time process_time(poi[:time])
83
+ else
84
+ wp.time process_time(Time.now)
85
+ end
86
+ wp.name poi[:name]
87
+
88
+ wp.cmt poi[:comment] unless poi[:comment].nil?
89
+ wp.cmt poi[:cmt] unless poi[:cmt].nil?
90
+
91
+ wp.sym poi[:sym] || "Flag, Blue" # default garmin symbol
92
+ end
93
+ end
94
+ end
95
+
96
+ #return string
97
+ return string.gsub(/\n/, '').gsub(/\r/, '')
98
+
99
+ end
100
+
101
+ attr_reader :pois
102
+
103
+ def self.symbols
104
+ # http://freegeographytools.com/2008/garmin-gps-unit-waypoint-icons-table
105
+ [
106
+ "Flag, Blue",
107
+ "Flag, Green",
108
+ "Flag, Red",
109
+
110
+ "Pin, Blue",
111
+ "Pin, Green",
112
+ "Pin, Red",
113
+
114
+ "Block, Blue",
115
+ "Block, Green",
116
+ "Block, Red",
117
+
118
+ "Summit",
119
+ "Trail Head", # other trail parts, not summits
120
+ "Lodging", # rooms
121
+
122
+ "Ground Transportation" # all public ground transportation
123
+ # ...
124
+
125
+ ]
126
+ end
127
+
128
+ def process_time(time)
129
+ time.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
130
+ end
131
+
132
+ end
133
+ end
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+
3
+ $:.unshift(File.dirname(__FILE__))
4
+
5
+ module GpxUtils
6
+ class WaypointsImporter
7
+
8
+ def initialize
9
+ @pois = Array.new
10
+ end
11
+
12
+ attr_reader :pois
13
+
14
+ def add_file(y)
15
+ @pois += parse_gpx_file(y)
16
+ end
17
+
18
+ def parse_gpx_file(path)
19
+ f = File.new(path)
20
+ doc = Nokogiri::XML(f)
21
+ doc.remove_namespaces!
22
+ a = Array.new
23
+
24
+ trackpoints = doc.xpath('//gpx/wpt')
25
+ trackpoints.each do |wpt|
26
+ w = {
27
+ :lat => wpt.xpath('@lat').to_s.to_f,
28
+ :lon => wpt.xpath('@lon').to_s.to_f,
29
+ :time => GpxUtils::TrackImporter.proc_time(wpt.xpath('time').children.first.to_s),
30
+ :alt => wpt.xpath('ele').children.first.to_s.to_f,
31
+ :name => wpt.xpath('name').children.first.to_s,
32
+ :sym => wpt.xpath('sym').children.first.to_s
33
+ }
34
+ a << w
35
+ end
36
+ f.close
37
+
38
+ return a
39
+ end
40
+
41
+ #def add(lat, lon, name, cmt = nil, time = nil, ele = nil, sym = nil)
42
+ # @pois << {
43
+ # :lat => lat,
44
+ # :lon => lon,
45
+ # :name => name,
46
+ # :cmt => cmt,
47
+ # :time => time,
48
+ # :ele => ele,
49
+ # :sym => sym
50
+ # }
51
+ #end
52
+
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gpx_utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aleksander Kwiatkowski
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: builder
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: jeweler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: GPX file utilities. Import track file, import/export waypoints file.
111
+ email: bobikx@poczta.fm
112
+ executables:
113
+ - generate_garmin_waypoints
114
+ extensions: []
115
+ extra_rdoc_files:
116
+ - LICENSE.txt
117
+ - README.md
118
+ files:
119
+ - Gemfile
120
+ - Gemfile.lock
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - VERSION
125
+ - bin/generate_garmin_waypoints
126
+ - lib/gpx_utils.rb
127
+ - lib/gpx_utils/track_importer.rb
128
+ - lib/gpx_utils/waypoints_exporter.rb
129
+ - lib/gpx_utils/waypoints_importer.rb
130
+ homepage: http://github.com/akwiatkowski/gpx_utils
131
+ licenses:
132
+ - LGPLv3
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ segments:
144
+ - 0
145
+ hash: 1493344088922146458
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 1.8.24
155
+ signing_key:
156
+ specification_version: 3
157
+ summary: GPX file utilities
158
+ test_files: []