andrewhao-gpx 0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
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"><metadata><name><![CDATA[waypoints.gpx]]></name><time>2006-01-02T08:55:21Z</time><bounds min_lat="25.061783" min_lon="-111.946110" max_lat="50.982883" max_lon="121.640267"/></metadata><extensions/>
3
+ <wpt lat="40.035557" lon="-105.248268"><name><![CDATA[001]]></name><sym>Waypoint</sym><ele>1639.161</ele><cmt><![CDATA[001]]></cmt><desc><![CDATA[Just some waypoint...]]></desc></wpt>
4
+ <wpt lat="39.993070" lon="-105.296588"><name><![CDATA[002]]></name><sym>Waypoint</sym><ele>1955.192</ele></wpt>
5
+ <wpt lat="39.990151" lon="-105.295680"><name><![CDATA[003]]></name><sym>Waypoint</sym><ele>2129.91</ele></wpt>
6
+ <wpt lat="39.990157" lon="-105.295686"><name><![CDATA[004]]></name><sym>Waypoint</sym><ele>2136.399</ele></wpt>
7
+ <wpt lat="39.990134" lon="-105.295251"><name><![CDATA[005]]></name><sym>Waypoint</sym><ele>2174.612</ele></wpt>
8
+ <wpt lat="39.990116" lon="-105.295147"><name><![CDATA[006]]></name><sym>Waypoint</sym><ele>2156.106</ele></wpt>
9
+ <wpt lat="39.990099" lon="-105.295207"><name><![CDATA[007]]></name><sym>Waypoint</sym><ele>2155.145</ele></wpt>
10
+ <wpt lat="39.990067" lon="-105.295185"><name><![CDATA[008]]></name><sym>Waypoint</sym><ele>2152.021</ele></wpt>
11
+ <wpt lat="39.995700" lon="-105.292805"><name><![CDATA[AMPTHT]]></name><sym>Waypoint</sym><ele>1854.735</ele></wpt>
12
+ <wpt lat="38.855550" lon="-94.799017"><name><![CDATA[GARMIN]]></name><sym>Waypoint</sym><ele>325.0491</ele></wpt>
13
+ <wpt lat="39.997298" lon="-105.292674"><name><![CDATA[GRG-CA]]></name><sym>Waypoint</sym><ele>1766.535</ele></wpt>
14
+ <wpt lat="50.982883" lon="-1.463900"><name><![CDATA[GRMEUR]]></name><sym>Waypoint</sym><ele>35.93469</ele></wpt>
15
+ <wpt lat="33.330190" lon="-111.946110"><name><![CDATA[GRMPHX]]></name><sym>Waypoint</sym><ele>361.0981</ele></wpt>
16
+ <wpt lat="25.061783" lon="121.640267"><name><![CDATA[GRMTWN]]></name><sym>Waypoint</sym><ele>38.09766</ele></wpt>
17
+ <wpt lat="39.999840" lon="-105.214696"><name><![CDATA[SBDR]]></name><sym>Waypoint</sym><ele>1612.965</ele></wpt>
18
+ <wpt lat="39.989739" lon="-105.295285"><name><![CDATA[TO]]></name><sym>Waypoint</sym><ele>2163.556</ele></wpt>
19
+ <wpt lat="40.035301" lon="-105.254443"><name><![CDATA[VICS]]></name><sym>Waypoint</sym><ele>1535.34</ele></wpt>
20
+ </gpx>
@@ -0,0 +1,29 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
2
+ <gpx xmlns="http://www.topografix.com/GPX/1/1" creator="MapSource 6.5" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
3
+
4
+ <metadata>
5
+ <link href="http://www.garmin.com">
6
+ <text>Garmin International</text>
7
+ </link>
8
+ <time>2007-04-16T18:11:47Z</time>
9
+ <bounds maxlat="40.207429" maxlon="116.670578" minlat="39.876895" minlon="101.636217"/>
10
+ </metadata>
11
+
12
+ <trk>
13
+ <name>ACTIVE LOG</name>
14
+ <trkseg>
15
+ <trkpt lat="40.079434" lon="116.295948">
16
+ <ele>50.606567</ele>
17
+ <time>2007-03-25T05:17:34Z</time>
18
+ </trkpt>
19
+ </trkseg>
20
+ </trk>
21
+
22
+ <trk>
23
+ <name>LINE-13</name>
24
+ <trkseg>
25
+ <trkpt lat="39.949744" lon="116.427398"/>
26
+ </trkseg>
27
+ </trk>
28
+
29
+ </gpx>
@@ -0,0 +1,18 @@
1
+ require 'test/unit'
2
+ require 'gpx'
3
+
4
+ class MagellanTest < Test::Unit::TestCase
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
12
+
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
17
+
18
+ end
@@ -0,0 +1,115 @@
1
+ require 'test/unit'
2
+ require 'fileutils'
3
+ require 'gpx'
4
+
5
+ class OutputTest < Test::Unit::TestCase
6
+
7
+ include GPX
8
+
9
+ def setup
10
+ FileUtils.mkdir_p(File.join(File.dirname(__FILE__), "output"))
11
+ end
12
+
13
+ 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
+ ]
47
+
48
+ waypoint_data.each do |wpt_hash|
49
+ gpx_file.waypoints << Waypoint.new(wpt_hash)
50
+ end
51
+
52
+ route_point_data = [
53
+ {:lat => 40.035467, :lon =>-105.254366, :time => Time.parse("2005-12-31T22:02:29Z"), :elevation => 1735.798},
54
+ {:lat => 40.035317, :lon =>-105.254388, :time => Time.parse("2005-12-31T22:02:33Z"), :elevation => 1735.798},
55
+ {:lat => 40.035274, :lon =>-105.254431, :time => Time.parse("2005-12-31T22:02:49Z"), :elevation => 1736.278} ]
56
+
57
+ route = Route.new()
58
+ route_point_data.each do |rte_pt_hash|
59
+ route.points << Point.new(rte_pt_hash)
60
+ end
61
+
62
+ gpx_file.routes << route
63
+
64
+ gpx_file.write(output_file(name_of_test))
65
+
66
+
67
+ written_gpx_file = GPXFile.new(:gpx_file => output_file(name_of_test))
68
+
69
+ assert_equal(File.basename(output_file(name_of_test)), written_gpx_file.name)
70
+ assert_equal(1, written_gpx_file.tracks.size)
71
+ assert_equal(1, written_gpx_file.tracks[0].segments.size)
72
+ assert_equal(track_point_data.size, written_gpx_file.tracks[0].segments[0].points.size)
73
+ assert_equal(track_point_data.size, written_gpx_file.tracks[0].points.size)
74
+
75
+ # Make sure each point in the segment has the attributes it was initialized with
76
+ written_segment = written_gpx_file.tracks[0].segments[0]
77
+ track_point_data.each_with_index do |trk_pt_hash, index|
78
+ trk_pt_hash.each do |key, value|
79
+ assert_equal(value, written_segment.points[index].send(key))
80
+ end
81
+ end
82
+
83
+
84
+
85
+ # Make sure the one route has the attributes we initialized it with
86
+ assert_equal(1, written_gpx_file.routes.size)
87
+ written_route = written_gpx_file.routes[0]
88
+ assert_equal(route_point_data.size, written_route.points.size)
89
+ route_point_data.each_with_index do |rte_pt_hash, index|
90
+ rte_pt_hash.each do |key, value|
91
+ assert_equal(value, written_route.points[index].send(key))
92
+ end
93
+ end
94
+
95
+ # Make sure the waypoints have all of the attributes we initialized them with
96
+ written_waypoints = written_gpx_file.waypoints
97
+ assert_equal(waypoint_data.size, written_waypoints.size)
98
+ waypoint_data.each_with_index do |wpt_hash, index|
99
+ wpt_hash.each do |key, value|
100
+ assert_equal(value, written_waypoints[index].send(key.to_s), key)
101
+ end
102
+ end
103
+ end
104
+
105
+ def name_of_test
106
+ caller[0] =~ /`test_([^']*)'/ and $1
107
+ end
108
+
109
+ def output_file(test_name)
110
+ File.join(File.dirname(__FILE__), "output/#{test_name}.gpx")
111
+ end
112
+
113
+ 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"
114
+
115
+ end
@@ -0,0 +1,63 @@
1
+ require 'test/unit'
2
+ require 'gpx'
3
+
4
+ class RouteTest < Test::Unit::TestCase
5
+
6
+ def test_read_routes
7
+ gpx = GPX::GPXFile.new(:gpx_file => File.join(File.dirname(__FILE__), "gpx_files/routes.gpx"))
8
+ assert_equal(2, gpx.routes.size)
9
+ first_route = gpx.routes.first
10
+ assert_equal(3, first_route.points.size)
11
+ assert_equal('GRG-CA-TO', first_route.name)
12
+
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>
20
+ assert_equal(39.997298, first_route.points[0].lat)
21
+ assert_equal(-105.292674, first_route.points[0].lon)
22
+ assert_equal(1766.535, first_route.points[0].elevation)
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>
31
+ assert_equal(39.995700, first_route.points[1].lat)
32
+ assert_equal(-105.292805, first_route.points[1].lon)
33
+ assert_equal(1854.735, first_route.points[1].elevation)
34
+
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>
41
+ assert_equal(39.989739, first_route.points[2].lat)
42
+ assert_equal(-105.295285, first_route.points[2].lon)
43
+ assert_equal(2163.556, first_route.points[2].elevation)
44
+
45
+
46
+ second_route = gpx.routes[1]
47
+ assert_equal(1, second_route.points.size)
48
+ assert_equal('SBDR-SBDR', second_route.name)
49
+
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>
56
+ assert_equal(39.999840, second_route.points[0].lat)
57
+ assert_equal(-105.214696, second_route.points[0].lon)
58
+ assert_equal(1612.965, second_route.points[0].elevation)
59
+
60
+ end
61
+
62
+
63
+ end
@@ -0,0 +1,58 @@
1
+ require 'test/unit'
2
+ require 'yaml'
3
+ require 'gpx'
4
+
5
+ class SegmentTest < Test::Unit::TestCase
6
+ ONE_SEGMENT = File.join(File.dirname(__FILE__), "gpx_files/one_segment.gpx")
7
+
8
+ def setup
9
+ @gpx_file = GPX::GPXFile.new(:gpx_file => ONE_SEGMENT)
10
+ @segment = @gpx_file.tracks.first.segments.first
11
+ end
12
+
13
+ def test_segment_read
14
+ assert_equal(189, @segment.points.size)
15
+ assert_equal(1144433525, @segment.earliest_point.time.to_i)
16
+ assert_equal(1144437991, @segment.latest_point.time.to_i)
17
+ assert_equal(1334.447, @segment.lowest_point.elevation)
18
+ assert_equal(1480.087, @segment.highest_point.elevation)
19
+ assert_in_delta(6.98803359528853, @segment.distance, 0.001)
20
+ end
21
+
22
+ def test_segment_crop
23
+ crop_rectangle = GPX::Bounds.new( :min_lat=> 39.173000,
24
+ :min_lon=> -109.010000,
25
+ :max_lat=> 39.188000,
26
+ :max_lon=> -108.999000)
27
+ @segment.crop(crop_rectangle)
28
+
29
+ assert_equal(106, @segment.points.size)
30
+ assert_in_delta(4.11422061733046, @segment.distance, 0.001)
31
+ assert_equal(1144435041, @segment.earliest_point.time.to_i)
32
+ assert_equal(1144437752, @segment.latest_point.time.to_i)
33
+ assert_equal(1407.027, @segment.lowest_point.elevation)
34
+ assert_equal(1480.087, @segment.highest_point.elevation)
35
+ assert_equal(39.173834, @segment.bounds.min_lat)
36
+ assert_equal(-109.009995, @segment.bounds.min_lon)
37
+ assert_equal(39.187868, @segment.bounds.max_lat)
38
+ assert_equal(-108.999546, @segment.bounds.max_lon)
39
+ end
40
+
41
+ def test_segment_delete
42
+ delete_rectangle = GPX::Bounds.new( :min_lat=> 39.173000,
43
+ :min_lon=> -109.010000,
44
+ :max_lat=> 39.188000,
45
+ :max_lon=> -108.999000)
46
+ @segment.delete_area(delete_rectangle)
47
+ assert_equal(83, @segment.points.size)
48
+ assert_in_delta(3.35967118153605, @segment.distance, 0.001)
49
+ assert_equal(1144433525, @segment.earliest_point.time.to_i)
50
+ assert_equal(1144437991, @segment.latest_point.time.to_i)
51
+ assert_equal(1334.447, @segment.lowest_point.elevation)
52
+ assert_equal(1428.176, @segment.highest_point.elevation)
53
+ assert_equal(39.180572, @segment.bounds.min_lat)
54
+ assert_equal(-109.016604, @segment.bounds.min_lon)
55
+ assert_equal(39.188747, @segment.bounds.max_lat)
56
+ assert_equal(-109.007978, @segment.bounds.max_lon)
57
+ end
58
+ end
@@ -0,0 +1,75 @@
1
+ require 'test/unit'
2
+ require 'gpx'
3
+
4
+ class TrackFileTest < Test::Unit::TestCase
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
+
39
+ second_to_last_segment = @track_file.tracks[2].segments[-2]
40
+ assert_equal("2006-01-02T00:00:51Z", second_to_last_segment.points.last.time.strftime("%Y-%m-%dT%H:%M:%SZ"))
41
+ assert_equal(39.998045, second_to_last_segment.points.last.lat)
42
+ assert_equal(-105.292368, second_to_last_segment.points.last.lon)
43
+ end
44
+
45
+ def test_find_nearest_point_by_time
46
+ time = Time.parse("2005-12-31T22:02:01Z")
47
+ pt = @track_file.tracks[0].closest_point(time)
48
+ #puts "pt: #{pt.lat_lon}"
49
+
50
+ end
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
+
75
+ end
@@ -0,0 +1,30 @@
1
+ require 'test/unit'
2
+ require 'gpx'
3
+
4
+ class TrackPointTest < Test::Unit::TestCase
5
+ def setup
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
+ end
15
+
16
+ def test_haversine_distance_from
17
+ distance = @point1.haversine_distance_from(@point2)
18
+ assert_equal(0.00197862991592239, distance)
19
+ end
20
+
21
+ def test_pythagorean_distance_from
22
+ distance = @point1.pythagorean_distance_from(@point2)
23
+ assert_equal(3.642891416092969e-07, distance)
24
+ end
25
+
26
+ def test_law_of_cosines_distance_from
27
+ distance = @point1.law_of_cosines_distance_from(@point2)
28
+ assert_equal(0.001982307218559664, distance)
29
+ end
30
+ end
@@ -0,0 +1,65 @@
1
+ require 'test/unit'
2
+ require 'gpx'
3
+
4
+ class TrackTest < Test::Unit::TestCase
5
+ ONE_TRACK = File.join(File.dirname(__FILE__), "gpx_files/one_track.gpx")
6
+
7
+ def setup
8
+ @gpx_file = GPX::GPXFile.new(:gpx_file => ONE_TRACK)
9
+ @track = @gpx_file.tracks.first
10
+ end
11
+
12
+ def test_track_read
13
+ assert_equal("ACTIVE LOG", @track.name)
14
+ assert_equal( 182, @track.points.size)
15
+ assert_equal(8, @track.segments.size)
16
+ assert_in_delta(3.07249668492626, @track.distance, 0.001)
17
+ assert_equal(1267.155, @track.lowest_point.elevation)
18
+ assert_equal(1594.003, @track.highest_point.elevation)
19
+ assert_equal(38.681488, @track.bounds.min_lat)
20
+ assert_equal(-109.606948, @track.bounds.min_lon)
21
+ assert_equal(38.791759, @track.bounds.max_lat)
22
+ assert_equal(-109.447045, @track.bounds.max_lon)
23
+ end
24
+
25
+ def test_track_crop
26
+ area = GPX::Bounds.new(
27
+ :min_lat => 38.710000,
28
+ :min_lon => -109.600000,
29
+ :max_lat => 38.791759,
30
+ :max_lon => -109.450000)
31
+ @track.crop(area)
32
+ assert_equal("ACTIVE LOG", @track.name)
33
+ assert_equal( 111, @track.points.size)
34
+ assert_equal(4, @track.segments.size)
35
+ assert_in_delta(1.62136024923607, @track.distance, 0.001)
36
+ assert_equal(1557.954, @track.lowest_point.elevation)
37
+ assert_equal(1582.468, @track.highest_point.elevation)
38
+ assert_equal(38.782511, @track.bounds.min_lat)
39
+ assert_equal(-109.599781, @track.bounds.min_lon)
40
+ assert_equal(38.789527, @track.bounds.max_lat)
41
+ assert_equal(-109.594996, @track.bounds.max_lon)
42
+ end
43
+
44
+ def test_track_delete
45
+ area = GPX::Bounds.new(
46
+ :min_lat => 38.710000,
47
+ :min_lon => -109.600000,
48
+ :max_lat => 38.791759,
49
+ :max_lon => -109.450000)
50
+ @track.delete_area(area)
51
+
52
+ #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)
63
+ end
64
+
65
+ end