Class: MercConvert

Inherits:
Object
  • Object
show all
Extended by:
Math
Defined in:
lib/merc_convert.rb

Overview

Constant Summary collapse

MAXEXTENT =
20037508.34

Class Method Summary collapse

Class Method Details

.forward(lon, lat) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/merc_convert.rb', line 18

def forward(lon, lat)
  x = lon * MAXEXTENT / 180
  y = log(tan((90+lat) * PI / 360)) / (PI / 180)
  y = y * MAXEXTENT / 180
  
  [x, y]
end

.inverse(x, y) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/merc_convert.rb', line 10

def inverse(x, y)
  lon = (x / MAXEXTENT) * 180
  lat = (y / MAXEXTENT) * 180
  lat = 180/PI * (2 * atan(exp(lat * PI / 180)) - PI / 2)
  
  [lon, lat]
end