Class: GeoHex::PP

Inherits:
Struct
  • Object
show all
Defined in:
lib/geo_hex/pp.rb

Overview

Mercator projection point

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#eastingObject

Returns the value of attribute easting

Returns:

  • (Object)

    the current value of easting



4
5
6
# File 'lib/geo_hex/pp.rb', line 4

def easting
  @easting
end

#northingObject

Returns the value of attribute northing

Returns:

  • (Object)

    the current value of northing



4
5
6
# File 'lib/geo_hex/pp.rb', line 4

def northing
  @northing
end

Instance Method Details

#latFloat

Returns latitude.

Returns:

  • (Float)

    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

#lonFloat

Returns longitude.

Returns:

  • (Float)

    longitude



7
8
9
# File 'lib/geo_hex/pp.rb', line 7

def lon
  @lon ||= LL.normalize(easting / H_BASE * 180.0)
end

#to_llGeoHex::LL

Returns lat/lon coordinates.

Returns:



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`

Parameters:

  • level (Integer)

    the level

Returns:



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