geo_calc 0.7.1 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. data/Gemfile +4 -1
  2. data/README.textile +8 -59
  3. data/VERSION +1 -1
  4. data/geo_calc.gemspec +15 -22
  5. data/lib/geo_calc/calc/bearing.rb +1 -1
  6. data/lib/geo_calc/calc/destination.rb +3 -2
  7. data/lib/geo_calc/calc/distance.rb +1 -1
  8. data/lib/geo_calc/calc/intersection.rb +8 -8
  9. data/lib/geo_calc/calc/midpoint.rb +8 -6
  10. data/lib/geo_calc/calc/rhumb.rb +35 -16
  11. data/lib/geo_calc/calc.rb +15 -21
  12. data/lib/geo_calc/extensions/array.rb +1 -3
  13. data/lib/geo_calc/extensions/hash.rb +1 -3
  14. data/lib/geo_calc/extensions/string.rb +8 -17
  15. data/lib/geo_calc/extensions.rb +0 -1
  16. data/lib/geo_calc/pretty_print.rb +14 -14
  17. data/lib/geo_calc.rb +7 -4
  18. data/spec/geo_calc/calculations_spec.rb +2 -1
  19. data/spec/geo_calc/core_ext/array_ext_spec.rb +1 -9
  20. data/spec/geo_calc/core_ext/hash_ext_spec.rb +3 -9
  21. data/spec/geo_calc/core_ext/string_ext_spec.rb +1 -9
  22. data/spec/geo_calc/core_ext_spec.rb +1 -7
  23. data/spec/geo_calc/include_apis_spec.rb +32 -0
  24. data/spec/spec_helper.rb +13 -5
  25. metadata +52 -35
  26. data/lib/geo_calc/dms/converter.rb +0 -106
  27. data/lib/geo_calc/dms.rb +0 -5
  28. data/lib/geo_calc/extensions/math.rb +0 -6
  29. data/lib/geo_calc/extensions/numeric.rb +0 -24
  30. data/lib/geo_calc/geo_point/class_methods.rb +0 -15
  31. data/lib/geo_calc/geo_point/core_extension.rb +0 -11
  32. data/lib/geo_calc/geo_point/shared.rb +0 -29
  33. data/lib/geo_calc/geo_point.rb +0 -135
  34. data/lib/geo_units/converter.rb +0 -123
  35. data/lib/geo_units/numeric_ext.rb +0 -117
  36. data/lib/geo_units.rb +0 -21
  37. data/spec/geo_calc/dms/converter_spec.rb +0 -60
  38. data/spec/geo_calc/geo_point/class_methods_spec.rb +0 -31
  39. data/spec/geo_calc/geo_point/initializer_spec.rb +0 -148
  40. data/spec/geo_calc/geo_point/lat_lon.rb +0 -115
  41. data/spec/geo_calc/geo_point_spec.rb +0 -99
  42. data/spec/geo_units/converter_spec.rb +0 -57
data/Gemfile CHANGED
@@ -1,7 +1,10 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem "require_all", "~> 1.2.0"
4
- gem "sugar-high", "~> 0.4.5.2"
4
+ gem "sugar-high", "~> 0.4.6.3"
5
+ gem "geo_units", ">= 0.2.0"
6
+ gem 'i18n'
7
+ gem 'activesupport', '>= 3.0.1'
5
8
 
6
9
  # Add dependencies to develop your gem here.
7
10
  # Include everything needed to run rake, tests, features, etc.
data/README.textile CHANGED
@@ -2,17 +2,12 @@ h1. Geo calculations
2
2
 
3
3
  Geo Calculation library. Useful functions to add to your geo arsenal, fx when designing your own Geo library.
4
4
 
5
- h2. Status update (June 10, 2011)
5
+ h2. Status update (June 14, 2011)
6
6
 
7
- - Major refactoring splitting into more logical file/modular structure
8
- - Use autoload
9
- - Extract GeoUnits
10
- - Extract Dms with converter
11
- - GeoPoint can now have set :coords_mode which affects how Ruby Core objects such as String and Array are parsed into :lng and :lat.
7
+ Extracted GeoUnits and GeoPoint into separate gems:
12
8
 
