geo_calc 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +7 -6
- data/VERSION +1 -1
- data/geo_calc.gemspec +9 -5
- data/lib/geo_calc/calc/bearing.rb +10 -9
- data/lib/geo_calc/calc/destination.rb +5 -5
- data/lib/geo_calc/calc/distance.rb +4 -4
- data/lib/geo_calc/calc/intersection.rb +2 -2
- data/lib/geo_calc/calc/midpoint.rb +1 -1
- data/lib/geo_calc/calc/rhumb.rb +3 -3
- data/lib/geo_calc/extensions/array.rb +1 -1
- data/lib/geo_calc/geo_calculations.rb +278 -0
- data/lib/geo_calc.rb +1 -0
- data/spec/geo_calc/calculations_spec.rb +1 -1
- metadata +37 -25
data/Gemfile
CHANGED
@@ -2,16 +2,17 @@ source "http://rubygems.org"
|
|
2
2
|
|
3
3
|
gem "require_all", "~> 1.2.0"
|
4
4
|
gem "sugar-high", "~> 0.4.6.3"
|
5
|
-
gem "geo_units", "
|
5
|
+
gem "geo_units", "~> 0.2.1"
|
6
6
|
gem 'i18n'
|
7
7
|
gem 'activesupport', '>= 3.0.1'
|
8
8
|
|
9
9
|
# Add dependencies to develop your gem here.
|
10
10
|
# Include everything needed to run rake, tests, features, etc.
|
11
11
|
group :development do
|
12
|
-
gem "
|
13
|
-
gem "
|
14
|
-
gem "
|
15
|
-
gem "
|
16
|
-
gem "
|
12
|
+
gem "geo_point", ">= 0.2.1"
|
13
|
+
gem "rspec", ">= 2.5.0"
|
14
|
+
gem "bundler", ">= 1"
|
15
|
+
gem "jeweler", ">= 1.5.2"
|
16
|
+
gem "rcov", ">= 0"
|
17
|
+
gem "rake", ">= 0.9"
|
17
18
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.7.
|
1
|
+
0.7.4
|
data/geo_calc.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{geo_calc}
|
8
|
-
s.version = "0.7.
|
8
|
+
s.version = "0.7.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Kristian Mandrup}]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-19}
|
13
13
|
s.description = %q{Geo calculations in ruby and javascript}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -39,6 +39,7 @@ Gem::Specification.new do |s|
|
|
39
39
|
"lib/geo_calc/extensions/hash.rb",
|
40
40
|
"lib/geo_calc/extensions/string.rb",
|
41
41
|
"lib/geo_calc/extensions/symbol.rb",
|
42
|
+
"lib/geo_calc/geo_calculations.rb",
|
42
43
|
"lib/geo_calc/pretty_print.rb",
|
43
44
|
"spec/geo_calc/calculations_spec.rb",
|
44
45
|
"spec/geo_calc/core_ext/array_ext_spec.rb",
|
@@ -62,9 +63,10 @@ Gem::Specification.new do |s|
|
|
62
63
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
63
64
|
s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
|
64
65
|
s.add_runtime_dependency(%q<sugar-high>, ["~> 0.4.6.3"])
|
65
|
-
s.add_runtime_dependency(%q<geo_units>, ["
|
66
|
+
s.add_runtime_dependency(%q<geo_units>, ["~> 0.2.1"])
|
66
67
|
s.add_runtime_dependency(%q<i18n>, [">= 0"])
|
67
68
|
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.1"])
|
69
|
+
s.add_development_dependency(%q<geo_point>, [">= 0.2.1"])
|
68
70
|
s.add_development_dependency(%q<rspec>, [">= 2.5.0"])
|
69
71
|
s.add_development_dependency(%q<bundler>, [">= 1"])
|
70
72
|
s.add_development_dependency(%q<jeweler>, [">= 1.5.2"])
|
@@ -73,9 +75,10 @@ Gem::Specification.new do |s|
|
|
73
75
|
else
|
74
76
|
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
75
77
|
s.add_dependency(%q<sugar-high>, ["~> 0.4.6.3"])
|
76
|
-
s.add_dependency(%q<geo_units>, ["
|
78
|
+
s.add_dependency(%q<geo_units>, ["~> 0.2.1"])
|
77
79
|
s.add_dependency(%q<i18n>, [">= 0"])
|
78
80
|
s.add_dependency(%q<activesupport>, [">= 3.0.1"])
|
81
|
+
s.add_dependency(%q<geo_point>, [">= 0.2.1"])
|
79
82
|
s.add_dependency(%q<rspec>, [">= 2.5.0"])
|
80
83
|
s.add_dependency(%q<bundler>, [">= 1"])
|
81
84
|
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
|
@@ -85,9 +88,10 @@ Gem::Specification.new do |s|
|
|
85
88
|
else
|
86
89
|
s.add_dependency(%q<require_all>, ["~> 1.2.0"])
|
87
90
|
s.add_dependency(%q<sugar-high>, ["~> 0.4.6.3"])
|
88
|
-
s.add_dependency(%q<geo_units>, ["
|
91
|
+
s.add_dependency(%q<geo_units>, ["~> 0.2.1"])
|
89
92
|
s.add_dependency(%q<i18n>, [">= 0"])
|
90
93
|
s.add_dependency(%q<activesupport>, [">= 3.0.1"])
|
94
|
+
s.add_dependency(%q<geo_point>, [">= 0.2.1"])
|
91
95
|
s.add_dependency(%q<rspec>, [">= 2.5.0"])
|
92
96
|
s.add_dependency(%q<bundler>, [">= 1"])
|
93
97
|
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
|
@@ -1,16 +1,17 @@
|
|
1
1
|
module GeoCalc
|
2
2
|
module Bearing
|
3
|
+
# @returns [Numeric] bearing in degrees
|
3
4
|
def bearing_to point
|
4
|
-
GeoCalc::
|
5
|
+
GeoCalc::Bearing.bearing_to self, point
|
5
6
|
end
|
6
7
|
|
7
8
|
# Returns the (initial) bearing from this point to the supplied point, in degrees
|
8
|
-
#
|
9
|
+
# see(http:#williams.best.vwh.net/avform.htm#Crs)
|
9
10
|
#
|
10
|
-
#
|
11
|
+
# @param [GeoPoint] Latitude/longitude of destination point
|
11
12
|
#
|
12
|
-
#
|
13
|
-
|
13
|
+
# @return [Numeric] initial bearing in degrees from North
|
14
|
+
#
|
14
15
|
def self.bearing_to base_point, point
|
15
16
|
lat1 = base_point.lat.to_rad
|
16
17
|
lat2 = point.lat.to_rad
|
@@ -24,16 +25,16 @@ module GeoCalc
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def final_bearing_to point
|
27
|
-
GeoCalc::
|
28
|
+
GeoCalc::Bearing.final_bearing_to self, point
|
28
29
|
end
|
29
30
|
|
30
31
|
# Returns final bearing arriving at supplied destination point from this point; the final bearing
|
31
32
|
# will differ from the initial bearing by varying degrees according to distance and latitude
|
32
33
|
#
|
33
|
-
#
|
34
|
+
# @param [GeoPoint] Latitude/longitude of destination point
|
35
|
+
#
|
36
|
+
# @return [Numeric] final bearing in degrees from North
|
34
37
|
#
|
35
|
-
# Returns Numeric: Final bearing in degrees from North
|
36
|
-
|
37
38
|
def self.final_bearing_to base_point, point
|
38
39
|
# get initial bearing from supplied point back to this point...
|
39
40
|
lat1 = point.lat.to_rad
|
@@ -1,17 +1,17 @@
|
|
1
1
|
module GeoCalc
|
2
2
|
module Destination
|
3
3
|
def destination_point brng, dist
|
4
|
-
GeoCalc::
|
4
|
+
GeoCalc::Destination.destination_point self, brng, dist
|
5
5
|
end
|
6
6
|
|
7
7
|
# Returns the destination point from this point having travelled the given distance (in km) on the
|
8
8
|
# given initial bearing (bearing may vary before destination is reached)
|
9
9
|
#
|
10
|
-
#
|
10
|
+
# see(http:#williams.best.vwh.net/avform.htm#LL)
|
11
11
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
12
|
+
# @param [Numeric] Initial bearing in degrees
|
13
|
+
# @param [Numeric] Distance in km
|
14
|
+
# @return [Array] Destination point
|
15
15
|
|
16
16
|
def self.destination_point base_point, brng, dist
|
17
17
|
dist = dist / base_point.earth_radius_km # convert dist to angular distance in radians
|
@@ -6,7 +6,7 @@
|
|
6
6
|
module GeoCalc
|
7
7
|
module Distance
|
8
8
|
def distance_to point, precision = 4
|
9
|
-
GeoCalc::
|
9
|
+
GeoCalc::Distance.distance_to self, point, precision
|
10
10
|
end
|
11
11
|
|
12
12
|
# Returns the distance from this point to the supplied point, in km
|
@@ -15,10 +15,10 @@ module GeoCalc
|
|
15
15
|
# from: Haversine formula - R. W. Sinnott, "Virtues of the Haversine",
|
16
16
|
# Sky and Telescope, vol 68, no 2, 1984
|
17
17
|
#
|
18
|
-
# GeoPoint
|
19
|
-
#
|
18
|
+
# @param [GeoPoint] Latitude/longitude of destination point
|
19
|
+
# @param [Numeric] number of significant digits to use for returned value
|
20
20
|
#
|
21
|
-
#
|
21
|
+
# @return [Numeric] distance in km between this point and destination point
|
22
22
|
|
23
23
|
def self.distance_to base_point, point, precision = 4
|
24
24
|
# default 4 sig figs reflects typical 0.3% accuracy of spherical model
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module GeoCalc
|
2
2
|
module Intersection
|
3
3
|
def intersection brng1, p2, brng2
|
4
|
-
GeoCalc::
|
4
|
+
GeoCalc::Intersection.intersection self, brng1, p2, brng2
|
5
5
|
end
|
6
6
|
|
7
7
|
# Returns the point of intersection of two paths defined by point and bearing
|
@@ -12,7 +12,7 @@ module GeoCalc
|
|
12
12
|
# @param [Number] brng1: Initial bearing from first point
|
13
13
|
# @param [GeoPoint] p2: Second point
|
14
14
|
# @param [Number] brng2: Initial bearing from second point
|
15
|
-
# @
|
15
|
+
# @return [Array] Destination point (null if no unique intersection defined)
|
16
16
|
|
17
17
|
def self.intersection p1, brng1, p2, brng2
|
18
18
|
lat1 = p1.lat.to_rad
|
data/lib/geo_calc/calc/rhumb.rb
CHANGED
@@ -7,7 +7,7 @@ module GeoCalc
|
|
7
7
|
# @param [GeoPoint] Destination point latitude and longitude of
|
8
8
|
# @return [Numeric] Distance in km between start and destination point
|
9
9
|
def rhumb_distance_to point
|
10
|
-
GeoCalc::
|
10
|
+
GeoCalc::Rhumb.rhumb_distance_to self, point
|
11
11
|
end
|
12
12
|
|
13
13
|
# Returns the distance from this point to the supplied point, in km, travelling along a rhumb line
|
@@ -45,7 +45,7 @@ module GeoCalc
|
|
45
45
|
# @return [Numeric] Bearing in degrees from North
|
46
46
|
#
|
47
47
|
def rhumb_bearing_to point
|
48
|
-
GeoCalc::
|
48
|
+
GeoCalc::Rhumb.rhumb_bearing_to self, point
|
49
49
|
end
|
50
50
|
# Returns the bearing from this point to the supplied point along a rhumb line, in degrees
|
51
51
|
#
|
@@ -75,7 +75,7 @@ module GeoCalc
|
|
75
75
|
# @param [Number] dist: Distance in km
|
76
76
|
# @returns [Array] Destination point as an array [lat, long]
|
77
77
|
def rhumb_destination_point brng, dist
|
78
|
-
GeoCalc::
|
78
|
+
GeoCalc::Rhumb.rhumb_destination_point self, brng, dist
|
79
79
|
end
|
80
80
|
|
81
81
|
# Returns the destination point from this point having travelled the given distance (in km) on the
|
@@ -0,0 +1,278 @@
|
|
1
|
+
module GeoCalculations
|
2
|
+
extend self
|
3
|
+
|
4
|
+
##
|
5
|
+
# Compass point names, listed clockwise starting at North.
|
6
|
+
#
|
7
|
+
# If you want bearings named using more, fewer, or different points
|
8
|
+
# override Geocoder::Calculations.COMPASS_POINTS with your own array.
|
9
|
+
#
|
10
|
+
COMPASS_POINTS = %w[N NE E SE S SW W NW]
|
11
|
+
|
12
|
+
##
|
13
|
+
# Radius of the Earth, in kilometers.
|
14
|
+
# Value taken from: http://en.wikipedia.org/wiki/Earth_radius
|
15
|
+
#
|
16
|
+
EARTH_RADIUS = 6371.0
|
17
|
+
|
18
|
+
##
|
19
|
+
# Conversion factor: multiply by kilometers to get miles.
|
20
|
+
#
|
21
|
+
KM_IN_MI = 0.621371192
|
22
|
+
|
23
|
+
##
|
24
|
+
# Distance spanned by one degree of latitude in the given units.
|
25
|
+
#
|
26
|
+
def latitude_degree_distance(units = :mi)
|
27
|
+
2 * Math::PI * earth_radius(units) / 360
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Distance spanned by one degree of longitude at the given latitude.
|
32
|
+
# This ranges from around 69 miles at the equator to zero at the poles.
|
33
|
+
#
|
34
|
+
def longitude_degree_distance(latitude, units = :mi)
|
35
|
+
latitude_degree_distance(units) * Math.cos(to_radians(latitude))
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Distance between two points on Earth (Haversine formula).
|
40
|
+
# Takes two points and an options hash.
|
41
|
+
# The points are given in the same way that points are given to all
|
42
|
+
# Geocoder methods that accept points as arguments. They can be:
|
43
|
+
#
|
44
|
+
# * an array of coordinates ([lat,lon])
|
45
|
+
# * a geocodable address (string)
|
46
|
+
# * a geocoded object (one which implements a +to_coordinates+ method
|
47
|
+
# which returns a [lat,lon] array
|
48
|
+
#
|
49
|
+
# The options hash supports:
|
50
|
+
#
|
51
|
+
# * <tt>:units</tt> - <tt>:mi</tt> (default) or <tt>:km</tt>
|
52
|
+
#
|
53
|
+
def distance_between(point1, point2, options = {})
|
54
|
+
|
55
|
+
# set default options
|
56
|
+
options[:units] ||= :mi
|
57
|
+
|
58
|
+
# convert to coordinate arrays
|
59
|
+
point1 = extract_coordinates(point1)
|
60
|
+
point2 = extract_coordinates(point2)
|
61
|
+
|
62
|
+
# convert degrees to radians
|
63
|
+
point1 = to_radians(point1)
|
64
|
+
point2 = to_radians(point2)
|
65
|
+
|
66
|
+
# compute deltas
|
67
|
+
dlat = point2[0] - point1[0]
|
68
|
+
dlon = point2[1] - point1[1]
|
69
|
+
|
70
|
+
a = (Math.sin(dlat / 2))**2 + Math.cos(point1[0]) *
|
71
|
+
(Math.sin(dlon / 2))**2 * Math.cos(point2[0])
|
72
|
+
c = 2 * Math.atan2( Math.sqrt(a), Math.sqrt(1-a))
|
73
|
+
c * earth_radius(options[:units])
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# Bearing between two points on Earth.
|
78
|
+
# Returns a number of degrees from due north (clockwise).
|
79
|
+
#
|
80
|
+
# See Geocoder::Calculations.distance_between for
|
81
|
+
# ways of specifying the points. Also accepts an options hash:
|
82
|
+
#
|
83
|
+
# * <tt>:method</tt> - <tt>:linear</tt> (default) or <tt>:spherical</tt>;
|
84
|
+
# the spherical method is "correct" in that it returns the shortest path
|
85
|
+
# (one along a great circle) but the linear method is the default as it
|
86
|
+
# is less confusing (returns due east or west when given two points with
|
87
|
+
# the same latitude)
|
88
|
+
#
|
89
|
+
# Based on: http://www.movable-type.co.uk/scripts/latlong.html
|
90
|
+
#
|
91
|
+
def bearing_between(point1, point2, options = {})
|
92
|
+
|
93
|
+
# set default options
|
94
|
+
options[:method] = :linear unless options[:method] == :spherical
|
95
|
+
|
96
|
+
# convert to coordinate arrays
|
97
|
+
point1 = extract_coordinates(point1)
|
98
|
+
point2 = extract_coordinates(point2)
|
99
|
+
|
100
|
+
# convert degrees to radians
|
101
|
+
point1 = to_radians(point1)
|
102
|
+
point2 = to_radians(point2)
|
103
|
+
|
104
|
+
# compute deltas
|
105
|
+
dlat = point2[0] - point1[0]
|
106
|
+
dlon = point2[1] - point1[1]
|
107
|
+
|
108
|
+
case options[:method]
|
109
|
+
when :linear
|
110
|
+
y = dlon
|
111
|
+
x = dlat
|
112
|
+
|
113
|
+
when :spherical
|
114
|
+
y = Math.sin(dlon) * Math.cos(point2[0])
|
115
|
+
x = Math.cos(point1[0]) * Math.sin(point2[0]) -
|
116
|
+
Math.sin(point1[0]) * Math.cos(point2[0]) * Math.cos(dlon)
|
117
|
+
end
|
118
|
+
|
119
|
+
bearing = Math.atan2(x,y)
|
120
|
+
# Answer is in radians counterclockwise from due east.
|
121
|
+
# Convert to degrees clockwise from due north:
|
122
|
+
(90 - to_degrees(bearing) + 360) % 360
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
# Translate a bearing (float) into a compass direction (string, eg "North").
|
127
|
+
#
|
128
|
+
def compass_point(bearing, points = COMPASS_POINTS)
|
129
|
+
seg_size = 360 / points.size
|
130
|
+
points[((bearing + (seg_size / 2)) % 360) / seg_size]
|
131
|
+
end
|
132
|
+
|
133
|
+
##
|
134
|
+
# Compute the geographic center (aka geographic midpoint, center of
|
135
|
+
# gravity) for an array of geocoded objects and/or [lat,lon] arrays
|
136
|
+
# (can be mixed). Any objects missing coordinates are ignored. Follows
|
137
|
+
# the procedure documented at http://www.geomidpoint.com/calculation.html.
|
138
|
+
#
|
139
|
+
def geographic_center(points)
|
140
|
+
|
141
|
+
# convert objects to [lat,lon] arrays and convert degrees to radians
|
142
|
+
coords = points.map{ |p| to_radians(extract_coordinates(p)) }
|
143
|
+
|
144
|
+
# convert to Cartesian coordinates
|
145
|
+
x = []; y = []; z = []
|
146
|
+
coords.each do |p|
|
147
|
+
x << Math.cos(p[0]) * Math.cos(p[1])
|
148
|
+
y << Math.cos(p[0]) * Math.sin(p[1])
|
149
|
+
z << Math.sin(p[0])
|
150
|
+
end
|
151
|
+
|
152
|
+
# compute average coordinate values
|
153
|
+
xa, ya, za = [x,y,z].map do |c|
|
154
|
+
c.inject(0){ |tot,i| tot += i } / c.size.to_f
|
155
|
+
end
|
156
|
+
|
157
|
+
# convert back to latitude/longitude
|
158
|
+
lon = Math.atan2(ya, xa)
|
159
|
+
hyp = Math.sqrt(xa**2 + ya**2)
|
160
|
+
lat = Math.atan2(za, hyp)
|
161
|
+
|
162
|
+
# return answer in degrees
|
163
|
+
to_degrees [lat, lon]
|
164
|
+
end
|
165
|
+
|
166
|
+
##
|
167
|
+
# Returns coordinates of the lower-left and upper-right corners of a box
|
168
|
+
# with the given point at its center. The radius is the shortest distance
|
169
|
+
# from the center point to any side of the box (the length of each side
|
170
|
+
# is twice the radius).
|
171
|
+
#
|
172
|
+
# This is useful for finding corner points of a map viewport, or for
|
173
|
+
# roughly limiting the possible solutions in a geo-spatial search
|
174
|
+
# (ActiveRecord queries use it thusly).
|
175
|
+
#
|
176
|
+
# See Geocoder::Calculations.distance_between for
|
177
|
+
# ways of specifying the point. Also accepts an options hash:
|
178
|
+
#
|
179
|
+
# * <tt>:units</tt> - <tt>:mi</tt> (default) or <tt>:km</tt>
|
180
|
+
#
|
181
|
+
def bounding_box(point, radius, options = {})
|
182
|
+
lat,lon = extract_coordinates(point)
|
183
|
+
radius = radius.to_f
|
184
|
+
units = options[:units] || :mi
|
185
|
+
[
|
186
|
+
lat - (radius / latitude_degree_distance(units)),
|
187
|
+
lon - (radius / longitude_degree_distance(lat, units)),
|
188
|
+
lat + (radius / latitude_degree_distance(units)),
|
189
|
+
lon + (radius / longitude_degree_distance(lat, units))
|
190
|
+
]
|
191
|
+
end
|
192
|
+
|
193
|
+
##
|
194
|
+
# Convert degrees to radians.
|
195
|
+
# If an array (or multiple arguments) is passed,
|
196
|
+
# converts each value and returns array.
|
197
|
+
#
|
198
|
+
def to_radians(*args)
|
199
|
+
args = args.first if args.first.is_a?(Array)
|
200
|
+
if args.size == 1
|
201
|
+
args.first * (Math::PI / 180)
|
202
|
+
else
|
203
|
+
args.map{ |i| to_radians(i) }
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
##
|
208
|
+
# Convert radians to degrees.
|
209
|
+
# If an array (or multiple arguments) is passed,
|
210
|
+
# converts each value and returns array.
|
211
|
+
#
|
212
|
+
def to_degrees(*args)
|
213
|
+
args = args.first if args.first.is_a?(Array)
|
214
|
+
if args.size == 1
|
215
|
+
(args.first * 180.0) / Math::PI
|
216
|
+
else
|
217
|
+
args.map{ |i| to_degrees(i) }
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def distance_to_radians(distance, units = :mi)
|
222
|
+
distance.to_f / earth_radius(units)
|
223
|
+
end
|
224
|
+
|
225
|
+
def radians_to_distance(radians, units = :mi)
|
226
|
+
radians * earth_radius(units)
|
227
|
+
end
|
228
|
+
|
229
|
+
##
|
230
|
+
# Convert miles to kilometers.
|
231
|
+
#
|
232
|
+
def to_kilometers(mi)
|
233
|
+
mi * mi_in_km
|
234
|
+
end
|
235
|
+
|
236
|
+
##
|
237
|
+
# Convert kilometers to miles.
|
238
|
+
#
|
239
|
+
def to_miles(km)
|
240
|
+
km * km_in_mi
|
241
|
+
end
|
242
|
+
|
243
|
+
##
|
244
|
+
# Radius of the Earth in the given units (:mi or :km). Default is :mi.
|
245
|
+
#
|
246
|
+
def earth_radius(units = :mi)
|
247
|
+
units == :km ? EARTH_RADIUS : to_miles(EARTH_RADIUS)
|
248
|
+
end
|
249
|
+
|
250
|
+
##
|
251
|
+
# Conversion factor: km to mi.
|
252
|
+
#
|
253
|
+
def km_in_mi
|
254
|
+
KM_IN_MI
|
255
|
+
end
|
256
|
+
|
257
|
+
##
|
258
|
+
# Conversion factor: mi to km.
|
259
|
+
#
|
260
|
+
def mi_in_km
|
261
|
+
1.0 / KM_IN_MI
|
262
|
+
end
|
263
|
+
|
264
|
+
##
|
265
|
+
# Takes an object which is a [lat,lon] array, a geocodable string,
|
266
|
+
# or an object that implements +to_coordinates+ and returns a
|
267
|
+
# [lat,lon] array. Note that if a string is passed this may be a slow-
|
268
|
+
# running method and may return nil.
|
269
|
+
#
|
270
|
+
def extract_coordinates(point)
|
271
|
+
case point
|
272
|
+
when Array; point
|
273
|
+
when String; Geocoder.coordinates(point)
|
274
|
+
else point.to_coordinates
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
data/lib/geo_calc.rb
CHANGED
@@ -96,7 +96,7 @@ describe GeoCalc do
|
|
96
96
|
# Intersection point: 50°54′06″N, 004°29′39″E
|
97
97
|
describe '#intersection' do
|
98
98
|
it 'should return the intersection between p1 and p2 as (50 54 06 N, 004 29 39 E)' do
|
99
|
-
GeoCalc::
|
99
|
+
GeoCalc::Intersection.intersection(@p1, @brng1, @p2, @brng2).to_dms.should match /50.+54.+06.+N, 004.+29.+39.+E/
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
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.4
|
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-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: require_all
|
16
|
-
requirement: &
|
16
|
+
requirement: &2164287640 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.2.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2164287640
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sugar-high
|
27
|
-
requirement: &
|
27
|
+
requirement: &2164286840 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,21 +32,21 @@ dependencies:
|
|
32
32
|
version: 0.4.6.3
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2164286840
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: geo_units
|
38
|
-
requirement: &
|
38
|
+
requirement: &2164286060 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ~>
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 0.2.
|
43
|
+
version: 0.2.1
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2164286060
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: i18n
|
49
|
-
requirement: &
|
49
|
+
requirement: &2164285160 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2164285160
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: activesupport
|
60
|
-
requirement: &
|
60
|
+
requirement: &2164284460 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,21 @@ dependencies:
|
|
65
65
|
version: 3.0.1
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2164284460
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: geo_point
|
71
|
+
requirement: &2164283680 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.2.1
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2164283680
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: rspec
|
71
|
-
requirement: &
|
82
|
+
requirement: &2164282980 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ! '>='
|
@@ -76,10 +87,10 @@ dependencies:
|
|
76
87
|
version: 2.5.0
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *2164282980
|
80
91
|
- !ruby/object:Gem::Dependency
|
81
92
|
name: bundler
|
82
|
-
requirement: &
|
93
|
+
requirement: &2164282340 !ruby/object:Gem::Requirement
|
83
94
|
none: false
|
84
95
|
requirements:
|
85
96
|
- - ! '>='
|
@@ -87,10 +98,10 @@ dependencies:
|
|
87
98
|
version: '1'
|
88
99
|
type: :development
|
89
100
|
prerelease: false
|
90
|
-
version_requirements: *
|
101
|
+
version_requirements: *2164282340
|
91
102
|
- !ruby/object:Gem::Dependency
|
92
103
|
name: jeweler
|
93
|
-
requirement: &
|
104
|
+
requirement: &2162210200 !ruby/object:Gem::Requirement
|
94
105
|
none: false
|
95
106
|
requirements:
|
96
107
|
- - ! '>='
|
@@ -98,10 +109,10 @@ dependencies:
|
|
98
109
|
version: 1.5.2
|
99
110
|
type: :development
|
100
111
|
prerelease: false
|
101
|
-
version_requirements: *
|
112
|
+
version_requirements: *2162210200
|
102
113
|
- !ruby/object:Gem::Dependency
|
103
114
|
name: rcov
|
104
|
-
requirement: &
|
115
|
+
requirement: &2162209620 !ruby/object:Gem::Requirement
|
105
116
|
none: false
|
106
117
|
requirements:
|
107
118
|
- - ! '>='
|
@@ -109,10 +120,10 @@ dependencies:
|
|
109
120
|
version: '0'
|
110
121
|
type: :development
|
111
122
|
prerelease: false
|
112
|
-
version_requirements: *
|
123
|
+
version_requirements: *2162209620
|
113
124
|
- !ruby/object:Gem::Dependency
|
114
125
|
name: rake
|
115
|
-
requirement: &
|
126
|
+
requirement: &2162209080 !ruby/object:Gem::Requirement
|
116
127
|
none: false
|
117
128
|
requirements:
|
118
129
|
- - ! '>='
|
@@ -120,7 +131,7 @@ dependencies:
|
|
120
131
|
version: '0.9'
|
121
132
|
type: :development
|
122
133
|
prerelease: false
|
123
|
-
version_requirements: *
|
134
|
+
version_requirements: *2162209080
|
124
135
|
description: Geo calculations in ruby and javascript
|
125
136
|
email: kmandrup@gmail.com
|
126
137
|
executables: []
|
@@ -151,6 +162,7 @@ files:
|
|
151
162
|
- lib/geo_calc/extensions/hash.rb
|
152
163
|
- lib/geo_calc/extensions/string.rb
|
153
164
|
- lib/geo_calc/extensions/symbol.rb
|
165
|
+
- lib/geo_calc/geo_calculations.rb
|
154
166
|
- lib/geo_calc/pretty_print.rb
|
155
167
|
- spec/geo_calc/calculations_spec.rb
|
156
168
|
- spec/geo_calc/core_ext/array_ext_spec.rb
|
@@ -176,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
176
188
|
version: '0'
|
177
189
|
segments:
|
178
190
|
- 0
|
179
|
-
hash: -
|
191
|
+
hash: -3260923342157281303
|
180
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
193
|
none: false
|
182
194
|
requirements:
|