gpx 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,132 +1,60 @@
1
- 2009-07-07 02:51 dougfales
1
+ 2010-02-27 Doug Fales <doug@falesafeconsulting.com>
2
+ * Putting the gem building stuff into a gemspec.
3
+ * Fixing some tests since git does not believe in empty directories.
4
+ * Fixing README formatting.
2
5
 
3
- * lib/gpx/gpx.rb: Revving to version 0.5.
6
+ 2010-02-27 Doug Fales <doug@falesafeconsulting.com>
7
+ * README edits.
8
+ * More rdoc tweaks.
9
+ * Changing README to rdoc ext for github.
4
10
 
5
- 2009-07-07 02:43 dougfales
11
+ 2009-10-13 Doug Fales <doug@falesafeconsulting.com>
12
+ * Adding the ability to write GPX to a string in addition to a file. Thanks to Douglas Robertson for the patch.
6
13
 
7
- * README: Changing my contact email address.
14
+ 2009-09-27 Doug Fales <doug@falesafeconsulting.com>
15
+ * Adding a patch from Douglas Robertson that allows using version 1.0 of the schema for output.
8
16
 
9
- 2009-07-07 02:41 dougfales
17
+ 2009-07-07 Doug Fales <doug@falesafeconsulting.com>
18
+ * Adding changelog.
19
+ * Revving to version 0.5.
20
+ * Changing my contact email address.
21
+ * Patches from Tom Verbeure (mtbguru.com) to work with libxml-ruby 1.x.
10
22
 
11
- * lib/gpx/gpx_file.rb, tests/gpx_file_test.rb,
12
- tests/gpx_files/with_or_without_elev.gpx: Patches from Tom
13
- Verbeure (mtbguru.com) to work with libxml-ruby 1.x.
23
+ 2009-06-17 Doug Fales <doug@falesafeconsulting.com>
24
+ * Patch from Kang-min Liu to support speed element.
14
25
 
15
- 2009-06-17 14:20 dougfales
26
+ 2008-02-19 Doug Fales <doug@falesafeconsulting.com>
27
+ * Revving to 0.4.
28
+ * Adding some new unit tests and fixing several file export bugs reported by Jochen Topf. New unit tests also uncovered a bug where the number of trackpoints reported in a file was twice the actual number.
16
29
 
17
- * lib/gpx/point.rb: Patch from Kang-min Liu to support speed
18
- element.
30
+ 2008-02-11 Doug Fales <doug@falesafeconsulting.com>
31
+ * Going to version 0.3.
32
+ * Updating unit tests in light of recent fixes to routes and waypoints code.
19
33
 
20
- 2008-02-19 04:09 dougfales
34
+ 2008-02-08 Doug Fales <doug@falesafeconsulting.com>
35
+ * Thanks to Mike Gauland for discovering some route- and waypoint-related bugs. I've fixed them and also added #to_s on Waypoint so it's easier to debug.
21
36
 
22
- * lib/gpx/gpx.rb: Revving to 0.4.
37
+ 2007-12-04 Doug Fales <doug@falesafeconsulting.com>
38
+ * Thanks to Christian Koerner for finding and fixing these bugs in the waypoint code.
39
+ * Another patch from Gaku Ueda. This one allows you to pass in a string of GPX data using the :gpx_date => option. Thanks Gaku!
23
40
 
24
- 2008-02-19 04:06 dougfales
41
+ 2007-11-30 Doug Fales <doug@falesafeconsulting.com>
42
+ * Updating the version #.
43
+ * Updates courtesy of Gaku Ueda: * Adding support for GPX 1.0 as well as 1.1 (since libxml namespace parsing was hard-coded to 1.1. previously). * Adding a GPX 1.0 unit test file. * Miscellaneous updates to make it work with Ruby 1.8.6.
25
44
 
