Remove trailing whitespaces

master
Guillaume Dott 2013-06-15 12:11:43 +02:00
parent 66d384b46d
commit b1d18e8261
14 changed files with 93 additions and 93 deletions

View File

@ -1,5 +1,5 @@
#-- #--
# Copyright (c) 2006 Doug Fales # Copyright (c) 2006 Doug Fales
# #
# Permission is hereby granted, free of charge, to any person obtaining # Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the # a copy of this software and associated documentation files (the

View File

@ -1,5 +1,5 @@
#-- #--
# Copyright (c) 2006 Doug Fales # Copyright (c) 2006 Doug Fales
# #
# Permission is hereby granted, free of charge, to any person obtaining # Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the # a copy of this software and associated documentation files (the

View File

@ -1,5 +1,5 @@
#-- #--
# Copyright (c) 2006 Doug Fales # Copyright (c) 2006 Doug Fales
# #
# Permission is hereby granted, free of charge, to any person obtaining # Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the # a copy of this software and associated documentation files (the
@ -31,7 +31,7 @@ module GPX
# an attribute to be initialized on the instance. This means you don't # an attribute to be initialized on the instance. This means you don't
# have to pick out individual text elements in each initializer of each # have to pick out individual text elements in each initializer of each
# class (Route, TrackPoint, Track, etc). Just pass an array of possible # class (Route, TrackPoint, Track, etc). Just pass an array of possible
# attributes to this method. # attributes to this method.
def instantiate_with_text_elements(parent, text_elements) def instantiate_with_text_elements(parent, text_elements)
text_elements.each do |el| text_elements.each do |el|
child_xpath = "//#{el}" child_xpath = "//#{el}"

View File

