gpx 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d9422311878830d3e5f57b2a671379cc2c5d972
4
- data.tar.gz: a08f7e74bb07c826d57fbaf8095c54d6057ab5cf
3
+ metadata.gz: 73e06b9476bcb99bfba6431fca25891846a88941
4
+ data.tar.gz: c7b44986fbc47413feee9975f83a50ddd9100fa6
5
5
  SHA512:
6
- metadata.gz: 904238365d5532474c876b710dd62a025e211f626e8a95585046d0473e9eb046c191de2c87418a3c59fbf9a047ce6fee67ed514f82f85b81d58ae944262d8436
7
- data.tar.gz: e08bde0c7857f130ab3c6ad24a565c922377a5b965fe54b5be4d3af8ec609c1d77af8aeed39ebf7cd31a0d5f9e431b32f447fb11763c4e71e4dd9111658e4711
6
+ metadata.gz: 00368da47e1de3b6379ac55b758c403035de545f89ebb1040cd5af802c5351ae09615554ecdd4195d43ca240ed7e5e5912df0b66237b8f1a7b9d03360121e3db
7
+ data.tar.gz: 25fcae7c2c17bf40ad44b2f464baf4e1f682bcfdb58d4ca7ab6833b2cb154b2867caaecc7de9ae99d127f5ec3545df8b58bd130cd208d0a48ba75853d63f5867
@@ -1,3 +1,8 @@
1
+ ## [0.8.2] - 2015-08-03
2
+
3
+ * Enhance calculation of average speed (with usage of new
4
+ moving_duration). (@doc75)
5
+
1
6
  ## [0.8.1] - 2015-08-01
2
7
 
3
8
  * Added support for a GPX `desc` tag. (@doc75)
@@ -22,7 +22,7 @@
22
22
  #++
23
23
  module GPX
24
24
  class GPXFile < Base
25
- attr_accessor :tracks, :routes, :waypoints, :bounds, :lowest_point, :highest_point, :duration, :ns, :time, :name, :version, :creator, :description
25
+ attr_accessor :tracks, :routes, :waypoints, :bounds, :lowest_point, :highest_point, :duration, :ns, :time, :name, :version, :creator, :description, :moving_duration
26
26
 
27
27
  DEFAULT_CREATOR = "GPX RubyGem #{GPX::VERSION} -- http://dougfales.github.io/gpx/".freeze
28
28
 
@@ -127,15 +127,16 @@ module GPX
127
127
 
128
128
  # Returns the average speed, in km/hr, meters/hr, or miles/hr, of this
129
129
  # GPXFile. The calculation is based on the total distance divided by the
130
- # total duration of the entire file.
130
+ # sum of duration of all segments of all tracks
131
+ # (not taking into accounting pause time).
131
132
  def average_speed(opts = { :units => 'kilometers' })
132
133
  case opts[:units]
133
134
  when /kilometers/i
134
- return @distance / (@duration/3600.0)
135
+ return distance / (moving_duration/3600.0)
135
136
  when /meters/i
136
- return (@distance * 1000) / (@duration/3600.0)
137
+ return (distance * 1000) / (moving_duration/3600.0)
137
138
  when /miles/i
138
- return (@distance * 0.62) / (@duration/3600.0)
139
+ return (distance * 0.62) / (moving_duration/3600.0)
139
140
  end
140
141
  end
141
142
 
@@ -187,6 +188,7 @@ module GPX
187
188
  @highest_point = nil
188
189
  @lowest_point = nil
189
190
  @distance = 0.0
191
+ @moving_duration = 0.0
190
192
  end
191
193
 
192
194
  # Updates the meta data for this GPX file. Meta data includes the
@@ -198,6 +200,7 @@ module GPX
198
200
  @highest_point = trk.highest_point if(@highest_point.nil? or (!trk.highest_point.nil? and trk.highest_point.elevation > @highest_point.elevation))
199
201
  @bounds.add(trk.bounds) if get_bounds
200
202
  @distance += trk.distance
203
+ @moving_duration += trk.moving_duration
201
204
  end
202
205
 
203
206
  # Serialize the current GPXFile to a gpx file named <filename>.
@@ -27,7 +27,7 @@ module GPX
27
27
  # latest points, distance, and bounds.
28
28
  class Segment < Base
29
29
 
30
- attr_reader :earliest_point, :latest_point, :bounds, :highest_point, :lowest_point, :distance
30
+ attr_reader :earliest_point, :latest_point, :bounds, :highest_point, :lowest_point, :distance, :duration
31
31
  attr_accessor :points, :track
32
32
 
33
33
  # If a XML::Node object is passed-in, this will initialize a new
@@ -41,6 +41,7 @@ module GPX
41
41
  @highest_point = nil
42
42
  @lowest_point = nil
43
43
  @distance = 0.0
44
+ @duration = 0.0
44
45
  @bounds = Bounds.new
45
46
  if(opts[:element])
46
47
  segment_element = opts[:element]
@@ -57,11 +58,16 @@ module GPX
57
58
  # Tack on a point to this Segment. All meta-data will be updated.
58
59
  def append_point(pt)
59
60
  last_pt = @points[-1]
60
- unless pt.time.nil?
61
+ if pt.time
61
62
  @earliest_point = pt if(@earliest_point.nil? or pt.time < @earliest_point.time)
62
63
  @latest_point = pt if(@latest_point.nil? or pt.time > @latest_point.time)
64
+ else
65
+ # when no time information in data, we consider the points are ordered
66
+ @earliest_point = @points[0]
67
+ @latest_point = pt
63
68
  end
64
- unless pt.elevation.nil?
69
+
70
+ if pt.elevation
65
71
  @lowest_point = pt if(@lowest_point.nil? or pt.elevation < @lowest_point.elevation)
66
72
  @highest_point = pt if(@highest_point.nil? or pt.elevation > @highest_point.elevation)
67
73
  end
@@ -69,7 +75,10 @@ module GPX
69
75
  @bounds.min_lon = pt.lon if pt.lon < @bounds.min_lon
70
76
  @bounds.max_lat = pt.lat if pt.lat > @bounds.max_lat
