proj4rb 2.2.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,224 +1,226 @@
1
- # encoding: UTF-8
2
-
3
- require_relative './abstract_test'
4
-
5
- class ProjectionTest < AbstractTest
6
- PRECISION = 0.1 ** 4
7
-
8
- def setup
9
- @proj_wgs84 = Proj::Projection.new(["init=epsg:4326"]) # WGS84
10
- @proj_gk = Proj::Projection.new(["+init=epsg:31467"]) # Gauss-Kruger Zone 3
11
- @proj_merc = Proj::Projection.new(["proj=merc"])
12
- @proj_conakry = Proj::Projection.new(["+init=epsg:31528"]) # Conakry 1905 / UTM zone 28N
13
- @proj_ortel = Proj::Projection.new(["+proj=ortel", "+lon_0=90w"]) # Ortelius Oval Projection
14
- @epsg2029i = ['+init=epsg:2029']
15
- @epsg2029_args = ['+proj=utm', '+zone=17', '+ellps=clrk66', '+units=m', '+no_defs']
16
- end
17
-
18
- def test_arg_fail
19
- assert_raises ArgumentError do
20
- Proj::Projection.parse()
21
- end
22
- assert_raises ArgumentError do
23
- Proj::Projection.parse(nil)
24
- end
25
- assert_raises ArgumentError do
26
- Proj::Projection.parse(1)
27
- end
28
- end
29
-
30
- def test_arg_string
31
- args = Proj::Projection.parse('+init=epsg:2029')
32
- assert_equal(@epsg2029i, args)
33
- args = Proj::Projection.parse(' +proj=utm +zone=17 +ellps=clrk66 +units=m +no_defs ')
34
- assert_equal(@epsg2029_args, args)
35
- end
36
-
37
- def test_arg_string_with_plus
38
- args = Proj::Projection.parse('+init=epsg:2029')
39
- assert_equal(@epsg2029i, args)
40
- args = Proj::Projection.parse('+proj=utm +zone=17 +ellps=clrk66 +units=m +no_defs')
41
- assert_equal(@epsg2029_args, args)
42
- end
43
-
44
- def test_arg_array
45
- args = Proj::Projection.parse(['+init=epsg:2029'])
46
- assert_equal(@epsg2029i, args)
47
- args = Proj::Projection.parse(['+proj=utm', '+zone=17', '+ellps=clrk66', '+units=m', '+no_defs'])
48
- assert_equal(@epsg2029_args, args)
49
- end
50
-
51
- def test_arg_array_with_plus
52
- args = Proj::Projection.parse(['+init=epsg:2029'])
53
- assert_equal(@epsg2029i, args)
54
- args = Proj::Projection.parse(['+proj=utm', '+zone=17', '+ellps=clrk66', '+units=m', '+no_defs'])
55
- assert_equal(@epsg2029_args, args)
56
- end
57
-
58
- def test_arg_hash_with_string
59
- args = Proj::Projection.parse('init' => 'epsg:2029')
60
- assert_equal(@epsg2029i, args)
61
- args = Proj::Projection.parse('proj' => 'utm', 'zone' => '17', 'ellps' => 'clrk66', 'units' => 'm', 'no_defs' => nil)
62
- assert_equal(@epsg2029_args, args)
63
- end
64
-
65
- def test_arg_hash_with_symbol
66
- args = Proj::Projection.parse(:init => 'epsg:2029')
67
- assert_equal(@epsg2029i, args)
68
- args = Proj::Projection.parse(:proj => 'utm', :zone => '17', :ellps => 'clrk66', :units => 'm', :no_defs => nil)
69
- assert_equal(@epsg2029_args, args)
70
- end
71
-
72
- def test_arg_hash_with_symbol_simple
73
- args = Proj::Projection.parse(:init => 'epsg:2029')
74
- assert_equal(@epsg2029i, args)
75
- args = Proj::Projection.parse(:proj => 'utm', :zone => '17', :ellps => 'clrk66', :units => 'm', :no_defs => nil)
76
- assert_equal(@epsg2029_args, args)
77
- end
78
-
79
- def test_arg_projection
80
- proj = Proj::Projection.new(['+init=epsg:2029'])
81
- args = Proj::Projection.parse(proj)
82
- assert_equal(["+init=epsg:2029", "+proj=utm", "+zone=17", "+ellps=clrk66", "+units=m", "+no_defs"], args)
83
- end
84
-
85
- def test_init_arg_string
86
- proj = Proj::Projection.new('+init=epsg:2029')
87
- assert_equal(' +init=epsg:2029 +proj=utm +zone=17 +ellps=clrk66 +units=m +no_defs', proj.getDef)
88
- end
89
-
90
- def test_init_arg_array
91
- proj = Proj::Projection.new(['+init=epsg:2029'])
92
- assert_equal(' +init=epsg:2029 +proj=utm +zone=17 +ellps=clrk66 +units=m +no_defs', proj.getDef)
93
- end
94
-
95
- def test_init_arg_hash
96
- proj = Proj::Projection.new(:proj => 'utm', 'zone' => '17', 'ellps' => 'clrk66', :units => 'm', :no_defs => nil)
97
- assert_equal(' +proj=utm +zone=17 +ellps=clrk66 +units=m +no_defs', proj.getDef)
98
- end
99
-
100
- def test_init_arg_fail
101
- assert_raises Proj::Error do
102
- Proj::Projection.new(:proj => 'xxxx')
103
- end
104
-
105
- assert_raises Proj::Error do
106
- Proj::Projection.new(:foo => 'xxxx')
107
- end
108
- end
109
-
110
- def test_is_latlong
111
- assert(@proj_wgs84.isLatLong?)
112
- refute(@proj_gk.isLatLong?)
113
- refute(@proj_conakry.isLatLong?)
114
- refute(@proj_ortel.isLatLong?)
115
- end
116
-
117
- def test_is_geocent
118
- assert_equal(@proj_gk.isGeocent?, @proj_gk.isGeocentric?) # two names for same method
119
- refute(@proj_wgs84.isGeocent?)
120
- refute(@proj_gk.isGeocent?)
121
- refute(@proj_conakry.isGeocent?)
122
- refute(@proj_ortel.isGeocent?)
123
- end
124
-
125
- def test_get_def
126
- assert_equal(' +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0', @proj_wgs84.getDef)
127
- assert_equal(' +init=epsg:31467 +proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +ellps=bessel +units=m +no_defs', @proj_gk.getDef)
128
- assert_equal('+proj=ortel +lon_0=90w +ellps=GRS80', @proj_ortel.getDef.strip)
129
- end
130
-
131
- def test_to_s
132
- assert_equal('#<Proj::Projection +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0>', @proj_wgs84.to_s)
133
- end
134
-
135
- def test_projection
136
- assert_equal('longlat', @proj_wgs84.projection)
137
- assert_equal('tmerc', @proj_gk.projection)
138
- assert_equal('utm', @proj_conakry.projection)
139
- assert_equal('ortel', @proj_ortel.projection)
140
- end
141
-
142
- def test_datum
143
- assert_equal('WGS84', @proj_wgs84.datum)
144
- assert_nil(@proj_gk.datum)
145
- assert_nil(@proj_conakry.datum)
146
- end
147
-
148
- # echo "8.4302123334 48.9906726079" | proj +init=epsg:31467 -
149
- def test_forward_gk
150
- point = Proj::Point.new(8.4302123334, 48.9906726079)
151
- result = @proj_gk.forward(point.to_radians)
152
- assert_in_delta(3458305.0, result.x, 0.1)
153
- assert_in_delta(5428192.0, result.y, 0.1)
154
- end
155
-
156
- def test_forward_gk_degrees
157
- point = Proj::Point.new(8.4302123334, 48.9906726079)
158
- result = @proj_gk.forwardDeg(point)
159
- assert_in_delta(3458305.0, result.x, 0.1)
160
- assert_in_delta(5428192.0, result.y, 0.1)
161
- end
162
-
163
- # echo "3458305 5428192" | invproj -f '%.10f' +init=epsg:31467 -
164
- def test_inverse_gk
165
- point = Proj::Point.new(3458305.0, 5428192.0)
166
- result = @proj_gk.inverse(point).to_degrees
167
- assert_in_delta(result.x, 8.4302123334, PRECISION)
168
- assert_in_delta(result.y, 48.9906726079, PRECISION)
169
- end
170
-
171
- def test_inverse_gk_degrees
172
- point = Proj::Point.new(3458305.0, 5428192.0)
173
- result = @proj_gk.inverseDeg(point)
174
- assert_in_delta(result.x, 8.4302123334, PRECISION)
175
- assert_in_delta(result.y, 48.9906726079, PRECISION)
176
- end
177
-
178
- # echo "190 92" | proj +init=epsg:31467 -
179
- def test_out_of_bounds
180
- error = assert_raises(Proj::Error) do
181
- point = Proj::Point.new(190, 92).to_radians
182
- @proj_gk.forward(point)
183
- end
184
- assert_equal('latitude or longitude exceeded limits', error.message)
185
- end
186
-
187
- # echo "3458305 5428192" | cs2cs -f '%.10f' +init=epsg:31467 +to +init=epsg:4326 -
188
- def test_gk_to_wgs84
189
- from = Proj::Point.new(3458305.0, 5428192.0)
190
- to = @proj_gk.transform(@proj_wgs84, from).to_degrees
191
- assert_in_delta(8.4302123334, to.x, PRECISION)
192
- assert_in_delta(48.9906726079, to.y, PRECISION)
193
- end
194
-
195
- # echo "8.4293092923 48.9896114523" | cs2cs -f '%.10f' +init=epsg:4326 +to +init=epsg:31467 -
196
- def test_wgs84_to_gk
197
- from = Proj::Point.new(8.4302123334, 48.9906726079)
198
- to = @proj_wgs84.transform(@proj_gk, from.to_radians)
199
- assert_in_delta(3458305.0, to.x, PRECISION)
200
- assert_in_delta(5428192.0, to.y, PRECISION)
201
- end
202
-
203
- def test_mercator_at_pole_raise
204
- from = Proj::Point.new(0, 90)
205
- assert_raises(Proj::Error) do
206
- @proj_wgs84.transform(@proj_merc, from.to_radians)
207
- end
208
- end
209
-
210
- def test_collection
211
- from0 = Proj::Point.new(3458305.0, 5428192.0)
212
- from1 = Proj::Point.new(0, 0)
213
- collection = @proj_gk.transform_all(@proj_wgs84, [from0, from1])
214
-
215
- to0 = collection[0].to_degrees
216
- to1 = collection[1].to_degrees
217
-
218
- assert_in_delta(8.4302123334, to0.x, PRECISION)
219
- assert_in_delta(48.9906726079, to0.y, PRECISION)
220
-
221
- assert_in_delta(-20.9657785647, to1.x, PRECISION)
222
- assert_in_delta(0, to1.y, PRECISION)
223
- end
1
+ # encoding: UTF-8
2
+
3
+ require_relative './abstract_test'
4
+
5
+ if Proj::Api::PROJ_VERSION < Gem::Version.new('8.0.0')
6
+ class ProjectionTest < AbstractTest
7
+ PRECISION = 0.1 ** 4
8
+
9
+ def setup
10
+ @proj_wgs84 = Proj::Projection.new(["init=epsg:4326"]) # WGS84
11
+ @proj_gk = Proj::Projection.new(["+init=epsg:31467"]) # Gauss-Kruger Zone 3
12
+ @proj_merc = Proj::Projection.new(["proj=merc"])
13
+ @proj_conakry = Proj::Projection.new(["+init=epsg:31528"]) # Conakry 1905 / UTM zone 28N
14
+ @proj_ortel = Proj::Projection.new(["+proj=ortel", "+lon_0=90w"]) # Ortelius Oval Projection
15
+ @epsg2029i = ['+init=epsg:2029']
16
+ @epsg2029_args = ['+proj=utm', '+zone=17', '+ellps=clrk66', '+units=m', '+no_defs']
17
+ end
18
+
19
+ def test_arg_fail
20
+ assert_raises ArgumentError do
21
+ Proj::Projection.parse()
22
+ end
23
+ assert_raises ArgumentError do
24
+ Proj::Projection.parse(nil)
25
+ end
26
+ assert_raises ArgumentError do
27
+ Proj::Projection.parse(1)
28
+ end
29
+ end
30
+
31
+ def test_arg_string
32
+ args = Proj::Projection.parse('+init=epsg:2029')
33
+ assert_equal(@epsg2029i, args)
34
+ args = Proj::Projection.parse(' +proj=utm +zone=17 +ellps=clrk66 +units=m +no_defs ')
35
+ assert_equal(@epsg2029_args, args)
36
+ end
37
+
38
+ def test_arg_string_with_plus
39
+ args = Proj::Projection.parse('+init=epsg:2029')
40
+ assert_equal(@epsg2029i, args)
41
+ args = Proj::Projection.parse('+proj=utm +zone=17 +ellps=clrk66 +units=m +no_defs')
42
+ assert_equal(@epsg2029_args, args)
43
+ end
44
+
45
+ def test_arg_array
46
+ args = Proj::Projection.parse(['+init=epsg:2029'])
47
+ assert_equal(@epsg2029i, args)
48
+ args = Proj::Projection.parse(['+proj=utm', '+zone=17', '+ellps=clrk66', '+units=m', '+no_defs'])
49
+ assert_equal(@epsg2029_args, args)
50
+ end
51
+
52
+ def test_arg_array_with_plus
53
+ args = Proj::Projection.parse(['+init=epsg:2029'])
54
+ assert_equal(@epsg2029i, args)
55
+ args = Proj::Projection.parse(['+proj=utm', '+zone=17', '+ellps=clrk66', '+units=m', '+no_defs'])
56
+ assert_equal(@epsg2029_args, args)
57
+ end
58
+
59
+ def test_arg_hash_with_string
60
+ args = Proj::Projection.parse('init' => 'epsg:2029')
61
+ assert_equal(@epsg2029i, args)
62
+ args = Proj::Projection.parse('proj' => 'utm', 'zone' => '17', 'ellps' => 'clrk66', 'units' => 'm', 'no_defs' => nil)
63
+ assert_equal(@epsg2029_args, args)
64
+ end
65
+
66
+ def test_arg_hash_with_symbol
67
+ args = Proj::Projection.parse(:init => 'epsg:2029')
68
+ assert_equal(@epsg2029i, args)
69
+ args = Proj::Projection.parse(:proj => 'utm', :zone => '17', :ellps => 'clrk66', :units => 'm', :no_defs => nil)
70
+ assert_equal(@epsg2029_args, args)
71
+ end
72
+
73
+ def test_arg_hash_with_symbol_simple
74
+ args = Proj::Projection.parse(:init => 'epsg:2029')
75
+ assert_equal(@epsg2029i, args)
76
+ args = Proj::Projection.parse(:proj => 'utm', :zone => '17', :ellps => 'clrk66', :units => 'm', :no_defs => nil)
77
+ assert_equal(@epsg2029_args, args)
78
+ end
79
+
80
+ def test_arg_projection
81
+ proj = Proj::Projection.new(['+init=epsg:2029'])
82
+ args = Proj::Projection.parse(proj)
83
+ assert_equal(["+init=epsg:2029", "+proj=utm", "+zone=17", "+ellps=clrk66", "+units=m", "+no_defs"], args)
84
+ end
85
+
86
+ def test_init_arg_string
87
+ proj = Proj::Projection.new('+init=epsg:2029')
88
+ assert_equal(' +init=epsg:2029 +proj=utm +zone=17 +ellps=clrk66 +units=m +no_defs', proj.getDef)
89
+ end
90
+
91
+ def test_init_arg_array
92
+ proj = Proj::Projection.new(['+init=epsg:2029'])
93
+ assert_equal(' +init=epsg:2029 +proj=utm +zone=17 +ellps=clrk66 +units=m +no_defs', proj.getDef)
94
+ end
95
+
96
+ def test_init_arg_hash
97
+ proj = Proj::Projection.new(:proj => 'utm', 'zone' => '17', 'ellps' => 'clrk66', :units => 'm', :no_defs => nil)
98
+ assert_equal(' +proj=utm +zone=17 +ellps=clrk66 +units=m +no_defs', proj.getDef)
99
+ end
100
+
101
+ def test_init_arg_fail
102
+ assert_raises Proj::Error do
103
+ Proj::Projection.new(:proj => 'xxxx')
104
+ end
105
+
106
+ assert_raises Proj::Error do
107
+ Proj::Projection.new(:foo => 'xxxx')
108
+ end
109
+ end
110
+
111
+ def test_is_latlong
112
+ assert(@proj_wgs84.isLatLong?)
113
+ refute(@proj_gk.isLatLong?)
114
+ refute(@proj_conakry.isLatLong?)
115
+ refute(@proj_ortel.isLatLong?)
116
+ end
117
+
118
+ def test_is_geocent
119
+ assert_equal(@proj_gk.isGeocent?, @proj_gk.isGeocentric?) # two names for same method
120
+ refute(@proj_wgs84.isGeocent?)
121
+ refute(@proj_gk.isGeocent?)
122
+ refute(@proj_conakry.isGeocent?)
123
+ refute(@proj_ortel.isGeocent?)
124
+ end
125
+
126
+ def test_get_def
127
+ assert_equal(' +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0', @proj_wgs84.getDef)
128
+ assert_equal(' +init=epsg:31467 +proj=tmerc +lat_0=0 +lon_0=9 +k=1 +x_0=3500000 +y_0=0 +ellps=bessel +units=m +no_defs', @proj_gk.getDef)
129
+ assert_equal('+proj=ortel +lon_0=90w +ellps=GRS80', @proj_ortel.getDef.strip)
130
+ end
131
+
132
+ def test_to_s
133
+ assert_equal('#<Proj::Projection +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0>', @proj_wgs84.to_s)
134
+ end
135
+
136
+ def test_projection
137
+ assert_equal('longlat', @proj_wgs84.projection)
138
+ assert_equal('tmerc', @proj_gk.projection)
139
+ assert_equal('utm', @proj_conakry.projection)
140
+ assert_equal('ortel', @proj_ortel.projection)
141
+ end
142
+
143
+ def test_datum
144
+ assert_equal('WGS84', @proj_wgs84.datum)
145
+ assert_nil(@proj_gk.datum)
146
+ assert_nil(@proj_conakry.datum)
147
+ end
148
+
149
+ # echo "8.4302123334 48.9906726079" | proj +init=epsg:31467 -
150
+ def test_forward_gk
151
+ point = Proj::Point.new(8.4302123334, 48.9906726079)
152
+ result = @proj_gk.forward(point.to_radians)
153
+ assert_in_delta(3458305.0, result.x, 0.1)
154
+ assert_in_delta(5428192.0, result.y, 0.1)
155
+ end
156
+
157
+ def test_forward_gk_degrees
158
+ point = Proj::Point.new(8.4302123334, 48.9906726079)
159
+ result = @proj_gk.forwardDeg(point)
160
+ assert_in_delta(3458305.0, result.x, 0.1)
161
+ assert_in_delta(5428192.0, result.y, 0.1)
162
+ end
163
+
164
+ # echo "3458305 5428192" | invproj -f '%.10f' +init=epsg:31467 -
165
+ def test_inverse_gk
166
+ point = Proj::Point.new(3458305.0, 5428192.0)
167
+ result = @proj_gk.inverse(point).to_degrees
168
+ assert_in_delta(result.x, 8.4302123334, PRECISION)
169
+ assert_in_delta(result.y, 48.9906726079, PRECISION)
170
+ end
171
+
172
+ def test_inverse_gk_degrees
173
+ point = Proj::Point.new(3458305.0, 5428192.0)
174
+ result = @proj_gk.inverseDeg(point)
175
+ assert_in_delta(result.x, 8.4302123334, PRECISION)
176
+ assert_in_delta(result.y, 48.9906726079, PRECISION)
177
+ end
178
+
179
+ # echo "190 92" | proj +init=epsg:31467 -
180
+ def test_out_of_bounds
181
+ error = assert_raises(Proj::Error) do
182
+ point = Proj::Point.new(190, 92).to_radians
183
+ @proj_gk.forward(point)
184
+ end
185
+ assert_equal('latitude or longitude exceeded limits', error.message)
186
+ end
187
+
188
+ # echo "3458305 5428192" | cs2cs -f '%.10f' +init=epsg:31467 +to +init=epsg:4326 -
189
+ def test_gk_to_wgs84
190
+ from = Proj::Point.new(3458305.0, 5428192.0)
191
+ to = @proj_gk.transform(@proj_wgs84, from).to_degrees
192
+ assert_in_delta(8.4302123334, to.x, PRECISION)
193
+ assert_in_delta(48.9906726079, to.y, PRECISION)
194
+ end
195
+
196
+ # echo "8.4293092923 48.9896114523" | cs2cs -f '%.10f' +init=epsg:4326 +to +init=epsg:31467 -
197
+ def test_wgs84_to_gk
198
+ from = Proj::Point.new(8.4302123334, 48.9906726079)
199
+ to = @proj_wgs84.transform(@proj_gk, from.to_radians)
200
+ assert_in_delta(3458305.0, to.x, PRECISION)
201
+ assert_in_delta(5428192.0, to.y, PRECISION)
202
+ end
203
+
204
+ def test_mercator_at_pole_raise
205
+ from = Proj::Point.new(0, 90)
206
+ assert_raises(Proj::Error) do
207
+ @proj_wgs84.transform(@proj_merc, from.to_radians)
208
+ end
209
+ end
210
+
211
+ def test_collection
212
+ from0 = Proj::Point.new(3458305.0, 5428192.0)
213
+ from1 = Proj::Point.new(0, 0)
214
+ collection = @proj_gk.transform_all(@proj_wgs84, [from0, from1])
215
+
216
+ to0 = collection[0].to_degrees
217
+ to1 = collection[1].to_degrees
218
+
219
+ assert_in_delta(8.4302123334, to0.x, PRECISION)
220
+ assert_in_delta(48.9906726079, to0.y, PRECISION)
221
+
222
+ assert_in_delta(-20.9657785647, to1.x, PRECISION)
223
+ assert_in_delta(0, to1.y, PRECISION)
224
+ end
225
+ end
224
226
  end
