Class: GPX::Route
Overview
A Route in GPX is very similar to a Track, but it is created by a user from a series of Waypoints, whereas a Track is created by the GPS device automatically logging your progress at regular intervals.
Instance Attribute Summary collapse
-
#gpx_file ⇒ Object
readonly
Returns the value of attribute gpx_file.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Instance Method Summary collapse
-
#crop(area) ⇒ Object
Delete points outside of a given area.
-
#delete_area(area) ⇒ Object
Delete points within the given area.
-
#initialize(opts = {}) ⇒ Route
constructor
Initialize a Route from a REXML::Element.
-
#to_xml ⇒ Object
Convert this Route to a REXML::Element.
Methods inherited from Base
#instantiate_with_text_elements
Constructor Details
#initialize(opts = {}) ⇒ Route
Initialize a Route from a REXML::Element.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gpx/route.rb', line 33 def initialize(opts = {}) rte_element = opts[:element] @gpx_file = opts[:gpx_file] @name = rte_element.elements["child::name"].text @points = [] XPath.each(rte_element, "child::rtept") do |point| @points << Point.new(:element => point) end end |
Instance Attribute Details
#gpx_file ⇒ Object (readonly)
Returns the value of attribute gpx_file.
30 31 32 |
# File 'lib/gpx/route.rb', line 30 def gpx_file @gpx_file end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32 |
# File 'lib/gpx/route.rb', line 30 def name @name end |
#points ⇒ Object (readonly)
Returns the value of attribute points.
30 31 32 |
# File 'lib/gpx/route.rb', line 30 def points @points end |
Instance Method Details
#crop(area) ⇒ Object
Delete points outside of a given area.
45 46 47 |
# File 'lib/gpx/route.rb', line 45 def crop(area) points.delete_if{ |pt| not area.contains? pt } end |
#delete_area(area) ⇒ Object
Delete points within the given area.
50 51 52 |
# File 'lib/gpx/route.rb', line 50 def delete_area(area) points.delete_if{ |pt| area.contains? pt } end |
#to_xml ⇒ Object
Convert this Route to a REXML::Element.
55 56 57 58 59 60 61 62 |
# File 'lib/gpx/route.rb', line 55 def to_xml rte = Element.new('rte') name_elem = Element.new('name') name_elem.text = name rte.elements << name_elem points.each { |rte_pt| rte.elements << rte_pt.to_xml('rtept') } rte end |