swissgrid 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 +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +58 -0
- data/Rakefile +2 -0
- data/lib/swissgrid/ch1903.rb +66 -0
- data/lib/swissgrid/version.rb +3 -0
- data/lib/swissgrid/wgs84.rb +52 -0
- data/lib/swissgrid.rb +15 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/swissgrid_spec.rb +26 -0
- data/swissgrid.gemspec +23 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e5587b567763c2ca15b1d8b2b9b483f98d3d470
|
4
|
+
data.tar.gz: 9cc965ba0e9bf87cde2ff83f86366350c923f613
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d13624a5963cdb45ce43c8dff246732b58c34bacdba02b6f3704504268872d39bef22d197cf2be415d3e674ac8c6b50a0c43dd046cb864ebb776ad2835515d57
|
7
|
+
data.tar.gz: b72d2f7e60cc1dd09b97aa6b33eb1dcb5cd2f0440fb48150dd8b2c5238158cafa56516df6917f0373b547abd137b215585f7edea52bbac1f691ac0f225511ea2
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Alexander Rueedlinger
|
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,58 @@
|
|
1
|
+
# Swissgrid
|
2
|
+
|
3
|
+
The swissgrid rubygem is conversion library to convert WGS84 (GPS) points into the Swiss coordinate system (CH1903)
|
4
|
+
and vice versa.
|
5
|
+
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'swissgrid'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install swissgrid
|
22
|
+
|
23
|
+
##Usage
|
24
|
+
Require the swissgrid library as follows:
|
25
|
+
```ruby
|
26
|
+
require 'swissgrid'
|
27
|
+
```
|
28
|
+
###From WGS84(GPS) to CH1903
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
gps_point = [46.881908, 7.471829] # [lat, lon] Bern
|
32
|
+
swiss_coord = Swissgrid::CH1903(gps_point)
|
33
|
+
```
|
34
|
+
###From CH1903 to WGS84(GPS)
|
35
|
+
```ruby
|
36
|
+
ch1903_point = [600000, 200000] # [y, x] Bern
|
37
|
+
wgs84_coord = Swissgrid::WGS84(ch1903_point)
|
38
|
+
```
|
39
|
+
|
40
|
+
###Convert a list of points
|
41
|
+
```ruby
|
42
|
+
gps_points = [ [46.881908, 7.471829], [47.220833, 7.028056] ]
|
43
|
+
|
44
|
+
# convert to ch1903 points
|
45
|
+
ch1903_points = gps_points.map { |p| Swissgrid::CH1903(p) }
|
46
|
+
|
47
|
+
# convert back to gps points
|
48
|
+
new_gps_points = ch1903_points.map { |p| Swissgrid::WGS84(p) }
|
49
|
+
```
|
50
|
+
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it ( https://github.com/[my-github-username]/swissgrid/fork )
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
module Swissgrid
|
2
|
+
|
3
|
+
module Ch1903
|
4
|
+
|
5
|
+
PHI_BERN = 169028.66
|
6
|
+
LAMBDA_BERN = 26782.5
|
7
|
+
SCALE = 10000
|
8
|
+
|
9
|
+
def self.from_wgs84(a_point)
|
10
|
+
lat, lon, z = a_point
|
11
|
+
phi_sec = to_sexagesimal(lat)
|
12
|
+
lambda_sec = to_sexagesimal(lon)
|
13
|
+
lambda_prime = (lambda_sec - LAMBDA_BERN) / SCALE.to_f
|
14
|
+
phi_prime = (phi_sec - PHI_BERN) / SCALE.to_f
|
15
|
+
convert(lambda_prime, phi_prime, z)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def self.convert(lambda_prime, phi_prime, h)
|
21
|
+
y = [
|
22
|
+
600072.37,
|
23
|
+
211455.93 * lambda_prime,
|
24
|
+
-10938.51 * lambda_prime * phi_prime,
|
25
|
+
-0.36 * lambda_prime * (phi_prime ** 2),
|
26
|
+
-44.54 * (lambda_prime ** 3)
|
27
|
+
].reduce(:+)
|
28
|
+
|
29
|
+
x = [
|
30
|
+
200147.07,
|
31
|
+
308807.95 * phi_prime,
|
32
|
+
3745.25 * (lambda_prime ** 2),
|
33
|
+
76.63 * (phi_prime ** 2),
|
34
|
+
-194.56 * (lambda_prime ** 2) * phi_prime,
|
35
|
+
119.79 * (phi_prime ** 3)
|
36
|
+
].reduce(:+)
|
37
|
+
|
38
|
+
z = if h.nil?
|
39
|
+
h
|
40
|
+
else
|
41
|
+
[
|
42
|
+
h - 49.55,
|
43
|
+
2.73 * lambda_prime,
|
44
|
+
6.94 * phi_prime
|
45
|
+
].reduce(:+)
|
46
|
+
end
|
47
|
+
|
48
|
+
z.nil? ? [y, x] : [y, x, z]
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def self.to_gps_triple(dec_degress)
|
53
|
+
degrees = dec_degress.to_i
|
54
|
+
minutes = (60*(dec_degress - degrees)).to_i
|
55
|
+
seconds = (60*(dec_degress - degrees) - minutes) * 60
|
56
|
+
[degrees, minutes, seconds]
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.to_sexagesimal(dec_degress)
|
60
|
+
degree, minutes, seconds = to_gps_triple(dec_degress)
|
61
|
+
degree * 3600 + minutes * 60 + seconds
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Swissgrid
|
2
|
+
|
3
|
+
module WGS84
|
4
|
+
|
5
|
+
Y_BERN = 600000
|
6
|
+
X_BERN = 200000
|
7
|
+
SCALE = 1000
|
8
|
+
|
9
|
+
def self.from_ch1903(a_point)
|
10
|
+
y, x , z = a_point
|
11
|
+
y_prime = (y - Y_BERN) / SCALE.to_f
|
12
|
+
x_prime = (x - X_BERN) / SCALE.to_f
|
13
|
+
convert(y_prime, x_prime, z)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def self.convert(y_prime, x_prime, h_prime)
|
19
|
+
lambda_prime = [
|
20
|
+
2.6779094,
|
21
|
+
4.728982 * y_prime,
|
22
|
+
0.791484 * y_prime * x_prime,
|
23
|
+
0.1306 * y_prime * (x_prime ** 2),
|
24
|
+
-0.0436 * (y_prime ** 3)
|
25
|
+
].reduce(:+)
|
26
|
+
|
27
|
+
phi_prime = [
|
28
|
+
16.9023892 ,
|
29
|
+
3.238272 * x_prime,
|
30
|
+
-0.270978 * (y_prime ** 2),
|
31
|
+
-0.002528 * (x_prime ** 2),
|
32
|
+
-0.0447 * (y_prime ** 2) * x_prime,
|
33
|
+
-0.0140 * (x_prime ** 3)
|
34
|
+
].reduce(:+)
|
35
|
+
|
36
|
+
z = if h_prime.nil?
|
37
|
+
h_prime
|
38
|
+
else
|
39
|
+
[
|
40
|
+
h_prime + 49.55,
|
41
|
+
-12.60 * y_prime,
|
42
|
+
-22.64 * x_prime
|
43
|
+
].reduce(:+)
|
44
|
+
end
|
45
|
+
|
46
|
+
lat, lon = [phi_prime, lambda_prime].map { |v| v * 100/36.to_f }
|
47
|
+
z.nil? ? [lat, lon] : [lat, lon, z]
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
data/lib/swissgrid.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Swissgrid
|
4
|
+
|
5
|
+
describe Swissgrid do
|
6
|
+
|
7
|
+
it "test conversion from wgs84 to ch1903" do
|
8
|
+
gps_point = [46.881908, 7.471829]
|
9
|
+
swiss_coord = Swissgrid::CH1903(gps_point)
|
10
|
+
expect(swiss_coord[0]).to be_within(0.5).of(602530.221)
|
11
|
+
expect(swiss_coord[1]).to be_within(0.5).of(192310.331)
|
12
|
+
pp swiss_coord
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
it "test conversion from ch1903 to wgs84" do
|
17
|
+
ch1903_point = [600000, 200000]
|
18
|
+
wgs84_coord = Swissgrid::WGS84(ch1903_point)
|
19
|
+
expect(wgs84_coord[0]).to be_within(0.1/3600).of(46.951082877)
|
20
|
+
expect(wgs84_coord[1]).to be_within(0.1/3600).of(7.438632495)
|
21
|
+
pp wgs84_coord
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/swissgrid.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 'swissgrid/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "swissgrid"
|
8
|
+
spec.version = Swissgrid::VERSION
|
9
|
+
spec.authors = ["Alexander Rueedlinger"]
|
10
|
+
spec.email = ["a.rueedlinger@gmail.com"]
|
11
|
+
spec.summary = %q{A library to convert gps points into the Swiss coordinate system (CH1903).}
|
12
|
+
spec.description = %q{Swissgrid is a library to convert gps points into the Swiss coordinate system (CH1903).}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swissgrid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Rueedlinger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-02 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Swissgrid is a library to convert gps points into the Swiss coordinate
|
42
|
+
system (CH1903).
|
43
|
+
email:
|
44
|
+
- a.rueedlinger@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/swissgrid.rb
|
55
|
+
- lib/swissgrid/ch1903.rb
|
56
|
+
- lib/swissgrid/version.rb
|
57
|
+
- lib/swissgrid/wgs84.rb
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
- spec/swissgrid_spec.rb
|
60
|
+
- swissgrid.gemspec
|
61
|
+
homepage: ''
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.2.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: A library to convert gps points into the Swiss coordinate system (CH1903).
|
85
|
+
test_files:
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
- spec/swissgrid_spec.rb
|
88
|
+
has_rdoc:
|