Class: GeoHex::LL
- Inherits:
-
Object
- Object
- GeoHex::LL
- Defined in:
- lib/geo_hex/ll.rb
Overview
Lat/Lon coordinates
Instance Attribute Summary collapse
-
#lat ⇒ Object
readonly
Returns the value of attribute lat.
-
#lon ⇒ Object
readonly
Returns the value of attribute lon.
Class Method Summary collapse
-
.normalize(lon) ⇒ Float
Longitude.
Instance Method Summary collapse
-
#distance_to(other) ⇒ Float
Distance in meters.
-
#easting ⇒ Float
Mercator easting.
-
#initialize(lat, lon) ⇒ LL
constructor
A new instance of LL.
-
#northing ⇒ Float
Mercator northing.
-
#to_pp ⇒ GeoHex::PP
The full projection point coordinates.
-
#to_zone(level) ⇒ GeoHex::Zone
Converts coordinates to Zone.
Constructor Details
#initialize(lat, lon) ⇒ LL
Returns a new instance of LL.
21 22 23 |
# File 'lib/geo_hex/ll.rb', line 21 def initialize(lat, lon) @lat, @lon = lat, self.class.normalize(lon) end |
Instance Attribute Details
#lat ⇒ Object (readonly)
Returns the value of attribute lat.
17 18 19 |
# File 'lib/geo_hex/ll.rb', line 17 def lat @lat end |
#lon ⇒ Object (readonly)
Returns the value of attribute lon.
17 18 19 |
# File 'lib/geo_hex/ll.rb', line 17 def lon @lon end |
Class Method Details
.normalize(lon) ⇒ Float
Returns longitude.
7 8 9 10 11 12 13 14 15 |
# File 'lib/geo_hex/ll.rb', line 7 def self.normalize(lon) if lon < -180 lon += 360 elsif lon > 180 lon -= 360 else lon end end |
Instance Method Details
#distance_to(other) ⇒ Float
Returns distance in meters.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/geo_hex/ll.rb', line 49 def distance_to(other) d_lat, d_lon = (other.lat - lat) * H_D2R / 2.0, (other.lon - lon) * H_D2R / 2.0 lat1, lat2 = lat * H_D2R, other.lat * H_D2R a = Math.sin(d_lat) ** 2 + Math.sin(d_lon) ** 2 * Math.cos(lat1) * Math.cos(lat2) c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)) H_ER * c end |
#easting ⇒ Float
Returns mercator easting.
26 27 28 |
# File 'lib/geo_hex/ll.rb', line 26 def easting @easting ||= lon * H_BASE / 180.0 end |
#northing ⇒ Float
Returns mercator northing.
31 32 33 |
# File 'lib/geo_hex/ll.rb', line 31 def northing @northing ||= Math.log(Math.tan((90 + lat) * H_D2R / 2)) / Math::PI * H_BASE end |
#to_pp ⇒ GeoHex::PP
Returns the full projection point coordinates.
36 37 38 |
# File 'lib/geo_hex/ll.rb', line 36 def to_pp GeoHex::PP.new(easting, northing) end |
#to_zone(level) ⇒ GeoHex::Zone
Converts coordinates to Zone
43 44 45 |
# File 'lib/geo_hex/ll.rb', line 43 def to_zone(level) to_pp.to_zone(level) end |