gpx/lib/gpx/route.rb

60 lines
2.1 KiB
Ruby
Raw Normal View History

2006-10-14 13:20:23 +00:00
#--
2013-06-15 12:11:43 +02:00
# Copyright (c) 2006 Doug Fales
2006-10-14 13:20:23 +00:00
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
module GPX
# 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
2013-06-15 12:11:43 +02:00
# automatically logging your progress at regular intervals.
2006-10-14 13:20:23 +00:00
class Route < Base
attr_accessor :points, :name, :gpx_file
2006-10-14 13:20:23 +00:00
# Initialize a Route from a XML::Node.
2006-10-14 13:20:23 +00:00
def initialize(opts = {})
if(opts[:gpx_file] and opts[:element])
2006-10-14 13:20:23 +00:00
rte_element = opts[:element]
@gpx_file = opts[:gpx_file]
2013-06-16 01:20:28 +02:00
@name = rte_element.at("name").inner_text
2006-10-14 13:20:23 +00:00
@points = []
2013-06-16 01:20:28 +02:00
rte_element.search("rtept").each do |point|
@points << Point.new(:element => point, :gpx_file => @gpx_file)
2006-10-14 13:20:23 +00:00
end
else
@points = (opts[:points] or [])
@name = (opts[:name])
end
2006-10-14 13:20:23 +00:00
end
# Delete points outside of a given area.
def crop(area)
points.delete_if{ |pt| not area.contains? pt }
end
# Delete points within the given area.
def delete_area(area)
points.delete_if{ |pt| area.contains? pt }
end
end
end