Module: GeoUnits::Converter
- Extended by:
- Converter
- Includes:
- GeoCalc::NumericCheckExt
- Included in:
- Converter
- Defined in:
- lib/geo_units/converter.rb
Instance Method Summary collapse
-
#to_brng(deg, format = :dms, dp = 0) ⇒ Object
Convert numeric degrees to deg/min/sec as a bearing (0º..360º).
-
#to_lat(deg, format = :dms, dp = 0) ⇒ Object
Convert numeric degrees to deg/min/sec latitude (suffixed with N/S).
-
#to_lon(deg, format = :dms, dp = 0) ⇒ Object
Convert numeric degrees to deg/min/sec longitude (suffixed with E/W).
Methods included from GeoCalc::NumericCheckExt
Instance Method Details
#to_brng(deg, format = :dms, dp = 0) ⇒ Object
Convert numeric degrees to deg/min/sec as a bearing (0º..360º)
40 41 42 43 44 |
# File 'lib/geo_units/converter.rb', line 40 def to_brng deg, format = :dms, dp = 0 deg = (deg.to_f + 360) % 360 # normalise -ve values to 180º..360º brng = GeoCalc::Dms::Converter.to_dms deg, format, dp brng.gsub /360/, '0' # just in case rounding took us up to 360º! end |
#to_lat(deg, format = :dms, dp = 0) ⇒ Object
Convert numeric degrees to deg/min/sec latitude (suffixed with N/S)
13 14 15 16 17 |
# File 'lib/geo_units/converter.rb', line 13 def to_lat deg, format = :dms, dp = 0 deg = deg.normalize_lat _lat = GeoCalc::Dms::Converter.to_dms deg, format, dp _lat == '' ? '' : _lat[1..-1] + (deg<0 ? 'S' : 'N') # knock off initial '0' for lat! end |
#to_lon(deg, format = :dms, dp = 0) ⇒ Object
Convert numeric degrees to deg/min/sec longitude (suffixed with E/W)
26 27 28 29 30 |
# File 'lib/geo_units/converter.rb', line 26 def to_lon deg, format = :dms, dp = 0 deg = deg.normalize_lng lon = GeoCalc::Dms::Converter.to_dms deg, format, dp lon == '' ? '' : lon + (deg<0 ? 'W' : 'E') end |