twd97 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +32 -0
- data/MIT-LICENSE +20 -0
- data/README.md +19 -0
- data/Rakefile +6 -0
- data/lib/twd97.rb +44 -0
- data/lib/twd97/version.rb +3 -0
- data/spec/lib/twd97_spec.rb +16 -0
- data/spec/spec_helper.rb +1 -0
- data/twd97.gemspec +24 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1b70e1dfbb773e5a2d5b92acdaef76df4ff37c55
|
4
|
+
data.tar.gz: 555b07b2d064bdeb5b832b700872a21a49986661
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2cb9bec636f2cfa9ff2f7447c63375264168ad3721c4c096fea71a6db9672dbd87abd9981056ae796014388517ecc72e99ac15af7b08492e0efede449d4c701f
|
7
|
+
data.tar.gz: e4551db6a54e738d1a22d1a393ac1d13b2da97e6111044a273eedcbccdb2414eba7eb501dfbb7c09bd5ae9d513a44cb2578d403c5c045e4c34c694939e8f10c0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
twd97 (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
rake (10.4.2)
|
11
|
+
rspec (3.3.0)
|
12
|
+
rspec-core (~> 3.3.0)
|
13
|
+
rspec-expectations (~> 3.3.0)
|
14
|
+
rspec-mocks (~> 3.3.0)
|
15
|
+
rspec-core (3.3.2)
|
16
|
+
rspec-support (~> 3.3.0)
|
17
|
+
rspec-expectations (3.3.1)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.3.0)
|
20
|
+
rspec-mocks (3.3.2)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.3.0)
|
23
|
+
rspec-support (3.3.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (>= 1.3)
|
30
|
+
rake
|
31
|
+
rspec (>= 3.0.0)
|
32
|
+
twd97!
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2009-2015 Plataformatec. http://plataformatec.com.br
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/marsz/twd97.svg)](https://travis-ci.org/marsz/twd97)
|
2
|
+
|
3
|
+
Installation
|
4
|
+
============
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
gem 'twd97'
|
8
|
+
```
|
9
|
+
|
10
|
+
Usage
|
11
|
+
============
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
Twd97.convert(302745.088, 2771185.18)
|
15
|
+
# { lat: 25.047902, lng: 121.522737 }
|
16
|
+
|
17
|
+
Twd97.convert("304225.666", "2769534.8")
|
18
|
+
# { lat: 25.032950, lng: 121.537345 }
|
19
|
+
```
|
data/Rakefile
ADDED
data/lib/twd97.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Twd97
|
2
|
+
class << self
|
3
|
+
def convert(x, y)
|
4
|
+
x = x.to_f
|
5
|
+
y = y.to_f
|
6
|
+
a = 6378137.0
|
7
|
+
b = 6356752.314245
|
8
|
+
lng0 = 121 * Math::PI / 180
|
9
|
+
k0 = 0.9999
|
10
|
+
dx = 250000
|
11
|
+
dy = 0
|
12
|
+
e = ((1 - (b ** 2) / (a ** 2)) ** 0.5)
|
13
|
+
x -= dx
|
14
|
+
y -= dy
|
15
|
+
mm = y / k0
|
16
|
+
mu = mm / (a * (1.0 - (e ** 2) / 4.0 - 3 * (e ** 4) / 64.0 - 5 * (e ** 6) / 256.0))
|
17
|
+
e1 = (1.0 - ((1.0 - (e ** 2)) ** 0.5)) / (1.0 + ((1.0 - (e ** 2)) ** 0.5))
|
18
|
+
j1 = (3 * e1 / 2 - 27 * (e1 ** 3) / 32.0)
|
19
|
+
j2 = (21 * (e1 ** 2) / 16 - 55 * (e1 ** 4) / 32.0)
|
20
|
+
j3 = (151 * (e1 ** 3) / 96.0)
|
21
|
+
j4 = (1097 * (e1 ** 4) / 512.0)
|
22
|
+
fp = mu + j1 * Math.sin(2 * mu) + j2 * Math.sin(4 * mu) + j3 * Math.sin(6 * mu) + j4 * Math.sin(8 * mu)
|
23
|
+
e2 = ((e * a / b) ** 2)
|
24
|
+
c1 = (e2 * Math.cos(fp) ** 2)
|
25
|
+
t1 = (Math.tan(fp) ** 2)
|
26
|
+
r1 = a * (1 - (e ** 2)) / ((1 - (e ** 2) * (Math.sin(fp) ** 2)) ** (3.0 / 2.0))
|
27
|
+
n1 = a / ((1 - (e ** 2) * (Math.sin(fp) ** 2)) ** 0.5)
|
28
|
+
|
29
|
+
dd = x / (n1 * k0)
|
30
|
+
q1 = n1 * Math.tan(fp) / r1
|
31
|
+
q2 = ((dd ** 2) / 2.0)
|
32
|
+
q3 = (5 + 3 * t1 + 10 * c1 - 4 * (c1 ** 2) - 9 * e2) * (dd ** 4) / 24.0
|
33
|
+
q4 = (61 + 90 * t1 + 298 * c1 + 45 * (t1 ** 2) - 3 * (c1 ** 2) - 252 * e2) * (dd ** 6) / 720.0
|
34
|
+
lat = fp - q1 * (q2 - q3 + q4)
|
35
|
+
q5 = dd
|
36
|
+
q6 = (1 + 2 * t1 + c1) * (dd ** 3) / 6
|
37
|
+
q7 = (5 - 2 * c1 + 28 * t1 - 3 * (c1 ** 2) + 8 * e2 + 24 * (t1 ** 2)) * (dd ** 5) / 120.0
|
38
|
+
lng = lng0 + (q5 - q6 + q7) / Math.cos(fp)
|
39
|
+
lat = (lat * 180) / Math::PI
|
40
|
+
lng = (lng * 180) / Math::PI
|
41
|
+
{ lat: lat, lng: lng }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Twd97 do
|
4
|
+
describe ".convert" do
|
5
|
+
example "1" do
|
6
|
+
coordinates = described_class.convert(302745.088, 2771185.18)
|
7
|
+
expect( coordinates[:lat].round(6) ).to eq 25.047902
|
8
|
+
expect( coordinates[:lng].round(6) ).to eq 121.522737
|
9
|
+
end
|
10
|
+
example "2" do
|
11
|
+
coordinates = described_class.convert("304225.666", 2769534.8)
|
12
|
+
expect( coordinates[:lat].round(6) ).to eq 25.032950
|
13
|
+
expect( coordinates[:lng].round(6) ).to eq 121.537345
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'twd97'
|
data/twd97.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "twd97/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "twd97"
|
6
|
+
s.version = Twd97::VERSION.dup
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.licenses = ["MIT"]
|
9
|
+
s.summary = "Convert TWD97 to WGS84"
|
10
|
+
s.email = "marsz@5fpro.com"
|
11
|
+
s.homepage = "https://github.com/marsz/twd97"
|
12
|
+
s.description = "Convert TWD97 to WGS84"
|
13
|
+
s.authors = ['marsz']
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
|
+
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.required_ruby_version = '>= 2.0.0'
|
20
|
+
|
21
|
+
s.add_development_dependency "bundler", ">= 1.3"
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
s.add_development_dependency "rspec", ">= 3.0.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twd97
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- marsz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0
|
55
|
+
description: Convert TWD97 to WGS84
|
56
|
+
email: marsz@5fpro.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- ".gitignore"
|
62
|
+
- ".rspec"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- Gemfile.lock
|
66
|
+
- MIT-LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/twd97.rb
|
70
|
+
- lib/twd97/version.rb
|
71
|
+
- spec/lib/twd97_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
- twd97.gemspec
|
74
|
+
homepage: https://github.com/marsz/twd97
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 2.0.0
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.2.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Convert TWD97 to WGS84
|
98
|
+
test_files:
|
99
|
+
- spec/lib/twd97_spec.rb
|
100
|
+
- spec/spec_helper.rb
|