geo_units 0.2.6 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -1
- data/Gemfile +1 -0
- data/README.textile +15 -0
- data/VERSION +1 -1
- data/geo_units.gemspec +21 -5
- data/lib/geo_units.rb +48 -19
- data/lib/geo_units/constants.rb +5 -17
- data/lib/geo_units/converter.rb +11 -55
- data/lib/geo_units/converter/dms.rb +112 -0
- data/lib/geo_units/converter/normalizer.rb +52 -0
- data/lib/geo_units/converter/units.rb +41 -0
- data/lib/geo_units/core_ext.rb +60 -25
- data/lib/geo_units/maps.rb +6 -58
- data/lib/geo_units/maps/earth.rb +49 -0
- data/lib/geo_units/maps/meters.rb +25 -0
- data/lib/geo_units/numeric.rb +50 -0
- data/lib/geo_units/numeric/dms.rb +18 -0
- data/lib/geo_units/numeric/normalizer.rb +62 -0
- data/spec/geo_units/{dms_converter_spec.rb → converter/dms_spec.rb} +5 -5
- data/spec/geo_units/converter/normalizer_spec.rb +0 -0
- data/spec/geo_units/converter/units_spec.rb +0 -0
- data/spec/geo_units/converter_spec.rb +7 -7
- data/spec/geo_units/core_ext_spec.rb +62 -7
- data/spec/geo_units/maps/earth_spec.rb +25 -0
- data/spec/geo_units/maps/meters_spec.rb +24 -0
- data/spec/geo_units/maps_spec.rb +25 -0
- data/spec/geo_units/numeric/dms_spec.rb +0 -0
- data/spec/geo_units/numeric/normalizer_spec.rb +0 -0
- data/spec/geo_units/numeric_spec.rb +21 -0
- data/spec/geo_units_spec.rb +7 -1
- metadata +35 -6
- data/lib/geo_units/dms_converter.rb +0 -107
- data/lib/geo_units/numeric_ext.rb +0 -117
- data/spec/geo_units/numeric_ext_spec.rb +0 -12
@@ -1,117 +0,0 @@
|
|
1
|
-
module GeoUnits
|
2
|
-
module NumericExt
|
3
|
-
def to_lat
|
4
|
-
normalize_lat
|
5
|
-
end
|
6
|
-
|
7
|
-
def to_lng
|
8
|
-
normalize_lng
|
9
|
-
end
|
10
|
-
|
11
|
-
def is_between? lower, upper
|
12
|
-
(lower..upper).cover? self
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_dms format = :dms, dp = nil
|
16
|
-
GeoUnits::DmsConverter.to_dms self, format, dp
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_lat_dms format = :dms, dp = nil
|
20
|
-
GeoUnits::Converter.to_lat self, format, dp
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_lon_dms format = :dms, dp = nil
|
24
|
-
GeoUnits::Converter.to_lon self, format, dp
|
25
|
-
end
|
26
|
-
alias_method :to_lng_dms, :to_lon_dms
|
27
|
-
|
28
|
-
# Converts numeric degrees to radians
|
29
|
-
def to_rad
|
30
|
-
self * Math::PI / 180
|
31
|
-
end
|
32
|
-
alias_method :to_radians, :to_rad
|
33
|
-
alias_method :as_rad, :to_rad
|
34
|
-
alias_method :as_radians, :to_rad
|
35
|
-
alias_method :in_rad, :to_rad
|
36
|
-
alias_method :in_radians, :to_rad
|
37
|
-
|
38
|
-
|
39
|
-
# Converts radians to numeric (signed) degrees
|
40
|
-
# latitude (north to south) from equator +90 up then -90 down (equator again) = 180 then 180 for south = 360 total
|
41
|
-
# longitude (west to east) east +180, west -180 = 360 total
|
42
|
-
def to_deg
|
43
|
-
self * 180 / Math::PI
|
44
|
-
end
|
45
|
-
|
46
|
-
alias_method :to_degrees, :to_deg
|
47
|
-
alias_method :as_deg, :to_deg
|
48
|
-
alias_method :as_degrees, :to_deg
|
49
|
-
alias_method :in_deg, :to_deg
|
50
|
-
alias_method :in_degrees, :to_deg
|
51
|
-
|
52
|
-
|
53
|
-
# Formats the significant digits of a number, using only fixed-point notation (no exponential)
|
54
|
-
#
|
55
|
-
# @param {Number} precision: Number of significant digits to appear in the returned string
|
56
|
-
# @returns {String} A string representation of number which contains precision significant digits
|
57
|
-
def to_precision precision
|
58
|
-
self.round(precision).to_s
|
59
|
-
end
|
60
|
-
alias_method :to_fixed, :to_precision
|
61
|
-
|
62
|
-
# all degrees between -180 and 180
|
63
|
-
def normalize_lng
|
64
|
-
case self
|
65
|
-
when -360, 0, 360
|
66
|
-
0
|
67
|
-
when -360..-180
|
68
|
-
self % 180
|
69
|
-
when -180..0
|
70
|
-
-180 + (self % 180)
|
71
|
-
when 0..180
|
72
|
-
self
|
73
|
-
when 180..360
|
74
|
-
self % 180
|
75
|
-
else
|
76
|
-
return (self % 360).normalize_lng if self > 360
|
77
|
-
return (360 - (self % 360)).normalize_lng if self < -360
|
78
|
-
raise ArgumentError, "Degrees #{self} out of range"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
# all degrees between -90 and 90
|
83
|
-
def normalize_lat
|
84
|
-
case self
|
85
|
-
when -360, 0, 360
|
86
|
-
0
|
87
|
-
when -180, 180
|
88
|
-
0
|
89
|
-
when -360..-270
|
90
|
-
self % 90
|
91
|
-
when -270..-180
|
92
|
-
90 - (self % 90)
|
93
|
-
when -180..-90
|
94
|
-
- (self % 90)
|
95
|
-
when -90..0
|
96
|
-
-90 + (self % 90)
|
97
|
-
when 0..90
|
98
|
-
self
|
99
|
-
when 90..180
|
100
|
-
self % 90
|
101
|
-
when 180..270
|
102
|
-
- (self % 90)
|
103
|
-
when 270..360
|
104
|
-
- 90 + (self % 90)
|
105
|
-
else
|
106
|
-
return (self % 360).normalize_lat if self > 360
|
107
|
-
return (360 - (self % 360)).normalize_lat if self < -360
|
108
|
-
raise ArgumentError, "Degrees #{self} out of range"
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def normalize_deg shift = 0
|
113
|
-
(self + shift) % 360
|
114
|
-
end
|
115
|
-
alias_method :normalize_degrees, :normalize_deg
|
116
|
-
end
|
117
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# - www.movable-type.co.uk/scripts/latlong.html
|
4
|
-
describe Array do
|
5
|
-
# deg, format, dp
|
6
|
-
describe '#to_dms' do
|
7
|
-
it 'should convert [58.3, 4] to string of dms format' do
|
8
|
-
dms_arr = [58.3, 4].to_dms
|
9
|
-
puts dms_arr.inspect
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|