26
- * lib/gpx/gpx.rb, lib/gpx/gpx_file.rb, lib/gpx/point.rb,
27
- lib/gpx/route.rb, lib/gpx/track.rb, lib/gpx/waypoint.rb,
28
- tests/gpx_file_test.rb, tests/gpx_files, tests/gpx_files/big.gpx,
29
- tests/output, tests/output_test.rb, tests/track_test.rb: Adding
30
- some new unit tests and fixing several file export bugs reported
31
- by Jochen Topf.
32
- New unit tests also uncovered a bug where the number of
33
- trackpoints reported in a file was twice the actual number.
45
+ 2006-12-04 Doug Fales <doug@falesafeconsulting.com>
46
+ * First stab at using libxml-ruby instead of REXML. I'm seeing the unit tests finish in under 14 seconds. That is compared to 2 minutes using REXML.
34
47
 
35
- 2008-02-11 21:20 dougfales
48
+ 2006-12-03 Doug Fales <doug@falesafeconsulting.com>
49
+ * Fixing more nil time exceptions.
50
+ * Fixing an exception in contains_time?.
36
51
 
37
- * lib/gpx/gpx.rb: Going to version 0.3.
52
+ 2006-11-28 Doug Fales <doug@falesafeconsulting.com>
53
+ * A couple of fixes to make the library comply with the different attribute names possible on the bounds element.
38
54
 
39
- 2008-02-11 21:13 dougfales
55
+ 2006-10-28 Doug Fales <doug@falesafeconsulting.com>
56
+ * Fixing nil time bug.
40
57
 
