Class: RubyVolt::Meta::Geography::Point
- Inherits:
-
Object
- Object
- RubyVolt::Meta::Geography::Point
- Defined in:
- lib/ruby_volt/meta/geography.rb
Instance Attribute Summary collapse
-
#lat ⇒ Object
readonly
Returns the value of attribute lat.
-
#lng ⇒ Object
readonly
Returns the value of attribute lng.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(lng, lat) ⇒ Point
constructor
A new instance of Point.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #to_wkt ⇒ Object
- #to_XYZPoint ⇒ Object
Constructor Details
#initialize(lng, lat) ⇒ Point
Returns a new instance of Point.
20 21 22 23 24 25 |
# File 'lib/ruby_volt/meta/geography.rb', line 20 def initialize(lng, lat) raise(::ArgumentError, "Longitude must be in the range -180 ≤ longitude ≤ 180") unless lng >= -180 && lng <= 180 raise(::ArgumentError, "Latitude must be in the range -90 ≤ latitude ≤ 90") unless lat >= -90 && lat <= 90 @lng = lng @lat = lat end |
Instance Attribute Details
#lat ⇒ Object (readonly)
Returns the value of attribute lat.
5 6 7 |
# File 'lib/ruby_volt/meta/geography.rb', line 5 def lat @lat end |
#lng ⇒ Object (readonly)
Returns the value of attribute lng.
5 6 7 |
# File 'lib/ruby_volt/meta/geography.rb', line 5 def lng @lng end |
Class Method Details
.from_XYZPoint(x, y, z) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/ruby_volt/meta/geography.rb', line 10 def from_XYZPoint(x, y, z) degreesPerRadian = 180.0/Math::PI lngRadians = Math.atan2(y, x) latRadians = Math.atan2(z, Math.sqrt(x * x + y * y)) lng = (lngRadians * degreesPerRadian).round(6) lat = (latRadians * degreesPerRadian).round(6) new(lng, lat) end |
Instance Method Details
#==(other) ⇒ Object
50 51 52 |
# File 'lib/ruby_volt/meta/geography.rb', line 50 def ==(other) other.is_a?(Point) && (lng == other.lng) && (lat == other.lat) end |
#inspect ⇒ Object
38 39 40 |
# File 'lib/ruby_volt/meta/geography.rb', line 38 def inspect to_wkt end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/ruby_volt/meta/geography.rb', line 42 def to_s "#{lng} #{lat}" end |
#to_wkt ⇒ Object
46 47 48 |
# File 'lib/ruby_volt/meta/geography.rb', line 46 def to_wkt "POINT(#{to_s})" end |
#to_XYZPoint ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ruby_volt/meta/geography.rb', line 27 def to_XYZPoint radiansPerDegree = (Math::PI/180.0) # A conversion factor. latRadians = lat * radiansPerDegree # latitude is in degrees. lngRadians = lng * radiansPerDegree # longitude is in degrees. cosPhi = Math.cos(latRadians) x = Math.cos(lngRadians) * cosPhi y = Math.sin(lngRadians) * cosPhi z = Math.sin(latRadians) [x, y, z] end |