Module: Fdc::GeoLocation

Defined in:
lib/fdc/utilities.rb

Overview

Helper functions for geocoordinate conversion

Class Method Summary collapse

Class Method Details

.to_dec(long, lat) ⇒ Float

Convert geocoordinates from mindec notation of IGC to dec notation

Examples:

Convert a pair of coordinates

GeoLocation.to_dec("01343272E", "4722676N")  #=>[13.7212,47.37793333333333]

Parameters:

  • long (String)

    The longitude from the igc file

  • lat (String)

    The Latitude from the igc file

Returns:

  • (Float, Float)

    Longitude and Latitude in decimal notation



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fdc/utilities.rb', line 17

def GeoLocation.to_dec(long, lat)

  long_m = long.match(/^(\d{3})((\d{2})(\d{3}))(E|W)/)
  lat_m = lat.match(/^(\d{2})((\d{2})(\d{3}))(N|S)/)

  # Convert minutes to decimal
  long_dec = long_m[1].to_f + (long_m[2].to_f / 1000 / 60)
  lat_dec = lat_m[1].to_f + (lat_m[2].to_f / 1000 / 60)

  # Change signs according to direction
  long_dec *= (-1) if long_m[5] == "W"
  lat_dec *= (-1) if lat_m[5] == "S"

  return long_dec, lat_dec
end