41
- * tests/gpx10_test.rb, tests/gpx_files/routes.gpx,
42
- tests/gpx_files/waypoints.gpx, tests/magellan_test.rb,
43
- tests/route_test.rb, tests/segment_test.rb,
44
- tests/track_file_test.rb, tests/track_test.rb,
45
- tests/waypoint_test.rb: Updating unit tests in light of recent
46
- fixes to routes and waypoints code.
47
-
48
- 2008-02-08 23:26 dougfales
49
-
50
- * lib/gpx/gpx.rb, lib/gpx/point.rb, lib/gpx/route.rb,
51
- lib/gpx/waypoint.rb: Thanks to Mike Gauland for discovering some
52
- route- and waypoint-related bugs. I've fixed them and also added
53
- #to_s on Waypoint so it's easier to debug.
54
-
55
- 2007-12-04 17:58 dougfales
56
-
57
- * lib/gpx/waypoint.rb: Thanks to Christian Koerner for finding and
58
- fixing these bugs in the waypoint
59
- code.
60
-
61
- 2007-12-04 17:52 dougfales
62
-
63
- * lib/gpx/gpx_file.rb, tests/gpx_file_test.rb: Another patch from
64
- Gaku Ueda. This one allows you to pass in a string of GPX
65
- data using the :gpx_date => option. Thanks Gaku!
66
-
67
- 2007-11-30 06:29 dougfales
68
-
69
- * lib/gpx/gpx.rb: Updating the version #.
70
-
71
- 2007-11-30 06:26 dougfales
72
-
73
- * lib/gpx/gpx.rb, lib/gpx/gpx_file.rb, lib/gpx/point.rb,
74
- lib/gpx/route.rb, lib/gpx/segment.rb, lib/gpx/track.rb,
75
- tests/gpx10_test.rb, tests/gpx_files/gpx10.gpx: Updates courtesy
76
- of Gaku Ueda:
77
- * Adding support for GPX 1.0 as well as 1.1 (since libxml
78
- namespace parsing
79
- was hard-coded to 1.1. previously).
80
- * Adding a GPX 1.0 unit test file.
81
- * Miscellaneous updates to make it work with Ruby 1.8.6.
82
-
83
- 2006-12-04 06:47 dougfales
84
-
85
- * README, lib/gpx.rb, lib/gpx/bounds.rb, lib/gpx/gpx.rb,
86
- lib/gpx/gpx_file.rb, lib/gpx/point.rb, lib/gpx/route.rb,
87
- lib/gpx/segment.rb, lib/gpx/track.rb, lib/gpx/waypoint.rb,
88
- tests/segment_test.rb: First stab at using libxml-ruby instead of
89
- REXML. I'm seeing the unit tests
90
- finish in under 14 seconds. That is compared to 2 minutes using
91
- REXML.
92
-
93
- 2006-12-03 07:31 dougfales
94
-
95
- * lib/gpx/point.rb, lib/gpx/segment.rb: Fixing more nil time
96
- exceptions.
97
-
98
- 2006-12-03 06:59 dougfales
99
-
100
- * lib/gpx/segment.rb: Fixing an exception in contains_time?.
101
-
102
- 2006-11-28 15:35 dougfales
103
-
104
- * lib/gpx/bounds.rb, lib/gpx/gpx_file.rb: A couple of fixes to make
105
- the library comply with the different attribute names
106
- possible on the bounds element.
107
-
108
- Formerly, a bounds element with a minlat or minLat attribute
109
- (instead of
110
- min_lat) would not be properly parsed. Now all three styles of
111
- attribute name
112
- are accepted.
113
-
114
- 2006-10-28 22:09 dougfales
115
-
116
- * lib/gpx/segment.rb: Fixing nil time bug.
117
-
118
- 2006-10-14 13:20 dougfales
119
-
120
- * ., README, Rakefile, bin, docs, lib, lib/gpx, lib/gpx.rb,
121
- lib/gpx/bounds.rb, lib/gpx/gpx.rb, lib/gpx/gpx_file.rb,
122
- lib/gpx/magellan_track_log.rb, lib/gpx/point.rb,
123
- lib/gpx/route.rb, lib/gpx/segment.rb, lib/gpx/track.rb,
124
- lib/gpx/trackpoint.rb, lib/gpx/waypoint.rb, tests,
125
- tests/gpx_files, tests/gpx_files/arches.gpx,
126
- tests/gpx_files/magellan_track.log,
127
- tests/gpx_files/one_segment.gpx, tests/gpx_files/one_track.gpx,
128
- tests/gpx_files/routes.gpx, tests/gpx_files/tracks.gpx,
129
- tests/gpx_files/waypoints.gpx, tests/magellan_test.rb,
130
- tests/segment_test.rb, tests/track_file_test.rb,
131
- tests/track_test.rb: Initial import of gpx gem.
58
+ 2006-10-14 Doug Fales <doug@falesafeconsulting.com>
59
+ * Initial import of gpx gem.
132
60
 
@@ -1,8 +1,9 @@
1
1
  = GPX Gem
2
- Copyright (C) 2006 Doug Fales
3
- Doug Fales mailto:doug@falesafeconsulting.com
2
+
3
+ Copyright (C) 2006 Doug Fales mailto:doug@falesafeconsulting.com
4
4
 
5
5
  == What It Does
6
+
6
7
  This library reads GPX files and provides an API for reading and manipulating
7
8
  the data as objects. For more info on the GPX format, see
8
9
  http://www.topografix.com/gpx.asp.
@@ -14,6 +15,7 @@ the tracks and points in a file (such as distance, duration, average speed,
14
15
  etc).
15
16
 
16
17
  == Examples
18
+
17
19
  Reading a GPX file, and cropping its contents to a given area:
18
20
  gpx = GPX::GPXFile.new(:gpx_file => filename) # Read GPX file
19
21
  bounds = GPX::Bounds.new(params) # Create a rectangular area to crop
@@ -27,6 +29,7 @@ Converting a Magellan track log to GPX:
27
29
 
28
30
 
29
31
  == Notes
32
+
30
33
  This library was written to bridge the gap between my Garmin Geko
31
34
  and my website, WalkingBoss.org (RIP). For that reason, it has always been more of a