71
77
  @bounds.max_lon = pt.lon if pt.lon > @bounds.max_lon
72
- @distance += haversine_distance(last_pt, pt) unless last_pt.nil?
78
+ if last_pt
79
+ @distance += haversine_distance(last_pt, pt)
80
+ @duration += pt.time - last_pt.time if pt.time and last_pt.time
81
+ end
73
82
  @points << pt
74
83
  end
75
84
 
@@ -181,7 +190,6 @@ module GPX
181
190
  tmp_points.push tmp_point
182
191
  end
183
192
  last_pt = nil
184
- @distance = 0
185
193
  @points.clear
186
194
  reset_meta_data
187
195
  #now commit the averages back and recalculate the distances
@@ -232,20 +240,29 @@ module GPX
232
240
  @highest_point = nil
233
241
  @lowest_point = nil
234
242
  @distance = 0.0
243
+ @duration = 0.0
235
244
  @bounds = Bounds.new
236
245
  end
237
246
 
238
247
  def update_meta_data(pt, last_pt)
239
- unless pt.time.nil?
248
+ if pt.time
240
249
  @earliest_point = pt if(@earliest_point.nil? or pt.time < @earliest_point.time)
241
250
  @latest_point = pt if(@latest_point.nil? or pt.time > @latest_point.time)
251
+ else
252
+ # when no time information in data, we consider the points are ordered
253
+ @earliest_point = @points[0]
254
+ @latest_point = @points[-1]
242
255
  end
243
- unless pt.elevation.nil?
256
+
257
+ if pt.elevation
244
258
  @lowest_point = pt if(@lowest_point.nil? or pt.elevation < @lowest_point.elevation)
245
259
  @highest_point = pt if(@highest_point.nil? or pt.elevation > @highest_point.elevation)
246
260
  end
247
261
  @bounds.add(pt)
248
- @distance += haversine_distance(last_pt, pt) unless last_pt.nil?
262
+ if last_pt
263
+ @distance += haversine_distance(last_pt, pt)
264
+ @duration += pt.time - last_pt.time if pt.time and last_pt.time
265
+ end
249
266
  end
250
267
 
251
268
  end
@@ -28,7 +28,7 @@ module GPX
28
28
  # array of the segments that copmrise it, but additionally each track holds
29
29
  # a reference to all of its points as one big array called "points".
30
30
  class Track < Base
31
- attr_reader :points, :bounds, :lowest_point, :highest_point, :distance
31
+ attr_reader :points, :bounds, :lowest_point, :highest_point, :distance, :moving_duration, :comment, :description
32
32
  attr_accessor :segments, :name, :gpx_file
33
33
 
34
34
  # Initialize a track from a XML::Node, or, if no :element option is
@@ -41,6 +41,8 @@ module GPX
41
41
  if(opts[:element])
42
42
  trk_element = opts[:element]
43
43
  @name = (trk_element.at("name").inner_text rescue "")
44
+ @comment = (trk_element.at('cmt').inner_text rescue '')
45
+ @description = (trk_element.at('desc').inner_text rescue '')
44
46
  trk_element.search("trkseg").each do |seg_element|
45
47
  seg = Segment.new(:element => seg_element, :track => self, :gpx_file => @gpx_file)
46
48
  update_meta_data(seg)
@@ -105,9 +107,12 @@ module GPX
105
107
  def to_s
106
108
  result = "Track \n"
107
109
  result << "\tName: #{name}\n"
110
+ result << "\tComment: #{comment}\n"
111
+ result << "\tDescription: #{description}\n"
108
112
  result << "\tSize: #{points.size} points\n"
109
113
  result << "\tSegments: #{segments.size} \n"
110
114
  result << "\tDistance: #{distance} km\n"
115
+ result << "\tMoving duration: #{moving_duration} km\n"
111
116
  result << "\tLowest Point: #{lowest_point.elevation} \n"
112
117
  result << "\tHighest Point: #{highest_point.elevation}\n "
113
118
  result << "\tBounds: #{bounds.to_s}"
@@ -128,6 +133,7 @@ module GPX
128
133
  @highest_point = seg.highest_point if(@highest_point.nil? or seg.highest_point.elevation > @highest_point.elevation)
129
134
  @bounds.add(seg.bounds)
130
135
  @distance += seg.distance
136
+ @moving_duration += seg.duration
131
137
  @points.concat(seg.points)
132
138
  end
133
139
 
@@ -136,6 +142,7 @@ module GPX
136
142
  @highest_point = nil
137
143
  @lowest_point = nil
138
144
  @distance = 0.0
145
+ @moving_duration = 0.0
139
146
  @points = []
140
147
  end
141
148
 
@@ -1,3 +1,3 @@
1
1
  module GPX
2
- VERSION = "0.8.1"
2
+ VERSION = "0.8.2"
3
3
  end
@@ -19,6 +19,11 @@ class GPXFileTest < Minitest::Test
19
19
  assert_equal(38.791759, gpx_file.bounds.max_lat)
20
20
  assert_equal(-109.447045, gpx_file.bounds.max_lon)
21
21
  assert_equal('description of my GPX file with special char like &, <, >', gpx_file.description)
22
+ assert_equal('description of my GPX file with special char like &, <, >', gpx_file.description)
23
+ assert_equal(3.0724966849262554, gpx_file.distance)
24
+ assert_equal(15237.0, gpx_file.duration)
25
+ assert_equal(3036.0, gpx_file.moving_duration)
26
+ assert_equal(3.6432767014935834, gpx_file.average_speed)
22
27
  end
23
28
 
24
29
  def test_load_data_from_file
@@ -33,17 +38,27 @@ class GPXFileTest < Minitest::Test
33
38
  assert_equal(38.791759, gpx_file.bounds.max_lat)
34
39
  assert_equal(-109.447045, gpx_file.bounds.max_lon)
35
40
  assert_equal('description of my GPX file with special char like &, <, >', gpx_file.description)
41
+ assert_equal(3.0724966849262554, gpx_file.distance)
42
+ assert_equal(15237.0, gpx_file.duration)
43
+ assert_equal(3036.0, gpx_file.moving_duration)
44
+ assert_equal(3.6432767014935834, gpx_file.average_speed)
36
45
  end