@ -1,5 +1,5 @@
#-- #--
# Copyright (c) 2006 Doug Fales # Copyright (c) 2006 Doug Fales
# #
# Permission is hereby granted, free of charge, to any person obtaining # Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the # a copy of this software and associated documentation files (the
@ -42,7 +42,7 @@ module GPX
# some_track = get_track_from_csv('some_other_format.csv') # some_track = get_track_from_csv('some_other_format.csv')
# gpx_file = GPXFile.new(:tracks => [some_track]) # gpx_file = GPXFile.new(:tracks => [some_track])
# #
def initialize(opts = {}) def initialize(opts = {})
@duration = 0 @duration = 0
if(opts[:gpx_file] or opts[:gpx_data]) if(opts[:gpx_file] or opts[:gpx_data])
if opts[:gpx_file] if opts[:gpx_file]
@ -51,7 +51,7 @@ module GPX
#when String #when String
# gpx_file = File.open(gpx_file) # gpx_file = File.open(gpx_file)
#end #end
gpx_file = gpx_file.name if gpx_file.is_a?(File) gpx_file = gpx_file.name if gpx_file.is_a?(File)
@xml = Hpricot(File.open(gpx_file)) @xml = Hpricot(File.open(gpx_file))
else else
@xml = Hpricot(opts[:gpx_data]) @xml = Hpricot(opts[:gpx_data])
@ -62,7 +62,7 @@ module GPX
#else #else
# @ns = 'gpx:http://www.topografix.com/GPX/1/1' # default to GPX 1.1 # @ns = 'gpx:http://www.topografix.com/GPX/1/1' # default to GPX 1.1
#end #end
reset_meta_data reset_meta_data
bounds_element = (@xml.at("//metadata/bounds") rescue nil) bounds_element = (@xml.at("//metadata/bounds") rescue nil)
if bounds_element if bounds_element
@ -76,13 +76,13 @@ module GPX
@time = Time.parse(@xml.at("//metadata/time").inner_text) rescue nil @time = Time.parse(@xml.at("//metadata/time").inner_text) rescue nil
@name = @xml.at("//metadata/name").inner_text rescue nil @name = @xml.at("//metadata/name").inner_text rescue nil
@tracks = [] @tracks = []
@xml.search("//trk").each do |trk| @xml.search("//trk").each do |trk|
trk = Track.new(:element => trk, :gpx_file => self) trk = Track.new(:element => trk, :gpx_file => self)
update_meta_data(trk, get_bounds) update_meta_data(trk, get_bounds)
@tracks << trk @tracks << trk
end end
@waypoints = [] @waypoints = []
@xml.search("//wpt").each { |wpt| @waypoints << Waypoint.new(:element => wpt, :gpx_file => self) } @xml.search("//wpt").each { |wpt| @waypoints << Waypoint.new(:element => wpt, :gpx_file => self) }
@routes = [] @routes = []
@xml.search("//rte").each { |rte| @routes << Route.new(:element => rte, :gpx_file => self) } @xml.search("//rte").each { |rte| @routes << Route.new(:element => rte, :gpx_file => self) }
@ -116,7 +116,7 @@ module GPX
def distance(opts = { :units => 'kilometers' }) def distance(opts = { :units => 'kilometers' })
case opts[:units] case opts[:units]
when /kilometers/i when /kilometers/i
return @distance return @distance
when /meters/i when /meters/i
return (@distance * 1000) return (@distance * 1000)
when /miles/i when /miles/i
@ -126,7 +126,7 @@ module GPX
# Returns the average speed, in km/hr, meters/hr, or miles/hr, of this # Returns the average speed, in km/hr, meters/hr, or miles/hr, of this
# GPXFile. The calculation is based on the total distance divided by the # GPXFile. The calculation is based on the total distance divided by the
# total duration of the entire file. # total duration of the entire file.
def average_speed(opts = { :units => 'kilometers' }) def average_speed(opts = { :units => 'kilometers' })
case opts[:units] case opts[:units]
when /kilometers/i when /kilometers/i
@ -145,11 +145,11 @@ module GPX
def crop(area) def crop(area)
reset_meta_data reset_meta_data
keep_tracks = [] keep_tracks = []
tracks.each do |trk| tracks.each do |trk|
trk.crop(area) trk.crop(area)
unless trk.empty? unless trk.empty?
update_meta_data(trk) update_meta_data(trk)
keep_tracks << trk keep_tracks << trk
end end
end end
@tracks = keep_tracks @tracks = keep_tracks
@ -167,11 +167,11 @@ module GPX
def delete_area(area) def delete_area(area)
reset_meta_data reset_meta_data
keep_tracks = [] keep_tracks = []
tracks.each do |trk| tracks.each do |trk|
trk.delete_area(area) trk.delete_area(area)
unless trk.empty? unless trk.empty?
update_meta_data(trk) update_meta_data(trk)
keep_tracks << trk keep_tracks << trk
end end
end end
@tracks = keep_tracks @tracks = keep_tracks
@ -180,7 +180,7 @@ module GPX
end end
# Resets the meta data for this GPX file. Meta data includes the bounds, # Resets the meta data for this GPX file. Meta data includes the bounds,
# the high and low points, and the distance. # the high and low points, and the distance.
def reset_meta_data def reset_meta_data
@bounds = Bounds.new @bounds = Bounds.new
@highest_point = nil @highest_point = nil
@ -214,7 +214,7 @@ module GPX
doc.to_s doc.to_s
end end
private private
def generate_xml_doc def generate_xml_doc
doc = Document.new doc = Document.new
doc.root = Node.new('gpx') doc.root = Node.new('gpx')
@ -222,9 +222,9 @@ module GPX
gpx_elem['xsi'] = "http://www.w3.org/2001/XMLSchema-instance" gpx_elem['xsi'] = "http://www.w3.org/2001/XMLSchema-instance"
@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) @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)
version_dir = @version.gsub('.','/') version_dir = @version.gsub('.','/')
gpx_elem['xmlns'] = @ns || "http://www.topografix.com/GPX/#{version_dir}" gpx_elem['xmlns'] = @ns || "http://www.topografix.com/GPX/#{version_dir}"
gpx_elem['version'] = "#{@version}" gpx_elem['version'] = "#{@version}"
gpx_elem['creator'] = "GPX RubyGem #{GPX::VERSION} Copyright 2006-2009 Doug Fales -- http://gpx.rubyforge.org/" gpx_elem['creator'] = "GPX RubyGem #{GPX::VERSION} Copyright 2006-2009 Doug Fales -- http://gpx.rubyforge.org/"
gpx_elem['xsi:schemaLocation'] = "http://www.topografix.com/GPX/#{version_dir} http://www.topografix.com/GPX/#{version_dir}/gpx.xsd" gpx_elem['xsi:schemaLocation'] = "http://www.topografix.com/GPX/#{version_dir} http://www.topografix.com/GPX/#{version_dir}/gpx.xsd"
# setup the metadata elements # setup the metadata elements
@ -237,12 +237,12 @@ module GPX
if (@version == '1.0') then if (@version == '1.0') then
gpx_elem << name_elem gpx_elem << name_elem
gpx_elem << time_elem gpx_elem << time_elem
gpx_elem << bounds.to_xml gpx_elem << bounds.to_xml
else else
meta_data_elem = Node.new('metadata') meta_data_elem = Node.new('metadata')
meta_data_elem << name_elem meta_data_elem << name_elem
meta_data_elem << time_elem meta_data_elem << time_elem
meta_data_elem << bounds.to_xml meta_data_elem << bounds.to_xml
gpx_elem << meta_data_elem gpx_elem << meta_data_elem
end end

