Module: GeoUnits::Converter
- Extended by:
- Converter
- Includes:
- Normalizer, NumericCheckExt
- Included in:
- Converter
- Defined in:
- lib/geo_units/converter.rb,
lib/geo_units/converter/dms.rb,
lib/geo_units/converter/units.rb,
lib/geo_units/converter/normalizer.rb
Defined Under Namespace
Modules: Dms, Normalizer, Units
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_deg(radians) ⇒ Object
(also: #to_degrees, #as_deg, #as_degrees, #in_deg, #in_degrees)
Converts radians to numeric (signed) degrees latitude (north to south) from equator 90 up then -90 down (equator again) = 180 then 180 for south = 360 total longitude (west to east) east 180, west -180 = 360 total.
-
#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).
-
#to_rad(degrees) ⇒ Object
(also: #to_radians, #as_rad, #as_radians, #in_rad, #in_radians)
Converts numeric degrees to radians.
Methods included from Normalizer
#normalize_deg, #normalize_lat, #normalize_lng
Instance Method Details
#to_brng(deg, format = :dms, dp = 0) ⇒ Object
Convert numeric degrees to deg/min/sec as a bearing (0º..360º)
41 42 43 44 45 |
# File 'lib/geo_units/converter.rb', line 41 def to_brng deg, format = :dms, dp = 0 deg = (deg.to_f + 360) % 360 # normalise -ve values to 180º..360º brng = Dms.to_dms deg, format, dp brng.gsub /360/, '0' # just in case rounding took us up to 360º! end |
#to_deg(radians) ⇒ Object Also known as: to_degrees, as_deg, as_degrees, in_deg, in_degrees
Converts radians to numeric (signed) degrees latitude (north to south) from equator 90 up then -90 down (equator again) = 180 then 180 for south = 360 total longitude (west to east) east 180, west -180 = 360 total
63 64 65 |
# File 'lib/geo_units/converter.rb', line 63 def to_deg radians radians * 180 / Math::PI end |
#to_lat(deg, format = :dms, dp = 0) ⇒ Object
Convert numeric degrees to deg/min/sec latitude (suffixed with N/S)
14 15 16 17 18 |
# File 'lib/geo_units/converter.rb', line 14 def to_lat deg, format = :dms, dp = 0 deg = deg.normalize_lat _lat = Dms.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)
27 28 29 30 31 |
# File 'lib/geo_units/converter.rb', line 27 def to_lon deg, format = :dms, dp = 0 deg = deg.normalize_lng lon = Dms.to_dms deg, format, dp lon == '' ? '' : lon + (deg<0 ? 'W' : 'E') end |
#to_rad(degrees) ⇒ Object Also known as: to_radians, as_rad, as_radians, in_rad, in_radians
Converts numeric degrees to radians
50 51 52 |
# File 'lib/geo_units/converter.rb', line 50 def to_rad degrees degrees * Math::PI / 180 end |