gpx 0.9.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +36 -0
  3. data/.gitignore +4 -0
  4. data/.rubocop.yml +162 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +6 -5
  7. data/CHANGELOG.md +15 -0
  8. data/Gemfile +2 -0
  9. data/LICENSE.txt +1 -1
  10. data/README.md +20 -5
  11. data/Rakefile +22 -12
  12. data/bin/gpx_distance +5 -6
  13. data/bin/gpx_smooth +25 -26
  14. data/gpx.gemspec +13 -12
  15. data/lib/gpx/bounds.rb +13 -31
  16. data/lib/gpx/geo_json.rb +199 -0
  17. data/lib/gpx/gpx.rb +4 -26
  18. data/lib/gpx/gpx_file.rb +140 -134
  19. data/lib/gpx/magellan_track_log.rb +34 -66
  20. data/lib/gpx/point.rb +22 -35
  21. data/lib/gpx/route.rb +10 -31
  22. data/lib/gpx/segment.rb +63 -90
  23. data/lib/gpx/track.rb +38 -42
  24. data/lib/gpx/track_point.rb +32 -0
  25. data/lib/gpx/version.rb +3 -1
  26. data/lib/gpx/waypoint.rb +10 -34
  27. data/lib/gpx.rb +13 -34
  28. data/tests/geojson_files/combined_data.json +68 -0
  29. data/tests/geojson_files/line_string_data.json +83 -0
  30. data/tests/geojson_files/multi_line_string_data.json +74 -0
  31. data/tests/geojson_files/multi_point_data.json +14 -0
  32. data/tests/geojson_files/point_data.json +22 -0
  33. data/tests/geojson_test.rb +92 -0
  34. data/tests/gpx10_test.rb +7 -6
  35. data/tests/gpx_file_test.rb +31 -19
  36. data/tests/gpx_files/one_segment_mixed_times.gpx +884 -0
  37. data/tests/gpx_files/routes_without_names.gpx +29 -0
  38. data/tests/gpx_files/with_empty_tracks.gpx +72 -0
  39. data/tests/magellan_test.rb +12 -11
  40. data/tests/output_test.rb +93 -94
  41. data/tests/route_test.rb +75 -30
  42. data/tests/segment_test.rb +104 -93
  43. data/tests/track_file_test.rb +50 -70
  44. data/tests/track_point_test.rb +22 -11
  45. data/tests/track_test.rb +73 -61
  46. data/tests/waypoint_test.rb +46 -48
  47. metadata +47 -18
  48. data/lib/gpx/trackpoint.rb +0 -60
@@ -0,0 +1,29 @@
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[routes.gpx]]></name>
5
+ <time>2006-01-02T08:55:34Z</time>
6
+ <bounds min_lat="39.989739" min_lon="-105.295285" max_lat="39.999840" max_lon="-105.214696"/>
7
+ </metadata>
8
+ <extensions/>
9
+ <rte>
10
+ <rtept lat="39.997298" lon="-105.292674">
11
+ <sym>Waypoint</sym>
12
+ <ele>1766.535</ele>
13
+ </rtept>
14
+ <rtept lat="39.995700" lon="-105.292805">
15
+ <sym>Waypoint</sym>
16
+ <ele>1854.735</ele>
17
+ </rtept>
18
+ <rtept lat="39.989739" lon="-105.295285">
19
+ <sym>Waypoint</sym>
20
+ <ele>2163.556</ele>
21
+ </rtept>
22
+ </rte>
23
+ <rte>
24
+ <rtept lat="39.999840" lon="-105.214696">
25
+ <sym>Waypoint</sym>
26
+ <ele>1612.965</ele>
27
+ </rtept>
28
+ </rte>
29
+ </gpx>
@@ -0,0 +1,72 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="Open GPX Tracker for iOS">
3
+ <wpt lat="51.185170" lon="4.662453">
4
+ <time>2018-01-16T11:35:01Z</time>
5
+ <name>12:35:01</name>
6
+ <desc>16 jan. 2018 12:35:01</desc>
7
+ </wpt>
8
+ <trk>
9
+ <trkseg>
10
+ <trkpt lat="51.183019" lon="4.664619">
11
+ <ele>0.751247</ele>
12
+ <time>2018-01-16T11:06:00Z</time>
13
+ </trkpt>
14
+ <trkpt lat="51.183037" lon="4.664587">
15
+ <ele>0.622036</ele>
16
+ <time>2018-01-16T11:06:02Z</time>
17
+ </trkpt>
18
+ <trkpt lat="51.183053" lon="4.664553">
19
+ <ele>0.042019</ele>
20
+ <time>2018-01-16T11:06:04Z</time>
21
+ </trkpt>
22
+ <trkpt lat="51.183073" lon="4.664515">
23
+ <ele>0.177456</ele>
24
+ <time>2018-01-16T11:06:06Z</time>
25
+ </trkpt>
26
+ <trkpt lat="51.183095" lon="4.664480">
27
+ <ele>0.564846</ele>
28
+ <time>2018-01-16T11:06:08Z</time>
29
+ </trkpt>
30
+ <trkpt lat="51.183115" lon="4.664446">
31
+ <ele>0.941067</ele>
32
+ <time>2018-01-16T11:06:10Z</time>
33
+ </trkpt>
34
+ <trkpt lat="51.183143" lon="4.664401">
35
+ <ele>1.960781</ele>
36
+ <time>2018-01-16T11:06:12Z</time>
37
+ </trkpt>
38
+ <trkpt lat="51.183160" lon="4.664372">
39
+ <ele>2.115200</ele>
40
+ <time>2018-01-16T11:06:13Z</time>
41
+ </trkpt>
42
+ <trkpt lat="51.183176" lon="4.664342">
43
+ <ele>2.191250</ele>
44
+ <time>2018-01-16T11:06:14Z</time>
45
+ </trkpt>
46
+ <trkpt lat="51.183192" lon="4.664315">
47
+ <ele>2.492947</ele>
48
+ <time>2018-01-16T11:06:15Z</time>
49
+ </trkpt>
50
+ <trkpt lat="51.183205" lon="4.664291">
51
+ <ele>2.459927</ele>
52
+ <time>2018-01-16T11:06:16Z</time>
53
+ </trkpt>
54
+ <trkpt lat="51.183217" lon="4.664270">
55
+ <ele>2.226833</ele>
56
+ <time>2018-01-16T11:06:17Z</time>
57
+ </trkpt>
58
+ <trkpt lat="51.183240" lon="4.664233">
59
+ <ele>2.175198</ele>
60
+ <time>2018-01-16T11:06:19Z</time>
61
+ </trkpt>
62
+ <trkpt lat="51.183255" lon="4.664207">
63
+ <ele>2.643887</ele>
64
+ <time>2018-01-16T11:06:21Z</time>
65
+ </trkpt>
66
+ </trkseg>
67
+ <trkseg>
68
+ </trkseg>
69
+ <trkseg>
70
+ </trkseg>
71
+ </trk>
72
+ </gpx>
@@ -1,18 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'gpx'
3
5
 
4
6
  class MagellanTest < Minitest::Test
5
- MAGELLAN_TRACK_LOG = File.join(File.dirname(__FILE__), "gpx_files/magellan_track.log")
6
- GPX_FILE = File.join(File.dirname(__FILE__), "gpx_files/one_segment.gpx")
7
-
8
- def test_convert
9
- GPX::MagellanTrackLog.convert_to_gpx(MAGELLAN_TRACK_LOG, "/tmp/gpx_from_magellan.gpx")
10
- @gpx_file = GPX::GPXFile.new(:gpx_file => "/tmp/gpx_from_magellan.gpx")
11
- end
7
+ MAGELLAN_TRACK_LOG = File.join(File.dirname(__FILE__), 'gpx_files/magellan_track.log')
8
+ GPX_FILE = File.join(File.dirname(__FILE__), 'gpx_files/one_segment.gpx')
12
9
 