View File

@ -1,5 +1,5 @@
#-- #--
# Copyright (c) 2006 Doug Fales # Copyright (c) 2006 Doug Fales
# #
# Permission is hereby granted, free of charge, to any person obtaining # Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the # a copy of this software and associated documentation files (the
@ -27,14 +27,14 @@ module GPX
class MagellanTrackLog class MagellanTrackLog
#PMGNTRK #PMGNTRK
# This message is to be used to transmit Track information (basically a list of previous position fixes) # This message is to be used to transmit Track information (basically a list of previous position fixes)
# which is often displayed on the plotter or map screen of the unit. The first field in this message # which is often displayed on the plotter or map screen of the unit. The first field in this message
# is the Latitude, followed by N or S. The next field is the Longitude followed by E or W. The next # is the Latitude, followed by N or S. The next field is the Longitude followed by E or W. The next
# field is the altitude followed by “F” for feet or “M” for meters. The next field is # field is the altitude followed by “F” for feet or “M” for meters. The next field is
# the UTC time of the fix. The next field consists of a status letter of “A” to indicated that # the UTC time of the fix. The next field consists of a status letter of “A” to indicated that
# the data is valid, or “V” to indicate that the data is not valid. The last character field is # the data is valid, or “V” to indicate that the data is not valid. The last character field is
# the name of the track, for those units that support named tracks. The last field contains the UTC date # the name of the track, for those units that support named tracks. The last field contains the UTC date
# of the fix. Note that this field is (and its preceding comma) is only produced by the unit when the # of the fix. Note that this field is (and its preceding comma) is only produced by the unit when the
# command PMGNCMD,TRACK,2 is given. It is not present when a simple command of PMGNCMD,TRACK is issued. # command PMGNCMD,TRACK,2 is given. It is not present when a simple command of PMGNCMD,TRACK is issued.
#NOTE: The Latitude and Longitude Fields are shown as having two decimal #NOTE: The Latitude and Longitude Fields are shown as having two decimal
@ -42,13 +42,13 @@ module GPX
# length of the message does not exceed 82 bytes. # length of the message does not exceed 82 bytes.
# $PMGNTRK,llll.ll,a,yyyyy.yy,a,xxxxx,a,hhmmss.ss,A,c----c,ddmmyy*hh<CR><LF> # $PMGNTRK,llll.ll,a,yyyyy.yy,a,xxxxx,a,hhmmss.ss,A,c----c,ddmmyy*hh<CR><LF>
require 'csv' require 'csv'
LAT = 1 LAT = 1
LAT_HEMI = 2 LAT_HEMI = 2
LON = 3 LON = 3
LON_HEMI = 4 LON_HEMI = 4
ELE = 5 ELE = 5
ELE_UNITS = 6 ELE_UNITS = 6
TIME = 7 TIME = 7
INVALID_FLAG = 8 INVALID_FLAG = 8
@ -64,7 +64,7 @@ module GPX
segment = Segment.new segment = Segment.new
CSV.open(magellan_filename, "r").each do |row| CSV.open(magellan_filename, "r").each do |row|
next if(row.size < 10 or row[INVALID_FLAG] == 'V') next if(row.size < 10 or row[INVALID_FLAG] == 'V')
lat_deg = row[LAT][0..1] lat_deg = row[LAT][0..1]
@ -102,7 +102,7 @@ module GPX
pt = TrackPoint.new(:lat => lat, :lon => lon, :time => time, :elevation => ele) pt = TrackPoint.new(:lat => lat, :lon => lon, :time => time, :elevation => ele)
segment.append_point(pt) segment.append_point(pt)
end end
trk = Track.new trk = Track.new
trk.append_segment(segment) trk.append_segment(segment)
@ -118,11 +118,11 @@ module GPX
f.each do |line| f.each do |line|
i += 1 i += 1
if line =~ /^\$PMGNTRK/ if line =~ /^\$PMGNTRK/
return true return true
elsif line =~ /<\?xml/ elsif line =~ /<\?xml/
return false return false
elsif(i > 10) elsif(i > 10)
return false return false
end end
end end
end end