13
- TODO:
14
- - The GeoPoint class should be extracted into separate gem, then this geo_calc gem should only have the more generic geo functionality as modules to be included
15
- where needed in other gems!
9
+ * "geo_units":https://github.com/kristianmandrup/geo_units
10
+ * "geo_point":https://github.com/kristianmandrup/geo_point
16
11
 
17
12
  h2. Install
18
13
 
@@ -28,46 +23,14 @@ From command line, run bundler
28
23
 
29
24
  @$ bundle@
30
25
 
31
- h2. Objetive
26
+ h2. Objective
32
27
 
33
28
  The objective of this library is to act as a base for other geo libraries.
34
29
 
35
- Please take a look at "geo vectors":https://github.com/kristianmandrup/geo_vectors which builds on _geo calc_ and provides various vector operations on geo points.
36
- I also have plans to include _geo calc_ in "mongoid geo":https://github.com/kristianmandrup/mongoid_geo, the geo extension library for _Mongoid 2_.
30
+ The geo calculation API only requires that the point objects used, have a #lat and #lon method, which return the latitude and longitude respectively.
31
+ The lat/lng should each be a Numeric (ie. Float or Fixnum) within respective 'geo ranges': (-90 to 90, -180 to 180).
37
32
 
38
- h2. Quick start (Usage)
39
-
40
- First define the points on the globe you want to work with.
41
- The GeoPoint initializer is very flexible with regards to the arguments it can handle.
42
-
43
- <pre>
44
- # factory method on core ruby classes
45
- "51 12 03 N, 24 10 02 E".geo_point
46
- [51.5136, -0.0983].geo_point
47
- {:latitude => 27.3, :longitude => "24 10 02 E"}.geo_point
48
-
49
- # two arguments
50
- p1 = GeoPoint.new 51.5136, -0.0983
51
- p2 = GeoPoint.new "14 11 01 N", "-0.0983"
52
- p3 = GeoPoint.new 51.5136, "24 10 02 E"
53
-
54
- # a String
55
- p1 = GeoPoint.new "51.5136, -0.0983"
56
- p1 = GeoPoint.new "51.5136, 24 10 02 E"
57
- p3 = GeoPoint.new "51.4778, -0.0015"
58
- p1 = GeoPoint.new "51 12 03 N, 24 10 02 E"
59
-
60
- # an Array
61
- p2 = GeoPoint.new [51.5136, -0.0983]
62
- p2 = GeoPoint.new [51.5136, "24 10 02 E"]
63
- p2 = GeoPoint.new [51.5136, {:lon => 27.3}]
64
-
65
- # a Hash
66
- p4 = GeoPoint.new {:lat => 27.3, :lng => "24 10 02 E"}
67
- p4 = GeoPoint.new {:latitude => 27.3, :longitude => "24 10 02 E"}
68
- </pre>
69
-
70
- h3. Shortes distance
33
+ h3. Shortest distance
71
34
 
72
35
  Calculate *distance in kms between points p1 and p2*
73
36
 
@@ -129,20 +92,6 @@ h2. Rhumb lines
129
92
  p1.rhumb_destination_point(brng, dist)
130
93
  </pre>
131
94
 
132
- h2. Utility methods
133
-
134
- These are some of the utility methods you can use on a GeoPoint object
135
-
136
- <pre>
137
- p1 = GeoPoint.new 5.1, -7
138
- p1.lat # latitude
139
- p1.lon # longitude
140
- p1.to_arr # array representation of [lat, lng]
141
- p1.reverse_arr! # reverse to_arr to instead return [lng, lat]
142
- p1.normal_arr! # return to normal to_arr functionality: [lat, lng]
143
- p1.to_s # string representation
144
- </pre>
145
-
146
95
  h2. Core Extensions
147
96
 