13
- def test_file_type
14
- assert(GPX::MagellanTrackLog::is_magellan_file?(MAGELLAN_TRACK_LOG))
15
- assert(!GPX::MagellanTrackLog::is_magellan_file?(GPX_FILE))
16
- end
10
+ def test_convert
11
+ GPX::MagellanTrackLog.convert_to_gpx(MAGELLAN_TRACK_LOG, '/tmp/gpx_from_magellan.gpx')
12
+ @gpx_file = GPX::GPXFile.new(gpx_file: '/tmp/gpx_from_magellan.gpx')
13
+ end
17
14
 
15
+ def test_file_type
16
+ assert(GPX::MagellanTrackLog.magellan_file?(MAGELLAN_TRACK_LOG))
17
+ assert(!GPX::MagellanTrackLog.magellan_file?(GPX_FILE))
18
+ end
18
19
  end
data/tests/output_test.rb CHANGED
@@ -1,110 +1,110 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'fileutils'
3
5
  require 'gpx'
4
6
 
5
7
  class OutputTest < Minitest::Test
6
-
7
8
  include GPX
8
9
 
9
10
  def setup
10
- FileUtils.mkdir_p(File.join(File.dirname(__FILE__), "output"))
11
+ FileUtils.mkdir_p(File.join(File.dirname(__FILE__), 'output'))
11
12
  end
12
13
 
13
14
  def test_new_gpx_file_from_scratch
