dr-ffi-proj4 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,108 @@
1
+
2
+ $: << File.dirname(__FILE__)
3
+ require 'test_helper'
4
+
5
+ class TransformationTests < MiniTest::Unit::TestCase
6
+ include TestHelper
7
+
8
+ def setup
9
+ @proj_wgs84 = Proj4::Projection.new(["init=epsg:4326"])
10
+ @proj_gk = Proj4::Projection.new(["init=epsg:31467"])
11
+ @proj_merc = Proj4::Projection.new(["proj=merc"])
12
+ @lon = 8.429263044355672
13
+ @lat = 48.98963932449638
14
+ @z = 46.318651656620204
15
+ @rw = 3458305
16
+ @hw = 5428192
17
+ @zw = -51.49743285309523
18
+ end
19
+
20
+ def test_gk_to_wgs84
21
+ from = Proj4::Point.new(@rw, @hw, @zw)
22
+ to = @proj_gk.transform(@proj_wgs84, from)
23
+ refute_equal(from.object_id, to.object_id)
24
+ assert_in_delta(@lon, to.x * Proj4::RAD_TO_DEG, TOLERANCE)
25
+ assert_in_delta(@lat, to.y * Proj4::RAD_TO_DEG, TOLERANCE)
26
+ assert_in_delta(0, to.z, TOLERANCE * (10 ** 3))
27
+ end
28
+
29
+ def test_gk_to_wgs84_inplace
30
+ from = Proj4::Point.new(@rw, @hw, @zw)
31
+ to = @proj_gk.transform!(@proj_wgs84, from)
32
+ assert_equal(from.object_id, to.object_id)
33
+ assert_in_delta(@lon, to.x * Proj4::RAD_TO_DEG, TOLERANCE)
34
+ assert_in_delta(@lat, to.y * Proj4::RAD_TO_DEG, TOLERANCE)
35
+ assert_in_delta(0, to.z, TOLERANCE * (10 ** 3))
36
+ end
37
+
38
+ def test_wgs84_to_gk
39
+ point = @proj_wgs84.transform(@proj_gk, Proj4::Point.new(@lon * Proj4::DEG_TO_RAD, @lat * Proj4::DEG_TO_RAD, 0))
40
+ assert_equal(@rw, point.x.round)
41
+ assert_equal(@hw, point.y.round)
42
+ assert_in_delta(@zw, point.z, TOLERANCE)
43
+ end
44
+
45
+ def test_no_dst_proj
46
+ assert_raises TypeError do
47
+ point = @proj_wgs84.transform(nil, Proj4::Point.new(@lon * Proj4::DEG_TO_RAD, @lat * Proj4::DEG_TO_RAD, 0))
48
+ end
49
+ end
50
+
51
+ def test_not_a_point
52
+ assert_raises TypeError do
53
+ point = @proj_wgs84.transform(@proj_gk, nil)
54
+ end
55
+ end
56
+
57
+ def test_mercator_at_pole_raise
58
+ assert_raises Proj4::ToleranceConditionError do
59
+ point = @proj_wgs84.transform(@proj_merc, Proj4::Point.new(0, 90 * Proj4::DEG_TO_RAD, 0))
60
+ end
61
+ end
62
+
63
+ def test_mercator_at_pole_rescue
64
+ begin
65
+ point = @proj_wgs84.transform(@proj_merc, Proj4::Point.new(0, 90 * Proj4::DEG_TO_RAD, 0))
66
+ rescue => exception
67
+ assert_kind_of(Proj4::ToleranceConditionError, exception)
68
+ assert_equal('tolerance condition error', exception.message)
69
+ assert_equal(20, exception.errnum)
70
+ end
71
+ end
72
+
73
+ class XYPoint
74
+ attr_accessor :x, :y, :extra
75
+
76
+ def initialize(x, y, extra)
77
+ @x = x
78
+ @y = y
79
+ @extra = extra
80
+ end
81
+ end
82
+
83
+ def test_no_z
84
+ point = @proj_gk.transform(@proj_wgs84, XYPoint.new(@rw, @hw, 'foo'))
85
+ assert_kind_of(XYPoint, point)
86
+ assert_equal('foo', point.extra)
87
+ assert_in_delta(@lon, point.x * Proj4::RAD_TO_DEG, TOLERANCE)
88
+ assert_in_delta(@lat, point.y * Proj4::RAD_TO_DEG, TOLERANCE)
89
+ end
90
+
91
+ def test_no_float
92
+ assert_raises TypeError do
93
+ @proj_gk.transform(@proj_wgs84, XYPoint.new('x', 'y', 'foo'))
94
+ end
95
+ end
96
+
97
+ def test_collection
98
+ from0 = Proj4::Point.new(@rw, @hw, @zw)
99
+ from1 = Proj4::Point.new(0, 0, 0)
100
+ collection = @proj_gk.transform_all!(@proj_wgs84, [ from0, from1 ])
101
+ to0 = collection[0]
102
+ to1 = collection[1]
103
+ assert_equal(from1.object_id, to1.object_id)
104
+ assert_in_delta(@lon, to0.x * Proj4::RAD_TO_DEG, TOLERANCE)
105
+ assert_in_delta(@lat, to0.y * Proj4::RAD_TO_DEG, TOLERANCE)
106
+ assert_in_delta(0, to0.z, TOLERANCE * (10 ** 3))
107
+ end
108
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dr-ffi-proj4
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - J Smith
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-12-18 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: ffi
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 23
29
+ segments:
30
+ - 1
31
+ - 0
32
+ - 0
33
+ version: 1.0.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: An ffi wrapper for the PROJ.4 Cartographic Projections library.
37
+ email: dark.panda@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - .travis.yml
47
+ - Gemfile
48
+ - Guardfile
49
+ - MIT-LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - data/FL
53
+ - data/GL27
54
+ - data/IGNF
55
+ - data/MD
56
+ - data/TN
57
+ - data/WI
58
+ - data/WO
59
+ - data/alaska
60
+ - data/conus
61
+ - data/epsg
62
+ - data/esri
63
+ - data/esri.extra
64
+ - data/hawaii
65
+ - data/nad.lst
66
+ - data/nad27
67
+ - data/nad83
68
+ - data/ntf_r93.gsb
69
+ - data/ntv1_can.dat
70
+ - data/null
71
+ - data/nzgd2kgrid0005.gsb
72
+ - data/other.extra
73
+ - data/proj_def.dat
74
+ - data/prvi
75
+ - data/stgeorge
76
+ - data/stlrnc
77
+ - data/stpaul
78
+ - data/world
79
+ - ffi-proj4.gemspec
80
+ - lib/ffi-proj4.rb
81
+ - lib/ffi-proj4/error.rb
82
+ - lib/ffi-proj4/point.rb
83
+ - lib/ffi-proj4/projection.rb
84
+ - lib/ffi-proj4/projxy.rb
85
+ - lib/ffi-proj4/tools.rb
86
+ - lib/ffi-proj4/version.rb
87
+ - test/point_tests.rb
88
+ - test/projection_tests.rb
89
+ - test/simple_transformation_tests.rb
90
+ - test/test_helper.rb
91
+ - test/transformation_tests.rb
92
+ homepage: http://github.com/dark-panda/ffi-proj4
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options: []
97
+
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">"
113
+ - !ruby/object:Gem::Version
114
+ hash: 25
115
+ segments:
116
+ - 1
117
+ - 3
118
+ - 1
119
+ version: 1.3.1
120
+ requirements: []
121
+
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.24
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: An ffi wrapper for the PROJ.4 Cartographic Projections library.
127
+ test_files:
128
+ - test/point_tests.rb
129
+ - test/projection_tests.rb
130
+ - test/simple_transformation_tests.rb
131
+ - test/test_helper.rb
132
+ - test/transformation_tests.rb
133
+ has_rdoc: