gpx 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +4 -0
- data/.rubocop.yml +165 -0
- data/.travis.yml +3 -3
- data/CHANGELOG.md +8 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/Rakefile +15 -12
- data/bin/gpx_distance +3 -6
- data/bin/gpx_smooth +20 -24
- data/gpx.gemspec +12 -11
- data/lib/gpx.rb +11 -34
- data/lib/gpx/bounds.rb +10 -31
- data/lib/gpx/gpx.rb +2 -26
- data/lib/gpx/gpx_file.rb +112 -108
- data/lib/gpx/magellan_track_log.rb +32 -66
- data/lib/gpx/point.rb +18 -35
- data/lib/gpx/route.rb +7 -31
- data/lib/gpx/segment.rb +56 -88
- data/lib/gpx/track.rb +31 -42
- data/lib/gpx/track_point.rb +30 -0
- data/lib/gpx/version.rb +1 -1
- data/lib/gpx/waypoint.rb +7 -34
- data/tests/gpx10_test.rb +5 -6
- data/tests/gpx_file_test.rb +29 -19
- data/tests/gpx_files/with_empty_tracks.gpx +72 -0
- data/tests/magellan_test.rb +10 -11
- data/tests/output_test.rb +92 -95
- data/tests/route_test.rb +25 -32
- data/tests/segment_test.rb +93 -94
- data/tests/track_file_test.rb +47 -70
- data/tests/track_point_test.rb +20 -11
- data/tests/track_test.rb +71 -61
- data/tests/waypoint_test.rb +44 -48
- metadata +29 -13
- data/lib/gpx/trackpoint.rb +0 -60
data/tests/track_file_test.rb
CHANGED
@@ -2,74 +2,51 @@ require 'minitest/autorun'
|
|
2
2
|
require 'gpx'
|
3
3
|
|
4
4
|
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
|
-
def test_find_distance
|
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
|
-
|
5
|
+
TRACK_FILE = File.join(File.dirname(__FILE__), 'gpx_files/tracks.gpx')
|
6
|
+
OTHER_TRACK_FILE = File.join(File.dirname(__FILE__), 'gpx_files/arches.gpx')
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@track_file = GPX::GPXFile.new(gpx_file: TRACK_FILE)
|
10
|
+
@other_track_file = GPX::GPXFile.new(gpx_file: OTHER_TRACK_FILE)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_track_read
|
14
|
+
assert_equal(3, @track_file.tracks.size)
|
15
|
+
assert_equal('First Track', @track_file.tracks[0].name)
|
16
|
+
assert_equal('Second Track', @track_file.tracks[1].name)
|
17
|
+
assert_equal('Third Track', @track_file.tracks[2].name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_track_segment_and_point_counts
|
21
|
+
# One segment with 398 points...
|
22
|
+
assert_equal(1, @track_file.tracks[0].segments.size)
|
23
|
+
assert_equal(389, @track_file.tracks[0].segments.first.points.size)
|
24
|
+
|
25
|
+
# One segment with 299 points...
|
26
|
+
assert_equal(1, @track_file.tracks[1].segments.size)
|
27
|
+
assert_equal(299, @track_file.tracks[1].segments.first.points.size)
|
28
|
+
|
29
|
+
# Many segments of many different sizes
|
30
|
+
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]
|
31
|
+
assert_equal(43, @track_file.tracks[2].segments.size)
|
32
|
+
@track_file.tracks[2].segments.each_with_index do |seg, i|
|
33
|
+
assert_equal(segment_sizes[i].to_i, seg.points.size)
|
34
|
+
end
|
35
|
+
last_segment = @track_file.tracks[2].segments.last
|
36
|
+
assert_equal(1680.041, last_segment.points.last.elevation)
|
37
|
+
|
38
|
+
second_to_last_segment = @track_file.tracks[2].segments[-2]
|
39
|
+
assert_equal('2006-01-02T00:00:51Z', second_to_last_segment.points.last.time.strftime('%Y-%m-%dT%H:%M:%SZ'))
|
40
|
+
assert_equal(39.998045, second_to_last_segment.points.last.lat)
|
41
|
+
assert_equal(-105.292368, second_to_last_segment.points.last.lon)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_write
|
45
|
+
output_path = 'tests/output/myoutput.gpx'
|
46
|
+
@other_track_file.write(output_path)
|
47
|
+
new_track_file = GPX::GPXFile.new(gpx_file: output_path)
|
48
|
+
orig_segments = @other_track_file.tracks.first.segments
|
49
|
+
new_segments = new_track_file.tracks.first.segments
|
50
|
+
assert_equal(orig_segments.first.points.map(&:lat_lon), new_segments.first.points.map(&:lat_lon))
|
51
|
+
end
|
75
52
|
end
|
data/tests/track_point_test.rb
CHANGED
@@ -3,14 +3,18 @@ require 'gpx'
|
|
3
3
|
|
4
4
|
class TrackPointTest < Minitest::Test
|
5
5
|
def setup
|
6
|
-
@point1 = GPX::TrackPoint.new(
|
7
|
-
:
|
8
|
-
:
|
9
|
-
|
10
|
-
@point2 = GPX::TrackPoint.new(
|
11
|
-
:
|
12
|
-
:
|
13
|
-
|
6
|
+
@point1 = GPX::TrackPoint.new(
|
7
|
+
lat: 37.7985474,
|
8
|
+
lon: -122.2554386
|
9
|
+
)
|
10
|
+
@point2 = GPX::TrackPoint.new(
|
11
|
+
lat: 37.7985583,
|
12
|
+
lon: -122.2554564
|
13
|
+
)
|
14
|
+
@point3 = GPX::TrackPoint.new(
|
15
|
+
lat: 38.7985583,
|
16
|
+
lon: -121.2554564
|
17
|
+
)
|
14
18
|
end
|
15
19
|
|
16
20
|
def test_haversine_distance_from
|
@@ -18,13 +22,18 @@ class TrackPointTest < Minitest::Test
|
|
18
22
|
assert_in_delta(0.00197862991592239, distance, 1e-18)
|
19
23
|
end
|
20
24
|
|
21
|
-
def
|
22
|
-
distance = @
|
23
|
-
|
25
|
+
def test_longer_haversine_distance_from
|
26
|
+
distance = @point2.haversine_distance_from(@point3)
|
27
|
+
assert_in_delta(141.3465338444813, distance, 1e-18)
|
24
28
|
end
|
25
29
|
|
26
30
|
def test_law_of_cosines_distance_from
|
27
31
|
distance = @point1.law_of_cosines_distance_from(@point2)
|
28
32
|
assert_equal(0.001982307218559664, distance)
|
29
33
|
end
|
34
|
+
|
35
|
+
def test_longer_law_of_cosines_distance_from
|
36
|
+
distance = @point2.law_of_cosines_distance_from(@point3)
|
37
|
+
assert_equal(141.3465338444991, distance)
|
38
|
+
end
|
30
39
|
end
|
data/tests/track_test.rb
CHANGED
@@ -2,71 +2,81 @@ require 'minitest/autorun'
|
|
2
2
|
require 'gpx'
|
3
3
|
|
4
4
|
class TrackTest < Minitest::Test
|
5
|
-
|
5
|
+
ONE_TRACK = File.join(File.dirname(__FILE__), 'gpx_files/one_track.gpx')
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def setup
|
8
|
+
@gpx_file = GPX::GPXFile.new(gpx_file: ONE_TRACK)
|
9
|
+
@track = @gpx_file.tracks.first
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
12
|
+
def test_track_read
|
13
|
+
assert_equal('ACTIVE LOG', @track.name)
|
14
|
+
assert_equal('Comment Log', @track.comment)
|
15
|
+
assert_equal('Description Log', @track.description)
|
16
|
+
assert_equal(182, @track.points.size)
|
17
|
+
assert_equal(8, @track.segments.size)
|
18
|
+
assert_in_delta(3.07249668492626, @track.distance, 0.001)
|
19
|
+
assert_equal(1267.155, @track.lowest_point.elevation)
|
20
|
+
assert_equal(1594.003, @track.highest_point.elevation)
|
21
|
+
assert_equal(38.681488, @track.bounds.min_lat)
|
22
|
+
assert_equal(-109.606948, @track.bounds.min_lon)
|
23
|
+
assert_equal(38.791759, @track.bounds.max_lat)
|
24
|
+
assert_equal(-109.447045, @track.bounds.max_lon)
|
25
|
+
assert_equal(3036.0, @track.moving_duration)
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
28
|
+
def test_track_crop
|
29
|
+
area = GPX::Bounds.new(
|
30
|
+
min_lat: 38.710000,
|
31
|
+
min_lon: -109.600000,
|
32
|
+
max_lat: 38.791759,
|
33
|
+
max_lon: -109.450000
|
34
|
+
)
|
35
|
+
@track.crop(area)
|
36
|
+
assert_equal('ACTIVE LOG', @track.name)
|
37
|
+
assert_equal('Comment Log', @track.comment)
|
38
|
+
assert_equal('Description Log', @track.description)
|
39
|
+
assert_equal(111, @track.points.size)
|
40
|
+
assert_equal(4, @track.segments.size)
|
41
|
+
assert_in_delta(1.62136024923607, @track.distance, 0.001)
|
42
|
+
assert_equal(1557.954, @track.lowest_point.elevation)
|
43
|
+
assert_equal(1582.468, @track.highest_point.elevation)
|
44
|
+
assert_equal(38.782511, @track.bounds.min_lat)
|
45
|
+
assert_equal(-109.599781, @track.bounds.min_lon)
|
46
|
+
assert_equal(38.789527, @track.bounds.max_lat)
|
47
|
+
assert_equal(-109.594996, @track.bounds.max_lon)
|
48
|
+
assert_equal(1773.0, @track.moving_duration)
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
def test_track_delete
|
52
|
+
area = GPX::Bounds.new(
|
53
|
+
min_lat: 38.710000,
|
54
|
+
min_lon: -109.600000,
|
55
|
+
max_lat: 38.791759,
|
56
|
+
max_lon: -109.450000
|
57
|
+
)
|
58
|
+
@track.delete_area(area)
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
60
|
+
assert_equal(1229.0, @track.moving_duration)
|
61
|
+
# puts @track
|
62
|
+
assert_equal('ACTIVE LOG', @track.name)
|
63
|
+
assert_equal(71, @track.points.size)
|
64
|
+
assert_equal(6, @track.segments.size)
|
65
|
+
assert_in_delta(1.197905851972874, @track.distance, 0.00000000001)
|
66
|
+
assert_equal(1267.155, @track.lowest_point.elevation)
|
67
|
+
assert_equal(1594.003, @track.highest_point.elevation)
|
68
|
+
assert_equal(38.681488, @track.bounds.min_lat)
|
69
|
+
assert_equal(-109.606948, @track.bounds.min_lon)
|
70
|
+
assert_equal(38.791759, @track.bounds.max_lat)
|
71
|
+
assert_equal(-109.447045, @track.bounds.max_lon)
|
72
|
+
end
|
71
73
|
|
74
|
+
def test_append_segment
|
75
|
+
trk = GPX::Track.new
|
76
|
+
seg = GPX::Segment.new(track: trk)
|
77
|
+
pt = GPX::TrackPoint.new(lat: -118, lon: 34)
|
78
|
+
seg.append_point(pt)
|
79
|
+
trk.append_segment(seg)
|
80
|
+
assert_equal(1, trk.points.size)
|
81
|
+
end
|
72
82
|
end
|
data/tests/waypoint_test.rb
CHANGED
@@ -1,48 +1,44 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'gpx'
|
3
|
-
|
4
|
-
class WaypointTest < Minitest::Test
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
# <
|
13
|
-
# <
|
14
|
-
# <
|
15
|
-
# <
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
first_wpt
|
21
|
-
assert_equal(
|
22
|
-
assert_equal(
|
23
|
-
assert_equal('
|
24
|
-
assert_equal('
|
25
|
-
assert_equal(
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
#
|
30
|
-
# <
|
31
|
-
# <
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
second_wpt
|
36
|
-
assert_equal(
|
37
|
-
assert_equal(
|
38
|
-
assert_equal(
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'gpx'
|
3
|
+
|
4
|
+
class WaypointTest < Minitest::Test
|
5
|
+
def test_read_waypoints
|
6
|
+
gpx = GPX::GPXFile.new(gpx_file: File.join(File.dirname(__FILE__), 'gpx_files/waypoints.gpx'))
|
7
|
+
assert_equal(18, gpx.waypoints.size)
|
8
|
+
|
9
|
+
# First Waypoint
|
10
|
+
# <wpt lat="40.035557" lon="-105.248268">
|
11
|
+
# <name><![CDATA[001]]></name>
|
12
|
+
# <sym>Waypoint</sym>
|
13
|
+
# <ele>1639.161</ele>
|
14
|
+
# <cmt><![CDATA[001]]></cmt>
|
15
|
+
# <desc><![CDATA[Just some waypoint...]]></desc>
|
16
|
+
# </wpt>
|
17
|
+
|
18
|
+
first_wpt = gpx.waypoints[0]
|
19
|
+
assert_equal(40.035557, first_wpt.lat)
|
20
|
+
assert_equal(-105.248268, first_wpt.lon)
|
21
|
+
assert_equal('001', first_wpt.name)
|
22
|
+
assert_equal('001', first_wpt.cmt)
|
23
|
+
assert_equal('Just some waypoint...', first_wpt.desc)
|
24
|
+
assert_equal('Waypoint', first_wpt.sym)
|
25
|
+
assert_equal(1639.161, first_wpt.elevation)
|
26
|
+
|
27
|
+
# Second Waypoint
|
28
|
+
# <wpt lat="39.993070" lon="-105.296588">
|
29
|
+
# <name><![CDATA[002]]></name>
|
30
|
+
# <sym>Waypoint</sym>
|
31
|
+
# <ele>1955.192</ele>
|
32
|
+
# </wpt>
|
33
|
+
second_wpt = gpx.waypoints[1]
|
34
|
+
assert_equal(39.993070, second_wpt.lat)
|
35
|
+
assert_equal(-105.296588, second_wpt.lon)
|
36
|
+
assert_equal('002', second_wpt.name)
|
37
|
+
assert_equal('Waypoint', second_wpt.sym)
|
38
|
+
assert_equal(1955.192, second_wpt.elevation)
|
39
|
+
|
40
|
+
# test loads time properly in waypoint
|
41
|
+
time_wpt = gpx.waypoints[17]
|
42
|
+
assert_equal(Time.xmlschema('2015-01-01T12:12:12Z'), time_wpt.time)
|
43
|
+
end
|
44
|
+
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.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillaume Dott
|
@@ -10,8 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2018-03-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: nokogiri
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.7'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.7'
|
15
29
|
- !ruby/object:Gem::Dependency
|
16
30
|
name: rake
|
17
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -27,21 +41,21 @@ dependencies:
|
|
27
41
|
- !ruby/object:Gem::Version
|
28
42
|
version: '0'
|
29
43
|
- !ruby/object:Gem::Dependency
|
30
|
-
name:
|
44
|
+
name: bundler
|
31
45
|
requirement: !ruby/object:Gem::Requirement
|
32
46
|
requirements:
|
33
|
-
- - "
|
47
|
+
- - ">="
|
34
48
|
- !ruby/object:Gem::Version
|
35
|
-
version: '
|
36
|
-
type: :
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
37
51
|
prerelease: false
|
38
52
|
version_requirements: !ruby/object:Gem::Requirement
|
39
53
|
requirements:
|
40
|
-
- - "
|
54
|
+
- - ">="
|
41
55
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
56
|
+
version: '0'
|
43
57
|
- !ruby/object:Gem::Dependency
|
44
|
-
name:
|
58
|
+
name: minitest
|
45
59
|
requirement: !ruby/object:Gem::Requirement
|
46
60
|
requirements:
|
47
61
|
- - ">="
|
@@ -55,7 +69,7 @@ dependencies:
|
|
55
69
|
- !ruby/object:Gem::Version
|
56
70
|
version: '0'
|
57
71
|
- !ruby/object:Gem::Dependency
|
58
|
-
name:
|
72
|
+
name: rubocop
|
59
73
|
requirement: !ruby/object:Gem::Requirement
|
60
74
|
requirements:
|
61
75
|
- - ">="
|
@@ -78,6 +92,7 @@ extensions: []
|
|
78
92
|
extra_rdoc_files: []
|
79
93
|
files:
|
80
94
|
- ".gitignore"
|
95
|
+
- ".rubocop.yml"
|
81
96
|
- ".travis.yml"
|
82
97
|
- CHANGELOG.md
|
83
98
|
- Gemfile
|
@@ -96,7 +111,7 @@ files:
|
|
96
111
|
- lib/gpx/route.rb
|
97
112
|
- lib/gpx/segment.rb
|
98
113
|
- lib/gpx/track.rb
|
99
|
-
- lib/gpx/
|
114
|
+
- lib/gpx/track_point.rb
|
100
115
|
- lib/gpx/version.rb
|
101
116
|
- lib/gpx/waypoint.rb
|
102
117
|
- tests/gpx10_test.rb
|
@@ -111,6 +126,7 @@ files:
|
|
111
126
|
- tests/gpx_files/routes.gpx
|
112
127
|
- tests/gpx_files/tracks.gpx
|
113
128
|
- tests/gpx_files/waypoints.gpx
|
129
|
+
- tests/gpx_files/with_empty_tracks.gpx
|
114
130
|
- tests/gpx_files/with_or_without_elev.gpx
|
115
131
|
- tests/magellan_test.rb
|
116
132
|
- tests/output_test.rb
|
@@ -131,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
147
|
requirements:
|
132
148
|
- - "~>"
|
133
149
|
- !ruby/object:Gem::Version
|
134
|
-
version: '2.
|
150
|
+
version: '2.2'
|
135
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
152
|
requirements:
|
137
153
|
- - ">="
|
@@ -139,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
155
|
version: '0'
|
140
156
|
requirements: []
|
141
157
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
158
|
+
rubygems_version: 2.7.3
|
143
159
|
signing_key:
|
144
160
|
specification_version: 4
|
145
161
|
summary: A basic API for reading and writing GPX files.
|