View File

@ -1,5 +1,5 @@
#-- #--
# Copyright (c) 2006 Doug Fales # Copyright (c) 2006 Doug Fales
# #
# Permission is hereby granted, free of charge, to any person obtaining # Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the # a copy of this software and associated documentation files (the
@ -24,7 +24,7 @@ module GPX
# A Route in GPX is very similar to a Track, but it is created by a user # 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 # from a series of Waypoints, whereas a Track is created by the GPS device
# automatically logging your progress at regular intervals. # automatically logging your progress at regular intervals.
class Route < Base class Route < Base
attr_accessor :points, :name, :gpx_file attr_accessor :points, :name, :gpx_file

View File

@ -1,5 +1,5 @@
#-- #--
# Copyright (c) 2006 Doug Fales # Copyright (c) 2006 Doug Fales
# #
# Permission is hereby granted, free of charge, to any person obtaining # Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the # a copy of this software and associated documentation files (the
@ -29,7 +29,7 @@ module GPX
class Segment < Base class Segment < Base
attr_reader :earliest_point, :latest_point, :bounds, :highest_point, :lowest_point, :distance attr_reader :earliest_point, :latest_point, :bounds, :highest_point, :lowest_point, :distance
attr_accessor :points, :track attr_accessor :points, :track
# If a XML::Node object is passed-in, this will initialize a new # If a XML::Node object is passed-in, this will initialize a new
# Segment based on its contents. Otherwise, a blank Segment is created. # Segment based on its contents. Otherwise, a blank Segment is created.
@ -47,8 +47,8 @@ module GPX
segment_element = opts[:element] segment_element = opts[:element]
last_pt = nil last_pt = nil
if segment_element.is_a?(Hpricot::Elem) if segment_element.is_a?(Hpricot::Elem)
segment_element.search("//trkpt").each do |trkpt| segment_element.search("//trkpt").each do |trkpt|
pt = TrackPoint.new(:element => trkpt, :segment => self, :gpx_file => @gpx_file) pt = TrackPoint.new(:element => trkpt, :segment => self, :gpx_file => @gpx_file)
unless pt.time.nil? unless pt.time.nil?
@earliest_point = pt if(@earliest_point.nil? or pt.time < @earliest_point.time) @earliest_point = pt if(@earliest_point.nil? or pt.time < @earliest_point.time)
@latest_point = pt if(@latest_point.nil? or pt.time > @latest_point.time) @latest_point = pt if(@latest_point.nil? or pt.time > @latest_point.time)
@ -117,7 +117,7 @@ module GPX
reset_meta_data reset_meta_data
keep_points = [] keep_points = []
last_pt = nil last_pt = nil
points.each do |pt| points.each do |pt|
unless yield(pt) unless yield(pt)
keep_points << pt keep_points << pt
update_meta_data(pt, last_pt) update_meta_data(pt, last_pt)
@ -175,7 +175,7 @@ module GPX
RADIUS = 6371; # earth's mean radius in km RADIUS = 6371; # earth's mean radius in km
# Calculate the Haversine distance between two points. This is the method # Calculate the Haversine distance between two points. This is the method
# the library uses to calculate the cumulative distance of GPX files. # the library uses to calculate the cumulative distance of GPX files.
def haversine_distance(p1, p2) def haversine_distance(p1, p2)
d_lat = p2.latr - p1.latr; d_lat = p2.latr - p1.latr;
d_lon = p2.lonr - p1.lonr; d_lon = p2.lonr - p1.lonr;