32
35
  work-in-progress than an attempt at full GPX compliance. The track side of the
data/Rakefile CHANGED
@@ -42,35 +42,6 @@ Rake::RDocTask.new("doc") { |rdoc|
42
42
  rdoc.rdoc_files.include('lib/**/*.rb')
43
43
  }
44
44
 
45
- # Genereate the package
46
- spec = Gem::Specification.new do |s|
47
-
48
- s.name = 'gpx'
49
- s.version = PKG_VERSION
50
- s.summary = <<-EOF
51
- A basic API for reading and writing GPX files.
52
- EOF
53
- s.description = <<-EOF
54
- A basic API for reading and writing GPX files.
55
- EOF
56
-
57
- s.files = PKG_FILES
58
-
59
- s.require_path = 'lib'
60
- s.autorequire = 'gpx'
61
-
62
- s.has_rdoc = true
63
-
64
- s.author = "Doug Fales"
65
- s.email = "doug.fales@gmail.com"
66
- s.homepage = "http://gpx.rubyforge.com/"
67
- end
68
-
69
- Rake::GemPackageTask.new(spec) do |pkg|
70
- pkg.need_zip = true
71
- pkg.need_tar = true
72
- end
73
-
74
45
  desc "Report code statistics (KLOCs, etc) from the application"
75
46
  task :stats do
76
47
  require 'code_statistics'
@@ -21,7 +21,7 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
  module GPX
24
- VERSION = "0.5"
24
+ VERSION = "0.6"
25
25
 
26
26
  # A common base class which provides a useful initializer method to many
27
27
  # class in the GPX library.
@@ -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
25
+ attr_accessor :tracks, :routes, :waypoints, :bounds, :lowest_point, :highest_point, :duration, :ns, :version, :time, :name
26
26
 
27
27
 
28
28
  # This initializer can be used to create a new GPXFile from an existing
@@ -205,41 +205,57 @@ module GPX
205
205
  # Serialize the current GPXFile to a gpx file named <filename>.
206
206
  # If the file does not exist, it is created. If it does exist, it is overwritten.
207
207
  def write(filename, update_time = true)
208
+ @time = Time.now if(@time.nil? or update_time)
209
+ @name ||= File.basename(filename)
210
+ doc = generate_xml_doc
211
+ doc.save(filename, :indent => true)
212
+ end
213
+
214
+ def to_s(update_time = true)
215
+ @time = Time.now if(@time.nil? or update_time)
216
+ doc = generate_xml_doc
217
+ doc.to_s
218
+ end
208
219
 
220
+ private
221
+ def generate_xml_doc
209
222
  doc = Document.new
210
223
  doc.root = Node.new('gpx')
211
224
  gpx_elem = doc.root
212
- gpx_elem['xmlns:xsi'] = "http://www.w3.org/2001/XMLSchema-instance"
213
- gpx_elem['xmlns'] = "http://www.topografix.com/GPX/1/1"
214
- gpx_elem['version'] = "1.1"
215
- gpx_elem['creator'] = "GPX RubyGem 0.1 Copyright 2006 Doug Fales -- http://walkingboss.com"
216
- gpx_elem['xsi:schemaLocation'] = "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
225
+ gpx_elem['xmlns:xsi'] = "http://www.w3.org/2001/XMLSchema-instance"
226
+ @version = '1.1' if (@version.nil? || !(['1.0', '1.1'].include?(@version))) # default to version 1.1 of the schema (only version 1.0 and 1.1 of the schema exist)
227
+ version_dir = @version.gsub('.','/')
228
+ gpx_elem['xmlns'] = @ns || "http://www.topografix.com/GPX/#{version_dir}"
229
+ gpx_elem['version'] = "#{@version}"
230
+ gpx_elem['creator'] = "GPX RubyGem #{GPX::VERSION} Copyright 2006-2009 Doug Fales -- http://gpx.rubyforge.org/"
231
+ gpx_elem['xsi:schemaLocation'] = "http://www.topografix.com/GPX/#{version_dir} http://www.topografix.com/GPX/#{version_dir}/gpx.xsd"
217
232
 
