evil_transform 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +26 -0
- data/lib/evil_transform.rb +104 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 627db54540139b56d5274682ab6f6ddc6609fac4
|
4
|
+
data.tar.gz: 57764ca4e5a57d2e4aa9317033c281eb7555e354
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dd88d6eba416827503e27b3247764dd64ad15be8c2739cd7a0b9717f1590b3aed8633934e4e6a4ce739b03bcf60aecc642aa92ea38a6df09c7156660117e9d39
|
7
|
+
data.tar.gz: ace37fa4d888f368db33098235011af8cc86ce5e241a4ed577f2b5c5c09ef53fbad7cfcdfa47453ab18204e736ca4c5475c2e762ed0da9bb749103daa5ea3bdf
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Thierry Zires
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# evil_transform
|
2
|
+
|
3
|
+
[ruby译]地球坐标系 (WGS-84) 到火星坐标系 (GCJ-02) 的转换算法
|
4
|
+
|
5
|
+
Code from https://on4wp7.codeplex.com/SourceControl/changeset/view/21483#353936
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem install evil_transform
|
11
|
+
```
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
EvilTransform.to_MGS(lat: 39.909745000000, lon: 116.359496000000)
|
15
|
+
# => [39.911112866392486, 116.36569790916941]
|
16
|
+
|
17
|
+
EvilTransform.new(lat: 39.909745000000, lon: 116.359496000000).to_MGS
|
18
|
+
# => [39.911112866392486, 116.36569790916941]
|
19
|
+
```
|
20
|
+
|
21
|
+
## Methods
|
22
|
+
|
23
|
+
* #to_MGS _Mars Geodetic System_
|
24
|
+
* #to_WGS _World Geodetic System_
|
25
|
+
* #to_BGS _Baidu Geodetic System_
|
26
|
+
* #bgs_to_MGS _Baidu Geodetic System ==> Mars Geodetic System_
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# http://blog.csdn.net/coolypf/article/details/8686588
|
3
|
+
# Code from https://on4wp7.codeplex.com/SourceControl/changeset/view/21483#353936
|
4
|
+
# http://blog.csdn.net/coolypf/article/details/8569813
|
5
|
+
class EvilTransform
|
6
|
+
VERSION = '0.0.1'
|
7
|
+
|
8
|
+
PI = 3.14159265358979324
|
9
|
+
A = 6378245.0
|
10
|
+
EE = 0.00669342162296594323
|
11
|
+
|
12
|
+
BAIDU_PI = 3.14159265358979324 * 3000.0 / 180.0
|
13
|
+
|
14
|
+
# @example
|
15
|
+
# EvilTransform.new(lat: 39.909745000000, lon: 116.359496000000)
|
16
|
+
# EvilTransform.new(39.909745000000, 116.359496000000)
|
17
|
+
# EvilTransform.new([39.909745000000, 116.359496000000])
|
18
|
+
def initialize(*coordinates)
|
19
|
+
coordinates = coordinates.flatten
|
20
|
+
if coordinates.last.is_a?(Hash)
|
21
|
+
@lat, @lon = coordinates.last.values_at(:lat, :lon)
|
22
|
+
else
|
23
|
+
@lat, @lon = coordinates
|
24
|
+
end
|
25
|
+
calculation
|
26
|
+
end
|
27
|
+
|
28
|
+
# World Geodetic System ==> Mars Geodetic System
|
29
|
+
# @example Usage
|
30
|
+
# EvilTransform.new(lat: 39.909745000000, lon: 116.359496000000).to_MGS
|
31
|
+
# # => [39.911112866392486, 116.36569790916941]
|
32
|
+
def to_MGS
|
33
|
+
if out_of_china?
|
34
|
+
[@lat, @lon]
|
35
|
+
else
|
36
|
+
[@lat + @d_lat, @lon + @d_lon]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Mars Geodetic System ==> World Geodetic System
|
41
|
+
def to_WGS
|
42
|
+
[@lat - @d_lat, @lon - @d_lon]
|
43
|
+
end
|
44
|
+
|
45
|
+
# Mars Geodetic System ==> Baidu Geodetic System
|
46
|
+
def to_BGS
|
47
|
+
z = Math.sqrt(@lon * @lon + @lat * @lat) + 0.00002 * Math.sin(@lat * BAIDU_PI)
|
48
|
+
theta = Math.atan2(@lat, @lon) + 0.000003 * Math.cos(@lon * BAIDU_PI)
|
49
|
+
[z * Math.sin(theta) + 0.006, z * Math.cos(theta) + 0.0065]
|
50
|
+
end
|
51
|
+
|
52
|
+
# Baidu Geodetic System ==> Mars Geodetic System
|
53
|
+
def bgs_to_MGS
|
54
|
+
x = @lon - 0.0065; y = @lat - 0.006
|
55
|
+
z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * BAIDU_PI)
|
56
|
+
theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * BAIDU_PI)
|
57
|
+
[z * Math.sin(theta), z * Math.cos(theta)]
|
58
|
+
end
|
59
|
+
|
60
|
+
def out_of_china?
|
61
|
+
@lon < 72.004 || @lon > 137.8347 || @lat < 0.8293 || @lat > 55.8271
|
62
|
+
end
|
63
|
+
|
64
|
+
protected
|
65
|
+
|
66
|
+
def transform_lat
|
67
|
+
x = @lon - 105.0; y = @lat - 35.0
|
68
|
+
ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(x.abs)
|
69
|
+
ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0
|
70
|
+
ret += (20.0 * Math.sin(y * PI) + 40.0 * Math.sin(y / 3.0 * PI)) * 2.0 / 3.0
|
71
|
+
ret += (160.0 * Math.sin(y / 12.0 * PI) + 320 * Math.sin(y * PI / 30.0)) * 2.0 / 3.0
|
72
|
+
end
|
73
|
+
|
74
|
+
def transform_lon
|
75
|
+
x = @lon - 105.0; y = @lat - 35.0
|
76
|
+
ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(x.abs)
|
77
|
+
ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0;
|
78
|
+
ret += (20.0 * Math.sin(x * PI) + 40.0 * Math.sin(x / 3.0 * PI)) * 2.0 / 3.0;
|
79
|
+
ret += (150.0 * Math.sin(x / 12.0 * PI) + 300.0 * Math.sin(x / 30.0 * PI)) * 2.0 / 3.0;
|
80
|
+
end
|
81
|
+
|
82
|
+
def calculation
|
83
|
+
rad_lat = @lat / 180.0 * PI
|
84
|
+
magic = Math.sin(rad_lat)
|
85
|
+
magic = 1 - EE * magic * magic
|
86
|
+
sqrt_magic = Math.sqrt(magic)
|
87
|
+
@d_lat = (transform_lat * 180.0) / ((A * (1 - EE)) / (magic * sqrt_magic) * PI)
|
88
|
+
@d_lon = (transform_lon * 180.0) / (A / sqrt_magic * Math.cos(rad_lat) * PI)
|
89
|
+
end
|
90
|
+
|
91
|
+
class << self
|
92
|
+
# @example Usage
|
93
|
+
# EvilTransform.to_MGS(lat: 39.909745000000, lon: 116.359496000000)
|
94
|
+
# # => [39.911112866392486, 116.36569790916941]
|
95
|
+
[:to_MGS, :to_WGS, :to_BGS, :bgs_to_MGS].each do |m|
|
96
|
+
class_eval <<-CODE
|
97
|
+
def #{m}(*coordinates)
|
98
|
+
self.new(coordinates).#{m}
|
99
|
+
end
|
100
|
+
CODE
|
101
|
+
end
|
102
|
+
end # End of class << self
|
103
|
+
|
104
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: evil_transform
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- zires
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: yard
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: turn
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: '[ruby译]地球坐标系 (WGS-84) 到火星坐标系 (GCJ-02) 的转换算法.'
|
56
|
+
email:
|
57
|
+
- zshuaibin@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/evil_transform.rb
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
homepage: https://github.com/zires/evil_transform
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.0.0.rc.2
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: WGS-84 to GCJ-02.
|
89
|
+
test_files: []
|
90
|
+
has_rdoc:
|