148
97
  The library also extends core Ruby classes with geo related functions (see _core_ext_spec.rb_)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.1
1
+ 0.7.3
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.1"
8
+ s.version = "0.7.3"
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-11}
12
+ s.date = %q{2011-06-13}
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 = [
@@ -34,35 +34,19 @@ Gem::Specification.new do |s|
34
34
  "lib/geo_calc/calc/intersection.rb",
35
35
  "lib/geo_calc/calc/midpoint.rb",
36
36
  "lib/geo_calc/calc/rhumb.rb",
37
- "lib/geo_calc/dms.rb",
38
- "lib/geo_calc/dms/converter.rb",
39
37
  "lib/geo_calc/extensions.rb",
40
38
  "lib/geo_calc/extensions/array.rb",
41
39
  "lib/geo_calc/extensions/hash.rb",
42
- "lib/geo_calc/extensions/math.rb",
43
- "lib/geo_calc/extensions/numeric.rb",
44
40
  "lib/geo_calc/extensions/string.rb",
45
41
  "lib/geo_calc/extensions/symbol.rb",
46
- "lib/geo_calc/geo_point.rb",
47
- "lib/geo_calc/geo_point/class_methods.rb",
48
- "lib/geo_calc/geo_point/core_extension.rb",
49
- "lib/geo_calc/geo_point/shared.rb",
50
42
  "lib/geo_calc/pretty_print.rb",
51
- "lib/geo_units.rb",
52
- "lib/geo_units/converter.rb",
53
- "lib/geo_units/numeric_ext.rb",
54
43
  "spec/geo_calc/calculations_spec.rb",
55
44
  "spec/geo_calc/core_ext/array_ext_spec.rb",
56
45
  "spec/geo_calc/core_ext/hash_ext_spec.rb",
57
46
  "spec/geo_calc/core_ext/numeric_geo_ext_spec.rb",
58
47
  "spec/geo_calc/core_ext/string_ext_spec.rb",
59
48
  "spec/geo_calc/core_ext_spec.rb",
60
- "spec/geo_calc/dms/converter_spec.rb",
61
- "spec/geo_calc/geo_point/class_methods_spec.rb",
62
- "spec/geo_calc/geo_point/initializer_spec.rb",
63
- "spec/geo_calc/geo_point/lat_lon.rb",
64
- "spec/geo_calc/geo_point_spec.rb",
65
- "spec/geo_units/converter_spec.rb",
49
+ "spec/geo_calc/include_apis_spec.rb",
66
50
  "spec/spec_helper.rb",
67
51
  "vendor/assets/javascript/geo_calc.js"
68
52
  ]
@@ -77,7 +61,10 @@ Gem::Specification.new do |s|
77
61
 
78
62
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
79
63
  s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
80
- s.add_runtime_dependency(%q<sugar-high>, ["~> 0.4.5.2"])
64
+ s.add_runtime_dependency(%q<sugar-high>, ["~> 0.4.6.3"])
65
+ s.add_runtime_dependency(%q<geo_units>, [">= 0.2.0"])
66
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
67
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.0.1"])
81
68
  s.add_development_dependency(%q<rspec>, [">= 2.5.0"])
82
69
  s.add_development_dependency(%q<bundler>, [">= 1"])
83
70
  s.add_development_dependency(%q<jeweler>, [">= 1.5.2"])
@@ -85,7 +72,10 @@ Gem::Specification.new do |s|
85
72
  s.add_development_dependency(%q<rake>, [">= 0.9"])
86
73
  else
87
74
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
88
- s.add_dependency(%q<sugar-high>, ["~> 0.4.5.2"])
75
+ s.add_dependency(%q<sugar-high>, ["~> 0.4.6.3"])
76
+ s.add_dependency(%q<geo_units>, [">= 0.2.0"])
77
+ s.add_dependency(%q<i18n>, [">= 0"])
78
+ s.add_dependency(%q<activesupport>, [">= 3.0.1"])
89
79
  s.add_dependency(%q<rspec>, [">= 2.5.0"])
