Class: GeoHex::PP
- Inherits:
-
Struct
- Object
- Struct
- GeoHex::PP
- Defined in:
- lib/geo_hex/pp.rb
Overview
Mercator projection point
Instance Attribute Summary collapse
-
#easting ⇒ Object
Returns the value of attribute easting.
-
#northing ⇒ Object
Returns the value of attribute northing.
Instance Method Summary collapse
-
#lat ⇒ Float
Latitude.
-
#lon ⇒ Float
Longitude.
-
#to_ll ⇒ GeoHex::LL
Lat/lon coordinates.
-
#to_zone(level) ⇒ GeoHex::Zone
Converts point coordinates into a Zone for a given ‘level`.
Instance Attribute Details
#easting ⇒ Object
Returns the value of attribute easting
4 5 6 |
# File 'lib/geo_hex/pp.rb', line 4 def easting @easting end |
#northing ⇒ Object
Returns the value of attribute northing
4 5 6 |
# File 'lib/geo_hex/pp.rb', line 4 def northing @northing end |
Instance Method Details
#lat ⇒ Float
Returns latitude.
12 13 14 |
# File 'lib/geo_hex/pp.rb', line 12 def lat @lat ||= 180.0 / Math::PI * (2 * Math.atan(Math.exp(northing / H_BASE * 180.0 * H_D2R)) - Math::PI / 2.0) end |
#lon ⇒ Float
Returns longitude.
7 8 9 |
# File 'lib/geo_hex/pp.rb', line 7 def lon @lon ||= LL.normalize(easting / H_BASE * 180.0) end |
#to_ll ⇒ GeoHex::LL
Returns lat/lon coordinates.
17 18 19 |
# File 'lib/geo_hex/pp.rb', line 17 def to_ll LL.new(lat, lon) end |
#to_zone(level) ⇒ GeoHex::Zone
Converts point coordinates into a Zone for a given ‘level`
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/geo_hex/pp.rb', line 24 def to_zone(level) u = Unit[level] x = (easting + northing / H_K) / u.width y = (northing - H_K * easting) / u.height x0, y0 = x.floor, y.floor xq, yq = x - x0, y - y0 xn, yn = if yq > -xq + 1 && yq < 2 * xq && yq > 0.5 * xq [x0 + 1, y0 + 1] elsif yq < -xq + 1 && yq > 2 * xq - 1 && yq < 0.5 * xq + 0.5 [x0, y0] else [x.round, y.round] end Zone.new(xn, yn, level) end |