View File

@ -1,5 +1,5 @@
#-- #--
# Copyright (c) 2006 Doug Fales # Copyright (c) 2006 Doug Fales
# #
# Permission is hereby granted, free of charge, to any person obtaining # Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the # a copy of this software and associated documentation files (the
@ -39,7 +39,7 @@ module GPX
@segments = [] @segments = []
@points = [] @points = []
reset_meta_data reset_meta_data
if(opts[:element]) if(opts[:element])
trk_element = opts[:element] trk_element = opts[:element]
@name = (trk_element.at("//name").inner_text rescue "") @name = (trk_element.at("//name").inner_text rescue "")
trk_element.search("//trkseg").each do |seg_element| trk_element.search("//trkseg").each do |seg_element|
@ -49,7 +49,7 @@ module GPX
end end
end end
end end
# Append a segment to this track, updating its meta data along the way. # Append a segment to this track, updating its meta data along the way.
def append_segment(seg) def append_segment(seg)
update_meta_data(seg) update_meta_data(seg)
@ -77,18 +77,18 @@ module GPX
# The "area" paremeter is usually a Bounds object. # The "area" paremeter is usually a Bounds object.
def crop(area) def crop(area)
reset_meta_data reset_meta_data
segments.each do |seg| segments.each do |seg|
seg.crop(area) seg.crop(area)
update_meta_data(seg) unless seg.empty? update_meta_data(seg) unless seg.empty?
end end
segments.delete_if { |seg| seg.empty? } segments.delete_if { |seg| seg.empty? }
end end
# Deletes all points within a given area and updates the meta data. # Deletes all points within a given area and updates the meta data.
def delete_area(area) def delete_area(area)
reset_meta_data reset_meta_data
segments.each do |seg| segments.each do |seg|
seg.delete_area(area) seg.delete_area(area)
update_meta_data(seg) unless seg.empty? update_meta_data(seg) unless seg.empty?
end end
segments.delete_if { |seg| seg.empty? } segments.delete_if { |seg| seg.empty? }

View File

@ -1,5 +1,5 @@
#-- #--
# Copyright (c) 2006 Doug Fales # Copyright (c) 2006 Doug Fales
# #
# Permission is hereby granted, free of charge, to any person obtaining # Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the # a copy of this software and associated documentation files (the

View File

@ -1,5 +1,5 @@
#-- #--
# Copyright (c) 2006 Doug Fales # Copyright (c) 2006 Doug Fales
# #
# Permission is hereby granted, free of charge, to any person obtaining # Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the # a copy of this software and associated documentation files (the
@ -24,10 +24,10 @@
module GPX module GPX
# This class supports the concept of a waypoint. Beware that this class has # This class supports the concept of a waypoint. Beware that this class has
# not seen much use yet, since WalkingBoss does not use waypoints right now. # not seen much use yet, since WalkingBoss does not use waypoints right now.
class Waypoint < Point class Waypoint < Point
SUB_ELEMENTS = %w{ magvar geoidheight name cmt desc src link sym type fix sat hdop vdop pdop ageofdgpsdata dgpsid extensions } SUB_ELEMENTS = %w{ magvar geoidheight name cmt desc src link sym type fix sat hdop vdop pdop ageofdgpsdata dgpsid extensions }
attr_reader :gpx_file attr_reader :gpx_file
SUB_ELEMENTS.each { |sub_el| attr_accessor sub_el.to_sym } SUB_ELEMENTS.each { |sub_el| attr_accessor sub_el.to_sym }
@ -81,7 +81,7 @@ module GPX
SUB_ELEMENTS.each do |sub_element_name| SUB_ELEMENTS.each do |sub_element_name|
if(self.respond_to?(sub_element_name) and (!self.send(sub_element_name).nil?)) if(self.respond_to?(sub_element_name) and (!self.send(sub_element_name).nil?))
sub_elem_node = Node.new(sub_element_name) sub_elem_node = Node.new(sub_element_name)
sub_elem_node << self.send(sub_element_name) sub_elem_node << self.send(sub_element_name)
wpt << sub_elem_node wpt << sub_elem_node
end end
end end