90
80
  s.add_dependency(%q<bundler>, [">= 1"])
91
81
  s.add_dependency(%q<jeweler>, [">= 1.5.2"])
@@ -94,7 +84,10 @@ Gem::Specification.new do |s|
94
84
  end
95
85
  else
96
86
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
97
- s.add_dependency(%q<sugar-high>, ["~> 0.4.5.2"])
87
+ s.add_dependency(%q<sugar-high>, ["~> 0.4.6.3"])
88
+ s.add_dependency(%q<geo_units>, [">= 0.2.0"])
89
+ s.add_dependency(%q<i18n>, [">= 0"])
90
+ s.add_dependency(%q<activesupport>, [">= 3.0.1"])
98
91
  s.add_dependency(%q<rspec>, [">= 2.5.0"])
99
92
  s.add_dependency(%q<bundler>, [">= 1"])
100
93
  s.add_dependency(%q<jeweler>, [">= 1.5.2"])
@@ -1,4 +1,4 @@
1
- module GeoCalc::Calc
1
+ module GeoCalc
2
2
  module Bearing
3
3
  def bearing_to point
4
4
  GeoCalc::Calc::Bearing.bearing_to self, point
@@ -1,4 +1,4 @@
1
- module GeoCalc::Calc
1
+ module GeoCalc
2
2
  module Destination
3
3
  def destination_point brng, dist
4
4
  GeoCalc::Calc::Destination.destination_point self, brng, dist
@@ -24,7 +24,8 @@ module GeoCalc::Calc
24
24
 
25
25
  lon2 = (lon2 + 3*Math::PI) % (2*Math::PI) - Math::PI # normalise to -180...+180
26
26
 
27
- GeoPoint.new lat2.to_deg, lon2.to_deg
27
+ [lat2.to_deg, lon2.to_deg]
28
+ # GeoPoint.new lat2.to_deg, lon2.to_deg
28
29
  end
29
30
  end
30
31
  end
@@ -3,7 +3,7 @@
3
3
  # - www.movable-type.co.uk/scripts/latlong.html
4
4
  #
5
5
 
6
- module GeoCalc::Calc
6
+ module GeoCalc
7
7
  module Distance
8
8
  def distance_to point, precision = 4
9
9
  GeoCalc::Calc::Distance.distance_to self, point, precision
@@ -1,4 +1,4 @@
1
- module GeoCalc::Calc
1
+ module GeoCalc
2
2
  module Intersection
3
3
  def intersection brng1, p2, brng2
4
4
  GeoCalc::Calc::Intersection.intersection self, brng1, p2, brng2
@@ -8,11 +8,11 @@ module GeoCalc::Calc
8
8
  #
9
9
  # see http:#williams.best.vwh.net/avform.htm#Intersection
10
10
  #
11
- # @param {LatLon} p1: First point
12
- # @param {Number} brng1: Initial bearing from first point
13
- # @param {LatLon} p2: Second point
14
- # @param {Number} brng2: Initial bearing from second point
15
- # @returns {LatLon} Destination point (null if no unique intersection defined)
11
+ # @param [GeoPoint] p1: First point
12
+ # @param [Number] brng1: Initial bearing from first point
13
+ # @param [GeoPoint] p2: Second point
14
+ # @param [Number] brng2: Initial bearing from second point
15
+ # @returns [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
@@ -66,7 +66,7 @@ module GeoCalc::Calc
66
66
  lon3 = lon1 + dlon13;
67
67
  lon3 = (lon3 + Math::PI) % (2*Math::PI) - Math::PI # normalise to -180..180º
68
68
 
69
- GeoPoint.new lat3.to_deg, lon3.to_deg
70
- end
69
+ [lat3.to_deg, lon3.to_deg]
70
+ end
71
71
  end
72
72
  end
@@ -1,15 +1,16 @@
1
- module GeoCalc::Calc
1
+ module GeoCalc
2
2
  module Midpoint
3
3
  def midpoint_to point
4
4
  GeoCalc::Calc::Midpoint.midpoint_to self, point
