Class: EvilTransform
- Inherits:
-
Object
- Object
- EvilTransform
- 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
-
#bgs_to_MGS ⇒ Object
Baidu Geodetic System ==> Mars Geodetic System.
-
#initialize(*coordinates) ⇒ EvilTransform
constructor
A new instance of EvilTransform.
- #out_of_china? ⇒ Boolean
-
#to_BGS ⇒ Object
Mars Geodetic System ==> Baidu Geodetic System.
-
#to_MGS ⇒ Object
World Geodetic System ==> Mars Geodetic System.
-
#to_WGS ⇒ Object
Mars Geodetic System ==> World Geodetic System.
Constructor Details
#initialize(*coordinates) ⇒ EvilTransform
Returns a new instance of EvilTransform.
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_MGS ⇒ Object
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
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_BGS ⇒ Object
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_MGS ⇒ Object
World Geodetic System ==> Mars Geodetic System
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_WGS ⇒ Object
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 |