geo_calc 0.7.1 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -1
- data/README.textile +8 -59
- data/VERSION +1 -1
- data/geo_calc.gemspec +15 -22
- data/lib/geo_calc/calc/bearing.rb +1 -1
- data/lib/geo_calc/calc/destination.rb +3 -2
- data/lib/geo_calc/calc/distance.rb +1 -1
- data/lib/geo_calc/calc/intersection.rb +8 -8
- data/lib/geo_calc/calc/midpoint.rb +8 -6
- data/lib/geo_calc/calc/rhumb.rb +35 -16
- data/lib/geo_calc/calc.rb +15 -21
- data/lib/geo_calc/extensions/array.rb +1 -3
- data/lib/geo_calc/extensions/hash.rb +1 -3
- data/lib/geo_calc/extensions/string.rb +8 -17
- data/lib/geo_calc/extensions.rb +0 -1
- data/lib/geo_calc/pretty_print.rb +14 -14
- data/lib/geo_calc.rb +7 -4
- data/spec/geo_calc/calculations_spec.rb +2 -1
- data/spec/geo_calc/core_ext/array_ext_spec.rb +1 -9
- data/spec/geo_calc/core_ext/hash_ext_spec.rb +3 -9
- data/spec/geo_calc/core_ext/string_ext_spec.rb +1 -9
- data/spec/geo_calc/core_ext_spec.rb +1 -7
- data/spec/geo_calc/include_apis_spec.rb +32 -0
- data/spec/spec_helper.rb +13 -5
- metadata +52 -35
- data/lib/geo_calc/dms/converter.rb +0 -106
- data/lib/geo_calc/dms.rb +0 -5
- data/lib/geo_calc/extensions/math.rb +0 -6
- data/lib/geo_calc/extensions/numeric.rb +0 -24
- data/lib/geo_calc/geo_point/class_methods.rb +0 -15
- data/lib/geo_calc/geo_point/core_extension.rb +0 -11
- data/lib/geo_calc/geo_point/shared.rb +0 -29
- data/lib/geo_calc/geo_point.rb +0 -135
- data/lib/geo_units/converter.rb +0 -123
- data/lib/geo_units/numeric_ext.rb +0 -117
- data/lib/geo_units.rb +0 -21
- data/spec/geo_calc/dms/converter_spec.rb +0 -60
- data/spec/geo_calc/geo_point/class_methods_spec.rb +0 -31
- data/spec/geo_calc/geo_point/initializer_spec.rb +0 -148
- data/spec/geo_calc/geo_point/lat_lon.rb +0 -115
- data/spec/geo_calc/geo_point_spec.rb +0 -99
- data/spec/geo_units/converter_spec.rb +0 -57
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class CalcApis
|
4
|
+
include GeoCalc
|
5
|
+
end
|
6
|
+
|
7
|
+
class CalcDistance
|
8
|
+
include GeoCalc::Distance
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
# - www.movable-type.co.uk/scripts/latlong.html
|
14
|
+
describe GeoPoint do
|
15
|
+
describe 'include all Apis' do
|
16
|
+
it 'should have Bearing api' do
|
17
|
+
CalcApis.new.should respond_to :bearing_to
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'include select Apis' do
|
22
|
+
it 'should not have Bearing api' do
|
23
|
+
dist = CalcDistance.new
|
24
|
+
dist.should_not respond_to :bearing_to
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should have Distance api' do
|
28
|
+
dist = CalcDistance.new
|
29
|
+
dist.should respond_to :distance_to
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
1
|
require 'rspec'
|
4
2
|
require 'geo_calc'
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
class GeoPoint
|
5
|
+
attr_accessor :lat, :lon
|
6
|
+
|
7
|
+
def initialize lat, lon
|
8
|
+
@lat = lat
|
9
|
+
@lon = lon
|
10
|
+
end
|
11
|
+
|
12
|
+
def lng
|
13
|
+
lon
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
9
17
|
|
10
18
|
RSpec.configure do |config|
|
11
19
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geo_calc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-06-
|
12
|
+
date: 2011-06-13 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: require_all
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153783140 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,21 +21,54 @@ dependencies:
|
|
21
21
|
version: 1.2.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2153783140
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sugar-high
|
27
|
-
requirement: &
|
27
|
+
requirement: &2153782640 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.4.
|
32
|
+
version: 0.4.6.3
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2153782640
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: geo_units
|
38
|
+
requirement: &2153782120 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.2.0
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2153782120
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: i18n
|
49
|
+
requirement: &2153781640 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2153781640
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: activesupport
|
60
|
+
requirement: &2153781060 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 3.0.1
|
66
|
+
type: :runtime
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2153781060
|
36
69
|
- !ruby/object:Gem::Dependency
|
37
70
|
name: rspec
|
38
|
-
requirement: &
|
71
|
+
requirement: &2153780540 !ruby/object:Gem::Requirement
|
39
72
|
none: false
|
40
73
|
requirements:
|
41
74
|
- - ! '>='
|
@@ -43,10 +76,10 @@ dependencies:
|
|
43
76
|
version: 2.5.0
|
44
77
|
type: :development
|
45
78
|
prerelease: false
|
46
|
-
version_requirements: *
|
79
|
+
version_requirements: *2153780540
|
47
80
|
- !ruby/object:Gem::Dependency
|
48
81
|
name: bundler
|
49
|
-
requirement: &
|
82
|
+
requirement: &2153779960 !ruby/object:Gem::Requirement
|
50
83
|
none: false
|
51
84
|
requirements:
|
52
85
|
- - ! '>='
|
@@ -54,10 +87,10 @@ dependencies:
|
|
54
87
|
version: '1'
|
55
88
|
type: :development
|
56
89
|
prerelease: false
|
57
|
-
version_requirements: *
|
90
|
+
version_requirements: *2153779960
|
58
91
|
- !ruby/object:Gem::Dependency
|
59
92
|
name: jeweler
|
60
|
-
requirement: &
|
93
|
+
requirement: &2153779440 !ruby/object:Gem::Requirement
|
61
94
|
none: false
|
62
95
|
requirements:
|
63
96
|
- - ! '>='
|
@@ -65,10 +98,10 @@ dependencies:
|
|
65
98
|
version: 1.5.2
|
66
99
|
type: :development
|
67
100
|
prerelease: false
|
68
|
-
version_requirements: *
|
101
|
+
version_requirements: *2153779440
|
69
102
|
- !ruby/object:Gem::Dependency
|
70
103
|
name: rcov
|
71
|
-
requirement: &
|
104
|
+
requirement: &2153778720 !ruby/object:Gem::Requirement
|
72
105
|
none: false
|
73
106
|
requirements:
|
74
107
|
- - ! '>='
|
@@ -76,10 +109,10 @@ dependencies:
|
|
76
109
|
version: '0'
|
77
110
|
type: :development
|
78
111
|
prerelease: false
|
79
|
-
version_requirements: *
|
112
|
+
version_requirements: *2153778720
|
80
113
|
- !ruby/object:Gem::Dependency
|
81
114
|
name: rake
|
82
|
-
requirement: &
|
115
|
+
requirement: &2153778000 !ruby/object:Gem::Requirement
|
83
116
|
none: false
|
84
117
|
requirements:
|
85
118
|
- - ! '>='
|
@@ -87,7 +120,7 @@ dependencies:
|
|
87
120
|
version: '0.9'
|
88
121
|
type: :development
|
89
122
|
prerelease: false
|
90
|
-
version_requirements: *
|
123
|
+
version_requirements: *2153778000
|
91
124
|
description: Geo calculations in ruby and javascript
|
92
125
|
email: kmandrup@gmail.com
|
93
126
|
executables: []
|
@@ -113,35 +146,19 @@ files:
|
|
113
146
|
- lib/geo_calc/calc/intersection.rb
|
114
147
|
- lib/geo_calc/calc/midpoint.rb
|
115
148
|
- lib/geo_calc/calc/rhumb.rb
|
116
|
-
- lib/geo_calc/dms.rb
|
117
|
-
- lib/geo_calc/dms/converter.rb
|
118
149
|
- lib/geo_calc/extensions.rb
|
119
150
|
- lib/geo_calc/extensions/array.rb
|
120
151
|
- lib/geo_calc/extensions/hash.rb
|
121
|
-
- lib/geo_calc/extensions/math.rb
|
122
|
-
- lib/geo_calc/extensions/numeric.rb
|
123
152
|
- lib/geo_calc/extensions/string.rb
|
124
153
|
- lib/geo_calc/extensions/symbol.rb
|
125
|
-
- lib/geo_calc/geo_point.rb
|
126
|
-
- lib/geo_calc/geo_point/class_methods.rb
|
127
|
-
- lib/geo_calc/geo_point/core_extension.rb
|
128
|
-
- lib/geo_calc/geo_point/shared.rb
|
129
154
|
- lib/geo_calc/pretty_print.rb
|
130
|
-
- lib/geo_units.rb
|
131
|
-
- lib/geo_units/converter.rb
|
132
|
-
- lib/geo_units/numeric_ext.rb
|
133
155
|
- spec/geo_calc/calculations_spec.rb
|
134
156
|
- spec/geo_calc/core_ext/array_ext_spec.rb
|
135
157
|
- spec/geo_calc/core_ext/hash_ext_spec.rb
|
136
158
|
- spec/geo_calc/core_ext/numeric_geo_ext_spec.rb
|
137
159
|
- spec/geo_calc/core_ext/string_ext_spec.rb
|
138
160
|
- spec/geo_calc/core_ext_spec.rb
|
139
|
-
- spec/geo_calc/
|
140
|
-
- spec/geo_calc/geo_point/class_methods_spec.rb
|
141
|
-
- spec/geo_calc/geo_point/initializer_spec.rb
|
142
|
-
- spec/geo_calc/geo_point/lat_lon.rb
|
143
|
-
- spec/geo_calc/geo_point_spec.rb
|
144
|
-
- spec/geo_units/converter_spec.rb
|
161
|
+
- spec/geo_calc/include_apis_spec.rb
|
145
162
|
- spec/spec_helper.rb
|
146
163
|
- vendor/assets/javascript/geo_calc.js
|
147
164
|
homepage: http://github.com/kristianmandrup/geo_calc
|
@@ -159,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
159
176
|
version: '0'
|
160
177
|
segments:
|
161
178
|
- 0
|
162
|
-
hash: -
|
179
|
+
hash: -4458324713817276308
|
163
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
181
|
none: false
|
165
182
|
requirements:
|
@@ -1,106 +0,0 @@
|
|
1
|
-
module GeoCalc
|
2
|
-
module Dms
|
3
|
-
module Converter
|
4
|
-
include GeoCalc::NumericCheckExt
|
5
|
-
|
6
|
-
def parse_dms dms_str
|
7
|
-
# check for signed decimal degrees without NSEW, if so return it directly
|
8
|
-
return dms_str if is_numeric?(dms_str)
|
9
|
-
|
10
|
-
# strip off any sign or compass dir'n & split out separate d/m/s
|
11
|
-
dms = dms_str.trim.gsub(/^-/,'').gsub(/[NSEW]$/i,'').split(/[^0-9.,]+/).map(&:trim).map(&:to_f)
|
12
|
-
return nil if dms.empty?
|
13
|
-
|
14
|
-
# and convert to decimal degrees...
|
15
|
-
deg = case dms.length
|
16
|
-
when 3 # interpret 3-part result as d/m/s
|
17
|
-
dms[0]/1 + dms[1]/60 + dms[2]/3600
|
18
|
-
when 2 # interpret 2-part result as d/m
|
19
|
-
dms[0]/1 + dms[1]/60
|
20
|
-
when 1 # just d (possibly decimal) or non-separated dddmmss
|
21
|
-
d = dms[0];
|
22
|
-
# check for fixed-width unseparated format eg 0033709W
|
23
|
-
d = "0#{d}" if (/[NS]/i.match(dms_str)) # - normalise N/S to 3-digit degrees
|
24
|
-
d = "#{d.slice(0,3)/1}#{deg.slice(3,5)/60}#{deg.slice(5)/3600}" if (/[0-9]{7}/.match(deg))
|
25
|
-
d
|
26
|
-
else
|
27
|
-
nil
|
28
|
-
end
|
29
|
-
return nil if !deg
|
30
|
-
deg = (deg * -1) if (/^-|[WS]$/i.match(dms_str.trim)) # take '-', west and south as -ve
|
31
|
-
deg.to_f
|
32
|
-
end
|
33
|
-
|
34
|
-
# Convert decimal degrees to deg/min/sec format
|
35
|
-
# - degree, prime, double-prime symbols are added, but sign is discarded, though no compass
|
36
|
-
# direction is added
|
37
|
-
#
|
38
|
-
#
|
39
|
-
# @param {Number} deg: Degrees
|
40
|
-
# @param {String} [format=dms]: Return value as 'd', 'dm', 'dms'
|
41
|
-
# @param {Number} [dp=0|2|4]: No of decimal places to use - default 0 for dms, 2 for dm, 4 for d
|
42
|
-
# @returns {String} deg formatted as deg/min/secs according to specified format
|
43
|
-
# @throws {TypeError} deg is an object, perhaps DOM object without .value?
|
44
|
-
|
45
|
-
def to_dms deg, format = :dms, dp = nil
|
46
|
-
deg = begin
|
47
|
-
deg.to_f
|
48
|
-
rescue
|
49
|
-
nil
|
50
|
-
end
|
51
|
-
return nil if !deg # give up here if we can't make a number from deg
|
52
|
-
|
53
|
-
# default values
|
54
|
-
format ||= :dms
|
55
|
-
dp = if dp.nil?
|
56
|
-
case format.to_sym
|
57
|
-
when :d
|
58
|
-
4
|
59
|
-
when :dm
|
60
|
-
2
|
61
|
-
else
|
62
|
-
0 # default
|
63
|
-
end
|
64
|
-
end
|
65
|
-
dp ||= 0
|
66
|
-
|
67
|
-
deg = deg.abs # (unsigned result ready for appending compass dir'n)
|
68
|
-
|
69
|
-
case format
|
70
|
-
when :d
|
71
|
-
d = deg.round(dp) # round degrees
|
72
|
-
ds = "0#{d}" if (d <100) # pad with leading zeros
|
73
|
-
ds = "0#{ds}" if (d <10)
|
74
|
-
dms = ds.to_s.concat("\u00B0") # add º symbol
|
75
|
-
when :dm
|
76
|
-
min = (deg*60).round(dp) # convert degrees to minutes & round
|
77
|
-
d = d.to_i
|
78
|
-
d = (min / 60).floor # get component deg/min
|
79
|
-
m = (min % 60).round(dp) # pad with trailing zeros
|
80
|
-
ds = d
|
81
|
-
ms = m
|
82
|
-
ds = "0#{d}" if (d<100) # pad with leading zeros
|
83
|
-
ds = "0#{d}" if (d<10)
|
84
|
-
ms = "0#{m}" if (m<10)
|
85
|
-
dms = ds.to_s.concat("\u00B0", ms, "\u2032") # add º, ' symbols
|
86
|
-
when :dms
|
87
|
-
sec = (deg * 3600).round # convert degrees to seconds & round
|
88
|
-
d = (sec / 3600).floor # get component deg/min/sec
|
89
|
-
m = ((sec / 60) % 60).floor
|
90
|
-
s = (sec % 60).round(dp) # pad with trailing zeros
|
91
|
-
ds = d
|
92
|
-
ms = m
|
93
|
-
ss = s
|
94
|
-
ds = "0#{d}" if (d < 100) # pad with leading zeros
|
95
|
-
ds = "0#{ds}" if (d < 10)
|
96
|
-
ms = "0#{m}" if (m < 10)
|
97
|
-
ss = "0#{s}" if (s < 10)
|
98
|
-
dms = ds.to_s.concat("\u00B0", ms, "\u2032", ss, "\u2033") # add º, ', " symbols
|
99
|
-
end
|
100
|
-
return dms
|
101
|
-
end
|
102
|
-
|
103
|
-
extend self
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
data/lib/geo_calc/dms.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'geo_units'
|
2
|
-
|
3
|
-
module GeoCalc
|
4
|
-
module NumericCheckExt
|
5
|
-
def is_numeric? arg
|
6
|
-
arg.is_a? Numeric
|
7
|
-
end
|
8
|
-
|
9
|
-
alias_method :is_num?, :is_numeric?
|
10
|
-
|
11
|
-
def check_numeric! arg
|
12
|
-
raise ArgumentError, "Argument must be Numeric" if !is_numeric? arg
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Fixnum
|
18
|
-
include ::GeoUnits::NumericExt
|
19
|
-
end
|
20
|
-
|
21
|
-
class Float
|
22
|
-
include ::GeoUnits::NumericExt
|
23
|
-
end
|
24
|
-
|
@@ -1,29 +0,0 @@
|
|
1
|
-
class GeoPoint
|
2
|
-
module Shared
|
3
|
-
def unit
|
4
|
-
:degrees
|
5
|
-
end
|
6
|
-
|
7
|
-
def earth_radius_km= radius_km
|
8
|
-
raise ArgumentException, "Not a valid earth km radius: #{radius_km}" unless valid_earth_radius? radius_km
|
9
|
-
@earth_radius_km = radius_km
|
10
|
-
end
|
11
|
-
|
12
|
-
def coord_mode= mode
|
13
|
-
raise ArgumentException, "Not a valid coordinates mode: #{mode}" unless valid_mode? mode
|
14
|
-
@coord_mode = mode
|
15
|
-
end
|
16
|
-
|
17
|
-
protected
|
18
|
-
|
19
|
-
include GeoCalc::NumericCheckExt
|
20
|
-
|
21
|
-
def valid_earth_radius? radius_km
|
22
|
-
is_numeric?(radius_km) && radius_km.is_between?(6350, 6380)
|
23
|
-
end
|
24
|
-
|
25
|
-
def valid_mode? mode
|
26
|
-
[:lng_lat, :lat_lng].include? mode
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/lib/geo_calc/geo_point.rb
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
require 'sugar-high/arguments'
|
2
|
-
require 'geo_calc/calc'
|
3
|
-
require 'geo_calc/extensions'
|
4
|
-
require 'geo_calc/geo_point/shared'
|
5
|
-
|
6
|
-
# Sample usage:
|
7
|
-
# p1 = GeoPoint.new(51.5136, -0.0983)
|
8
|
-
# p2 = GeoPoint.new(51.4778, -0.0015)
|
9
|
-
# dist = p1.distance_to(p2) # in km
|
10
|
-
# brng = p1.bearing_to(p2) # in degrees clockwise from north
|
11
|
-
# ... etc
|
12
|
-
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
13
|
-
|
14
|
-
class GeoPoint
|
15
|
-
include GeoCalc::Calc::All
|
16
|
-
|
17
|
-
autoload :Shared, 'geo_calc/geo_point/shared'
|
18
|
-
autoload :ClassMethods, 'geo_calc/geo_point/class_methods'
|
19
|
-
autoload :CoreExtension, 'geo_calc/geo_point/core_extension'
|
20
|
-
|
21
|
-
attr_reader :lat, :lon
|
22
|
-
|
23
|
-
# Creates a point on the earth's surface at the supplied latitude / longitude
|
24
|
-
#
|
25
|
-
# - Numeric latitude in numeric degrees
|
26
|
-
# - Numeric longitude in numeric degrees
|
27
|
-
|
28
|
-
# Optional options
|
29
|
-
# - :radius - earth radius in km
|
30
|
-
# - :mode - coordinates mode, either :lng_lat or :lat_lng, otherwise uses global setting as per GeoPoint.coord_mode
|
31
|
-
def initialize *args
|
32
|
-
options = args.is_a?(GeoPoint) ? {} : args.last_option
|
33
|
-
earth_radius_km = options[:radius]
|
34
|
-
coord_mode = options[:mode]
|
35
|
-
|
36
|
-
case args.size
|
37
|
-
when 1
|
38
|
-
create_from_one args
|
39
|
-
when 2
|
40
|
-
create_from_two *args
|
41
|
-
else
|
42
|
-
raise "GeoPoint must be initialized with either one or to arguments defining the (latitude, longitude) coordinate on the map"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
extend ClassMethods
|
47
|
-
include Shared
|
48
|
-
|
49
|
-
def coord_mode
|
50
|
-
@coord_mode ||= GeoPoint.coord_mode
|
51
|
-
end
|
52
|
-
|
53
|
-
def earth_radius_km
|
54
|
-
@earth_radius_km ||= GeoPoint.earth_radius_km # default
|
55
|
-
end
|
56
|
-
|
57
|
-
def lat= value
|
58
|
-
@lat = value.to_lat
|
59
|
-
end
|
60
|
-
|
61
|
-
def lon= value
|
62
|
-
@lon = value.to_lng
|
63
|
-
end
|
64
|
-
|
65
|
-
(Symbol.lng_symbols - [:lon]).each do |sym|
|
66
|
-
class_eval %{
|
67
|
-
alias_method :#{sym}, :lon
|
68
|
-
alias_method :#{sym}=, :lon=
|
69
|
-
}
|
70
|
-
end
|
71
|
-
alias_method :to_lng, :lng
|
72
|
-
|
73
|
-
(Symbol.lat_symbols - [:lat]).each do |sym|
|
74
|
-
class_eval %{
|
75
|
-
alias_method :#{sym}, :lat
|
76
|
-
alias_method :#{sym}=, :lat=
|
77
|
-
}
|
78
|
-
end
|
79
|
-
alias_method :to_lat, :lat
|
80
|
-
|
81
|
-
def [] key
|
82
|
-
case key
|
83
|
-
when Fixnum
|
84
|
-
raise ArgumentError, "Index must be 0 or 1" if !(0..1).cover?(key)
|
85
|
-
to_a[key]
|
86
|
-
when String, Symbol
|
87
|
-
send(key) if respond_to? key
|
88
|
-
else
|
89
|
-
raise ArgumentError, "Key must be a Fixnum (index) or a method name"
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
alias_method :to_dms, :to_s
|
94
|
-
|
95
|
-
def reverse_point!
|
96
|
-
self.lat = lat * -1
|
97
|
-
self.lng = lng * -1
|
98
|
-
self
|
99
|
-
end
|
100
|
-
|
101
|
-
def reverse_point
|
102
|
-
self.dup.reverse_point!
|
103
|
-
end
|
104
|
-
|
105
|
-
def to_lat_lng
|
106
|
-
[lat, lng]
|
107
|
-
end
|
108
|
-
|
109
|
-
def to_lng_lat
|
110
|
-
[lng, lat]
|
111
|
-
end
|
112
|
-
|
113
|
-
def to_a
|
114
|
-
send(:"to_#{coord_mode}")
|
115
|
-
end
|
116
|
-
|
117
|
-
protected
|
118
|
-
|
119
|
-
include ::GeoCalc::NumericCheckExt
|
120
|
-
|
121
|
-
def to_coords points
|
122
|
-
points.send(:"to_#{coord_mode}")
|
123
|
-
end
|
124
|
-
|
125
|
-
def create_from_one args
|
126
|
-
args = args.first
|
127
|
-
create_from_two *to_coords(args)
|
128
|
-
end
|
129
|
-
|
130
|
-
def create_from_two lat, lon
|
131
|
-
@lat = lat.to_lat
|
132
|
-
@lon = lon.to_lng
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|