5
5
  end
6
6
 
7
7
  # Returns the midpoint between this point and the supplied point.
8
- # see http:#mathforum.org/library/drmath/view/51822.html for derivation
8
+ # see(http:#mathforum.org/library/drmath/view/51822.html for derivation)
9
9
  #
10
- # - GeoPoint point: Latitude/longitude of destination point
11
- # Returns GeoPoint: Midpoint between this point and the supplied point
12
-
10
+ # @param [GeoPoint] base_point: Starting point (latitude, longitude)
11
+ # @param [GeoPoint] point: Destination point (latitude, longitude)
12
+ # @return [Array] Midpoint between this point and the supplied point
13
+ #
13
14
  def self.midpoint_to base_point, point
14
15
  lat1 = base_point.lat.to_rad
15
16
  lon1 = base_point.lon.to_rad;
@@ -23,7 +24,8 @@ module GeoCalc::Calc
23
24
 
24
25
  lon3 = lon1 + Math.atan2(by, Math.cos(lat1) + bx)
25
26
 
26
- GeoPoint.new lat3.to_deg, lon3.to_deg
27
+ [lat3.to_deg, lon3.to_deg]
28
+ # GeoPoint.new
27
29
  end
28
30
  end
29
31
  end
@@ -1,16 +1,21 @@
1
- module GeoCalc::Calc
1
+ module GeoCalc
2
2
  module Rhumb
3
+ # Returns the distance from this point to the supplied point, in km, travelling along a rhumb line
4
+ #
5
+ # see(http:#williams.best.vwh.net/avform.htm#Rhumb)
6
+ #
7
+ # @param [GeoPoint] Destination point latitude and longitude of
8
+ # @return [Numeric] Distance in km between start and destination point
3
9
  def rhumb_distance_to point
4
10
  GeoCalc::Calc::Rhumb.rhumb_distance_to self, point
5
11
  end
6
12
 
7
13
  # Returns the distance from this point to the supplied point, in km, travelling along a rhumb line
8
- #
9
- # see http:#williams.best.vwh.net/avform.htm#Rhumb
10
- #
11
- # - GeoPoint point: Latitude/longitude of destination point
12
- # Returns Numeric: Distance in km between this point and destination point
13
-
14
+ #
15
+ # @param [GeoPoint] Start point with (latitude, longitude)
16
+ # @param [GeoPoint] Destination point (latitude, longitude)
17
+ # @return [Numeric] Distance in km between start and destination point
18
+ #
14
19
  def self.rhumb_distance_to base_point, point
15
20
  lat1 = base_point.lat.to_rad
16
21
  lat2 = point.lat.to_rad
@@ -34,14 +39,19 @@ module GeoCalc::Calc
34
39
  dist.round(4) # 4 sig figures reflects typical 0.3% accuracy of spherical model
35
40
  end
36
41
 
42
+ # Returns the bearing from this point to the supplied point along a rhumb line, in degrees
43
+ #
44
+ # @param [GeoPoint] Destination point (latitude, longitude)
45
+ # @return [Numeric] Bearing in degrees from North
46
+ #
37
47
  def rhumb_bearing_to point
38
48
  GeoCalc::Calc::Rhumb.rhumb_bearing_to self, point
39
49
  end
40
50
  # Returns the bearing from this point to the supplied point along a rhumb line, in degrees
41
51
  #
42
- # - GeoPoint point: Latitude/longitude of destination point
43
- # Returns Numeric: Bearing in degrees from North
44
-
52
+ # @param [GeoPoint] Destination point (latitude, longitude)
53
+ # @return [Numeric] Bearing in degrees from North
54
+ #
45
55
  def self.rhumb_bearing_to base_point, point
46
56
  lat1 = base_point.lat.to_rad
47
57
  lat2 = point.lat.to_rad
@@ -58,16 +68,24 @@ module GeoCalc::Calc
58
68
  (brng.to_deg+360) % 360
59
69
  end
60
70
 
