Class: GPX::Point
Overview
The base class for all points. Trackpoint and Waypoint both descend from this base class.
Direct Known Subclasses
Constant Summary collapse
- D_TO_R =
Math::PI / 180.0
Instance Attribute Summary collapse
-
#elevation ⇒ Object
Returns the value of attribute elevation.
-
#extensions ⇒ Object
Returns the value of attribute extensions.
-
#gpx_file ⇒ Object
Returns the value of attribute gpx_file.
-
#lat ⇒ Object
Returns the value of attribute lat.
-
#lon ⇒ Object
Returns the value of attribute lon.
-
#speed ⇒ Object
Returns the value of attribute speed.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
-
#initialize(opts = { lat: 0.0, lon: 0.0, elevation: 0.0, time: Time.now }) ⇒ Point
constructor
When you need to manipulate individual points, you can create a Point object with a latitude, a longitude, an elevation, and a time.
-
#lat_lon(delim = ', ') ⇒ Object
Returns the latitude and longitude (in that order), separated by the given delimeter.
-
#latr ⇒ Object
Latitude in radians.
-
#lon_lat(delim = ', ') ⇒ Object
Returns the longitude and latitude (in that order), separated by the given delimeter.
-
#lonr ⇒ Object
Longitude in radians.
Methods inherited from Base
#instantiate_with_text_elements
Constructor Details
#initialize(opts = { lat: 0.0, lon: 0.0, elevation: 0.0, time: Time.now }) ⇒ Point
When you need to manipulate individual points, you can create a Point object with a latitude, a longitude, an elevation, and a time. In addition, you can pass an XML element to this initializer, and the relevant info will be parsed out.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gpx/point.rb', line 14 def initialize(opts = { lat: 0.0, lon: 0.0, elevation: 0.0, time: Time.now }) super() @gpx_file = opts[:gpx_file] if opts[:element] elem = opts[:element] @lat = elem['lat'].to_f @lon = elem['lon'].to_f @latr = (D_TO_R * @lat) @lonr = (D_TO_R * @lon) # '-'? yyyy '-' mm '-' dd 'T' hh ':' mm ':' ss ('.' s+)? (zzzzzz)? @time = ( begin Time.xmlschema(elem.at('time').inner_text) rescue StandardError nil end) @elevation = elem.at('ele').inner_text.to_f unless elem.at('ele').nil? @speed = elem.at('speed').inner_text.to_f unless elem.at('speed').nil? @extensions = elem.at('extensions') unless elem.at('extensions').nil? else @lat = opts[:lat] @lon = opts[:lon] @elevation = opts[:elevation] @time = opts[:time] @speed = opts[:speed] @extensions = opts[:extensions] end end |
Instance Attribute Details
#elevation ⇒ Object
Returns the value of attribute elevation.
7 8 9 |
# File 'lib/gpx/point.rb', line 7 def elevation @elevation end |
#extensions ⇒ Object
Returns the value of attribute extensions.
7 8 9 |
# File 'lib/gpx/point.rb', line 7 def extensions @extensions end |
#gpx_file ⇒ Object
Returns the value of attribute gpx_file.
7 8 9 |
# File 'lib/gpx/point.rb', line 7 def gpx_file @gpx_file end |
#lat ⇒ Object
Returns the value of attribute lat.
8 9 10 |
# File 'lib/gpx/point.rb', line 8 def lat @lat end |
#lon ⇒ Object
Returns the value of attribute lon.
8 9 10 |
# File 'lib/gpx/point.rb', line 8 def lon @lon end |
#speed ⇒ Object
Returns the value of attribute speed.
7 8 9 |
# File 'lib/gpx/point.rb', line 7 def speed @speed end |
#time ⇒ Object
Returns the value of attribute time.
7 8 9 |
# File 'lib/gpx/point.rb', line 7 def time @time end |
Instance Method Details
#lat_lon(delim = ', ') ⇒ Object
Returns the latitude and longitude (in that order), separated by the given delimeter. This is useful for passing a point into another API (i.e. the Google Maps javascript API).
46 47 48 |
# File 'lib/gpx/point.rb', line 46 def lat_lon(delim = ', ') "#{lat}#{delim}#{lon}" end |
#latr ⇒ Object
Latitude in radians.
58 59 60 |
# File 'lib/gpx/point.rb', line 58 def latr @latr ||= (@lat * D_TO_R) end |
#lon_lat(delim = ', ') ⇒ Object
Returns the longitude and latitude (in that order), separated by the given delimeter. This is useful for passing a point into another API (i.e. the Google Maps javascript API).
53 54 55 |
# File 'lib/gpx/point.rb', line 53 def lon_lat(delim = ', ') "#{lon}#{delim}#{lat}" end |
#lonr ⇒ Object
Longitude in radians.
63 64 65 |
# File 'lib/gpx/point.rb', line 63 def lonr @lonr ||= (@lon * D_TO_R) end |