Class: EvilTransform

Inherits:
Object
  • Object
show all
Defined in:
lib/evil_transform.rb

Overview

Constant Summary collapse

VERSION =
'0.0.1'
PI =
3.14159265358979324
A =
6378245.0
EE =
0.00669342162296594323
BAIDU_PI =
3.14159265358979324 * 3000.0 / 180.0

Instance Method Summary collapse

Constructor Details

#initialize(*coordinates) ⇒ EvilTransform

Returns a new instance of EvilTransform.

Examples:

EvilTransform.new(lat: 39.909745000000, lon: 116.359496000000)
EvilTransform.new(39.909745000000, 116.359496000000)
EvilTransform.new([39.909745000000, 116.359496000000])


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

def initialize(*coordinates)
  coordinates = coordinates.flatten
  if coordinates.last.is_a?(Hash)
    @lat, @lon = coordinates.last.values_at(:lat, :lon)
  else
    @lat, @lon = coordinates
  end
  calculation
end

Instance Method Details

#bgs_to_MGSObject

Baidu Geodetic System ==> Mars Geodetic System



53
54
55
56
57
58
# File 'lib/evil_transform.rb', line 53

def bgs_to_MGS
  x     = @lon - 0.0065; y = @lat - 0.006
  z     = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * BAIDU_PI)
  theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * BAIDU_PI)
  [z * Math.sin(theta), z * Math.cos(theta)]
end

#out_of_china?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/evil_transform.rb', line 60

def out_of_china?
  @lon < 72.004 || @lon > 137.8347 || @lat < 0.8293 || @lat > 55.8271
end

#to_BGSObject

Mars Geodetic System ==> Baidu Geodetic System



46
47
48
49
50
# File 'lib/evil_transform.rb', line 46

def to_BGS
  z     = Math.sqrt(@lon * @lon + @lat * @lat) + 0.00002 * Math.sin(@lat * BAIDU_PI)
  theta = Math.atan2(@lat, @lon) + 0.000003 * Math.cos(@lon * BAIDU_PI)
  [z * Math.sin(theta) + 0.006, z * Math.cos(theta) + 0.0065]
end

#to_MGSObject

World Geodetic System ==> Mars Geodetic System

Examples:

Usage

EvilTransform.new(lat: 39.909745000000, lon: 116.359496000000).to_MGS
# => [39.911112866392486, 116.36569790916941]


32
33
34
35
36
37
38
# File 'lib/evil_transform.rb', line 32

def to_MGS
  if out_of_china?
    [@lat, @lon]
  else
    [@lat + @d_lat, @lon + @d_lon]
  end
end

#to_WGSObject

Mars Geodetic System ==> World Geodetic System



41
42
43
# File 'lib/evil_transform.rb', line 41

def to_WGS
  [@lat - @d_lat, @lon - @d_lon]
end