71
+ # Returns the destination point from this point having travelled the given distance (in km) on the
72
+ # given bearing along a rhumb line
73
+ #
74
+ # @param [Number] brng: Bearing in degrees from North
75
+ # @param [Number] dist: Distance in km
76
+ # @returns [Array] Destination point as an array [lat, long]
61
77
  def rhumb_destination_point brng, dist
62
78
  GeoCalc::Calc::Rhumb.rhumb_destination_point self, brng, dist
63
79
  end
80
+
64
81
  # Returns the destination point from this point having travelled the given distance (in km) on the
65
82
  # given bearing along a rhumb line
66
- #
67
- # @param {Number} brng: Bearing in degrees from North
68
- # @param {Number} dist: Distance in km
69
- # @returns {LatLon} Destination point
70
-
83
+ #
84
+ # @param [GeoPoint] Starting point (latitude, longitude)
85
+ # @param [Number] brng: Bearing in degrees from North
86
+ # @param [Number] dist: Distance in km
87
+ # @returns [Array] Destination point as an array [lat, long]
88
+ #
71
89
  def self.rhumb_destination_point base_point, brng, dist
72
90
  d = dist / base_point.earth_radius_km # d = angular distance covered on earth's surface
73
91
  lat1 = base_point.lat.to_rad
@@ -92,7 +110,8 @@ module GeoCalc::Calc
92
110
  end
93
111
  lon2 = (lon1+dlon+3*Math::PI) % (2*Math::PI) - Math::PI
94
112
 
95
- GeoPoint.new lat2.to_deg, lon2.to_deg
113
+ [lat2.to_deg, lon2.to_deg]
114
+ # GeoPoint.new
96
115
  end
97
116
  end
98
117
  end
data/lib/geo_calc/calc.rb CHANGED
@@ -1,26 +1,20 @@
1
- module GeoCalc
2
- autoload :PrettyPrint, 'geo_calc/pretty_print'
3
- end
1
+ require 'active_support/inflector'
4
2
 
5
3
  module GeoCalc
6
- module Calc
7
- autoload :Bearing, 'geo_calc/calc/bearing'
8
- autoload :Destination, 'geo_calc/calc/destination'
9
- autoload :Distance, 'geo_calc/calc/distance'
10
- autoload :Intersection, 'geo_calc/calc/intersection'
11
- autoload :Midpoint, 'geo_calc/calc/midpoint'
12
- autoload :Rhumb, 'geo_calc/calc/rhumb'
4
+ autoload :Bearing, 'geo_calc/calc/bearing'
5
+ autoload :Destination, 'geo_calc/calc/destination'
6
+ autoload :Distance, 'geo_calc/calc/distance'
7
+ autoload :Intersection, 'geo_calc/calc/intersection'
8
+ autoload :Midpoint, 'geo_calc/calc/midpoint'
9
+ autoload :Rhumb, 'geo_calc/calc/rhumb'
10
+
11
+ def self.included base
12
+ apis.each do |api|
13
+ base.send :include, "GeoCalc::#{api}".constantize
14
+ end
15
+ end
13
16
 
14
- module All
15
- def self.included base
16
- base.send :include, GeoCalc::Calc::Bearing
17
- base.send :include, GeoCalc::Calc::Destination
18
- base.send :include, GeoCalc::Calc::Distance
19
- base.send :include, GeoCalc::Calc::Intersection
20
- base.send :include, GeoCalc::Calc::Midpoint
21
- base.send :include, GeoCalc::Calc::Rhumb
22
- base.send :include, GeoCalc::PrettyPrint
23
- end
24
- end
17
+ def self.apis
18
+ [:Bearing, :Destination, :Distance, :Intersection, :Midpoint, :Rhumb]
25
19
  end
26
20
  end
@@ -1,6 +1,4 @@
1
- class Array
2
- include ::GeoPoint::CoreExtension
3
-
1
+ class Array
4
2
  def to_lat_lng
5
3
  raise "Array must contain at least two elements to be converted to latitude and longitude" if !(size >= 2)
