jtsk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjdkZWMxZmZhYjhmNDMwNWVhZDNlNTMzYzE4M2VlMDFiMzJmZDIzYw==
5
+ data.tar.gz: !binary |-
6
+ M2UxOWU1Y2FjYmE2YzM3YzZmMWI3NzZmMDRlYWIzZDMwYzIxNWM4Mg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MjRiMjAwNTE0OTI3ZGQyNmU1NTU5M2IzMTAwNjFkNWI5NjlkMDkwZDE0OThj
10
+ MjA1MmMwNjQ5ODQ2ZWRjNWU5MGM2ODEwMTQ3ZTA4NWJiZjI3MDVhMDhjMTk3
11
+ NmYxNjA3ZDdhNDVkNjcyMTA1YmZmYTI4OTRjNTQwOGMzZDIxYzM=
12
+ data.tar.gz: !binary |-
13
+ MmM5NDY1Y2M3NzBmMGY4ZDUzZDg5ZWY1ZTFhYTRiMWFmNDQyYzM4ZmVmYmJk
14
+ N2JkOGYzNTM4NDczZDI1MmViNTdkYWFhYTg3NDViNTMwYjE4ZmJkZmJkYmMz
15
+ OTE2OTFhNzQzY2QxYjFlM2IxN2QyZjM2N2Y5NWY3NTZjODkzY2I=
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rspec', '3.0.0.beta2'
4
+
5
+ # Specify your gem's dependencies in jtsk.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Josef Šimánek
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # JTSK [![Build Status](https://travis-ci.org/simi/jtsk.svg?branch=master)](https://travis-ci.org/simi/jtsk)
2
+
3
+ Convert from JTSK to WGS48.
4
+
5
+ Based on [JTSK Converter](https://github.com/josefzamrzla/JTSK_Converter) by [@josefzamrzla](https://github.com/josefzamrzla).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'jtsk'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install jtsk
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ converter = JTSK::Converter.new
25
+ x = 1043033.89
26
+ y = 738371.58
27
+ result = converter.to_wgs48(x, y) #=> #<struct JTSK::Wgs48Result latitude=50.092696246901404, longitude=14.482746557404647>
28
+ result.latitude #=> 50.092696246901404
29
+ result.longitude #=> 14.482746557404647
30
+ ```
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it ( https://github.com/[my-github-username]/jtsk/fork )
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/jtsk.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jtsk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jtsk"
8
+ spec.version = Jtsk::VERSION
9
+ spec.authors = ["Josef Šimánek"]
10
+ spec.email = ["josef.simanek@gmail.com"]
11
+ spec.summary = %q{Convert from JTSK to WGS48.}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", ">= 1.5"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ end
data/lib/jtsk.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'jtsk/converter'
2
+ require 'jtsk/result'
3
+
4
+ module JTSK
5
+ end
@@ -0,0 +1,206 @@
1
+ module JTSK
2
+ class Converter
3
+ EPS = 1e-4
4
+
5
+ def to_wgs48(x, y)
6
+ delta = 5.0
7
+ latitude = 49.0
8
+ longitude = 14.0
9
+ steps = 0.0
10
+
11
+ loop {
12
+
13
+ jtsk = self.wgs48_to_jtsk(latitude - delta, longitude - delta)
14
+ if(jtsk.x && jtsk.y)
15
+ v1 = self.dist_points(jtsk.x, jtsk.y, x, y)
16
+ else
17
+ v1 = 1e32
18
+ end
19
+
20
+ jtsk = self.wgs48_to_jtsk(latitude - delta, longitude + delta)
21
+ if(jtsk.x && jtsk.y)
22
+ v2 = self.dist_points(jtsk.x, jtsk.y, x, y)
23
+ else
24
+ v2 = 1e32
25
+ end
26
+
27
+ jtsk = self.wgs48_to_jtsk(latitude + delta, longitude - delta)
28
+ if(jtsk.x && jtsk.y)
29
+ v3 = self.dist_points(jtsk.x, jtsk.y, x, y)
30
+ else
31
+ v3 = 1e32
32
+ end
33
+
34
+ jtsk = self.wgs48_to_jtsk(latitude + delta, longitude + delta)
35
+ if(jtsk.x && jtsk.y)
36
+ v4 = self.dist_points(jtsk.x, jtsk.y, x, y)
37
+ else
38
+ v4 = 1e32
39
+ end
40
+
41
+ if ((v1 <= v2) && (v1 <= v3) && (v1 <= v4))
42
+ latitude = latitude - delta / 2.0
43
+ longitude = longitude - delta / 2.0
44
+ end
45
+
46
+ if ((v2 <= v1) && (v2 <= v3) && (v2 <= v4))
47
+ latitude = latitude - delta / 2.0
48
+ longitude = longitude + delta / 2.0
49
+ end
50
+
51
+ if ((v3 <= v1) && (v3 <= v2) && (v3 <= v4))
52
+ latitude = latitude + delta / 2.0
53
+ longitude = longitude - delta / 2.0
54
+ end
55
+
56
+ if ((v4 <= v1) && (v4 <= v2) && (v4 <= v3))
57
+ latitude = latitude + delta / 2.0
58
+ longitude = longitude + delta / 2.0
59
+ end
60
+
61
+ delta = delta * 0.55;
62
+ steps = steps + 4.0;
63
+
64
+ break if (((delta < 0.00001) || steps > 1000.0));
65
+ }
66
+
67
+ JTSK::Wgs48Result.new(latitude, longitude)
68
+ end
69
+
70
+ def wgs48_to_jtsk(latitude, longitude)
71
+ if ((latitude < 40.0) || (latitude > 60.0) || (longitude < 5.0) || (longitude > 25.0))
72
+ JTSK::JtskResult.new(0.0, 0.0)
73
+ else
74
+ bessel = self.wgs48_to_bessel(latitude, longitude);
75
+ self.bessel_to_jtsk(bessel.latitude, bessel.longitude);
76
+ end
77
+ end
78
+
79
+ def wgs48_to_bessel(latitude, longitude, altitude = 0.0)
80
+ b = deg2rad(latitude)
81
+ l = deg2rad(longitude)
82
+ h = altitude;
83
+
84
+ x1, y1, z1 = self.blh_to_geo_coords(b, l, h)
85
+ x2, y2, z2 = self.transform_coords(x1, y1, z1)
86
+ b, l, h = self.geo_coords_to_blh(x2, y2, z2)
87
+
88
+ latitude = rad2deg(b);
89
+ longitude = rad2deg(l);
90
+ # altitude = h;
91
+
92
+ JTSK::BesselResult.new(latitude, longitude)
93
+ end
94
+
95
+ def bessel_to_jtsk(latitude, longitude)
96
+ a = 6377397.15508
97
+ e = 0.081696831215303
98
+ n = 0.97992470462083
99
+ rho_0 = 12310230.12797036
100
+ sinUQ = 0.863499969506341
101
+ cosUQ = 0.504348889819882
102
+ sinVQ = 0.420215144586493
103
+ cosVQ = 0.907424504992097
104
+ alfa = 1.000597498371542
105
+ k_2 = 1.00685001861538
106
+
107
+ b = deg2rad(latitude)
108
+ l= deg2rad(longitude)
109
+
110
+ sinB = Math.sin(b)
111
+ t = (1 - e * sinB) / (1 + e * sinB)
112
+ t = pow(1 + sinB, 2) / (1 - pow(sinB, 2)) * Math.exp(e * Math.log(t))
113
+ t = k_2 * Math.exp(alfa * Math.log(t))
114
+
115
+ sinU = (t - 1) / (t + 1)
116
+ cosU = Math.sqrt(1 - sinU * sinU)
117
+ v = alfa * l
118
+ sinV = Math.sin(v)
119
+ cosV = Math.cos(v)
120
+ cosDV = cosVQ * cosV + sinVQ * sinV
121
+ sinDV = sinVQ * cosV - cosVQ * sinV
122
+ sinS = sinUQ * sinU + cosUQ * cosU * cosDV
123
+ cosS = Math.sqrt(1 - sinS * sinS)
124
+ sinD = sinDV * cosU / cosS
125
+ cosD = Math.sqrt(1 - sinD * sinD)
126
+
127
+ eps = n * Math.atan(sinD / cosD)
128
+ rho = rho_0 * Math.exp(-n * Math.log((1 + sinS) / cosS))
129
+
130
+ JTSK::JtskResult.new(rho * Math.cos(eps), rho * Math.sin(eps))
131
+ end
132
+
133
+ def blh_to_geo_coords(b,l,h)
134
+ # WGS-84 ellipsoid parameters
135
+ a = 6378137.0;
136
+ f_1 = 298.257223563;
137
+ e2 = 1 - ((1 - 1 / f_1) ** 2)
138
+ rho = a / Math.sqrt(1 - e2 * (Math.sin(b) ** 2))
139
+ x = (rho + h) * Math.cos(b) * Math.cos(l)
140
+ y = (rho + h) * Math.cos(b) * Math.sin(l)
141
+ z = ((1 - e2) * rho + h) * Math.sin(b);
142
+
143
+ return x, y, z;
144
+ end
145
+
146
+ def transform_coords(xs, ys, zs)
147
+ # coeficients of transformation from WGS-84 to JTSK
148
+ dx = -570.69; dy = -85.69; dz = -462.84; # shift
149
+
150
+ # rotation
151
+ wx = 4.99821/3600.0 * Math::PI / 180.0
152
+ wy = 1.58676/3600.0 * Math::PI / 180.0
153
+ wz = 5.2611/3600.0 * Math::PI / 180.0
154
+ m = -3.543e-6; # scale
155
+
156
+ xn = dx + (1 + m) * (+xs + wz * ys - wy * zs);
157
+ yn = dy + (1 + m) * (-wz * xs + ys + wx * zs);
158
+ zn = dz + (1 + m) * (+wy * xs - wx * ys + zs);
159
+
160
+ return xn, yn, zn
161
+ end
162
+
163
+ def geo_coords_to_blh(x, y, z)
164
+ # Bessel's ellipsoid parameters
165
+ a = 6377397.15508
166
+ f_1 = 299.152812853
167
+ a_b = f_1 / (f_1-1)
168
+ p = Math.sqrt(pow(x, 2) + pow(y, 2))
169
+ e2 = 1 - pow(1 - 1 / f_1, 2)
170
+ th = Math.atan(z * a_b / p)
171
+ st = Math.sin(th)
172
+ ct = Math.cos(th)
173
+ t = (z + e2 * a_b * a * pow(st, 3)) / (p - e2 * a * pow(ct, 3))
174
+
175
+ b = Math.atan(t)
176
+ h = Math.sqrt(1 + t * t) * (p - a / Math.sqrt(1 + (1 - e2) * t * t))
177
+ l = 2 * Math.atan(y / (p + x))
178
+
179
+ return b, l, h
180
+ end
181
+
182
+ def dist_points(x1, y1, x2, y2)
183
+ dist = Math.hypot(x1 - x2, y1 - y2)
184
+
185
+ if (dist < self.class::EPS)
186
+ return 0
187
+ end
188
+
189
+ return dist
190
+ end
191
+
192
+ private
193
+
194
+ def deg2rad(degrees)
195
+ degrees * (Math::PI / 180.0 )
196
+ end
197
+
198
+ def rad2deg(radians)
199
+ radians * (180.0 / Math::PI)
200
+ end
201
+
202
+ def pow(a,b)
203
+ a ** b
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,8 @@
1
+ module JTSK
2
+ class Wgs48Result < Struct.new(:latitude, :longitude)
3
+ end
4
+ class BesselResult < Struct.new(:latitude, :longitude)
5
+ end
6
+ class JtskResult < Struct.new(:x, :y)
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Jtsk
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe JTSK::Converter do
4
+ let(:converter) { described_class.new }
5
+ let(:x) { 1043033.89 }
6
+ let(:y) { 738371.58 }
7
+ let(:result) { converter.to_wgs48(x,y) }
8
+
9
+ it 'EPS is properly set' do
10
+ expect(described_class::EPS).to eq(1e-4)
11
+ end
12
+
13
+ it 'can be initialized' do
14
+ expect(converter).to be_kind_of(described_class)
15
+ end
16
+
17
+ it 'result is JTSK::Result' do
18
+ expect(result).to be_kind_of(JTSK::Wgs48Result)
19
+ end
20
+
21
+ context 'Club Velbloud' do
22
+ let(:x) { 1043033.89 }
23
+ let(:y) { 738371.58 }
24
+ it 'calucaltes well' do
25
+ expect(result.latitude).to eq(50.092696246901404)
26
+ expect(result.longitude).to eq(14.482746557404647)
27
+ end
28
+ end
29
+
30
+ context 'Indian Bar' do
31
+ let(:x) { 1043070.32 }
32
+ let(:y) { 738988.72 }
33
+ it 'calculates well' do
34
+ expect(result.latitude).to eq(50.091628136117045)
35
+ expect(result.longitude).to eq(14.474266228665831)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ require 'bundler/setup'
2
+ require 'jtsk'
3
+
4
+ RSpec.configure do |config|
5
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jtsk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Josef Šimánek
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-13 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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: '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:
56
+ email:
57
+ - josef.simanek@gmail.com
58
+ executables:
59
+ - rake
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .rspec
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/rake
70
+ - jtsk.gemspec
71
+ - lib/jtsk.rb
72
+ - lib/jtsk/converter.rb
73
+ - lib/jtsk/result.rb
74
+ - lib/jtsk/version.rb
75
+ - spec/jtsk/converter_spec.rb
76
+ - spec/spec_helper.rb
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.1.10
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Convert from JTSK to WGS48.
101
+ test_files:
102
+ - spec/jtsk/converter_spec.rb
103
+ - spec/spec_helper.rb