218
- meta_data_elem = Node.new('metadata')
233
+ # setup the metadata elements
219
234
  name_elem = Node.new('name')
220
- name_elem << File.basename(filename)
221
- meta_data_elem << name_elem
222
-
235
+ name_elem << @name
223
236
  time_elem = Node.new('time')
237
+ time_elem << @time.xmlschema
224
238
 
225
- @time = Time.now if(@time.nil? or update_time)
226
- time_elem << @time.xmlschema
227
-
228
- meta_data_elem << time_elem
229
-
230
- meta_data_elem << bounds.to_xml
231
-
232
- gpx_elem << meta_data_elem
239
+ # version 1.0 of the schema doesn't support the metadata element, so push them straight to the root 'gpx' element
240
+ if (@version == '1.0') then
241
+ gpx_elem << name_elem
242
+ gpx_elem << time_elem
243
+ gpx_elem << bounds.to_xml
244
+ else
245
+ meta_data_elem = Node.new('metadata')
246
+ meta_data_elem << name_elem
247
+ meta_data_elem << time_elem
248
+ meta_data_elem << bounds.to_xml
249
+ gpx_elem << meta_data_elem
250
+ end
233
251
 
234
252
  tracks.each { |t| gpx_elem << t.to_xml } unless tracks.nil?
235
253
  waypoints.each { |w| gpx_elem << w.to_xml } unless waypoints.nil?
236
254
  routes.each { |r| gpx_elem << r.to_xml } unless routes.nil?
237
255
 
238
- doc.save(filename, :indent => true)
256
+ return doc
239
257
  end
240
258
 
241
- private
242
-
243
259
  # Calculates and sets the duration attribute by subtracting the time on
244
260
  # the very first point from the time on the very last point.
245
261
  def calculate_duration
@@ -23,74 +23,74 @@
23
23
 
24
24
  module GPX
25
25
 
26
- # This class supports the concept of a waypoint. Beware that this class has
27
- # not seen much use yet, since WalkingBoss does not use waypoints right now.
28
- class Waypoint < Point
26
+ # This class supports the concept of a waypoint. Beware that this class has
27
+ # not seen much use yet, since WalkingBoss does not use waypoints right now.
28
+ class Waypoint < Point
29
29
 
30
- SUB_ELEMENTS = %w{ magvar geoidheight name cmt desc src link sym type fix sat hdop vdop pdop ageofdgpsdata dgpsid extensions }
30
+ SUB_ELEMENTS = %w{ magvar geoidheight name cmt desc src link sym type fix sat hdop vdop pdop ageofdgpsdata dgpsid extensions }
31
31
 
32
- attr_reader :gpx_file
33
- SUB_ELEMENTS.each { |sub_el| attr_accessor sub_el.to_sym }
32
+ attr_reader :gpx_file
33
+ SUB_ELEMENTS.each { |sub_el| attr_accessor sub_el.to_sym }
34
34
 
35
- # Not implemented
36
- def crop(area)
37
- end
35
+ # Not implemented
36
+ def crop(area)
37
+ end
38
38
 
39
- # Not implemented
40
- def delete_area(area)
41
- end
39
+ # Not implemented
40
+ def delete_area(area)
41
+ end
42
42
 