6
4
  [to_lat, to_lng]
@@ -1,6 +1,4 @@
1
- class Hash
2
- include GeoPoint::CoreExtension
3
-
1
+ class Hash
4
2
  def to_lat_lng
5
3
  [to_lat, to_lng]
6
4
  end
@@ -1,17 +1,4 @@
1
1
  class String
2
- include ::GeoPoint::CoreExtension
3
-
4
- def concat *args
5
- args.inject(self) do |res, arg|
6
- res << arg.to_s
7
- res
8
- end
9
- end
10
-
11
- def parse_dms
12
- GeoCalc::Dms::Converter.parse_dms self
13
- end
14
-
15
2
  def to_rad
16
3
  parse_dms.to_rad
17
4
  end
@@ -33,12 +20,16 @@ class String
33
20
  end
34
21
 
35
22
  def to_lat
36
- raise "An empty String has no latitude" if empty?
37
- geo_clean.parse_dms.to_f.to_lat
23
+ raise "An empty String has no latitude" if self.empty?
24
+ s = geo_clean
25
+ s = s.parse_dms if s.respond_to? :parse_dms
26
+ s.to_f.to_lat
38
27
  end
39
28
 
40
29
  def to_lng
41
- raise "An empty String has no latitude" if empty?
42
- geo_clean.parse_dms.to_f.to_lng
30
+ raise "An empty String has no latitude" if self.empty?
31
+ s = geo_clean
32
+ s = s.parse_dms if s.respond_to? :parse_dms
33
+ s.to_f.to_lng
43
34
  end
44
35
  end
@@ -1,4 +1,3 @@
1
1
  require 'require_all'
2
- require 'geo_calc/geo_point/core_extension'
3
2
 
4
3
  require_all File.dirname(__FILE__) + '/extensions'
@@ -1,41 +1,41 @@
1
+ require 'geo_units'
2
+
1
3
  module GeoCalc
2
4
  module PrettyPrint
5
+
3
6
  # Returns the latitude of this point; signed numeric degrees if no format, otherwise format & dp
4
- # as per Geo.to_lat
5
7
  #
6
- # - String [format]: Return value as 'd', 'dm', 'dms'
7
- # - Numeric [dp=0|2|4]: No of decimal places to display
8
+ # @param [String] format: Return value as 'd', 'dm', 'dms'
9
+ # @param [Numeric] dp: No of decimal places to display (0|2|4)
8
10
  #
9
- # Returns {Numeric|String}: Numeric degrees if no format specified, otherwise deg/min/sec
11
+ # @return [Numeric|String]: Numeric degrees if no format specified, otherwise deg/min/sec
10
12
  #
11
-
12
13
  def to_lat format = :dms, dp = 0
13
14
  return lat if !format
14
- Geo.to_lat lat, format, dp
15
+ GeoUnits::Converter.to_lat lat, format, dp
15
16
  end
16
17
 
17
-
18
18
  # Returns the longitude of this point; signed numeric degrees if no format, otherwise format & dp
19
19
  # as per Geo.toLon()
20
20
  #
21
- # @param {String} [format]: Return value as 'd', 'dm', 'dms'
22
- # @param {Number} [dp=0|2|4]: No of decimal places to display
23
- # @returns {Number|String} Numeric degrees if no format specified, otherwise deg/min/sec
21
+ # @param [String} [format]: Return value as 'd', 'dm', 'dms'
22
+ # @param [Number} [dp=0|2|4]: No of decimal places to display
23
+ # @return [Number|String} Numeric degrees if no format specified, otherwise deg/min/sec
24
24
  #
25
25
  # @requires Geo
26
26
 
27
27
  def to_lon format, dp
28
28
  return lon if !format
29
- Geo.to_lon lon, format, dp
29
+ GeoUnits::Converter.to_lon lon, format, dp
30
30
  end
31
31
 
32
32
 
33
33
  # Returns a string representation of this point; format and dp as per lat()/lon()
34
34
  #