37
46
 
38
47
  def test_big_file
39
48
  gpx_file = GPX::GPXFile.new(:gpx_file => BIG_FILE)
40
49
  assert_equal(1, gpx_file.tracks.size)
41
50
  assert_equal(7968, gpx_file.tracks.first.points.size)
51
+ assert_equal(105508.0, gpx_file.duration)
52
+ assert_equal(57645.0, gpx_file.moving_duration)
53
+ assert_in_delta(99.60738958686505, gpx_file.average_speed, 1e-13)
42
54
  end
43
55
 
44
56
  def test_with_or_with_elev
45
57
  gpx_file = GPX::GPXFile.new(:gpx_file => WITH_OR_WITHOUT_ELEV_FILE)
46
58
  assert_equal(2, gpx_file.tracks.size)
59
+ assert_equal(0, gpx_file.duration)
60
+ assert_equal(0, gpx_file.moving_duration)
61
+ assert(gpx_file.average_speed.nan?)
47
62
  #assert_equal(7968, gpx_file.tracks.first.points.size)
48
63
  end
49
64
 
@@ -0,0 +1,580 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="Link2GPS - 2.0.2 - http://www.hiketech.com" xsi:schemaLocation="ttp://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
3
+ <metadata>
4
+ <name><![CDATA[rabbit_valley.gpx]]></name>
5
+ <bounds min_lat="39.173834" min_lon="-109.016604" max_lat="39.188747" max_lon="-108.999546"/>
6
+ </metadata>
7
+ <extensions/>
8
+ <trk>
9
+ <name><![CDATA[RABBIT U]]></name>
10
+ <trkseg>
11
+ <trkpt lat="39.185185" lon="-109.016433">
12
+ <ele>1334.447</ele>
13
+ </trkpt>
14
+ <trkpt lat="39.185143" lon="-109.016433">
15
+ <ele>1338.292</ele>
16
+ </trkpt>
17
+ <trkpt lat="39.185143" lon="-109.016433">
18
+ <ele>1344.061</ele>
19
+ </trkpt>
20
+ <trkpt lat="39.185143" lon="-109.016433">
21
+ <ele>1364.729</ele>
22
+ </trkpt>
23
+ <trkpt lat="39.185121" lon="-109.016433">
24
+ <ele>1371.938</ele>
25
+ </trkpt>
26
+ <trkpt lat="39.185121" lon="-109.016433">
27
+ <ele>1375.303</ele>
28
+ </trkpt>
29
+ <trkpt lat="39.185121" lon="-109.016433">
30
+ <ele>1389.723</ele>
31
+ </trkpt>
32
+ <trkpt lat="39.185121" lon="-109.016433">
33
+ <ele>1396.452</ele>
34
+ </trkpt>
35
+ <trkpt lat="39.185143" lon="-109.016433">
36
+ <ele>1400.778</ele>
37
+ </trkpt>
38
+ <trkpt lat="39.185143" lon="-109.016433">
39
+ <ele>1404.143</ele>
40
+ </trkpt>
41
+ <trkpt lat="39.185143" lon="-109.016433">
42
+ <ele>1410.391</ele>
43
+ </trkpt>
44
+ <trkpt lat="39.185143" lon="-109.016433">
45
+ <ele>1413.756</ele>
46
+ </trkpt>
47
+ <trkpt lat="39.185164" lon="-109.016454">
48
+ <ele>1414.237</ele>
49
+ </trkpt>
50
+ <trkpt lat="39.185271" lon="-109.016476">
51
+ <ele>1415.679</ele>
52
+ </trkpt>
53
+ <trkpt lat="39.185207" lon="-109.016497">
54
+ <ele>1415.679</ele>
55
+ </trkpt>
56
+ <trkpt lat="39.185228" lon="-109.016476">
57
+ <ele>1415.679</ele>
58
+ </trkpt>
59
+ <trkpt lat="39.185271" lon="-109.016519">
60
+ <ele>1415.198</ele>
61
+ </trkpt>
62
+ <trkpt lat="39.185228" lon="-109.016562">
63
+ <ele>1414.717</ele>
64
+ </trkpt>
65
+ <trkpt lat="39.185207" lon="-109.016476">
66
+ <ele>1415.679</ele>
67
+ </trkpt>
68
+ <trkpt lat="39.185185" lon="-109.016562">
69
+ <ele>1415.679</ele>
70
+ </trkpt>
71
+ <trkpt lat="39.185164" lon="-109.016562">
72
+ <ele>1415.679</ele>
73
+ </trkpt>
74
+ <trkpt lat="39.184735" lon="-109.016411">
75
+ <ele>1415.198</ele>
76
+ </trkpt>
77
+ <trkpt lat="39.184864" lon="-109.016368">
78
+ <ele>1415.679</ele>
79
+ </trkpt>
80
+ <trkpt lat="39.184928" lon="-109.016283">
81
+ <ele>1415.198</ele>
82
+ </trkpt>
83
+ <trkpt lat="39.185121" lon="-109.015746">
84
+ <ele>1416.159</ele>
85
+ </trkpt>
86
+ <trkpt lat="39.185357" lon="-109.015231">
87
+ <ele>1417.601</ele>
88
+ </trkpt>
89
+ <trkpt lat="39.185572" lon="-109.014802">
90
+ <ele>1417.601</ele>
91
+ </trkpt>
92
+ <trkpt lat="39.185593" lon="-109.014802">
93
+ <ele>1417.601</ele>
94
+ </trkpt>
95
+ <trkpt lat="39.185143" lon="-109.015725">
96
+ <ele>1417.601</ele>
97
+ </trkpt>
98
+ <trkpt lat="39.184928" lon="-109.016497">
99
+ <ele>1415.679</ele>
100
+ </trkpt>
101
+ <trkpt lat="39.185164" lon="-109.016540">
102
+ <ele>1416.159</ele>
103
+ </trkpt>
104
+ <trkpt lat="39.185164" lon="-109.016540">
105
+ <ele>1415.679</ele>
106
+ </trkpt>
107
+ <trkpt lat="39.185185" lon="-109.016540">
108
+ <ele>1413.756</ele>
109
+ </trkpt>
110
+ <trkpt lat="39.185164" lon="-109.016540">
111
+ <ele>1414.237</ele>
112
+ </trkpt>
113
+ <trkpt lat="39.185185" lon="-109.016497">
114
+ <ele>1414.237</ele>
115
+ </trkpt>
116
+ <trkpt lat="39.184992" lon="-109.016497">
117
+ <ele>1414.717</ele>
118
+ </trkpt>
119
+ <trkpt lat="39.184949" lon="-109.016283">
120
+ <ele>1415.198</ele>
121
+ </trkpt>
122
+ <trkpt lat="39.184992" lon="-109.016197">
123
+ <ele>1414.237</ele>
124
+ </trkpt>
125
+ <trkpt lat="39.185207" lon="-109.015596">
126
+ <ele>1418.082</ele>
127
+ </trkpt>
128
+ <trkpt lat="39.185593" lon="-109.014781">
129
+ <ele>1418.562</ele>
130
+ </trkpt>
131
+ <trkpt lat="39.185636" lon="-109.014652">
132
+ <ele>1417.121</ele>
133
+ </trkpt>
134
+ <trkpt lat="39.185593" lon="-109.014587">
135
+ <ele>1416.64</ele>
136
+ </trkpt>
137
+ <trkpt lat="39.185379" lon="-109.014523">
138
+ <ele>1419.043</ele>
139
+ </trkpt>
140
+ <trkpt lat="39.185078" lon="-109.014480">
141
+ <ele>1419.043</ele>
142
+ </trkpt>
143
+ <trkpt lat="39.184628" lon="-109.014266">
144
+ <ele>1416.159</ele>
145
+ </trkpt>
146
+ <trkpt lat="39.184155" lon="-109.013836">
147
+ <ele>1415.198</ele>
148
+ </trkpt>
149
+ <trkpt lat="39.183791" lon="-109.013665">
150
+ <ele>1414.717</ele>
151
+ </trkpt>
152
+ <trkpt lat="39.183018" lon="-109.013150">
153
+ <ele>1411.353</ele>
154
+ </trkpt>
155
+ <trkpt lat="39.182611" lon="-109.012806">
156
+ <ele>1409.911</ele>
157
+ </trkpt>
158
+ <trkpt lat="39.182053" lon="-109.012463">
159
+ <ele>1409.43</ele>
160
+ </trkpt>
161
+ <trkpt lat="39.181623" lon="-109.012463">
162
+ <ele>1408.469</ele>
163
+ </trkpt>
164
+ <trkpt lat="39.181173" lon="-109.012377">
165
+ <ele>1407.027</ele>
166
+ </trkpt>
167
+ <trkpt lat="39.180572" lon="-109.012098">
168
+ <ele>1403.662</ele>
169
+ </trkpt>
170
+ <trkpt lat="39.180572" lon="-109.012098">
171
+ <ele>1402.701</ele>
172
+ </trkpt>
173
+ <trkpt lat="39.180980" lon="-109.012270">
174
+ <ele>1406.065</ele>
175
+ </trkpt>
176
+ <trkpt lat="39.181516" lon="-109.012442">
177
+ <ele>1407.508</ele>
178
+ </trkpt>
179
+ <trkpt lat="39.181795" lon="-109.012420">
180
+ <ele>1408.469</ele>
181
+ </trkpt>
182
+ <trkpt lat="39.182010" lon="-109.012098">
183
+ <ele>1408.469</ele>
184
+ </trkpt>
185
+ <trkpt lat="39.182417" lon="-109.011734">
186
+ <ele>1409.43</ele>
187
+ </trkpt>
188
+ <trkpt lat="39.182675" lon="-109.011455">
189
+ <ele>1409.43</ele>
190
+ </trkpt>
191
+ <trkpt lat="39.183040" lon="-109.011133">
192
+ <ele>1411.353</ele>
193
+ </trkpt>
194
+ <trkpt lat="39.183340" lon="-109.010768">
195
+ <ele>1411.833</ele>
196
+ </trkpt>
197
+ <trkpt lat="39.183555" lon="-109.010468">
198
+ <ele>1412.314</ele>
199
+ </trkpt>
200
+ <trkpt lat="39.183576" lon="-109.010403">
201
+ <ele>1411.833</ele>
202
+ </trkpt>
203
+ <trkpt lat="39.183490" lon="-109.010253">
204
+ <ele>1412.314</ele>
205
+ </trkpt>
206
+ <trkpt lat="39.183040" lon="-109.010017">
207
+ <ele>1409.911</ele>
208
+ </trkpt>
209
+ <trkpt lat="39.182954" lon="-109.009759">
210
+ <ele>1410.391</ele>
211
+ </trkpt>
212
+ <trkpt lat="39.183104" lon="-109.009287">
213
+ <ele>1409.911</ele>
214
+ </trkpt>
215
+ <trkpt lat="39.183168" lon="-109.008901">
216
+ <ele>1408.469</ele>
217
+ </trkpt>
218
+ <trkpt lat="39.183104" lon="-109.008794">
219
+ <ele>1407.027</ele>
220
+ </trkpt>
221
+ <trkpt lat="39.182847" lon="-109.008622">
222
+ <ele>1408.469</ele>
223
+ </trkpt>
224
+ <trkpt lat="39.182568" lon="-109.008386">
225
+ <ele>1411.353</ele>
226
+ </trkpt>
227
+ <trkpt lat="39.182396" lon="-109.008107">
228
+ <ele>1411.353</ele>
229
+ </trkpt>
230
+ <trkpt lat="39.182181" lon="-109.007485">
231
+ <ele>1414.237</ele>
232
+ </trkpt>
233
+ <trkpt lat="39.181924" lon="-109.006777">
234
+ <ele>1416.159</ele>
235
+ </trkpt>
236
+ <trkpt lat="39.181602" lon="-109.005575">
237
+ <ele>1416.64</ele>
238
+ </trkpt>
239
+ <trkpt lat="39.181881" lon="-109.003923">
240
+ <ele>1419.524</ele>
241
+ </trkpt>
242
+ <trkpt lat="39.181924" lon="-109.003301">
243
+ <ele>1420.485</ele>
244
+ </trkpt>
245
+ <trkpt lat="39.181709" lon="-109.002807">
246
+ <ele>1421.447</ele>
247
+ </trkpt>
248
+ <trkpt lat="39.181387" lon="-109.002571">
249
+ <ele>1424.331</ele>
250
+ </trkpt>
251
+ <trkpt lat="39.180851" lon="-109.002357">
252
+ <ele>1425.772</ele>
253
+ </trkpt>
254
+ <trkpt lat="39.180465" lon="-109.002035">
255
+ <ele>1427.695</ele>
256
+ </trkpt>
257
+ <trkpt lat="39.180379" lon="-109.001606">
258
+ <ele>1428.656</ele>
259
+ </trkpt>
260
+ <trkpt lat="39.180207" lon="-109.001198">
261
+ <ele>1430.579</ele>
262
+ </trkpt>
263
+ <trkpt lat="39.180057" lon="-109.001133">
264
+ <ele>1429.137</ele>
265
+ </trkpt>
266
+ <trkpt lat="39.180100" lon="-109.001112">
267
+ <ele>1429.618</ele>
268
+ </trkpt>
269
+ <trkpt lat="39.180100" lon="-109.001133">
270
+ <ele>1428.176</ele>
271
+ </trkpt>
272
+ <trkpt lat="39.178984" lon="-109.001412">
273
+ <ele>1433.463</ele>
274
+ </trkpt>
275
+ <trkpt lat="39.178491" lon="-109.001348">
276
+ <ele>1433.944</ele>
277
+ </trkpt>
278
+ <trkpt lat="39.177632" lon="-109.001391">
279
+ <ele>1438.27</ele>
280
+ </trkpt>
281
+ <trkpt lat="39.177010" lon="-109.001498">
282
+ <ele>1445.479</ele>
283
+ </trkpt>
284
+ <trkpt lat="39.176774" lon="-109.001584">
285
+ <ele>1451.728</ele>
286
+ </trkpt>
287
+ <trkpt lat="39.176452" lon="-109.001520">
288
+ <ele>1454.132</ele>
289
+ </trkpt>
290
+ <trkpt lat="39.176345" lon="-109.001584">
291
+ <ele>1455.573</ele>
292
+ </trkpt>
293
+ <trkpt lat="39.176259" lon="-109.001820">
294
+ <ele>1457.015</ele>
295
+ </trkpt>
296
+ <trkpt lat="39.176152" lon="-109.001949">
297
+ <ele>1458.457</ele>
298
+ </trkpt>
299
+ <trkpt lat="39.175916" lon="-109.002013">
300
+ <ele>1461.341</ele>
301
+ </trkpt>
302
+ <trkpt lat="39.175766" lon="-109.001927">
303
+ <ele>1463.264</ele>
304
+ </trkpt>
305
+ <trkpt lat="39.175594" lon="-109.001863">
306
+ <ele>1467.109</ele>
307
+ </trkpt>
308
+ <trkpt lat="39.175422" lon="-109.001756">
309
+ <ele>1469.032</ele>
310
+ </trkpt>
311
+ <trkpt lat="39.175444" lon="-109.001756">
312
+ <ele>1469.032</ele>
313
+ </trkpt>
314
+ <trkpt lat="39.175379" lon="-109.001713">
315
+ <ele>1469.993</ele>
316
+ </trkpt>
317
+ <trkpt lat="39.175122" lon="-109.001455">
318
+ <ele>1471.916</ele>
319
+ </trkpt>
320
+ <trkpt lat="39.174886" lon="-109.001005">
321
+ <ele>1469.993</ele>
322
+ </trkpt>
323
+ <trkpt lat="39.174864" lon="-109.000769">
324
+ <ele>1468.551</ele>
325
+ </trkpt>
326
+ <trkpt lat="39.174650" lon="-109.000533">
327
+ <ele>1469.032</ele>
328
+ </trkpt>
329
+ <trkpt lat="39.174092" lon="-108.999996">
330
+ <ele>1474.319</ele>
331
+ </trkpt>
332
+ <trkpt lat="39.173985" lon="-108.999803">
333
+ <ele>1476.242</ele>
334
+ </trkpt>
335
+ <trkpt lat="39.173834" lon="-108.999546">
336
+ <ele>1480.087</ele>
337
+ </trkpt>
338
+ <trkpt lat="39.173834" lon="-108.999588">
339
+ <ele>1478.645</ele>
340
+ </trkpt>
341
+ <trkpt lat="39.173963" lon="-108.999760">
342
+ <ele>1478.164</ele>
343
+ </trkpt>
344
+ <trkpt lat="39.174092" lon="-108.999975">
345
+ <ele>1474.319</ele>
346
+ </trkpt>
347
+ <trkpt lat="39.174156" lon="-109.000061">
348
+ <ele>1472.396</ele>
349
+ </trkpt>
350
+ <trkpt lat="39.174178" lon="-109.000061">
351
+ <ele>1471.435</ele>
352
+ </trkpt>
353
+ <trkpt lat="39.174178" lon="-109.000103">
354
+ <ele>1471.916</ele>
355
+ </trkpt>
356
+ <trkpt lat="39.174178" lon="-109.000082">
357
+ <ele>1473.358</ele>
358
+ </trkpt>
359
+ <trkpt lat="39.174414" lon="-109.000275">
360
+ <ele>1470.955</ele>
361
+ </trkpt>
362
+ <trkpt lat="39.174500" lon="-109.000382">
363
+ <ele>1469.993</ele>
364
+ </trkpt>
365
+ <trkpt lat="39.174736" lon="-109.000576">
366
+ <ele>1468.071</ele>
367
+ </trkpt>
368
+ <trkpt lat="39.174864" lon="-109.000790">
369
+ <ele>1468.551</ele>
370
+ </trkpt>
371
+ <trkpt lat="39.174993" lon="-109.001155">
372
+ <ele>1471.435</ele>
373
+ </trkpt>
374
+ <trkpt lat="39.174950" lon="-109.001155">
375
+ <ele>1471.435</ele>
376
+ </trkpt>
377
+ <trkpt lat="39.174972" lon="-109.001155">
378
+ <ele>1468.071</ele>
379
+ </trkpt>
380
+ <trkpt lat="39.174972" lon="-109.001155">
381
+ <ele>1472.877</ele>
382
+ </trkpt>
383
+ <trkpt lat="39.174993" lon="-109.001176">
384
+ <ele>1469.513</ele>
385
+ </trkpt>
386
+ <trkpt lat="39.174993" lon="-109.001133">
387
+ <ele>1470.474</ele>
388
+ </trkpt>
389
+ <trkpt lat="39.174972" lon="-109.001176">
390
+ <ele>1471.435</ele>
391
+ </trkpt>
392
+ <trkpt lat="39.175208" lon="-109.001541">
393
+ <ele>1471.435</ele>
394
+ </trkpt>
395
+ <trkpt lat="39.175508" lon="-109.001799">
396
+ <ele>1468.551</ele>
397
+ </trkpt>
398
+ <trkpt lat="39.175680" lon="-109.001863">
399
+ <ele>1465.667</ele>
400
+ </trkpt>
401
+ <trkpt lat="39.175766" lon="-109.001949">
402
+ <ele>1462.302</ele>
403
+ </trkpt>
404
+ <trkpt lat="39.175894" lon="-109.002013">
405
+ <ele>1461.341</ele>
406
+ </trkpt>
407
+ <trkpt lat="39.176023" lon="-109.002035">
408
+ <ele>1459.899</ele>
409
+ </trkpt>
410
+ <trkpt lat="39.176280" lon="-109.001799">
411
+ <ele>1457.977</ele>
412
+ </trkpt>
413
+ <trkpt lat="39.176366" lon="-109.001606">
414
+ <ele>1456.054</ele>
415
+ </trkpt>
416
+ <trkpt lat="39.176431" lon="-109.001541">
417
+ <ele>1455.093</ele>
418
+ </trkpt>
419
+ <trkpt lat="39.176495" lon="-109.001520">
420
+ <ele>1453.651</ele>
421
+ </trkpt>
422
+ <trkpt lat="39.176838" lon="-109.001541">
423
+ <ele>1449.805</ele>
424
+ </trkpt>
425
+ <trkpt lat="39.176967" lon="-109.001498">
426
+ <ele>1446.921</ele>
427
+ </trkpt>
428
+ <trkpt lat="39.177954" lon="-109.001391">
429
+ <ele>1437.308</ele>
430
+ </trkpt>
431
+ <trkpt lat="39.178534" lon="-109.001369">
432
+ <ele>1435.385</ele>
433
+ </trkpt>
434
+ <trkpt lat="39.178941" lon="-109.001434">
435
+ <ele>1434.424</ele>
436
+ </trkpt>
437
+ <trkpt lat="39.180057" lon="-109.001176">
438
+ <ele>1432.021</ele>
439
+ </trkpt>
440
+ <trkpt lat="39.180207" lon="-109.001176">
441
+ <ele>1430.579</ele>
442
+ </trkpt>
443
+ <trkpt lat="39.180357" lon="-109.001412">
444
+ <ele>1429.618</ele>
445
+ </trkpt>
446
+ <trkpt lat="39.180443" lon="-109.001970">
447
+ <ele>1427.215</ele>
448
+ </trkpt>
449
+ <trkpt lat="39.180808" lon="-109.002335">
450
+ <ele>1425.772</ele>
451
+ </trkpt>
452
+ <trkpt lat="39.181001" lon="-109.002421">
453
+ <ele>1425.772</ele>
454
+ </trkpt>
455
+ <trkpt lat="39.181516" lon="-109.002678">
456
+ <ele>1423.369</ele>
457
+ </trkpt>
458
+ <trkpt lat="39.181881" lon="-109.003043">
459
+ <ele>1422.889</ele>
460
+ </trkpt>
461
+ <trkpt lat="39.181945" lon="-109.003515">
462
+ <ele>1420.966</ele>
463
+ </trkpt>
464
+ <trkpt lat="39.181902" lon="-109.004202">
465
+ <ele>1420.005</ele>
466
+ </trkpt>
467
+ <trkpt lat="39.181688" lon="-109.005189">
468
+ <ele>1416.64</ele>
469
+ </trkpt>
470
+ <trkpt lat="39.181623" lon="-109.005618">
471
+ <ele>1417.121</ele>
472
+ </trkpt>
473
+ <trkpt lat="39.181881" lon="-109.006648">
474
+ <ele>1416.64</ele>
475
+ </trkpt>
476
+ <trkpt lat="39.182224" lon="-109.007592">
477
+ <ele>1413.275</ele>
478
+ </trkpt>
479
+ <trkpt lat="39.182482" lon="-109.008279">
480
+ <ele>1413.275</ele>
481
+ </trkpt>
482
+ <trkpt lat="39.182739" lon="-109.008536">
483
+ <ele>1409.43</ele>
484
+ </trkpt>
485
+ <trkpt lat="39.183125" lon="-109.008794">
486
+ <ele>1408.469</ele>
487
+ </trkpt>
488
+ <trkpt lat="39.183190" lon="-109.009137">
489
+ <ele>1409.43</ele>
490
+ </trkpt>
491
+ <trkpt lat="39.182954" lon="-109.009953">
492
+ <ele>1409.43</ele>
493
+ </trkpt>
494
+ <trkpt lat="39.183147" lon="-109.010081">
495
+ <ele>1409.43</ele>
496
+ </trkpt>
497
+ <trkpt lat="39.183533" lon="-109.010210">
498
+ <ele>1412.314</ele>
499
+ </trkpt>
500
+ <trkpt lat="39.183555" lon="-109.009995">
501
+ <ele>1412.314</ele>
502
+ </trkpt>
503
+ <trkpt lat="39.183662" lon="-109.009867">
504
+ <ele>1411.353</ele>
505
+ </trkpt>
506
+ <trkpt lat="39.183683" lon="-109.009888">
507
+ <ele>1411.833</ele>
508
+ </trkpt>
509
+ <trkpt lat="39.183640" lon="-109.010146">
510
+ <ele>1412.795</ele>
511
+ </trkpt>
512
+ <trkpt lat="39.183726" lon="-109.010231">
513
+ <ele>1413.756</ele>
514
+ </trkpt>
515
+ <trkpt lat="39.183941" lon="-109.010210">
516
+ <ele>1414.717</ele>
517
+ </trkpt>
518
+ <trkpt lat="39.184821" lon="-109.009330">
519
+ <ele>1418.562</ele>
520
+ </trkpt>
521
+ <trkpt lat="39.185207" lon="-109.009094">
522
+ <ele>1420.005</ele>
523
+ </trkpt>
524
+ <trkpt lat="39.185593" lon="-109.009008">
525
+ <ele>1420.966</ele>
526
+ </trkpt>
527
+ <trkpt lat="39.185979" lon="-109.008815">
528
+ <ele>1420.005</ele>
529
+ </trkpt>
530
+ <trkpt lat="39.187181" lon="-109.008451">
531
+ <ele>1420.005</ele>
532
+ </trkpt>
533
+ <trkpt lat="39.187181" lon="-109.008536">
534
+ <ele>1421.447</ele>
535
+ </trkpt>
536
+ <trkpt lat="39.187353" lon="-109.008343">
537
+ <ele>1420.966</ele>
538
+ </trkpt>
539
+ <trkpt lat="39.187868" lon="-109.008129">
540
+ <ele>1421.447</ele>
541
+ </trkpt>
542
+ <trkpt lat="39.188468" lon="-109.007978">
543
+ <ele>1424.811</ele>
544
+ </trkpt>
545
+ <trkpt lat="39.188747" lon="-109.008000">
546
+ <ele>1426.253</ele>
547
+ </trkpt>
548
+ <trkpt lat="39.188683" lon="-109.008687">
549
+ <ele>1428.176</ele>
550
+ </trkpt>
551
+ <trkpt lat="39.188533" lon="-109.009759">
552
+ <ele>1424.811</ele>
553
+ </trkpt>
554
+ <trkpt lat="39.188018" lon="-109.010983">
555
+ <ele>1423.85</ele>
556
+ </trkpt>
557
+ <trkpt lat="39.187031" lon="-109.012635">
558
+ <ele>1420.485</ele>
559
+ </trkpt>
560
+ <trkpt lat="39.186172" lon="-109.013815">
561
+ <ele>1418.562</ele>
562
+ </trkpt>
563
+ <trkpt lat="39.185464" lon="-109.014995">
564
+ <ele>1416.64</ele>
565
+ </trkpt>
566
+ <trkpt lat="39.185014" lon="-109.016004">
567
+ <ele>1414.717</ele>
568
+ </trkpt>
569
+ <trkpt lat="39.184971" lon="-109.016604">
570
+ <ele>1414.717</ele>
571
+ </trkpt>
572
+ <trkpt lat="39.185057" lon="-109.016583">
573
+ <ele>1415.198</ele>
574
+ </trkpt>
575
+ <trkpt lat="39.185228" lon="-109.016540">
576
+ <ele>1413.756</ele>
577
+ </trkpt>
578
+ </trkseg>
579
+ </trk>
580
+ </gpx>
@@ -9,6 +9,8 @@
9
9
  <extensions/>