14
- gpx_file = GPXFile.new
15
-
16
- track = Track.new(:name => "My First Track")
17
- segment = Segment.new
18
-
19
- track_point_data = [
20
- {:lat => 40.036926, :lon =>-105.253487, :time => Time.parse('2005-12-31T22:01:24Z'), :elevation => 1737.24},
21
- {:lat => 40.036604, :lon =>-105.253487, :time => Time.parse("2005-12-31T22:02:01Z"), :elevation => 1738.682},
22
- {:lat => 40.036347, :lon =>-105.253830, :time => Time.parse("2005-12-31T22:02:08Z"), :elevation => 1738.682},
23
- {:lat => 40.035574, :lon =>-105.254045, :time => Time.parse("2005-12-31T22:02:20Z"), :elevation => 1737.24},
24
- {:lat => 40.035467, :lon =>-105.254366, :time => Time.parse("2005-12-31T22:02:29Z"), :elevation => 1735.798},
25
- {:lat => 40.035317, :lon =>-105.254388, :time => Time.parse("2005-12-31T22:02:33Z"), :elevation => 1735.798},
26
- {:lat => 40.035274, :lon =>-105.254431, :time => Time.parse("2005-12-31T22:02:49Z"), :elevation => 1736.278},
27
- {:lat => 40.035274, :lon =>-105.254431, :time => Time.parse("2005-12-31T22:02:54Z"), :elevation => 1739.643},
28
- {:lat => 40.035317, :lon =>-105.254431, :time => Time.parse("2005-12-31T22:05:08Z"), :elevation => 1732.433},
29
- {:lat => 40.035317, :lon =>-105.254431, :time => Time.parse("2005-12-31T22:05:09Z"), :elevation => 1726.665}]
30
-
31
- track_point_data.each do |trk_pt_hash|
32
- segment.points << TrackPoint.new(trk_pt_hash)
33
- end
34
-
35
- track.segments << segment
36
- gpx_file.tracks << track
37
-
38
- waypoint_data = [
39
- {:lat => 39.997298, :lon => -105.292674, :name => 'GRG-CA', :sym => 'Waypoint', :ele => '1766.535'},
40
- {:lat => 33.330190, :lon => -111.946110, :name => 'GRMPHX', :sym => 'Waypoint', :ele => '361.0981',
41
- :cmt => "Hey here's a comment.", :desc => "Somewhere in my backyard.", :fix => '3d', :sat => "8", :hdop => "50.5", :vdop => "6.8", :pdop => "7.6"},
42
- {:lat => 25.061783, :lon => 121.640267, :name => 'GRMTWN', :sym => 'Waypoint', :ele => '38.09766'},
43
- {:lat => 39.999840, :lon => -105.214696, :name => 'SBDR', :sym => 'Waypoint', :ele => '1612.965'},
44
- {:lat => 39.989739, :lon => -105.295285, :name => 'TO', :sym => 'Waypoint', :ele => '2163.556'},
45
- {:lat => 40.035301, :lon => -105.254443, :name => 'VICS', :sym => 'Waypoint', :ele => '1535.34'},
46
- {:lat => 40.035301, :lon => -105.254443, :name => 'TIMEDWPT', :sym => 'Waypoint', :ele => '1535.34', :time => Time.parse("2005-12-31T22:05:09Z")}
47
- ]
48
-
49
- waypoint_data.each do |wpt_hash|
50
- gpx_file.waypoints << Waypoint.new(wpt_hash)
51
- end
52
-
53
- route_point_data = [
54
- {:lat => 40.035467, :lon =>-105.254366, :time => Time.parse("2005-12-31T22:02:29Z"), :elevation => 1735.798},
55
- {:lat => 40.035317, :lon =>-105.254388, :time => Time.parse("2005-12-31T22:02:33Z"), :elevation => 1735.798},
56
- {:lat => 40.035274, :lon =>-105.254431, :time => Time.parse("2005-12-31T22:02:49Z"), :elevation => 1736.278} ]
57
-
58
- route = Route.new()
59
- route_point_data.each do |rte_pt_hash|
60
- route.points << Point.new(rte_pt_hash)
61
- end
62
-
63
- gpx_file.routes << route
64
-
65
- gpx_file.write(output_file(name_of_test))
66
-
67
-
68
- written_gpx_file = GPXFile.new(:gpx_file => output_file(name_of_test))
69
-
70
- assert_equal(File.basename(output_file(name_of_test)), written_gpx_file.name)
71
- assert_equal(1, written_gpx_file.tracks.size)
72
- assert_equal(1, written_gpx_file.tracks[0].segments.size)
73
- assert_equal(track_point_data.size, written_gpx_file.tracks[0].segments[0].points.size)
74
- assert_equal(track_point_data.size, written_gpx_file.tracks[0].points.size)
75
-
76
- # Make sure each point in the segment has the attributes it was initialized with
77
- written_segment = written_gpx_file.tracks[0].segments[0]
78
- track_point_data.each_with_index do |trk_pt_hash, index|
79
- trk_pt_hash.each do |key, value|
80
- assert_equal(value, written_segment.points[index].send(key))
81
- end
82
- end
83
-
84
-
85
-
86
- # Make sure the one route has the attributes we initialized it with
87
- assert_equal(1, written_gpx_file.routes.size)
88
- written_route = written_gpx_file.routes[0]
89
- assert_equal(route_point_data.size, written_route.points.size)
90
- route_point_data.each_with_index do |rte_pt_hash, index|
91
- rte_pt_hash.each do |key, value|
92
- assert_equal(value, written_route.points[index].send(key))
93
- end
94
- end
95
-
96
- # Make sure the waypoints have all of the attributes we initialized them with
97
- written_waypoints = written_gpx_file.waypoints
98
- assert_equal(waypoint_data.size, written_waypoints.size)
99
- waypoint_data.each_with_index do |wpt_hash, index|
100
- wpt_hash.each do |key, value|
101
- assert_equal(value, written_waypoints[index].send(key.to_s), key)
102
- end
103
- end
15
+ gpx_file = GPXFile.new
16
+
17
+ track = Track.new(name: 'My First Track')
18
+ segment = Segment.new
19
+
20
+ track_point_data = [
21
+ { lat: 40.036926, lon: -105.253487, time: Time.parse('2005-12-31T22:01:24Z'), elevation: 1737.24 },
22
+ { lat: 40.036604, lon: -105.253487, time: Time.parse('2005-12-31T22:02:01Z'), elevation: 1738.682 },
23
+ { lat: 40.036347, lon: -105.253830, time: Time.parse('2005-12-31T22:02:08Z'), elevation: 1738.682 },
24
+ { lat: 40.035574, lon: -105.254045, time: Time.parse('2005-12-31T22:02:20Z'), elevation: 1737.24 },
25
+ { lat: 40.035467, lon: -105.254366, time: Time.parse('2005-12-31T22:02:29Z'), elevation: 1735.798 },
26
+ { lat: 40.035317, lon: -105.254388, time: Time.parse('2005-12-31T22:02:33Z'), elevation: 1735.798 },
27
+ { lat: 40.035274, lon: -105.254431, time: Time.parse('2005-12-31T22:02:49Z'), elevation: 1736.278 },
28
+ { lat: 40.035274, lon: -105.254431, time: Time.parse('2005-12-31T22:02:54Z'), elevation: 1739.643 },
29
+ { lat: 40.035317, lon: -105.254431, time: Time.parse('2005-12-31T22:05:08Z'), elevation: 1732.433 },
30
+ { lat: 40.035317, lon: -105.254431, time: Time.parse('2005-12-31T22:05:09Z'), elevation: 1726.665 }
31
+ ]
32
+
33
+ track_point_data.each do |trk_pt_hash|
34
+ segment.points << TrackPoint.new(trk_pt_hash)
35
+ end
36
+
37
+ track.segments << segment
38
+ gpx_file.tracks << track
39
+
40
+ waypoint_data = [
41
+ { lat: 39.997298, lon: -105.292674, name: 'GRG-CA', sym: 'Waypoint', ele: '1766.535' },
42
+ { lat: 33.330190, lon: -111.946110, name: 'GRMPHX', sym: 'Waypoint', ele: '361.0981',
43
+ cmt: "Hey here's a comment.", desc: 'Somewhere in my backyard.', fix: '3d', sat: '8', hdop: '50.5', vdop: '6.8', pdop: '7.6' },
44
+ { lat: 25.061783, lon: 121.640267, name: 'GRMTWN', sym: 'Waypoint', ele: '38.09766' },
45
+ { lat: 39.999840, lon: -105.214696, name: 'SBDR', sym: 'Waypoint', ele: '1612.965' },
46
+ { lat: 39.989739, lon: -105.295285, name: 'TO', sym: 'Waypoint', ele: '2163.556' },
47
+ { lat: 40.035301, lon: -105.254443, name: 'VICS', sym: 'Waypoint', ele: '1535.34' },
48
+ { lat: 40.035301, lon: -105.254443, name: 'TIMEDWPT', sym: 'Waypoint', ele: '1535.34', time: Time.parse('2005-12-31T22:05:09Z') }
49
+ ]
50
+
51
+ waypoint_data.each do |wpt_hash|
52
+ gpx_file.waypoints << Waypoint.new(wpt_hash)
53
+ end
54
+
55
+ route_point_data = [
56
+ { lat: 40.035467, lon: -105.254366, time: Time.parse('2005-12-31T22:02:29Z'), elevation: 1735.798 },
57
+ { lat: 40.035317, lon: -105.254388, time: Time.parse('2005-12-31T22:02:33Z'), elevation: 1735.798 },
58
+ { lat: 40.035274, lon: -105.254431, time: Time.parse('2005-12-31T22:02:49Z'), elevation: 1736.278 }
59
+ ]
60
+
61
+ route = Route.new
62
+ route_point_data.each do |rte_pt_hash|
63
+ route.points << Point.new(rte_pt_hash)
64
+ end
65
+
66
+ gpx_file.routes << route
67
+
68
+ gpx_file.write(output_file(name_of_test))
69
+
70
+ written_gpx_file = GPXFile.new(gpx_file: output_file(name_of_test))
71
+
72
+ assert_equal(File.basename(output_file(name_of_test)), written_gpx_file.name)
73
+ assert_equal(1, written_gpx_file.tracks.size)
74
+ assert_equal(1, written_gpx_file.tracks[0].segments.size)
75
+ assert_equal(track_point_data.size, written_gpx_file.tracks[0].segments[0].points.size)
76
+ assert_equal(track_point_data.size, written_gpx_file.tracks[0].points.size)
77
+
78
+ # Make sure each point in the segment has the attributes it was initialized with
79
+ written_segment = written_gpx_file.tracks[0].segments[0]
80
+ track_point_data.each_with_index do |trk_pt_hash, index|
81
+ trk_pt_hash.each do |key, value|
82
+ assert_equal(value, written_segment.points[index].send(key))
83
+ end
84
+ end
85
+
86
+ # Make sure the one route has the attributes we initialized it with
87
+ assert_equal(1, written_gpx_file.routes.size)
88
+ written_route = written_gpx_file.routes[0]
89
+ assert_equal(route_point_data.size, written_route.points.size)
90
+ route_point_data.each_with_index do |rte_pt_hash, index|
91
+ rte_pt_hash.each do |key, value|
92
+ assert_equal(value, written_route.points[index].send(key))
93
+ end
94
+ end
95
+
96
+ # Make sure the waypoints have all of the attributes we initialized them with
97
+ written_waypoints = written_gpx_file.waypoints
98
+ assert_equal(waypoint_data.size, written_waypoints.size)
99
+ waypoint_data.each_with_index do |wpt_hash, index|
100
+ wpt_hash.each do |key, value|
101
+ assert_equal(value, written_waypoints[index].send(key.to_s), key)
102
+ end
103
+ end
104
104
  end