35
- # @param {String} [format]: Return value as 'd', 'dm', 'dms'
36
- # @param {Number} [dp=0|2|4]: No of decimal places to display
35
+ # @param [String] format: Return value as 'd', 'dm', 'dms'
36
+ # @param [Number] dp: No of decimal places to display (0|2|4)
37
37
 
38
- # @returns {String} Comma-separated latitude/longitude
38
+ # @return [String] Comma-separated latitude/longitude
39
39
  #
40
40
 
41
41
  def to_s format = :dms, dp = 0
data/lib/geo_calc.rb CHANGED
@@ -1,6 +1,9 @@
1
- require 'geo_calc/geo_point'
2
1
  require 'geo_units'
2
+ require 'sugar-high/math'
3
+ require 'geo_calc/calc'
3
4
 
4
- module GeoCalc
5
- autoload :Dms, 'geo_calc/dms'
6
- end
5
+ module GeoCalc
6
+ autoload :PrettyPrint, 'geo_calc/pretty_print'
7
+ end
8
+
9
+ require 'geo_calc/extensions'
@@ -17,8 +17,9 @@ require 'spec_helper'
17
17
  # For miles, divide km by 1.609344
18
18
  # For nautical miles, divide km by 1.852
19
19
 
20
- describe GeoCalc do
20
+ require 'geo_point'
21
21
 
22
+ describe GeoCalc do
22
23
  # Point 1: 50 03 59N, 005 42 53W
23
24
  # Point 2: 58 38 38N, 003 04 12W
24
25
  context 'p1= (50 03 59N, 005 42 53W) .. p2= (58 38 38N, 003 04 12W)' do
@@ -33,15 +33,7 @@ describe GeoPoint do
33
33
  @arr = ["3", {:lng => "2"}]
34
34
  @arr.to_lat_lng.should == [3, 2]
35
35
  end
36
- end
37
-
38
- describe '#geo_point' do
39
- it 'should return a GeoPoint' do
40
- @p = [3, 2].geo_point
41
- @p.should be_a(GeoPoint)
42
- @p.to_lat_lng.should == [3, 2]
43
- end
44
- end
36
+ end
45
37
  end # Array
46
38
  end
47
39
  end
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe GeoPoint do
2
4
  describe 'ruby core Class extensions' do
3
5
  describe 'Hash extension' do
@@ -30,15 +32,7 @@ describe GeoPoint do
30
32
  @hash = {:lng => 2, :lat => "3"}
31
33
  @hash.to_lat_lng.should == [3, 2]
32
34
  end
33
- end
34
-
35
- describe '#geo_point' do
36
- it 'should return a GeoPoint' do
37
- @p = {:lng => 2, :lat => "3"}.geo_point
38
- @p.should be_a(GeoPoint)
39
- @p.to_lat_lng.should == [3, 2]
40
- end
41
- end
35
+ end
42
36
  end # Hash
43
37
  end
44
38
  end
@@ -63,15 +63,7 @@ describe GeoPoint do
63
63
  @str = "4; 3"
64
64
  lambda { @str.to_lat_lng}.should raise_error
65
65
  end
66
- end
67
-
68
- describe '#geo_point' do
69
- it 'should return a GeoPoint' do
70
- @p = "3, 2".geo_point
71
- @p.should be_a(GeoPoint)
72
- @p.to_lat_lng.should == [3, 2]
73
- end
74
- end
66
+ end
75
67
  end # String
76
68
  end
77
69
  end
@@ -4,13 +4,7 @@ require 'spec_helper'
4
4
  describe GeoPoint do
5
5
  describe 'ruby core Class extensions' do
6
6
  describe 'Fixnum extension' do
7
- describe '#to_lat' do
8
- it 'should set origin at 0,0' do
9
- origin = [0, 0].geo_point
10
- origin.lat.should == 0
11
- origin.lng.should == 0
12
- end
13
-
7
+ describe '#to_lat' do
14
8
  it 'should return latitude degree value for 360' do
15
9
  360.to_lat.should == 0
16
10
  end