Class: GeoPoint
- Inherits:
-
Object
- Object
- GeoPoint
- Includes:
- GeoCalc, NumericCheckExt
- Defined in:
- lib/geo_calc/geo_point.rb
Overview
Instance Attribute Summary collapse
-
#lat ⇒ Object
(also: #to_lat)
Creates a point on the earth’s surface at the supplied latitude / longitude.
-
#lon ⇒ Object
Creates a point on the earth’s surface at the supplied latitude / longitude.
-
#radius ⇒ Object
Returns the value of attribute radius.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(*args) ⇒ GeoPoint
constructor
A new instance of GeoPoint.
- #normal_arr! ⇒ Object
- #reverse_arr! ⇒ Object
- #reverse_arr? ⇒ Boolean
- #to_arr ⇒ Object
- #to_lat_lng ⇒ Object
- #unit ⇒ Object
Methods included from NumericCheckExt
Methods included from GeoCalc
#bearing_to, #destination_point, #distance_to, #final_bearing_to, intersection, #midpoint_to, #rhumb_bearing_to, #rhumb_destination_point, #rhumb_distance_to, #to_lon, #to_s
Constructor Details
#initialize(*args) ⇒ GeoPoint
Returns a new instance of GeoPoint.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/geo_calc/geo_point.rb', line 27 def initialize *args rad = args.delete(args.size) if is_numeric?(args.last) && args.last.is_between?(6350, 6380) rad ||= 6371 # default case args.size when 1 create_from_one *args, rad when 2 create_from_two *args, rad else raise "GeoPoint must be initialized with either one or to arguments defining the (latitude, longitude) coordinate on the map" end end |
Instance Attribute Details
#lat ⇒ Object Also known as: to_lat
Creates a point on the earth’s surface at the supplied latitude / longitude
Constructor
-
Numeric lat: latitude in numeric degrees
-
Numeric lon: longitude in numeric degrees
-
Numeric [rad=6371]: radius of earth if different value is required from standard 6,371km
24 25 26 |
# File 'lib/geo_calc/geo_point.rb', line 24 def lat @lat end |
#lon ⇒ Object
Creates a point on the earth’s surface at the supplied latitude / longitude
Constructor
-
Numeric lat: latitude in numeric degrees
-
Numeric lon: longitude in numeric degrees
-
Numeric [rad=6371]: radius of earth if different value is required from standard 6,371km
24 25 26 |
# File 'lib/geo_calc/geo_point.rb', line 24 def lon @lon end |
#radius ⇒ Object
Returns the value of attribute radius.
25 26 27 |
# File 'lib/geo_calc/geo_point.rb', line 25 def radius @radius end |
Instance Method Details
#[](key) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/geo_calc/geo_point.rb', line 68 def [] key case key when Fixnum raise ArgumentError, "Index must be 0 or 1" if !(0..1).cover?(key) to_arr[key] when String, Symbol send(key) if respond_to? key else raise ArgumentError, "Key must be a Fixnum (index) or a method name" end end |
#normal_arr! ⇒ Object
99 100 101 |
# File 'lib/geo_calc/geo_point.rb', line 99 def normal_arr! @reverse_arr = false end |
#reverse_arr! ⇒ Object
95 96 97 |
# File 'lib/geo_calc/geo_point.rb', line 95 def reverse_arr! @reverse_arr = true end |
#reverse_arr? ⇒ Boolean
91 92 93 |
# File 'lib/geo_calc/geo_point.rb', line 91 def reverse_arr? @reverse_arr end |
#to_arr ⇒ Object
86 87 88 89 |
# File 'lib/geo_calc/geo_point.rb', line 86 def to_arr a = to_lat_lng reverse_arr? ? a.reverse : a end |
#to_lat_lng ⇒ Object
82 83 84 |
# File 'lib/geo_calc/geo_point.rb', line 82 def to_lat_lng [lat, lng] end |
#unit ⇒ Object
40 41 42 |
# File 'lib/geo_calc/geo_point.rb', line 40 def unit :degrees end |