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
Returns the value of attribute gpx_file.
-
#name ⇒ Object
Returns the value of attribute name.
-
#points ⇒ Object
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 XML::Node.
Methods inherited from Base
#instantiate_with_text_elements
Constructor Details
#initialize(opts = {}) ⇒ Route
Initialize a Route from a XML::Node.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gpx/route.rb', line 11 def initialize(opts = {}) super() if opts[:gpx_file] && opts[:element] rte_element = opts[:element] @gpx_file = opts[:gpx_file] @name = rte_element.at('name')&.inner_text @points = [] rte_element.search('rtept').each do |point| @points << Point.new(element: point, gpx_file: @gpx_file) end else @points = opts[:points] || [] @name = opts[:name] end end |
Instance Attribute Details
#gpx_file ⇒ Object
Returns the value of attribute gpx_file.
8 9 10 |
# File 'lib/gpx/route.rb', line 8 def gpx_file @gpx_file end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/gpx/route.rb', line 8 def name @name end |
#points ⇒ Object
Returns the value of attribute points.
8 9 10 |
# File 'lib/gpx/route.rb', line 8 def points @points end |
Instance Method Details
#crop(area) ⇒ Object
Delete points outside of a given area.
28 29 30 |
# File 'lib/gpx/route.rb', line 28 def crop(area) points.delete_if { |pt| !area.contains? pt } end |
#delete_area(area) ⇒ Object
Delete points within the given area.
33 34 35 |
# File 'lib/gpx/route.rb', line 33 def delete_area(area) points.delete_if { |pt| area.contains? pt } end |