@@ -1,68 +1,68 @@
1
- # encoding: UTF-8
2
-
3
- require_relative './abstract_test'
4
-
5
- class TransformationTest < AbstractTest
6
- PRECISION = 0.5
7
-
8
- def setup
9
- @crs_wgs84 = Proj::Crs.new('epsg:4326')
10
- @crs_gk = Proj::Crs.new('epsg:31467')
11
- end
12
-
13
- def test_create_from_strings
14
- transform = Proj::Transformation.new('epsg:31467', 'epsg:4326')
15
- assert(transform.info)
16
- end
17
-
18
- def test_create_crs
19
- transform = Proj::Transformation.new(@crs_wgs84, @crs_gk)
20
- assert(transform.info)
21
- end
22
-
23
- # echo "3458305 5428192" | cs2cs -f '%.10f' +init=epsg:31467 +to +init=epsg:4326 -
24
- def test_gk_to_wgs84_forward
25
- transform = Proj::Transformation.new(@crs_gk, @crs_wgs84)
26
- from = Proj::Coordinate.new(x: 5428192.0, y: 3458305.0, z: -5.1790915237)
27
- to = transform.forward(from)
28
-
29
- assert_in_delta(48.98963932450735, to.x, PRECISION)
30
- assert_in_delta(8.429263044355544, to.y, PRECISION)
31
- assert_in_delta(-5.1790915237, to.z, PRECISION)
32
- assert_in_delta(0, to.t, PRECISION)
33
- end
34
-
35
- def test_gk_to_wgs84_inverse
36
- transform = Proj::Transformation.new(@crs_gk, @crs_wgs84)
37
- from = Proj::Coordinate.new(lam: 48.9906726079, phi: 8.4302123334)
38
- to = transform.inverse(from)
39
-
40
- assert_in_delta(5428306.39, to.x, PRECISION)
41
- assert_in_delta(3458375, to.y, PRECISION)
42
- assert_in_delta(0, to.z, PRECISION)
43
- assert_in_delta(0, to.t, PRECISION)
44
- end
45
-
46
- # echo "8.4293092923 48.9896114523" | cs2cs -f '%.10f' +init=epsg:4326 +to +init=epsg:31467 -
47
- def test_wgs84_to_gk_forward
48
- transform = Proj::Transformation.new(@crs_wgs84, @crs_gk)
49
- from = Proj::Coordinate.new(lam: 48.9906726079, phi: 8.4302123334)
50
- to = transform.forward(from)
51
-
52
- assert_in_delta(5428306.39, to.x, PRECISION)
53
- assert_in_delta(3458375, to.y, PRECISION)
54
- assert_in_delta(0, to.z, PRECISION)
55
- assert_in_delta(0, to.t, PRECISION)
56
- end
57
-
58
- def test_wgs84_to_gk_forward_inverse
59
- transform = Proj::Transformation.new(@crs_wgs84, @crs_gk)
60
- from = Proj::Coordinate.new(x: 5428192.0, y: 3458305.0, z: -5.1790915237)
61
- to = transform.inverse(from)
62
-
63
- assert_in_delta(48.98963932450735, to.x, PRECISION)
64
- assert_in_delta(8.429263044355544, to.y, PRECISION)
65
- assert_in_delta(-5.1790915237, to.z, PRECISION)
66
- assert_in_delta(0, to.t, PRECISION)
67
- end
1
+ # encoding: UTF-8
2
+
3
+ require_relative './abstract_test'
4
+
5
+ class TransformationTest < AbstractTest
6
+ PRECISION = 0.5
7
+
8
+ def setup
9
+ @crs_wgs84 = Proj::Crs.new('epsg:4326')
10
+ @crs_gk = Proj::Crs.new('epsg:31467')
11
+ end
12
+
13
+ def test_create_from_strings
14
+ transform = Proj::Transformation.new('epsg:31467', 'epsg:4326')
15
+ assert(transform.info)
16
+ end
17
+
18
+ def test_create_crs
19
+ transform = Proj::Transformation.new(@crs_wgs84, @crs_gk)
20
+ assert(transform.info)
21
+ end
22
+
23
+ # echo "3458305 5428192" | cs2cs -f '%.10f' +init=epsg:31467 +to +init=epsg:4326 -
24
+ def test_gk_to_wgs84_forward
25
+ transform = Proj::Transformation.new(@crs_gk, @crs_wgs84)
26
+ from = Proj::Coordinate.new(x: 5428192.0, y: 3458305.0, z: -5.1790915237)
27
+ to = transform.forward(from)
28
+
29
+ assert_in_delta(48.98963932450735, to.x, PRECISION)
30
+ assert_in_delta(8.429263044355544, to.y, PRECISION)
31
+ assert_in_delta(-5.1790915237, to.z, PRECISION)
32
+ assert_in_delta(0, to.t, PRECISION)
33
+ end
34
+
35
+ def test_gk_to_wgs84_inverse
36
+ transform = Proj::Transformation.new(@crs_gk, @crs_wgs84)
37
+ from = Proj::Coordinate.new(lam: 48.9906726079, phi: 8.4302123334)
38
+ to = transform.inverse(from)
39
+
40
+ assert_in_delta(5428307, to.x, PRECISION)
41
+ assert_in_delta(3458375, to.y, PRECISION)
42
+ assert_in_delta(0, to.z, PRECISION)
43
+ assert_in_delta(0, to.t, PRECISION)
44
+ end
45
+
46
+ # echo "8.4293092923 48.9896114523" | cs2cs -f '%.10f' +init=epsg:4326 +to +init=epsg:31467 -
47
+ def test_wgs84_to_gk_forward
48
+ transform = Proj::Transformation.new(@crs_wgs84, @crs_gk)
49
+ from = Proj::Coordinate.new(lam: 48.9906726079, phi: 8.4302123334)
50
+ to = transform.forward(from)
51
+
52
+ assert_in_delta(5428307, to.x, PRECISION)
53
+ assert_in_delta(3458375, to.y, PRECISION)
54
+ assert_in_delta(0, to.z, PRECISION)
55
+ assert_in_delta(0, to.t, PRECISION)
56
+ end
57
+
58
+ def test_wgs84_to_gk_forward_inverse
59
+ transform = Proj::Transformation.new(@crs_wgs84, @crs_gk)
60
+ from = Proj::Coordinate.new(x: 5428192.0, y: 3458305.0, z: -5.1790915237)
61
+ to = transform.inverse(from)
62
+
63
+ assert_in_delta(48.98963932450735, to.x, PRECISION)
64
+ assert_in_delta(8.429263044355544, to.y, PRECISION)
65
+ assert_in_delta(-5.1790915237, to.z, PRECISION)
66
+ assert_in_delta(0, to.t, PRECISION)
67
+ end
68
68
  end