10
10
  <trk>
11
11
  <name><![CDATA[ACTIVE LOG]]></name>
12
+ <cmt><![CDATA[Comment Log]]></cmt>
13
+ <desc><![CDATA[Description Log]]></desc>
12
14
  <trkseg>
13
15
  <trkpt lat="38.782575" lon="-109.595146">
14
16
  <time>2006-04-08T18:25:33Z</time>
@@ -5,6 +5,7 @@ require 'gpx'
5
5
 
6
6
  class SegmentTest < Minitest::Test
7
7
  ONE_SEGMENT = File.join(File.dirname(__FILE__), "gpx_files/one_segment.gpx")
8
+ ONE_SEGMENT_NO_TIME = File.join(File.dirname(__FILE__), "gpx_files/one_segment_no_time.gpx")
8
9
 
9
10
  def setup
10
11
  @gpx_file = GPX::GPXFile.new(:gpx_file => ONE_SEGMENT)
@@ -18,6 +19,19 @@ class SegmentTest < Minitest::Test
18
19
  assert_equal(1334.447, @segment.lowest_point.elevation)
19
20
  assert_equal(1480.087, @segment.highest_point.elevation)
20
21
  assert_in_delta(6.98803359528853, @segment.distance, 0.001)
22
+ assert_equal(4466.0, @segment.duration)
23
+ end
24
+
25
+ def test_segment_read_no_time
26
+ gpx_file_no_time = GPX::GPXFile.new(:gpx_file => ONE_SEGMENT_NO_TIME)
27
+ segment_no_time = gpx_file_no_time.tracks.first.segments.first
28
+ assert_equal(189, segment_no_time.points.size)
29
+ assert_equal(1334.447, segment_no_time.earliest_point.elevation)
30
+ assert_equal(1413.756, segment_no_time.latest_point.elevation)
31
+ assert_equal(1334.447, segment_no_time.lowest_point.elevation)
32
+ assert_equal(1480.087, segment_no_time.highest_point.elevation)
33
+ assert_in_delta(6.98803359528853, segment_no_time.distance, 0.001)
34
+ assert_equal(0, segment_no_time.duration)
21
35
  end
22
36
 
23
37
  def test_segment_crop
@@ -37,6 +51,7 @@ class SegmentTest < Minitest::Test
37
51
  assert_equal(-109.009995, @segment.bounds.min_lon)
38
52
  assert_equal(39.187868, @segment.bounds.max_lat)
39
53
  assert_equal(-108.999546, @segment.bounds.max_lon)
54
+ assert_equal(2711.0, @segment.duration)
40
55
  end
41
56
 
42
57
  def test_segment_delete
@@ -55,6 +70,7 @@ class SegmentTest < Minitest::Test
55
70
  assert_equal(-109.016604, @segment.bounds.min_lon)
56
71
  assert_equal(39.188747, @segment.bounds.max_lat)
57
72
  assert_equal(-109.007978, @segment.bounds.max_lon)
73
+ assert_equal(4466.0, @segment.duration)
58
74
  end
59
75
 
60
76
  def test_segment_smooth
@@ -65,6 +81,7 @@ class SegmentTest < Minitest::Test
65
81
  assert_equal(1342.58, @segment.lowest_point.elevation)
66
82
  assert_equal(1479.09, @segment.highest_point.elevation)
67
83
  assert_in_delta(6.458085658, @segment.distance, 0.001)
84
+ assert_equal(4466.0, @segment.duration)
68
85
  end
69
86
 
70
87
  def test_segment_smooth_offset
@@ -75,6 +92,7 @@ class SegmentTest < Minitest::Test
75
92
  assert_equal(1334.447, @segment.lowest_point.elevation)
76
93
  assert_equal(1480.087, @segment.highest_point.elevation)
77
94
  assert_in_delta(6.900813095, @segment.distance, 0.001)
95
+ assert_equal(4466.0, @segment.duration)
78
96
  end
79
97
 
80
98
  def test_segment_smooth_absolute
@@ -85,6 +103,7 @@ class SegmentTest < Minitest::Test
85
103
  assert_equal(1334.447, @segment.lowest_point.elevation)
86
104
  assert_equal(1480.087, @segment.highest_point.elevation)
87
105
  assert_in_delta(6.900813095, @segment.distance, 0.001)
106
+ assert_equal(4466.0, @segment.duration)
88
107
  end
89
108
 
90
109
  end
@@ -15,7 +15,7 @@ class TrackPointTest < Minitest::Test
15
15
 
16
16
  def test_haversine_distance_from
17
17
  distance = @point1.haversine_distance_from(@point2)
18
- assert_equal(0.00197862991592239, distance)
18
+ assert_in_delta(0.00197862991592239, distance, 1e-18)
19
19
  end
20
20
 
21
21
  def test_pythagorean_distance_from
@@ -11,6 +11,8 @@ class TrackTest < Minitest::Test
11
11
 
12
12
  def test_track_read
13
13
  assert_equal("ACTIVE LOG", @track.name)
14
+ assert_equal("Comment Log", @track.comment)
15
+ assert_equal("Description Log", @track.description)
14
16
  assert_equal( 182, @track.points.size)
15
17
  assert_equal(8, @track.segments.size)
16
18
  assert_in_delta(3.07249668492626, @track.distance, 0.001)
@@ -20,6 +22,7 @@ class TrackTest < Minitest::Test
20
22
  assert_equal(-109.606948, @track.bounds.min_lon)
21
23
  assert_equal(38.791759, @track.bounds.max_lat)
22
24
  assert_equal(-109.447045, @track.bounds.max_lon)
25
+ assert_equal(3036.0, @track.moving_duration)
23
26
  end
24
27
 
25
28
  def test_track_crop
@@ -30,6 +33,8 @@ class TrackTest < Minitest::Test
30
33
  :max_lon => -109.450000)
31
34
  @track.crop(area)
32
35
  assert_equal("ACTIVE LOG", @track.name)
36
+ assert_equal("Comment Log", @track.comment)
37
+ assert_equal("Description Log", @track.description)
33
38
  assert_equal( 111, @track.points.size)
