Class: GeoUtm::LatLon

Inherits:
Object
  • Object
show all
Includes:
Math
Defined in:
lib/geoutm/latlon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lat, lon) ⇒ LatLon

Create a new coordinate instance based on latitude and longitude

Parameters:

  • the (Float)

    coordinate latitude

  • the (Float)

    coordinate longitude

Raises:



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

#latObject (readonly)

Returns the value of attribute lat



8
9
10
# File 'lib/geoutm/latlon.rb', line 8

def lat
  @lat
end

#lonObject (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_sObject

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

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :ellipsoid (String, Symbol, Ellipsoid)

    The ellipsoid to use

  • :zone (String)

    Force the coordiante into another UTM zone than it belongs. Use this to compare two coordinates in different zones

Returns:

  • (UTM)

    The converted UTM representation



31
32
33
# File 'lib/geoutm/latlon.rb', line 31

def to_utm(options = {})
  UTM::latlon_to_utm self, options
end