105
105
 
106
106
  def name_of_test
107
- caller[0] =~ /`test_([^']*)'/ and $1
107
+ caller[0] =~ /`test_([^']*)'/ && Regexp.last_match(1)
108
108
  end
109
109
 
110
110
  def output_file(test_name)
@@ -112,5 +112,4 @@ class OutputTest < Minitest::Test
112
112
  end
113
113
 
114
114
  THE_WORKS = "<?xml version=\"1.0\"?>\n<gpx xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/1\" version=\"1.1\" creator=\"GPX RubyGem #{GPX::VERSION} Copyright 2006-2009 Doug Fales -- http://gpx.rubyforge.org/\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n <metadata>\n <name>new_gpx_file_from_scratch.gpx</name>\n <time>%s</time>\n <bounds minlat=\"90.0\" minlon=\"180.0\" maxlat=\"-90.0\" maxlon=\"-180.0\"/>\n </metadata>\n <trk>\n <name/>\n <trkseg>\n <trkpt lat=\"40.036926\" lon=\"-105.253487\">\n <time>2005-12-31T22:01:24Z</time>\n <ele>1737.24</ele>\n </trkpt>\n <trkpt lat=\"40.036604\" lon=\"-105.253487\">\n <time>2005-12-31T22:02:01Z</time>\n <ele>1738.682</ele>\n </trkpt>\n <trkpt lat=\"40.036347\" lon=\"-105.25383\">\n <time>2005-12-31T22:02:08Z</time>\n <ele>1738.682</ele>\n </trkpt>\n <trkpt lat=\"40.035574\" lon=\"-105.254045\">\n <time>2005-12-31T22:02:20Z</time>\n <ele>1737.24</ele>\n </trkpt>\n <trkpt lat=\"40.035467\" lon=\"-105.254366\">\n <time>2005-12-31T22:02:29Z</time>\n <ele>1735.798</ele>\n </trkpt>\n <trkpt lat=\"40.035317\" lon=\"-105.254388\">\n <time>2005-12-31T22:02:33Z</time>\n <ele>1735.798</ele>\n </trkpt>\n <trkpt lat=\"40.035274\" lon=\"-105.254431\">\n <time>2005-12-31T22:02:49Z</time>\n <ele>1736.278</ele>\n </trkpt>\n <trkpt lat=\"40.035274\" lon=\"-105.254431\">\n <time>2005-12-31T22:02:54Z</time>\n <ele>1739.643</ele>\n </trkpt>\n <trkpt lat=\"40.035317\" lon=\"-105.254431\">\n <time>2005-12-31T22:05:08Z</time>\n <ele>1732.433</ele>\n </trkpt>\n <trkpt lat=\"40.035317\" lon=\"-105.254431\">\n <time>2005-12-31T22:05:09Z</time>\n <ele>1726.665</ele>\n </trkpt>\n </trkseg>\n </trk>\n <wpt lat=\"39.997298\" lon=\"-105.292674\">\n <name>GRG-CA</name>\n <sym>Waypoint</sym>\n <ele>1766.535</ele>\n </wpt>\n <wpt lat=\"33.33019\" lon=\"-111.94611\">\n <name>GRMPHX</name>\n <cmt>Hey here's a comment.</cmt>\n <desc>Somewhere in my backyard.</desc>\n <sym>Waypoint</sym>\n <fix>3d</fix>\n <sat>8</sat>\n <hdop>50.5</hdop>\n <vdop>6.8</vdop>\n <pdop>7.6</pdop>\n <ele>361.0981</ele>\n </wpt>\n <wpt lat=\"25.061783\" lon=\"121.640267\">\n <name>GRMTWN</name>\n <sym>Waypoint</sym>\n <ele>38.09766</ele>\n </wpt>\n <wpt lat=\"39.99984\" lon=\"-105.214696\">\n <name>SBDR</name>\n <sym>Waypoint</sym>\n <ele>1612.965</ele>\n </wpt>\n <wpt lat=\"39.989739\" lon=\"-105.295285\">\n <name>TO</name>\n <sym>Waypoint</sym>\n <ele>2163.556</ele>\n </wpt>\n <wpt lat=\"40.035301\" lon=\"-105.254443\">\n <name>VICS</name>\n <sym>Waypoint</sym>\n <ele>1535.34</ele>\n </wpt>\n <rte>\n <name/>\n <rtept lat=\"40.035467\" lon=\"-105.254366\">\n <time>2005-12-31T22:02:29Z</time>\n <ele>1735.798</ele>\n </rtept>\n <rtept lat=\"40.035317\" lon=\"-105.254388\">\n <time>2005-12-31T22:02:33Z</time>\n <ele>1735.798</ele>\n </rtept>\n <rtept lat=\"40.035274\" lon=\"-105.254431\">\n <time>2005-12-31T22:02:49Z</time>\n <ele>1736.278</ele>\n </rtept>\n </rte>\n</gpx>\n"
115
-
116
115
  end
data/tests/route_test.rb CHANGED
@@ -1,63 +1,108 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'gpx'
3
5
 
4
6
  class RouteTest < Minitest::Test
5
-
6
7
  def test_read_routes
7
- gpx = GPX::GPXFile.new(:gpx_file => File.join(File.dirname(__FILE__), "gpx_files/routes.gpx"))
8
+ gpx = GPX::GPXFile.new(gpx_file: File.join(File.dirname(__FILE__), 'gpx_files/routes.gpx'))
8
9
  assert_equal(2, gpx.routes.size)
9
10
  first_route = gpx.routes.first
10
11
  assert_equal(3, first_route.points.size)
11
12
  assert_equal('GRG-CA-TO', first_route.name)
12
13
 
13
-
14
- # Route 1, First Point
15
- # <rtept lat="39.997298" lon="-105.292674">
16
- # <name><![CDATA[GRG-CA]]></name>
17
- # <sym>Waypoint</sym>
18
- # <ele>1766.535</ele>
19
- # </rtept>
14
+ # Route 1, First Point
15
+ # <rtept lat="39.997298" lon="-105.292674">
16
+ # <name><![CDATA[GRG-CA]]></name>
17
+ # <sym>Waypoint</sym>
18
+ # <ele>1766.535</ele>
19
+ # </rtept>
20
20
  assert_equal(39.997298, first_route.points[0].lat)
21
21
  assert_equal(-105.292674, first_route.points[0].lon)
22
22
  assert_equal(1766.535, first_route.points[0].elevation)
23
23
 
24
-
25
- # Route 1, Second Point
26
- # <rtept lat="39.995700" lon="-105.292805">
27
- # <name><![CDATA[AMPTHT]]></name>
28
- # <sym>Waypoint</sym>
29
- # <ele>1854.735</ele>
30
- # </rtept>
24
+ # Route 1, Second Point
25
+ # <rtept lat="39.995700" lon="-105.292805">
26
+ # <name><![CDATA[AMPTHT]]></name>
27
+ # <sym>Waypoint</sym>
28
+ # <ele>1854.735</ele>
29
+ # </rtept>
31
30
  assert_equal(39.995700, first_route.points[1].lat)
32
31
  assert_equal(-105.292805, first_route.points[1].lon)
33
32
  assert_equal(1854.735, first_route.points[1].elevation)
34
33
 
35
- # Route 1, Third Point
36
- # <rtept lat="39.989739" lon="-105.295285">
37
- # <name><![CDATA[TO]]></name>
38
- # <sym>Waypoint</sym>
39
- # <ele>2163.556</ele>
40
- # </rtept>
34
+ # Route 1, Third Point
35
+ # <rtept lat="39.989739" lon="-105.295285">
36
+ # <name><![CDATA[TO]]></name>
37
+ # <sym>Waypoint</sym>
38
+ # <ele>2163.556</ele>
39
+ # </rtept>
41
40
  assert_equal(39.989739, first_route.points[2].lat)
42
41
  assert_equal(-105.295285, first_route.points[2].lon)
43
42
  assert_equal(2163.556, first_route.points[2].elevation)
44
43
 
45
-
46
44
  second_route = gpx.routes[1]
47
45
  assert_equal(1, second_route.points.size)
48
46
  assert_equal('SBDR-SBDR', second_route.name)
49
47
 
50
- # Route 2, Only Point
51
- # <rtept lat="39.999840" lon="-105.214696">
52
- # <name><![CDATA[SBDR]]></name>
53
- # <sym>Waypoint</sym>
54
- # <ele>1612.965</ele>
55
- # </rtept>
48
+ # Route 2, Only Point
49
+ # <rtept lat="39.999840" lon="-105.214696">
50
+ # <name><![CDATA[SBDR]]></name>
51
+ # <sym>Waypoint</sym>
52
+ # <ele>1612.965</ele>
53
+ # </rtept>
56
54
  assert_equal(39.999840, second_route.points[0].lat)
57
55
  assert_equal(-105.214696, second_route.points[0].lon)
58
56
  assert_equal(1612.965, second_route.points[0].elevation)
59
-
60
57
  end
61
58
 
59
+ def test_read_routes_without_name_fields
60
+ file = File.join(File.dirname(__FILE__), 'gpx_files/routes_without_names.gpx')
61
+ gpx = GPX::GPXFile.new(gpx_file: file)
62
+ assert_equal(2, gpx.routes.size)
63
+ first_route = gpx.routes.first
64
+ assert_equal(3, first_route.points.size)
65
+ assert_nil(first_route.name)
66
+
67
+ # Route 1, First Point
68
+ # <rtept lat="39.997298" lon="-105.292674">
69
+ # <sym>Waypoint</sym>
70
+ # <ele>1766.535</ele>
71
+ # </rtept>
72
+ assert_equal(39.997298, first_route.points[0].lat)
73
+ assert_equal(-105.292674, first_route.points[0].lon)
74
+ assert_equal(1766.535, first_route.points[0].elevation)
75
+
76
+ # Route 1, Second Point
77
+ # <rtept lat="39.995700" lon="-105.292805">
78
+ # <name><![CDATA[AMPTHT]]></name>
79
+ # <sym>Waypoint</sym>
80
+ # <ele>1854.735</ele>
81
+ # </rtept>
82
+ assert_equal(39.995700, first_route.points[1].lat)
83
+ assert_equal(-105.292805, first_route.points[1].lon)
84
+ assert_equal(1854.735, first_route.points[1].elevation)
85
+
86
+ # Route 1, Third Point
87
+ # <rtept lat="39.989739" lon="-105.295285">
88
+ # <sym>Waypoint</sym>
89
+ # <ele>2163.556</ele>
90
+ # </rtept>
91
+ assert_equal(39.989739, first_route.points[2].lat)
92
+ assert_equal(-105.295285, first_route.points[2].lon)
93
+ assert_equal(2163.556, first_route.points[2].elevation)
62
94
 
95
+ second_route = gpx.routes[1]
96
+ assert_equal(1, second_route.points.size)
97
+ assert_nil(second_route.name)
98
+
99
+ # Route 2, Only Point
100
+ # <rtept lat="39.999840" lon="-105.214696">
101
+ # <sym>Waypoint</sym>
102
+ # <ele>1612.965</ele>
103
+ # </rtept>
104
+ assert_equal(39.999840, second_route.points[0].lat)
105
+ assert_equal(-105.214696, second_route.points[0].lon)
106
+ assert_equal(1612.965, second_route.points[0].elevation)
107
+ end
63
108
  end