gpx2exif 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -6
- data/Gemfile.lock +65 -24
- data/Rakefile +2 -10
- data/VERSION +1 -1
- data/lib/ski_analyzer/analyzer.rb +192 -0
- data/lib/ski_analyzer.rb +6 -0
- metadata +80 -32
- data/bin/generate_garmin_waypoints +0 -46
- data/lib/gpx_utils/track_importer.rb +0 -63
- data/lib/gpx_utils/waypoints_exporter.rb +0 -133
- data/lib/gpx_utils/waypoints_importer.rb +0 -54
data/Gemfile
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
gem 'nokogiri'
|
4
3
|
gem 'mini_exiftool'
|
5
|
-
gem '
|
4
|
+
gem 'rmagick'
|
5
|
+
gem 'chunky_png'
|
6
|
+
gem 'gpx_utils'
|
6
7
|
|
7
8
|
group :development do
|
8
|
-
gem "rspec"
|
9
|
-
gem "bundler"
|
10
|
-
gem "jeweler"
|
11
|
-
gem "simplecov"
|
9
|
+
gem "rspec"
|
10
|
+
gem "bundler"
|
11
|
+
gem "jeweler"
|
12
|
+
gem "simplecov"
|
12
13
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,38 +1,79 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
addressable (2.3.5)
|
5
|
+
builder (3.2.2)
|
6
|
+
chunky_png (1.2.9)
|
7
|
+
diff-lcs (1.2.5)
|
8
|
+
docile (1.1.1)
|
9
|
+
faraday (0.8.8)
|
10
|
+
multipart-post (~> 1.2.0)
|
11
|
+
git (1.2.6)
|
12
|
+
github_api (0.10.1)
|
13
|
+
addressable
|
14
|
+
faraday (~> 0.8.1)
|
15
|
+
hashie (>= 1.2)
|
16
|
+
multi_json (~> 1.4)
|
17
|
+
nokogiri (~> 1.5.2)
|
18
|
+
oauth2
|
19
|
+
gpx_utils (0.0.1)
|
20
|
+
builder
|
21
|
+
nokogiri
|
22
|
+
hashie (2.0.5)
|
23
|
+
highline (1.6.20)
|
24
|
+
httpauth (0.2.0)
|
25
|
+
jeweler (1.8.8)
|
26
|
+
builder
|
8
27
|
bundler (~> 1.0)
|
9
28
|
git (>= 1.2.5)
|
29
|
+
github_api (= 0.10.1)
|
30
|
+
highline (>= 1.6.15)
|
31
|
+
nokogiri (= 1.5.10)
|
10
32
|
rake
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
33
|
+
rdoc
|
34
|
+
json (1.8.1)
|
35
|
+
jwt (0.1.8)
|
36
|
+
multi_json (>= 1.5)
|
37
|
+
mini_exiftool (2.3.0)
|
38
|
+
multi_json (1.8.2)
|
39
|
+
multi_xml (0.5.5)
|
40
|
+
multipart-post (1.2.0)
|
41
|
+
nokogiri (1.5.10)
|
42
|
+
oauth2 (0.9.2)
|
43
|
+
faraday (~> 0.8)
|
44
|
+
httpauth (~> 0.2)
|
45
|
+
jwt (~> 0.1.4)
|
24
46
|
multi_json (~> 1.0)
|
25
|
-
|
26
|
-
|
47
|
+
multi_xml (~> 0.5)
|
48
|
+
rack (~> 1.2)
|
49
|
+
rack (1.5.2)
|
50
|
+
rake (10.1.0)
|
51
|
+
rdoc (4.0.1)
|
52
|
+
json (~> 1.4)
|
53
|
+
rmagick (2.13.2)
|
54
|
+
rspec (2.14.1)
|
55
|
+
rspec-core (~> 2.14.0)
|
56
|
+
rspec-expectations (~> 2.14.0)
|
57
|
+
rspec-mocks (~> 2.14.0)
|
58
|
+
rspec-core (2.14.7)
|
59
|
+
rspec-expectations (2.14.4)
|
60
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
61
|
+
rspec-mocks (2.14.4)
|
62
|
+
simplecov (0.8.2)
|
63
|
+
docile (~> 1.1.0)
|
64
|
+
multi_json
|
65
|
+
simplecov-html (~> 0.8.0)
|
66
|
+
simplecov-html (0.8.0)
|
27
67
|
|
28
68
|
PLATFORMS
|
29
69
|
ruby
|
30
70
|
|
31
71
|
DEPENDENCIES
|
32
|
-
|
33
|
-
|
34
|
-
|
72
|
+
bundler
|
73
|
+
chunky_png
|
74
|
+
gpx_utils
|
75
|
+
jeweler
|
35
76
|
mini_exiftool
|
36
|
-
|
37
|
-
rspec
|
77
|
+
rmagick
|
78
|
+
rspec
|
38
79
|
simplecov
|
data/Rakefile
CHANGED
@@ -22,7 +22,7 @@ Jeweler::Tasks.new do |gem|
|
|
22
22
|
gem.email = "bobikx@poczta.fm"
|
23
23
|
gem.authors = ["Aleksander Kwiatkowski"]
|
24
24
|
# dependencies defined in Gemfile
|
25
|
-
gem.executables = ['geotag_all_images', 'geotag_simulate', '
|
25
|
+
gem.executables = ['geotag_all_images', 'geotag_simulate', 'gpx2png']
|
26
26
|
|
27
27
|
gem.files = FileList[
|
28
28
|
"[A-Z]*", "{bin,generators,lib,test}/**/*"
|
@@ -43,15 +43,7 @@ end
|
|
43
43
|
|
44
44
|
task :default => :spec
|
45
45
|
|
46
|
-
require '
|
47
|
-
Rake::RDocTask.new do |rdoc|
|
48
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
-
|
50
|
-
rdoc.rdoc_dir = 'rdoc'
|
51
|
-
rdoc.title = "gpx2exif #{version}"
|
52
|
-
rdoc.rdoc_files.include('README*')
|
53
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
-
end
|
46
|
+
require 'rdoc/task'
|
55
47
|
|
56
48
|
desc "Run RSpec with code coverage"
|
57
49
|
task :coverage do
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -0,0 +1,192 @@
|
|
1
|
+
require 'gpx_utils/waypoints_importer'
|
2
|
+
|
3
|
+
module SkiAnalyzer
|
4
|
+
class Analyzer
|
5
|
+
def initialize(gpx_file, start = nil, finish = nil)
|
6
|
+
@file = gpx_file
|
7
|
+
|
8
|
+
@i = GpxUtils::TrackImporter.new
|
9
|
+
@i.add_file(@file)
|
10
|
+
|
11
|
+
@coords = @i.coords.clone
|
12
|
+
|
13
|
+
# where you start sleeping
|
14
|
+
@start = start
|
15
|
+
@start = find_start if @start.nil?
|
16
|
+
puts "Start - #{@start.inspect}"
|
17
|
+
|
18
|
+
# where you start skiing
|
19
|
+
@finish = finish
|
20
|
+
@finish = find_finish if @finish.nil?
|
21
|
+
puts "Finish - #{@finish.inspect}"
|
22
|
+
|
23
|
+
calculate_speed
|
24
|
+
process
|
25
|
+
descend_results
|
26
|
+
|
27
|
+
#g = Geokit::LatLng.new(@coords.first[:lat], @coords.first[:lon])
|
28
|
+
#puts g.inspect
|
29
|
+
|
30
|
+
#@coords.each do |c|
|
31
|
+
# puts "#{c[:lat]},#{c[:lon]} #{c[:alt]}"
|
32
|
+
#end
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_start
|
36
|
+
@coords.sort { |a, b| a[:alt] <=> b[:alt] }.first
|
37
|
+
end
|
38
|
+
|
39
|
+
def find_finish
|
40
|
+
@coords.sort { |a, b| a[:alt] <=> b[:alt] }.last
|
41
|
+
end
|
42
|
+
|
43
|
+
def calculate_speed
|
44
|
+
(1...@coords.size).each do |i|
|
45
|
+
ga = Geokit::LatLng.new(@coords[i-1][:lat], @coords[i-1][:lon])
|
46
|
+
gb = Geokit::LatLng.new(@coords[i][:lat], @coords[i][:lon])
|
47
|
+
d = ga.distance_from(gb, units: :kms)
|
48
|
+
td = @coords[i][:time] - @coords[i-1][:time]
|
49
|
+
|
50
|
+
@coords[i][:distance] = d
|
51
|
+
@coords[i][:speed] = (@coords[i][:distance] * 1000.0) / td
|
52
|
+
|
53
|
+
puts "D - #{@coords[i][:distance]} m | S - #{@coords[i][:speed]} m/s"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def process
|
58
|
+
# do not add coords not near start point
|
59
|
+
j = nil
|
60
|
+
@coords.each_with_index do |c, i|
|
61
|
+
ga = Geokit::LatLng.new(@start[:lat], @start[:lon])
|
62
|
+
gb = Geokit::LatLng.new(c[:lat], c[:lon])
|
63
|
+
d = ga.distance_from(gb, units: :kms)
|
64
|
+
if j.nil? and d < 0.1
|
65
|
+
puts "Choosen #{i} waypoint as start, distance #{d}"
|
66
|
+
j = i
|
67
|
+
end
|
68
|
+
end
|
69
|
+
@coords = @coords[j..-1]
|
70
|
+
|
71
|
+
# calculate distance to start and finish
|
72
|
+
@coords.each do |c|
|
73
|
+
gf = Geokit::LatLng.new(@finish[:lat], @finish[:lon])
|
74
|
+
gs = Geokit::LatLng.new(@start[:lat], @start[:lon])
|
75
|
+
g = Geokit::LatLng.new(c[:lat], c[:lon])
|
76
|
+
|
77
|
+
df = g.distance_from(gf, units: :kms)
|
78
|
+
ds = g.distance_from(gs, units: :kms)
|
79
|
+
|
80
|
+
c[:d_start] = ds
|
81
|
+
c[:d_finish] = df
|
82
|
+
end
|
83
|
+
|
84
|
+
# check if ascend/descend
|
85
|
+
j = 0
|
86
|
+
t = :up
|
87
|
+
(1...@coords.size).each do |i|
|
88
|
+
if t == :up
|
89
|
+
if @coords[i][:d_finish] < 0.1 and @coords[i-1][:d_finish] < @coords[i][:d_finish]
|
90
|
+
t = :down
|
91
|
+
j += 1
|
92
|
+
puts "Type change #{i} - #{t} - #{j}"
|
93
|
+
end
|
94
|
+
elsif t == :down
|
95
|
+
if @coords[i][:d_start] < 0.1 and @coords[i-1][:d_start] < @coords[i][:d_start]
|
96
|
+
t = :up
|
97
|
+
j += 1
|
98
|
+
puts "Type change #{i} - #{t} - #{j}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
@coords[i][:type] = t
|
103
|
+
@coords[i][:round] = j
|
104
|
+
end
|
105
|
+
|
106
|
+
# some computing
|
107
|
+
# distance quant calculation, from "finish"
|
108
|
+
#q = 0.05 # quant
|
109
|
+
q = 0.2 # quant
|
110
|
+
gf = Geokit::LatLng.new(@finish[:lat], @finish[:lon])
|
111
|
+
gs = Geokit::LatLng.new(@start[:lat], @start[:lon])
|
112
|
+
round_distance = gf.distance_from(gs, units: :kms)
|
113
|
+
quant_count = round_distance / q
|
114
|
+
quant_count = quant_count.ceil
|
115
|
+
q = round_distance / quant_count
|
116
|
+
|
117
|
+
puts "Distance quant #{q}, count #{quant_count}"
|
118
|
+
|
119
|
+
results = Array.new
|
120
|
+
(0..j).each do |round|
|
121
|
+
# round loop
|
122
|
+
(0..quant_count).each do |qc|
|
123
|
+
# quant loop
|
124
|
+
|
125
|
+
d_from = q * qc
|
126
|
+
d_to = (q + 1) * qc
|
127
|
+
coords = @coords.select { |c| c[:round] == round and c[:d_finish] >= d_from and c[:d_finish] < d_to }
|
128
|
+
puts "Found coords #{coords.size} for round #{round} and quant #{qc}"
|
129
|
+
|
130
|
+
h = Hash.new
|
131
|
+
h[:round] = round
|
132
|
+
h[:quant] = qc
|
133
|
+
begin
|
134
|
+
h[:type] = coords.first[:type]
|
135
|
+
rescue
|
136
|
+
end
|
137
|
+
|
138
|
+
sq = 0
|
139
|
+
ss = 0.0
|
140
|
+
coords.each do |coord|
|
141
|
+
_s = coord[:speed]
|
142
|
+
if _s
|
143
|
+
ss += _s
|
144
|
+
sq += 1
|
145
|
+
end
|
146
|
+
end
|
147
|
+
if sq > 0
|
148
|
+
h[:speed] = ss / sq.to_f
|
149
|
+
end
|
150
|
+
|
151
|
+
results << h
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
@results = results
|
156
|
+
end
|
157
|
+
|
158
|
+
def descend_results
|
159
|
+
rs = @results.select { |r| r[:type] == :down }
|
160
|
+
#rs = @results.select { |r| r[:type] == :up }
|
161
|
+
|
162
|
+
rounds = rs.collect { |r| r[:round] }.sort.uniq
|
163
|
+
quants = rs.collect { |r| r[:quant] }.sort.uniq
|
164
|
+
|
165
|
+
s = ""
|
166
|
+
|
167
|
+
s += "\t\t"
|
168
|
+
rounds.each do |r|
|
169
|
+
s += "#{r}\t"
|
170
|
+
end
|
171
|
+
s += "\n\n"
|
172
|
+
|
173
|
+
quants.each do |q|
|
174
|
+
s += "#{q}\t\t"
|
175
|
+
|
176
|
+
rounds.each do |r|
|
177
|
+
_a = rs.select { |a| a[:round] == r and a[:quant] == q }
|
178
|
+
if _a.size > 0
|
179
|
+
speed = _a.first[:speed]
|
180
|
+
s += "#{(speed * 3.6).round}\t"
|
181
|
+
else
|
182
|
+
s += ".\t"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
s += "\n"
|
186
|
+
end
|
187
|
+
|
188
|
+
puts s
|
189
|
+
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
data/lib/ski_analyzer.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gpx2exif
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
15
|
+
name: mini_exiftool
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,31 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement:
|
31
|
+
name: rmagick
|
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: chunky_png
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
28
49
|
none: false
|
29
50
|
requirements:
|
30
51
|
- - ! '>='
|
@@ -32,10 +53,15 @@ dependencies:
|
|
32
53
|
version: '0'
|
33
54
|
type: :runtime
|
34
55
|
prerelease: false
|
35
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
36
62
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement:
|
63
|
+
name: gpx_utils
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
39
65
|
none: false
|
40
66
|
requirements:
|
41
67
|
- - ! '>='
|
@@ -43,43 +69,63 @@ dependencies:
|
|
43
69
|
version: '0'
|
44
70
|
type: :runtime
|
45
71
|
prerelease: false
|
46
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
47
78
|
- !ruby/object:Gem::Dependency
|
48
79
|
name: rspec
|
49
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
50
81
|
none: false
|
51
82
|
requirements:
|
52
|
-
- -
|
83
|
+
- - ! '>='
|
53
84
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
85
|
+
version: '0'
|
55
86
|
type: :development
|
56
87
|
prerelease: false
|
57
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
58
94
|
- !ruby/object:Gem::Dependency
|
59
95
|
name: bundler
|
60
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
61
97
|
none: false
|
62
98
|
requirements:
|
63
|
-
- -
|
99
|
+
- - ! '>='
|
64
100
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
101
|
+
version: '0'
|
66
102
|
type: :development
|
67
103
|
prerelease: false
|
68
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
69
110
|
- !ruby/object:Gem::Dependency
|
70
111
|
name: jeweler
|
71
|
-
requirement:
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
72
113
|
none: false
|
73
114
|
requirements:
|
74
|
-
- -
|
115
|
+
- - ! '>='
|
75
116
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
117
|
+
version: '0'
|
77
118
|
type: :development
|
78
119
|
prerelease: false
|
79
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
80
126
|
- !ruby/object:Gem::Dependency
|
81
127
|
name: simplecov
|
82
|
-
requirement:
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
83
129
|
none: false
|
84
130
|
requirements:
|
85
131
|
- - ! '>='
|
@@ -87,13 +133,17 @@ dependencies:
|
|
87
133
|
version: '0'
|
88
134
|
type: :development
|
89
135
|
prerelease: false
|
90
|
-
version_requirements:
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
91
142
|
description: Mass geotagger using GPX files.
|
92
143
|
email: bobikx@poczta.fm
|
93
144
|
executables:
|
94
145
|
- geotag_all_images
|
95
146
|
- geotag_simulate
|
96
|
-
- generate_garmin_waypoints
|
97
147
|
- gpx2png
|
98
148
|
extensions: []
|
99
149
|
extra_rdoc_files:
|
@@ -106,7 +156,6 @@ files:
|
|
106
156
|
- README.md
|
107
157
|
- Rakefile
|
108
158
|
- VERSION
|
109
|
-
- bin/generate_garmin_waypoints
|
110
159
|
- bin/geotag_all_images
|
111
160
|
- bin/geotag_simulate
|
112
161
|
- bin/gpx2png
|
@@ -123,10 +172,9 @@ files:
|
|
123
172
|
- lib/gpx2png/renderers/rmagick_renderer.rb
|
124
173
|
- lib/gpx2png/ump.rb
|
125
174
|
- lib/gpx_utils.rb
|
126
|
-
- lib/gpx_utils/track_importer.rb
|
127
|
-
- lib/gpx_utils/waypoints_exporter.rb
|
128
|
-
- lib/gpx_utils/waypoints_importer.rb
|
129
175
|
- lib/mini_exiftool/mini_exiftool.rb
|
176
|
+
- lib/ski_analyzer.rb
|
177
|
+
- lib/ski_analyzer/analyzer.rb
|
130
178
|
homepage: http://github.com/akwiatkowski/gpx2exif
|
131
179
|
licenses:
|
132
180
|
- LGPLv3
|
@@ -142,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
190
|
version: '0'
|
143
191
|
segments:
|
144
192
|
- 0
|
145
|
-
hash: -
|
193
|
+
hash: -2766757745175557176
|
146
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
195
|
none: false
|
148
196
|
requirements:
|
@@ -151,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
199
|
version: '0'
|
152
200
|
requirements: []
|
153
201
|
rubyforge_project:
|
154
|
-
rubygems_version: 1.8.
|
202
|
+
rubygems_version: 1.8.25
|
155
203
|
signing_key:
|
156
204
|
specification_version: 3
|
157
205
|
summary: Mass geotagger using GPX files
|
@@ -1,46 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'gpx2exif'
|
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
|
@@ -1,63 +0,0 @@
|
|
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
|
@@ -1,133 +0,0 @@
|
|
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
|
@@ -1,54 +0,0 @@
|
|
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
|