34
39
  assert_equal(4, @track.segments.size)
35
40
  assert_in_delta(1.62136024923607, @track.distance, 0.001)
@@ -39,6 +44,7 @@ class TrackTest < Minitest::Test
39
44
  assert_equal(-109.599781, @track.bounds.min_lon)
40
45
  assert_equal(38.789527, @track.bounds.max_lat)
41
46
  assert_equal(-109.594996, @track.bounds.max_lon)
47
+ assert_equal(1773.0, @track.moving_duration)
42
48
  end
43
49
 
44
50
  def test_track_delete
@@ -49,17 +55,18 @@ class TrackTest < Minitest::Test
49
55
  :max_lon => -109.450000)
50
56
  @track.delete_area(area)
51
57
 
58
+ assert_equal(1229.0, @track.moving_duration)
52
59
  #puts @track
53
- #assert_equal("ACTIVE LOG", @track.name)
54
- #assert_equal( 111, @track.points.size)
55
- #assert_equal(4, @track.segments.size)
56
- #assert_equal("1.62136024923607", @track.distance.to_s)
57
- #assert_equal(1557.954, @track.lowest_point.elevation)
58
- #assert_equal(1582.468, @track.highest_point.elevation)
59
- #assert_equal(38.782511, @track.bounds.min_lat)
60
- #assert_equal(-109.599781, @track.bounds.min_lon)
61
- #assert_equal(38.789527, @track.bounds.max_lat)
62
- #assert_equal(-109.594996, @track.bounds.max_lon)
60
+ assert_equal("ACTIVE LOG", @track.name)
61
+ assert_equal(71, @track.points.size)
62
+ assert_equal(6, @track.segments.size)
63
+ assert_in_delta(1.197905851972874, @track.distance, 0.00000000001)
64
+ assert_equal(1267.155, @track.lowest_point.elevation)
65
+ assert_equal(1594.003, @track.highest_point.elevation)
66
+ assert_equal(38.681488, @track.bounds.min_lat)
67
+ assert_equal(-109.606948, @track.bounds.min_lon)
68
+ assert_equal(38.791759, @track.bounds.max_lat)
69
+ assert_equal(-109.447045, @track.bounds.max_lon)
63
70
  end
64
71
 
65
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gpx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Dott
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-08-01 00:00:00.000000000 Z
13
+ date: 2015-08-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -106,6 +106,7 @@ files:
106
106
  - tests/gpx_files/gpx10.gpx
107
107
  - tests/gpx_files/magellan_track.log
108
108
  - tests/gpx_files/one_segment.gpx
109
+ - tests/gpx_files/one_segment_no_time.gpx
109
110
  - tests/gpx_files/one_track.gpx
110
111
  - tests/gpx_files/routes.gpx
111
112
  - tests/gpx_files/tracks.gpx