Class: GeoUtm::LatLon
Instance Attribute Summary collapse
-
#lat ⇒ Object
readonly
Returns the value of attribute lat.
-
#lon ⇒ Object
readonly
Returns the value of attribute lon.
Instance Method Summary collapse
-
#initialize(lat, lon) ⇒ LatLon
constructor
Create a new coordinate instance based on latitude and longitude.
-
#to_s ⇒ Object
Textual representation of the coordinate.
-
#to_utm(options = {}) ⇒ UTM
Convert the coordinate in latutude/longitude into the UTM coordinate system.
Constructor Details
#initialize(lat, lon) ⇒ LatLon
Create a new coordinate instance based on latitude and longitude
14 15 16 17 |
# File 'lib/geoutm/latlon.rb', line 14 def initialize(lat, lon) raise GeoUtmException, "Invalid longitude #{lon}" unless (-180.0...180.0).member? lon @lat, @lon = lat, lon end |
Instance Attribute Details
#lat ⇒ Object (readonly)
Returns the value of attribute lat.
8 9 10 |
# File 'lib/geoutm/latlon.rb', line 8 def lat @lat end |
#lon ⇒ Object (readonly)
Returns the value of attribute lon.
8 9 10 |
# File 'lib/geoutm/latlon.rb', line 8 def lon @lon end |
Instance Method Details
#to_s ⇒ Object
Textual representation of the coordinate
20 21 22 23 24 |
# File 'lib/geoutm/latlon.rb', line 20 def to_s north_south = if @lat >= 0.0 then 'N' else 'S' end east_west = if @lon >= 0.0 then 'E' else 'W' end '%0.6f%s %0.6f%s' % [@lat.abs, north_south, @lon.abs, east_west] end |
#to_utm(options = {}) ⇒ UTM
Convert the coordinate in latutude/longitude into the UTM coordinate system
31 32 33 |
# File 'lib/geoutm/latlon.rb', line 31 def to_utm( = {}) UTM::latlon_to_utm self, end |