View File

@ -13,7 +13,7 @@ class OutputTest < Test::Unit::TestCase
def test_new_gpx_file_from_scratch def test_new_gpx_file_from_scratch
gpx_file = GPXFile.new gpx_file = GPXFile.new
track = Track.new(:name => "My First Track") track = Track.new(:name => "My First Track")
segment = Segment.new segment = Segment.new
track_point_data = [ track_point_data = [
@ -37,7 +37,7 @@ class OutputTest < Test::Unit::TestCase
waypoint_data = [ waypoint_data = [
{:lat => 39.997298, :lon => -105.292674, :name => 'GRG-CA', :sym => 'Waypoint', :elevation => 1766.535}, {:lat => 39.997298, :lon => -105.292674, :name => 'GRG-CA', :sym => 'Waypoint', :elevation => 1766.535},
{:lat => 33.330190, :lon => -111.946110, :name => 'GRMPHX', :sym => 'Waypoint', :elevation => 361.0981, {:lat => 33.330190, :lon => -111.946110, :name => 'GRMPHX', :sym => 'Waypoint', :elevation => 361.0981,
:cmt => "Hey here's a comment.", :desc => "Somewhere in my backyard.", :fix => '3d', :sat => "8", :hdop => "50.5", :vdop => "6.8", :pdop => "7.6"}, :cmt => "Hey here's a comment.", :desc => "Somewhere in my backyard.", :fix => '3d', :sat => "8", :hdop => "50.5", :vdop => "6.8", :pdop => "7.6"},
{:lat => 25.061783, :lon => 121.640267, :name => 'GRMTWN', :sym => 'Waypoint', :elevation => 38.09766}, {:lat => 25.061783, :lon => 121.640267, :name => 'GRMTWN', :sym => 'Waypoint', :elevation => 38.09766},
{:lat => 39.999840, :lon => -105.214696, :name => 'SBDR', :sym => 'Waypoint', :elevation => 1612.965}, {:lat => 39.999840, :lon => -105.214696, :name => 'SBDR', :sym => 'Waypoint', :elevation => 1612.965},
@ -105,15 +105,15 @@ class OutputTest < Test::Unit::TestCase
assert_equal(expected_value, IO.read(output_file(name_of_test))) assert_equal(expected_value, IO.read(output_file(name_of_test)))
end end
def name_of_test def name_of_test
caller[0] =~ /`test_([^']*)'/ and $1 caller[0] =~ /`test_([^']*)'/ and $1
end end
def output_file(test_name) def output_file(test_name)
File.join(File.dirname(__FILE__), "output/#{test_name}.gpx") File.join(File.dirname(__FILE__), "output/#{test_name}.gpx")
end end
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" 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"
end end

View File

@ -21,7 +21,7 @@ class RouteTest < Test::Unit::TestCase
assert_equal(-105.292674, first_route.points[0].lon) assert_equal(-105.292674, first_route.points[0].lon)
assert_equal(1766.535, first_route.points[0].elevation) assert_equal(1766.535, first_route.points[0].elevation)
# Route 1, Second Point # Route 1, Second Point
# <rtept lat="39.995700" lon="-105.292805"> # <rtept lat="39.995700" lon="-105.292805">
# <name><![CDATA[AMPTHT]]></name> # <name><![CDATA[AMPTHT]]></name>
@ -35,7 +35,7 @@ class RouteTest < Test::Unit::TestCase
# Route 1, Third Point # Route 1, Third Point
# <rtept lat="39.989739" lon="-105.295285"> # <rtept lat="39.989739" lon="-105.295285">
# <name><![CDATA[TO]]></name> # <name><![CDATA[TO]]></name>
# <sym>Waypoint</sym> # <sym>Waypoint</sym>
# <ele>2163.556</ele> # <ele>2163.556</ele>
# </rtept> # </rtept>
assert_equal(39.989739, first_route.points[2].lat) assert_equal(39.989739, first_route.points[2].lat)
@ -50,7 +50,7 @@ class RouteTest < Test::Unit::TestCase
# Route 2, Only Point # Route 2, Only Point
# <rtept lat="39.999840" lon="-105.214696"> # <rtept lat="39.999840" lon="-105.214696">
# <name><![CDATA[SBDR]]></name> # <name><![CDATA[SBDR]]></name>
# <sym>Waypoint</sym> # <sym>Waypoint</sym>
# <ele>1612.965</ele> # <ele>1612.965</ele>
# </rtept> # </rtept>
assert_equal(39.999840, second_route.points[0].lat) assert_equal(39.999840, second_route.points[0].lat)
@ -59,5 +59,5 @@ class RouteTest < Test::Unit::TestCase
end end
end end

View File

@ -16,7 +16,7 @@ class SegmentTest < Test::Unit::TestCase
assert_equal(1144437991, @segment.latest_point.time.to_i) assert_equal(1144437991, @segment.latest_point.time.to_i)
assert_equal(1334.447, @segment.lowest_point.elevation) assert_equal(1334.447, @segment.lowest_point.elevation)
assert_equal(1480.087, @segment.highest_point.elevation) assert_equal(1480.087, @segment.highest_point.elevation)
assert_in_delta(6.98803359528853, @segment.distance, 0.001) assert_in_delta(6.98803359528853, @segment.distance, 0.001)
end end
def test_segment_crop def test_segment_crop
@ -26,8 +26,8 @@ class SegmentTest < Test::Unit::TestCase
:max_lon=> -108.999000) :max_lon=> -108.999000)
@segment.crop(crop_rectangle) @segment.crop(crop_rectangle)
assert_equal(106, @segment.points.size) assert_equal(106, @segment.points.size)
assert_in_delta(4.11422061733046, @segment.distance, 0.001) assert_in_delta(4.11422061733046, @segment.distance, 0.001)
assert_equal(1144435041, @segment.earliest_point.time.to_i) assert_equal(1144435041, @segment.earliest_point.time.to_i)
assert_equal(1144437752, @segment.latest_point.time.to_i) assert_equal(1144437752, @segment.latest_point.time.to_i)
assert_equal(1407.027, @segment.lowest_point.elevation) assert_equal(1407.027, @segment.lowest_point.elevation)
@ -44,8 +44,8 @@ class SegmentTest < Test::Unit::TestCase
:max_lat=> 39.188000, :max_lat=> 39.188000,
:max_lon=> -108.999000) :max_lon=> -108.999000)
@segment.delete_area(delete_rectangle) @segment.delete_area(delete_rectangle)
assert_equal(83, @segment.points.size) assert_equal(83, @segment.points.size)
assert_in_delta(3.35967118153605, @segment.distance, 0.001) assert_in_delta(3.35967118153605, @segment.distance, 0.001)
assert_equal(1144433525, @segment.earliest_point.time.to_i) assert_equal(1144433525, @segment.earliest_point.time.to_i)
assert_equal(1144437991, @segment.latest_point.time.to_i) assert_equal(1144437991, @segment.latest_point.time.to_i)
assert_equal(1334.447, @segment.lowest_point.elevation) assert_equal(1334.447, @segment.lowest_point.elevation)

View File

@ -11,38 +11,38 @@ class TrackTest < Test::Unit::TestCase
def test_track_read def test_track_read
assert_equal("ACTIVE LOG", @track.name) assert_equal("ACTIVE LOG", @track.name)
assert_equal( 182, @track.points.size) assert_equal( 182, @track.points.size)
assert_equal(8, @track.segments.size) assert_equal(8, @track.segments.size)
assert_in_delta(3.07249668492626, @track.distance, 0.001) assert_in_delta(3.07249668492626, @track.distance, 0.001)
assert_equal(1267.155, @track.lowest_point.elevation) assert_equal(1267.155, @track.lowest_point.elevation)
assert_equal(1594.003, @track.highest_point.elevation) assert_equal(1594.003, @track.highest_point.elevation)
assert_equal(38.681488, @track.bounds.min_lat) assert_equal(38.681488, @track.bounds.min_lat)
assert_equal(-109.606948, @track.bounds.min_lon) assert_equal(-109.606948, @track.bounds.min_lon)
assert_equal(38.791759, @track.bounds.max_lat) assert_equal(38.791759, @track.bounds.max_lat)
assert_equal(-109.447045, @track.bounds.max_lon) assert_equal(-109.447045, @track.bounds.max_lon)
end end
def test_track_crop def test_track_crop
area = GPX::Bounds.new( area = GPX::Bounds.new(
:min_lat => 38.710000, :min_lat => 38.710000,
:min_lon => -109.600000, :min_lon => -109.600000,
:max_lat => 38.791759, :max_lat => 38.791759,
:max_lon => -109.450000) :max_lon => -109.450000)
@track.crop(area) @track.crop(area)
assert_equal("ACTIVE LOG", @track.name) assert_equal("ACTIVE LOG", @track.name)
assert_equal( 111, @track.points.size) assert_equal( 111, @track.points.size)
assert_equal(4, @track.segments.size) assert_equal(4, @track.segments.size)
assert_in_delta(1.62136024923607, @track.distance, 0.001) assert_in_delta(1.62136024923607, @track.distance, 0.001)
assert_equal(1557.954, @track.lowest_point.elevation) assert_equal(1557.954, @track.lowest_point.elevation)
assert_equal(1582.468, @track.highest_point.elevation) assert_equal(1582.468, @track.highest_point.elevation)
assert_equal(38.782511, @track.bounds.min_lat) assert_equal(38.782511, @track.bounds.min_lat)
assert_equal(-109.599781, @track.bounds.min_lon) assert_equal(-109.599781, @track.bounds.min_lon)
assert_equal(38.789527, @track.bounds.max_lat) assert_equal(38.789527, @track.bounds.max_lat)
assert_equal(-109.594996, @track.bounds.max_lon) assert_equal(-109.594996, @track.bounds.max_lon)
end end
def test_track_delete def test_track_delete
area = GPX::Bounds.new( area = GPX::Bounds.new(
:min_lat => 38.710000, :min_lat => 38.710000,
:min_lon => -109.600000, :min_lon => -109.600000,
:max_lat => 38.791759, :max_lat => 38.791759,
@ -51,14 +51,14 @@ class TrackTest < Test::Unit::TestCase
#puts @track #puts @track
#assert_equal("ACTIVE LOG", @track.name) #assert_equal("ACTIVE LOG", @track.name)
#assert_equal( 111, @track.points.size) #assert_equal( 111, @track.points.size)
#assert_equal(4, @track.segments.size) #assert_equal(4, @track.segments.size)
#assert_equal("1.62136024923607", @track.distance.to_s) #assert_equal("1.62136024923607", @track.distance.to_s)
#assert_equal(1557.954, @track.lowest_point.elevation) #assert_equal(1557.954, @track.lowest_point.elevation)
#assert_equal(1582.468, @track.highest_point.elevation) #assert_equal(1582.468, @track.highest_point.elevation)
#assert_equal(38.782511, @track.bounds.min_lat) #assert_equal(38.782511, @track.bounds.min_lat)
#assert_equal(-109.599781, @track.bounds.min_lon) #assert_equal(-109.599781, @track.bounds.min_lon)
#assert_equal(38.789527, @track.bounds.max_lat) #assert_equal(38.789527, @track.bounds.max_lat)
#assert_equal(-109.594996, @track.bounds.max_lon) #assert_equal(-109.594996, @track.bounds.max_lon)
end end