swisstopo_reframe 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 339e630968c41565493c9a57376731137dae26c6
4
+ data.tar.gz: ea1ed76eee00f7dd77f7de6792af0072726fbd86
5
+ SHA512:
6
+ metadata.gz: 7927527006efd7cb34ca510e903fec1308b309fe3932010e57fb20641f3f5ae296ed29fa2ebf5a77c0aa5d35ee8992ee4c28f22ad05e7100652eb5baa53191fd
7
+ data.tar.gz: 9623c578dae704ae216d27003bacf356635969aacadc0e11059659047178db7896701186af2e33845d42d15f532eeac26a8c32ecb442f7f34d7eecf4e4492d96
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+
16
+ .idea/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in swisstopo_reframe.gemspec
4
+ gemspec
@@ -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.
@@ -0,0 +1,83 @@
1
+ # SwisstopoReframe
2
+
3
+ The ```SiwsstopoReframe``` Rubygem provides a simple client for the [Swisstopo Reframe REST API](http://www.swisstopo.admin.ch/internet/swisstopo/en/home/products/software/products/m2m.html).
4
+
5
+ The basic idea behind this client is to provide a tiny DSL for converting coordinates into different coordinate systems.
6
+
7
+ The following conversions are possible:
8
+
9
+ * CH1903 <=> CH1903+ / (LV03 <=> LV95)
10
+ * WGS84 <=> CH1903 / (WGS84 <=> LV03)
11
+ * WGS84 <=> CH1903+ / (WGS84 <=> LV95)
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'swisstopo_reframe'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install swisstopo_reframe
28
+
29
+ ## Usage
30
+
31
+ To convert a point from a coordinate system A into a coordinate system B we need to know the following facts:
32
+
33
+ * What kind of point is given?
34
+ * What kind of point do I need?
35
+ * What's the value of the northing component?
36
+ * What's the value of the easting component?
37
+ * What's the value of the altitude component? (Optional)
38
+
39
+ So here is an example how we can convert a WGS84 point (gps) to a CH1903 point:
40
+ ```ruby
41
+ result = SwisstopoReframe.reframe do
42
+ northing 46.951082877
43
+ easting 7.438632495
44
+ altitude 550 # is optional
45
+ given :wgs84
46
+ need :ch1903
47
+ end
48
+ p result #=> {:easting=>"599999.9998992428", :northing=>"199999.9999671315", :altitude=>"500.37780122086406"}
49
+ ```
50
+
51
+ And here is an example to convert a CH1903 point to a WGS84 point:
52
+ ```ruby
53
+ result = SwisstopoReframe.reframe do
54
+ northing 200_000
55
+ easting 600_000
56
+ altitude 550 # is optional
57
+ given :ch1903
58
+ need :wgs84
59
+ end
60
+ p result #=> {:easting=>"7.438632502714565", :northing=>"46.95108288705891", :altitude=>"599.6221912624314"}
61
+ ```
62
+
63
+ Other valid options for given and need are:
64
+
65
+ * given
66
+ * :wgs84
67
+ * :ch1903
68
+ * :'ch1903+'
69
+
70
+
71
+ * need
72
+ * :wgs84
73
+ * :ch1903
74
+ * :'ch1903+'
75
+
76
+
77
+ ## Contributing
78
+
79
+ 1. Fork it ( https://github.com/[my-github-username]/swisstopo_reframe/fork )
80
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
81
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
82
+ 4. Push to the branch (`git push origin my-new-feature`)
83
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,107 @@
1
+ require "swisstopo_reframe/version"
2
+ require 'json'
3
+ require 'net/http'
4
+
5
+ module SwisstopoReframe
6
+
7
+ class Reframe
8
+
9
+ LOOKUP = {
10
+ [:wgs84, :lv95] => 'wgs84tolv95',
11
+ [:wgs84, :lv03] => 'wgs84tolv03',
12
+
13
+ [:lv95, :lv03] => 'lv95tolv03',
14
+ [:lv95, :wgs84] => 'lv95towgs84',
15
+
16
+ [:lv03, :wgs84] => 'lv03towgs84',
17
+ [:lv03, :lv95] => 'lv03tolv95',
18
+
19
+ # alias
20
+ [:wgs84, :'ch1903+'] => 'wgs84tolv95',
21
+ [:wgs84, :ch1903] => 'wgs84tolv03',
22
+
23
+ [:ch1903, :lv95] => 'lv03tolv95',
24
+ [:ch1903, :'ch1903+'] => 'lv03tolv95',
25
+ [:ch1903, :wgs84] => 'lv03towgs84',
26
+
27
+ [:'ch1903+', :lv03] => 'lv95tolv03',
28
+ [:'ch1903+', :ch1903] => 'lv95tolv03',
29
+ [:'ch1903+', :wgs84] => 'lv95towgs84'
30
+ }
31
+
32
+
33
+ BASE_URL = 'http://tc-geodesy.bgdi.admin.ch/reframe/'
34
+
35
+ attr_writer :easting, :northing, :altitude, :given, :format, :want
36
+
37
+ def easting(value)
38
+ @easting = value
39
+ end
40
+
41
+ def northing(value)
42
+ @northing = value
43
+ end
44
+
45
+ def altitude(value)
46
+ @altitude = value
47
+ end
48
+
49
+ def need(value)
50
+ @want = value
51
+ end
52
+
53
+ def given(value)
54
+ @given = value.to_s.downcase.to_sym
55
+ end
56
+
57
+ def format(value)
58
+ @format = value
59
+ end
60
+
61
+ def request
62
+ uri_string = request_url + '?' + query_string
63
+ uri = URI(uri_string)
64
+ json_string = Net::HTTP.get_response(uri)
65
+ json_string
66
+ end
67
+
68
+ private
69
+
70
+ def request_url
71
+ converter = [@given, @want]
72
+ path = LOOKUP[converter]
73
+ raise 'converter not found!' if path.nil?
74
+ BASE_URL + path
75
+ end
76
+
77
+ def query_string
78
+ format = @format.nil? ? 'json' : @format
79
+ altitude = @altitude.nil? ? '' : @altitude
80
+ "northing=#{@northing}&easting=#{@easting}&altitude=#{altitude}&format=#{format}"
81
+ end
82
+
83
+ end
84
+
85
+ def self.new
86
+ Reframe.new
87
+ end
88
+
89
+ def self.reframe(&block)
90
+ reframe = Reframe.new
91
+ reframe.instance_eval &block
92
+ request = reframe.request
93
+ handle(request)
94
+ end
95
+
96
+ private
97
+
98
+ def self.handle(request)
99
+ case request.code.to_i
100
+ when 200
101
+ JSON.parse(request.body, symbolize_names: true)
102
+ else
103
+ raise 'HTTP Error, status: %s' % request.code
104
+ end
105
+ end
106
+
107
+ end
@@ -0,0 +1,3 @@
1
+ module SwisstopoReframe
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,176 @@
1
+ require 'spec_helper'
2
+
3
+ module SwisstopoReframe
4
+
5
+ describe SwisstopoReframe do
6
+
7
+ it "tests conversion from wgs84 to ch1903" do
8
+ result = SwisstopoReframe.reframe do
9
+ northing 46.951082877
10
+ easting 7.438632495
11
+ given :wgs84
12
+ need :ch1903
13
+ format :geojson
14
+ end
15
+ expect(result).not_to be_nil
16
+ expect(599_999.7270399226).to be_within(1).of(result[:coordinates][0])
17
+ expect(199_999.61419550685).to be_within(1).of(result[:coordinates][1])
18
+ end
19
+
20
+
21
+ it "tests conversion from wgs84 to ch1903+" do
22
+ result = SwisstopoReframe.reframe do
23
+ northing 46.951082877
24
+ easting 7.438632495
25
+ given :wgs84
26
+ need :'ch1903+'
27
+ format :geojson
28
+ end
29
+ expect(result).not_to be_nil
30
+ expect(2_599_999.810036594).to be_within(1).of(result[:coordinates][0])
31
+ expect(1_199_999.6801912596).to be_within(1).of(result[:coordinates][1])
32
+ end
33
+
34
+
35
+ it "tests conversion from wgs84 to lv03" do
36
+ result = SwisstopoReframe.reframe do
37
+ northing 46.951082877
38
+ easting 7.438632495
39
+ given :wgs84
40
+ need :lv03
41
+ format :geojson
42
+ end
43
+ expect(result).not_to be_nil
44
+ expect(599_999.7270399226).to be_within(1).of(result[:coordinates][0])
45
+ expect(199_999.61419550685).to be_within(1).of(result[:coordinates][1])
46
+ end
47
+
48
+
49
+ it "tests conversion from wgs84 to lv95" do
50
+ result = SwisstopoReframe.reframe do
51
+ northing 46.951082877
52
+ easting 7.438632495
53
+ given :wgs84
54
+ need :lv95
55
+ format :geojson
56
+ end
57
+ expect(result).not_to be_nil
58
+ expect(2_599_999.810036594).to be_within(1).of(result[:coordinates][0])
59
+ expect(1_199_999.6801912596).to be_within(1).of(result[:coordinates][1])
60
+ end
61
+
62
+
63
+ it "tests conversion from ch1903 to wgs84" do
64
+ result = SwisstopoReframe.reframe do
65
+ northing 200_000
66
+ easting 600_000
67
+ given :ch1903
68
+ need :wgs84
69
+ format :geojson
70
+ end
71
+ expect(result).not_to be_nil
72
+ expect(46.95108287667706).to be_within(0.1/3600).of(result[:coordinates][1])
73
+ expect(7.438632495).to be_within(0.1/3600).of(result[:coordinates][0])
74
+ end
75
+
76
+
77
+ it "tests conversion from lv03 to wgs84" do
78
+ result = SwisstopoReframe.reframe do
79
+ northing 200_000
80
+ easting 600_000
81
+ given :lv03
82
+ need :wgs84
83
+ format :geojson
84
+ end
85
+ expect(result).not_to be_nil
86
+ expect(46.95108287667706).to be_within(0.1/3600).of(result[:coordinates][1])
87
+ expect(7.438632495).to be_within(0.1/3600).of(result[:coordinates][0])
88
+ end
89
+
90
+
91
+ it "tests conversion from ch1903+ to wgs84" do
92
+ result = SwisstopoReframe.reframe do
93
+ northing 1_200_000
94
+ easting 2_600_000
95
+ given :'ch1903+'
96
+ need :wgs84
97
+ format :geojson
98
+ end
99
+ expect(result).not_to be_nil
100
+ expect(46.95108287667706).to be_within(0.1/3600).of(result[:coordinates][1])
101
+ expect(7.438632495).to be_within(0.1/3600).of(result[:coordinates][0])
102
+ end
103
+
104
+
105
+ it "tests conversion from lv95 to wgs84" do
106
+ result = SwisstopoReframe.reframe do
107
+ northing 1_200_000
108
+ easting 2_600_000
109
+ given :lv95
110
+ need :wgs84
111
+ format :geojson
112
+ end
113
+ expect(result).not_to be_nil
114
+ expect(46.95108287667706).to be_within(0.1/3600).of(result[:coordinates][1])
115
+ expect(7.438632495).to be_within(0.1/3600).of(result[:coordinates][0])
116
+ end
117
+
118
+
119
+ it "tests conversion from lv95 to lv03" do
120
+ result = SwisstopoReframe.reframe do
121
+ northing 1_200_000
122
+ easting 2_600_000
123
+ given :lv95
124
+ need :lv03
125
+ format :geojson
126
+ end
127
+ expect(result).not_to be_nil
128
+ expect(600_000).to be_within(1).of(result[:coordinates][0])
129
+ expect(200_000).to be_within(1).of(result[:coordinates][1])
130
+ end
131
+
132
+
133
+ it "tests conversion from ch1903+ to ch1903" do
134
+ result = SwisstopoReframe.reframe do
135
+ northing 1_200_000
136
+ easting 2_600_000
137
+ given :lv95
138
+ need :lv03
139
+ format :geojson
140
+ end
141
+ expect(result).not_to be_nil
142
+ expect(600_000).to be_within(1).of(result[:coordinates][0])
143
+ expect(200_000).to be_within(1).of(result[:coordinates][1])
144
+ end
145
+
146
+
147
+ it "tests conversion from lv03 to lv95" do
148
+ result = SwisstopoReframe.reframe do
149
+ northing 200_000
150
+ easting 600_000
151
+ given :lv03
152
+ need :lv95
153
+ format :geojson
154
+ end
155
+ expect(result).not_to be_nil
156
+ expect(2_600_000).to be_within(1).of(result[:coordinates][0])
157
+ expect(1_200_000).to be_within(1).of(result[:coordinates][1])
158
+ end
159
+
160
+
161
+ it "tests conversion from ch1903 to ch1903+" do
162
+ result = SwisstopoReframe.reframe do
163
+ northing 200_000
164
+ easting 600_000
165
+ given :ch1903
166
+ need :'ch1903+'
167
+ format :geojson
168
+ end
169
+ expect(result).not_to be_nil
170
+ expect(2_600_000).to be_within(1).of(result[:coordinates][0])
171
+ expect(1_200_000).to be_within(1).of(result[:coordinates][1])
172
+ end
173
+
174
+ end
175
+
176
+ end
@@ -0,0 +1,2 @@
1
+ require 'swisstopo_reframe'
2
+ require 'pp'
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'swisstopo_reframe/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "swisstopo_reframe"
8
+ spec.version = SwisstopoReframe::VERSION
9
+ spec.authors = ["Alexander Rueedlinger"]
10
+ spec.email = ["a.rueedlinger@gmail.com"]
11
+ spec.summary = %q{A simple wrapper for the Swisstopo Reframe REST API to convert coordinate points into different coordinate systems.}
12
+ spec.description = %q{swisstopo_reframe is a wrapper for the Swisstopo Reframe REST API to convert coordinate points into different coordinate systems.}
13
+ spec.homepage = "https://github.com/lexruee/swisstopo_reframe"
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
+ spec.add_development_dependency "rspec", "~> 0"
24
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swisstopo_reframe
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Rueedlinger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-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.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
+ - !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: swisstopo_reframe is a wrapper for the Swisstopo Reframe REST API to
56
+ convert coordinate points into different coordinate systems.
57
+ email:
58
+ - a.rueedlinger@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/swisstopo_reframe.rb
69
+ - lib/swisstopo_reframe/version.rb
70
+ - spec/client_spec.rb
71
+ - spec/spec_helper.rb
72
+ - swisstopo_reframe.gemspec
73
+ homepage: https://github.com/lexruee/swisstopo_reframe
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: A simple wrapper for the Swisstopo Reframe REST API to convert coordinate
97
+ points into different coordinate systems.
98
+ test_files:
99
+ - spec/client_spec.rb
100
+ - spec/spec_helper.rb
101
+ has_rdoc: