gpx 0.8.3 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +37 -0
- data/.gitignore +4 -0
- data/.rubocop +1 -0
- data/.rubocop.yml +162 -0
- data/.ruby-version +1 -0
- data/.tool-versions +1 -0
- data/.travis.yml +4 -6
- data/CHANGELOG.md +32 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +38 -17
- data/Rakefile +22 -12
- data/UPGRADING.md +7 -0
- data/bin/gpx_distance +5 -6
- data/bin/gpx_smooth +25 -26
- data/gpx.gemspec +14 -11
- data/lib/gpx/bounds.rb +13 -31
- data/lib/gpx/geo_json.rb +199 -0
- data/lib/gpx/gpx.rb +4 -26
- data/lib/gpx/gpx_file.rb +140 -134
- data/lib/gpx/magellan_track_log.rb +34 -66
- data/lib/gpx/point.rb +22 -35
- data/lib/gpx/route.rb +10 -31
- data/lib/gpx/segment.rb +63 -90
- data/lib/gpx/track.rb +38 -42
- data/lib/gpx/track_point.rb +32 -0
- data/lib/gpx/version.rb +3 -1
- data/lib/gpx/waypoint.rb +10 -34
- data/lib/gpx.rb +13 -34
- data/tests/geojson_files/combined_data.json +68 -0
- data/tests/geojson_files/line_string_data.json +83 -0
- data/tests/geojson_files/multi_line_string_data.json +74 -0
- data/tests/geojson_files/multi_point_data.json +14 -0
- data/tests/geojson_files/point_data.json +22 -0
- data/tests/geojson_test.rb +92 -0
- data/tests/gpx10_test.rb +7 -6
- data/tests/gpx_file_test.rb +31 -19
- data/tests/gpx_files/one_segment_mixed_times.gpx +884 -0
- data/tests/gpx_files/routes_without_names.gpx +29 -0
- data/tests/gpx_files/with_empty_tracks.gpx +72 -0
- data/tests/magellan_test.rb +12 -11
- data/tests/output_test.rb +93 -94
- data/tests/route_test.rb +75 -30
- data/tests/segment_test.rb +104 -93
- data/tests/track_file_test.rb +50 -70
- data/tests/track_point_test.rb +22 -11
- data/tests/track_test.rb +73 -61
- data/tests/waypoint_test.rb +46 -48
- metadata +45 -13
- data/lib/gpx/trackpoint.rb +0 -60
data/tests/segment_test.rb
CHANGED
@@ -1,109 +1,120 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'minitest/autorun'
|
3
4
|
require 'yaml'
|
4
5
|
require 'gpx'
|
5
6
|
|
6
7
|
class SegmentTest < Minitest::Test
|
7
|
-
|
8
|
-
|
8
|
+
ONE_SEGMENT = File.join(File.dirname(__FILE__), 'gpx_files/one_segment.gpx')
|
9
|
+
ONE_SEGMENT_NO_TIME = File.join(File.dirname(__FILE__), 'gpx_files/one_segment_no_time.gpx')
|
10
|
+
ONE_SEGMENT_MIXED_TIMES = File.join(File.dirname(__FILE__), 'gpx_files/one_segment_mixed_times.gpx')
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def setup
|
13
|
+
@gpx_file = GPX::GPXFile.new(gpx_file: ONE_SEGMENT)
|
14
|
+
@segment = @gpx_file.tracks.first.segments.first
|
15
|
+
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
def test_segment_read
|
18
|
+
assert_equal(189, @segment.points.size)
|
19
|
+
assert_equal(1_144_433_525, @segment.earliest_point.time.to_i)
|
20
|
+
assert_equal(1_144_437_991, @segment.latest_point.time.to_i)
|
21
|
+
assert_equal(1334.447, @segment.lowest_point.elevation)
|
22
|
+
assert_equal(1480.087, @segment.highest_point.elevation)
|
23
|
+
assert_in_delta(6.98803359528853, @segment.distance, 0.001)
|
24
|
+
assert_equal(4466.0, @segment.duration)
|
25
|
+
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
def test_segment_read_no_time
|
28
|
+
gpx_file_no_time = GPX::GPXFile.new(gpx_file: ONE_SEGMENT_NO_TIME)
|
29
|
+
segment_no_time = gpx_file_no_time.tracks.first.segments.first
|
30
|
+
assert_equal(189, segment_no_time.points.size)
|
31
|
+
assert_equal(1334.447, segment_no_time.earliest_point.elevation)
|
32
|
+
assert_equal(1413.756, segment_no_time.latest_point.elevation)
|
33
|
+
assert_equal(1334.447, segment_no_time.lowest_point.elevation)
|
34
|
+
assert_equal(1480.087, segment_no_time.highest_point.elevation)
|
35
|
+
assert_in_delta(6.98803359528853, segment_no_time.distance, 0.001)
|
36
|
+
assert_equal(0, segment_no_time.duration)
|
37
|
+
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
def test_segment_crop
|
40
|
+
crop_rectangle = GPX::Bounds.new(min_lat: 39.173000,
|
41
|
+
min_lon: -109.010000,
|
42
|
+
max_lat: 39.188000,
|
43
|
+
max_lon: -108.999000)
|
44
|
+
@segment.crop(crop_rectangle)
|
43
45
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
46
|
+
assert_equal(106, @segment.points.size)
|
47
|
+
assert_in_delta(4.11422061733046, @segment.distance, 0.001)
|
48
|
+
assert_equal(1_144_435_041, @segment.earliest_point.time.to_i)
|
49
|
+
assert_equal(1_144_437_752, @segment.latest_point.time.to_i)
|
50
|
+
assert_equal(1407.027, @segment.lowest_point.elevation)
|
51
|
+
assert_equal(1480.087, @segment.highest_point.elevation)
|
52
|
+
assert_equal(39.173834, @segment.bounds.min_lat)
|
53
|
+
assert_equal(-109.009995, @segment.bounds.min_lon)
|
54
|
+
assert_equal(39.187868, @segment.bounds.max_lat)
|
55
|
+
assert_equal(-108.999546, @segment.bounds.max_lon)
|
56
|
+
assert_equal(2711.0, @segment.duration)
|
57
|
+
end
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
59
|
+
def test_segment_delete
|
60
|
+
delete_rectangle = GPX::Bounds.new(min_lat: 39.173000,
|
61
|
+
min_lon: -109.010000,
|
62
|
+
max_lat: 39.188000,
|
63
|
+
max_lon: -108.999000)
|
64
|
+
@segment.delete_area(delete_rectangle)
|
65
|
+
assert_equal(83, @segment.points.size)
|
66
|
+
assert_in_delta(3.35967118153605, @segment.distance, 0.001)
|
67
|
+
assert_equal(1_144_433_525, @segment.earliest_point.time.to_i)
|
68
|
+
assert_equal(1_144_437_991, @segment.latest_point.time.to_i)
|
69
|
+
assert_equal(1334.447, @segment.lowest_point.elevation)
|
70
|
+
assert_equal(1428.176, @segment.highest_point.elevation)
|
71
|
+
assert_equal(39.180572, @segment.bounds.min_lat)
|
72
|
+
assert_equal(-109.016604, @segment.bounds.min_lon)
|
73
|
+
assert_equal(39.188747, @segment.bounds.max_lat)
|
74
|
+
assert_equal(-109.007978, @segment.bounds.max_lon)
|
75
|
+
assert_equal(4466.0, @segment.duration)
|
76
|
+
end
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
78
|
+
def test_segment_smooth
|
79
|
+
@segment.smooth_location_by_average
|
80
|
+
assert_equal(189, @segment.points.size)
|
81
|
+
assert_equal(1_144_433_525, @segment.earliest_point.time.to_i)
|
82
|
+
assert_equal(1_144_437_991, @segment.latest_point.time.to_i)
|
83
|
+
assert_equal(1342.58, @segment.lowest_point.elevation)
|
84
|
+
assert_equal(1479.09, @segment.highest_point.elevation)
|
85
|
+
assert_in_delta(6.458085658, @segment.distance, 0.001)
|
86
|
+
assert_equal(4466.0, @segment.duration)
|
87
|
+
end
|
86
88
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
89
|
+
def test_segment_smooth_offset
|
90
|
+
@segment.smooth_location_by_average(start: 1000, end: 2000)
|
91
|
+
assert_equal(189, @segment.points.size)
|
92
|
+
assert_equal(1_144_433_525, @segment.earliest_point.time.to_i)
|
93
|
+
assert_equal(1_144_437_991, @segment.latest_point.time.to_i)
|
94
|
+
assert_equal(1334.447, @segment.lowest_point.elevation)
|
95
|
+
assert_equal(1480.087, @segment.highest_point.elevation)
|
96
|
+
assert_in_delta(6.900813095, @segment.distance, 0.001)
|
97
|
+
assert_equal(4466.0, @segment.duration)
|
98
|
+
end
|
97
99
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
100
|
+
def test_segment_smooth_absolute
|
101
|
+
@segment.smooth_location_by_average(start: Time.at(1_144_434_520), end: Time.at(1_144_435_520))
|
102
|
+
assert_equal(189, @segment.points.size)
|
103
|
+
assert_equal(1_144_433_525, @segment.earliest_point.time.to_i)
|
104
|
+
assert_equal(1_144_437_991, @segment.latest_point.time.to_i)
|
105
|
+
assert_equal(1334.447, @segment.lowest_point.elevation)
|
106
|
+
assert_equal(1480.087, @segment.highest_point.elevation)
|
107
|
+
assert_in_delta(6.900813095, @segment.distance, 0.001)
|
108
|
+
assert_equal(4466.0, @segment.duration)
|
109
|
+
end
|
108
110
|
|
111
|
+
def test_segment_mixed_times
|
112
|
+
gpx_file_mixed_times = GPX::GPXFile.new(gpx_file: ONE_SEGMENT_MIXED_TIMES)
|
113
|
+
segment_mixed_times = gpx_file_mixed_times.tracks.first.segments.first
|
114
|
+
assert_equal(588, segment_mixed_times.points.size)
|
115
|
+
assert_equal(0, segment_mixed_times.earliest_point.time.to_i)
|
116
|
+
assert_equal(0, segment_mixed_times.latest_point.time.to_i)
|
117
|
+
assert_in_delta(40.763726054, segment_mixed_times.distance, 0.001)
|
118
|
+
assert_equal(0.0, segment_mixed_times.duration)
|
119
|
+
end
|
109
120
|
end
|
data/tests/track_file_test.rb
CHANGED
@@ -1,75 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'gpx'
|
3
5
|
|
4
6
|
class TrackFileTest < Minitest::Test
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
#puts "Distance: #{@other_track_file.distance(:units => 'miles')} miles"
|
54
|
-
#puts "Distance: #{@track_file.distance(:units => 'miles')} miles"
|
55
|
-
end
|
56
|
-
def test_high_low_elevation
|
57
|
-
#puts "Lowest: #{@track_file.lowest_point.elevation} m"
|
58
|
-
#puts "Highest: #{@track_file.highest_point.elevation} m"
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_duration
|
62
|
-
#puts "Duration 1: #{@other_track_file.duration} "
|
63
|
-
#puts "Duration 2: #{@track_file.duration} "
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_average_speed
|
67
|
-
#puts "Speed 1: #{@other_track_file.average_speed} "
|
68
|
-
#puts "Speed 2: #{@track_file.average_speed} "
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_write
|
72
|
-
@other_track_file.write("tests/output/myoutput.gpx")
|
73
|
-
end
|
74
|
-
|
7
|
+
TRACK_FILE = File.join(File.dirname(__FILE__), 'gpx_files/tracks.gpx')
|
8
|
+
OTHER_TRACK_FILE = File.join(File.dirname(__FILE__), 'gpx_files/arches.gpx')
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@track_file = GPX::GPXFile.new(gpx_file: TRACK_FILE)
|
12
|
+
@other_track_file = GPX::GPXFile.new(gpx_file: OTHER_TRACK_FILE)
|
13
|
+
FileUtils.mkdir_p(File.join(File.dirname(__FILE__), 'output'))
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_track_read
|
17
|
+
assert_equal(3, @track_file.tracks.size)
|
18
|
+
assert_equal('First Track', @track_file.tracks[0].name)
|
19
|
+
assert_equal('Second Track', @track_file.tracks[1].name)
|
20
|
+
assert_equal('Third Track', @track_file.tracks[2].name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_track_segment_and_point_counts
|
24
|
+
# One segment with 398 points...
|
25
|
+
assert_equal(1, @track_file.tracks[0].segments.size)
|
26
|
+
assert_equal(389, @track_file.tracks[0].segments.first.points.size)
|
27
|
+
|
28
|
+
# One segment with 299 points...
|
29
|
+
assert_equal(1, @track_file.tracks[1].segments.size)
|
30
|
+
assert_equal(299, @track_file.tracks[1].segments.first.points.size)
|
31
|
+
|
32
|
+
# Many segments of many different sizes
|
33
|
+
segment_sizes = %w[2 2 5 4 2 1 197 31 54 1 15 54 19 26 109 18 9 2 8 3 10 23 21 11 25 32 66 21 2 3 3 4 6 4 4 4 3 3 6 6 27 13 2]
|
34
|
+
assert_equal(43, @track_file.tracks[2].segments.size)
|
35
|
+
@track_file.tracks[2].segments.each_with_index do |seg, i|
|
36
|
+
assert_equal(segment_sizes[i].to_i, seg.points.size)
|
37
|
+
end
|
38
|
+
last_segment = @track_file.tracks[2].segments.last
|
39
|
+
assert_equal(1680.041, last_segment.points.last.elevation)
|
40
|
+
|
41
|
+
second_to_last_segment = @track_file.tracks[2].segments[-2]
|
42
|
+
assert_equal('2006-01-02T00:00:51Z', second_to_last_segment.points.last.time.strftime('%Y-%m-%dT%H:%M:%SZ'))
|
43
|
+
assert_equal(39.998045, second_to_last_segment.points.last.lat)
|
44
|
+
assert_equal(-105.292368, second_to_last_segment.points.last.lon)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_write
|
48
|
+
output_path = 'tests/output/myoutput.gpx'
|
49
|
+
@other_track_file.write(output_path)
|
50
|
+
new_track_file = GPX::GPXFile.new(gpx_file: output_path)
|
51
|
+
orig_segments = @other_track_file.tracks.first.segments
|
52
|
+
new_segments = new_track_file.tracks.first.segments
|
53
|
+
assert_equal(orig_segments.first.points.map(&:lat_lon), new_segments.first.points.map(&:lat_lon))
|
54
|
+
end
|
75
55
|
end
|
data/tests/track_point_test.rb
CHANGED
@@ -1,16 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'gpx'
|
3
5
|
|
4
6
|
class TrackPointTest < Minitest::Test
|
5
7
|
def setup
|
6
|
-
@point1 = GPX::TrackPoint.new(
|
7
|
-
:
|
8
|
-
:
|
9
|
-
|
10
|
-
@point2 = GPX::TrackPoint.new(
|
11
|
-
:
|
12
|
-
:
|
13
|
-
|
8
|
+
@point1 = GPX::TrackPoint.new(
|
9
|
+
lat: 37.7985474,
|
10
|
+
lon: -122.2554386
|
11
|
+
)
|
12
|
+
@point2 = GPX::TrackPoint.new(
|
13
|
+
lat: 37.7985583,
|
14
|
+
lon: -122.2554564
|
15
|
+
)
|
16
|
+
@point3 = GPX::TrackPoint.new(
|
17
|
+
lat: 38.7985583,
|
18
|
+
lon: -121.2554564
|
19
|
+
)
|
14
20
|
end
|
15
21
|
|
16
22
|
def test_haversine_distance_from
|
@@ -18,13 +24,18 @@ class TrackPointTest < Minitest::Test
|
|
18
24
|
assert_in_delta(0.00197862991592239, distance, 1e-18)
|
19
25
|
end
|
20
26
|
|
21
|
-
def
|
22
|
-
distance = @
|
23
|
-
|
27
|
+
def test_longer_haversine_distance_from
|
28
|
+
distance = @point2.haversine_distance_from(@point3)
|
29
|
+
assert_in_delta(141.3465338444813, distance, 1e-18)
|
24
30
|
end
|
25
31
|
|
26
32
|
def test_law_of_cosines_distance_from
|
27
33
|
distance = @point1.law_of_cosines_distance_from(@point2)
|
28
34
|
assert_equal(0.001982307218559664, distance)
|
29
35
|
end
|
36
|
+
|
37
|
+
def test_longer_law_of_cosines_distance_from
|
38
|
+
distance = @point2.law_of_cosines_distance_from(@point3)
|
39
|
+
assert_equal(141.3465338444991, distance)
|
40
|
+
end
|
30
41
|
end
|
data/tests/track_test.rb
CHANGED
@@ -1,72 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'gpx'
|
3
5
|
|
4
6
|
class TrackTest < Minitest::Test
|
5
|
-
|
7
|
+
ONE_TRACK = File.join(File.dirname(__FILE__), 'gpx_files/one_track.gpx')
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def setup
|
10
|
+
@gpx_file = GPX::GPXFile.new(gpx_file: ONE_TRACK)
|
11
|
+
@track = @gpx_file.tracks.first
|
12
|
+
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
14
|
+
def test_track_read
|
15
|
+
assert_equal('ACTIVE LOG', @track.name)
|
16
|
+
assert_equal('Comment Log', @track.comment)
|
17
|
+
assert_equal('Description Log', @track.description)
|
18
|
+
assert_equal(182, @track.points.size)
|
19
|
+
assert_equal(8, @track.segments.size)
|
20
|
+
assert_in_delta(3.07249668492626, @track.distance, 0.001)
|
21
|
+
assert_equal(1267.155, @track.lowest_point.elevation)
|
22
|
+
assert_equal(1594.003, @track.highest_point.elevation)
|
23
|
+
assert_equal(38.681488, @track.bounds.min_lat)
|
24
|
+
assert_equal(-109.606948, @track.bounds.min_lon)
|
25
|
+
assert_equal(38.791759, @track.bounds.max_lat)
|
26
|
+
assert_equal(-109.447045, @track.bounds.max_lon)
|
27
|
+
assert_equal(3036.0, @track.moving_duration)
|
28
|
+
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
30
|
+
def test_track_crop
|
31
|
+
area = GPX::Bounds.new(
|
32
|
+
min_lat: 38.710000,
|
33
|
+
min_lon: -109.600000,
|
34
|
+
max_lat: 38.791759,
|
35
|
+
max_lon: -109.450000
|
36
|
+
)
|
37
|
+
@track.crop(area)
|
38
|
+
assert_equal('ACTIVE LOG', @track.name)
|
39
|
+
assert_equal('Comment Log', @track.comment)
|
40
|
+
assert_equal('Description Log', @track.description)
|
41
|
+
assert_equal(111, @track.points.size)
|
42
|
+
assert_equal(4, @track.segments.size)
|
43
|
+
assert_in_delta(1.62136024923607, @track.distance, 0.001)
|
44
|
+
assert_equal(1557.954, @track.lowest_point.elevation)
|
45
|
+
assert_equal(1582.468, @track.highest_point.elevation)
|
46
|
+
assert_equal(38.782511, @track.bounds.min_lat)
|
47
|
+
assert_equal(-109.599781, @track.bounds.min_lon)
|
48
|
+
assert_equal(38.789527, @track.bounds.max_lat)
|
49
|
+
assert_equal(-109.594996, @track.bounds.max_lon)
|
50
|
+
assert_equal(1773.0, @track.moving_duration)
|
51
|
+
end
|
49
52
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
def test_track_delete
|
54
|
+
area = GPX::Bounds.new(
|
55
|
+
min_lat: 38.710000,
|
56
|
+
min_lon: -109.600000,
|
57
|
+
max_lat: 38.791759,
|
58
|
+
max_lon: -109.450000
|
59
|
+
)
|
60
|
+
@track.delete_area(area)
|
57
61
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
62
|
+
assert_equal(1229.0, @track.moving_duration)
|
63
|
+
# puts @track
|
64
|
+
assert_equal('ACTIVE LOG', @track.name)
|
65
|
+
assert_equal(71, @track.points.size)
|
66
|
+
assert_equal(6, @track.segments.size)
|
67
|
+
assert_in_delta(1.197905851972874, @track.distance, 0.00000000001)
|
68
|
+
assert_equal(1267.155, @track.lowest_point.elevation)
|
69
|
+
assert_equal(1594.003, @track.highest_point.elevation)
|
70
|
+
assert_equal(38.681488, @track.bounds.min_lat)
|
71
|
+
assert_equal(-109.606948, @track.bounds.min_lon)
|
72
|
+
assert_equal(38.791759, @track.bounds.max_lat)
|
73
|
+
assert_equal(-109.447045, @track.bounds.max_lon)
|
74
|
+
end
|
71
75
|
|
76
|
+
def test_append_segment
|
77
|
+
trk = GPX::Track.new
|
78
|
+
seg = GPX::Segment.new(track: trk)
|
79
|
+
pt = GPX::TrackPoint.new(lat: -118, lon: 34)
|
80
|
+
seg.append_point(pt)
|
81
|
+
trk.append_segment(seg)
|
82
|
+
assert_equal(1, trk.points.size)
|
83
|
+
end
|
72
84
|
end
|
data/tests/waypoint_test.rb
CHANGED
@@ -1,48 +1,46 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
gpx = GPX::GPXFile.new(:
|
9
|
-
assert_equal(18, gpx.waypoints.size)
|
10
|
-
|
11
|
-
# First Waypoint
|
12
|
-
# <wpt lat="40.035557" lon="-105.248268">
|
13
|
-
# <name><![CDATA[001]]></name>
|
14
|
-
# <sym>Waypoint</sym>
|
15
|
-
# <ele>1639.161</ele>
|
16
|
-
# <cmt><![CDATA[001]]></cmt>
|
17
|
-
# <desc><![CDATA[Just some waypoint...]]></desc>
|
18
|
-
# </wpt>
|
19
|
-
|
20
|
-
first_wpt = gpx.waypoints[0]
|
21
|
-
assert_equal(40.035557, first_wpt.lat)
|
22
|
-
assert_equal(-105.248268, first_wpt.lon)
|
23
|
-
assert_equal('001', first_wpt.name)
|
24
|
-
assert_equal('001', first_wpt.cmt)
|
25
|
-
assert_equal('Just some waypoint...', first_wpt.desc)
|
26
|
-
assert_equal('Waypoint', first_wpt.sym)
|
27
|
-
|
28
|
-
|
29
|
-
# Second Waypoint
|
30
|
-
# <wpt lat="39.993070" lon="-105.296588">
|
31
|
-
# <name><![CDATA[002]]></name>
|
32
|
-
# <sym>Waypoint</sym>
|
33
|
-
# <ele>1955.192</ele>
|
34
|
-
# </wpt>
|
35
|
-
second_wpt = gpx.waypoints[1]
|
36
|
-
assert_equal(39.993070, second_wpt.lat)
|
37
|
-
assert_equal(-105.296588, second_wpt.lon)
|
38
|
-
assert_equal('002', second_wpt.name)
|
39
|
-
assert_equal('Waypoint', second_wpt.sym)
|
40
|
-
assert_equal(1955.192, second_wpt.elevation)
|
41
|
-
|
42
|
-
# test loads time properly in waypoint
|
43
|
-
time_wpt = gpx.waypoints[17]
|
44
|
-
assert_equal(Time.xmlschema(
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'gpx'
|
5
|
+
|
6
|
+
class WaypointTest < Minitest::Test
|
7
|
+
def test_read_waypoints
|
8
|
+
gpx = GPX::GPXFile.new(gpx_file: File.join(File.dirname(__FILE__), 'gpx_files/waypoints.gpx'))
|
9
|
+
assert_equal(18, gpx.waypoints.size)
|
10
|
+
|
11
|
+
# First Waypoint
|
12
|
+
# <wpt lat="40.035557" lon="-105.248268">
|
13
|
+
# <name><![CDATA[001]]></name>
|
14
|
+
# <sym>Waypoint</sym>
|
15
|
+
# <ele>1639.161</ele>
|
16
|
+
# <cmt><![CDATA[001]]></cmt>
|
17
|
+
# <desc><![CDATA[Just some waypoint...]]></desc>
|
18
|
+
# </wpt>
|
19
|
+
|
20
|
+
first_wpt = gpx.waypoints[0]
|
21
|
+
assert_equal(40.035557, first_wpt.lat)
|
22
|
+
assert_equal(-105.248268, first_wpt.lon)
|
23
|
+
assert_equal('001', first_wpt.name)
|
24
|
+
assert_equal('001', first_wpt.cmt)
|
25
|
+
assert_equal('Just some waypoint...', first_wpt.desc)
|
26
|
+
assert_equal('Waypoint', first_wpt.sym)
|
27
|
+
assert_equal(1639.161, first_wpt.elevation)
|
28
|
+
|
29
|
+
# Second Waypoint
|
30
|
+
# <wpt lat="39.993070" lon="-105.296588">
|
31
|
+
# <name><![CDATA[002]]></name>
|
32
|
+
# <sym>Waypoint</sym>
|
33
|
+
# <ele>1955.192</ele>
|
34
|
+
# </wpt>
|
35
|
+
second_wpt = gpx.waypoints[1]
|
36
|
+
assert_equal(39.993070, second_wpt.lat)
|
37
|
+
assert_equal(-105.296588, second_wpt.lon)
|
38
|
+
assert_equal('002', second_wpt.name)
|
39
|
+
assert_equal('Waypoint', second_wpt.sym)
|
40
|
+
assert_equal(1955.192, second_wpt.elevation)
|
41
|
+
|
42
|
+
# test loads time properly in waypoint
|
43
|
+
time_wpt = gpx.waypoints[17]
|
44
|
+
assert_equal(Time.xmlschema('2015-01-01T12:12:12Z'), time_wpt.time)
|
45
|
+
end
|
46
|
+
end
|