43
- # Initializes a waypoint from a XML::Node.
44
- def initialize(opts = {})
45
- if(opts[:element] and opts[:gpx_file])
46
- wpt_elem = opts[:element]
47
- @gpx_file = opts[:gpx_file]
48
- super(:element => wpt_elem, :gpx_file => @gpx_file)
49
- instantiate_with_text_elements(wpt_elem, SUB_ELEMENTS, @gpx_file.ns)
50
- else
51
- opts.each do |key, value|
52
- assignment_method = "#{key}="
53
- if self.respond_to?(assignment_method)
54
- self.send(assignment_method, value)
55
- end
56
- end
57
- end
43
+ # Initializes a waypoint from a XML::Node.
44
+ def initialize(opts = {})
45
+ if(opts[:element] and opts[:gpx_file])
46
+ wpt_elem = opts[:element]
47
+ @gpx_file = opts[:gpx_file]
48
+ super(:element => wpt_elem, :gpx_file => @gpx_file)
49
+ instantiate_with_text_elements(wpt_elem, SUB_ELEMENTS, @gpx_file.ns)
50
+ else
51
+ opts.each do |key, value|
52
+ assignment_method = "#{key}="
53
+ if self.respond_to?(assignment_method)
54
+ self.send(assignment_method, value)
55
+ end
56
+ end
58
57
  end
58
+ end
59
59
 
60
- # Prints out a friendly summary of this track (sans points). Useful for
61
- # debugging and sanity checks.
62
- def to_s
63
- result = "Waypoint \n"
64
- result << "\tName: #{name}\n"
65
- result << "\tLatitude: #{lat} \n"
66
- result << "\tLongitude: #{lon} \n"
67
- result << "\tElevation: #{elevation}\n "
68
- result << "\tTime: #{time}\n"
69
- SUB_ELEMENTS.each do |sub_element_attribute|
70
- val = self.send(sub_element_attribute)
71
- result << "\t#{sub_element_attribute}: #{val}\n" unless val.nil?
72
- end
73
- result
60
+ # Prints out a friendly summary of this track (sans points). Useful for
61
+ # debugging and sanity checks.
62
+ def to_s
63
+ result = "Waypoint \n"
64
+ result << "\tName: #{name}\n"
65
+ result << "\tLatitude: #{lat} \n"
66
+ result << "\tLongitude: #{lon} \n"
67
+ result << "\tElevation: #{elevation}\n "
68
+ result << "\tTime: #{time}\n"
69
+ SUB_ELEMENTS.each do |sub_element_attribute|
70
+ val = self.send(sub_element_attribute)
71
+ result << "\t#{sub_element_attribute}: #{val}\n" unless val.nil?
74
72
  end
73
+ result
74
+ end
75
75
 
76
- # Converts a waypoint to a XML::Node.
77
- def to_xml
78
- wpt = Node.new('wpt')
79
- wpt['lat'] = lat.to_s
80
- wpt['lon'] = lon.to_s
81
- SUB_ELEMENTS.each do |sub_element_name|
82
- if(self.respond_to?(sub_element_name) and (!self.send(sub_element_name).nil?))
83
- sub_elem_node = Node.new(sub_element_name)
84
- sub_elem_node << self.send(sub_element_name)
85
- wpt << sub_elem_node
86
- end
87
- end
88
- unless(self.elevation.nil?)
89
- ele_node = Node.new('ele')
90
- ele_node << self.elevation
91
- wpt << ele_node
92
- end
93
- wpt
76
+ # Converts a waypoint to a XML::Node.
77
+ def to_xml(elem_name = 'wpt')
78
+ wpt = Node.new(elem_name)
79
+ wpt['lat'] = lat.to_s
80
+ wpt['lon'] = lon.to_s
81
+ SUB_ELEMENTS.each do |sub_element_name|
82
+ if(self.respond_to?(sub_element_name) and (!self.send(sub_element_name).nil?))
83
+ sub_elem_node = Node.new(sub_element_name)
84
+ sub_elem_node << self.send(sub_element_name)
85
+ wpt << sub_elem_node
86
+ end
87
+ end
88
+ unless(self.elevation.nil?)
89
+ ele_node = Node.new('ele')
90
+ ele_node << self.elevation
91
+ wpt << ele_node
94
92
  end
95
- end
93
+ wpt
94
+ end
95
+ end
96
96
  end