cb-ffi-proj4 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/data/ntv1_can.dat ADDED
Binary file
data/data/null ADDED
Binary file
data/data/other.extra ADDED
@@ -0,0 +1,49 @@
1
+ ## NAD83 / BC Albers (this has been superceeded but is kept for compatibility)
2
+ <42102> +proj=aea +ellps=GRS80 +lat_0=45 +lon_0=-126.0 +lat_1=50.0 +lat_2=58.5 +x_0=1000000.0 +y_0=0 +datum=NAD83 +units=m no_defs <>
3
+
4
+
5
+ #
6
+ # OGC-defined extended codes (41000--41999)
7
+ # see http://www.digitalearth.gov/wmt/auto.html
8
+ #
9
+ # WGS84 / Simple Mercator
10
+ <41001> +proj=merc +lat_ts=0 +lon_0=0 +k=1.000000 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs no_defs <>
11
+ #
12
+ # CubeWerx-defined extended codes (42100--42199)
13
+ #
14
+ # WGS 84 / LCC Canada
15
+ <42101> +proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=-8000000 +ellps=WGS84 +datum=WGS84 +units=m +no_defs no_defs <>
16
+ #EPSG:42102,"PROJCS[\"NAD83 / BC Albers\",GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Decimal_Degree\",0.0174532925199433]],PROJECTION[\"Albers_conic_equal_area\"],PARAMETER[\"central_meridian\",-126.0],PARAMETER[\"latitude_of_origin\",45],PARAMETER[\"standard_parallel_1\",50.0],PARAMETER[\"standard_parallel_2\",58.5],PARAMETER[\"false_easting\",1000000.0],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]"
17
+ # WGS 84 / LCC USA
18
+ <42103> +proj=lcc +lat_1=33 +lat_2=45 +lat_0=0 +lon_0=-100 +x_0=0 +y_0=0 +ellps=WGS72 +datum=WGS84 +units=m +no_defs no_defs <>
19
+ # NAD83 / MTM zone 8 Québec
20
+ <42104> +proj=tmerc +lat_0=0 +lon_0=-73.5 +k=0.999900 +x_0=304800 +y_0=0 +ellps=GRS80 +units=m +no_defs no_defs <>
21
+ # WGS84 / Merc NorthAm
22
+ <42105> +proj=merc +lat_ts=0 +lon_0=-96 +k=1.000000 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs no_defs <>
23
+ # WGS84 / Lambert Azim Mozambique
24
+ <42106> +proj=laea +lat_0=5 +lon_0=20 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +datum=WGS84 +units=m +no_defs no_defs <>
25
+ #
26
+ # CubeWerx-customer definitions (42300--42399)
27
+ #
28
+ # NAD27 / Polar Stereographic / CM=-98
29
+ <42301> +proj=stere +lat_0=90 +lon_0=-98 +x_0=0 +y_0=0 +ellps=clrk66 +datum=NAD27 +units=m +no_defs no_defs <>
30
+ # JapanOrtho.09 09
31
+ <42302> +proj=tmerc +lat_0=36 +lon_0=139.833333333333 +k=0.999900 +x_0=0 +y_0=0 +ellps=bessel +units=m +no_defs no_defs <>
32
+ # NAD83 / Albers NorthAm
33
+ <42303> +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs no_defs <>
34
+ # NAD83 / NRCan LCC Canada
35
+ <42304> +proj=lcc +lat_1=49 +lat_2=77 +lat_0=49 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs no_defs <>
36
+ # France_II
37
+ <42305> +proj=lcc +lat_1=45.898918964419 +lat_2=47.696014502038 +lat_0=46.8 +lon_0=2.337229166666667 +x_0=600000 +y_0=2200000 +a=6378249.2 +b=6356514.999904194 +pm=2.337229166666667 +units=m +no_defs no_defs <>
38
+ # NAD83/QC_LCC
39
+ <42306> +proj=lcc +lat_1=46 +lat_2=60 +lat_0=44 +lon_0=-68.5 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs no_defs <>
40
+ # NAD83 / Texas Central - feet
41
+ <42307> +proj=lcc +lat_1=31.8833333333333 +lat_2=30.1166666666667 +lat_0=29.6666666666667 +lon_0=-100.333333333333 +x_0=700000.0000000001 +y_0=3000000 +ellps=GRS80 +datum=NAD83 +to_meter=0.3048006096012192 +no_defs no_defs <>
42
+ # NAD27 / California Albers
43
+ <42308> +proj=aea +lat_1=34 +lat_2=40.5 +lat_0=0 +lon_0=-120 +x_0=0 +y_0=-4000000 +ellps=clrk66 +datum=NAD27 +units=m +no_defs no_defs <>
44
+ # NAD 83 / LCC Canada AVHRR-2
45
+ <42309> +proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs no_defs <>
46
+ # WGS84+GRS80 / Mercator
47
+ <42310> +proj=merc +lat_ts=0 +lon_0=0 +k=1.000000 +x_0=0 +y_0=0 +ellps=GRS80 +datum=WGS84 +units=m +no_defs no_defs <>
48
+ # NAD83 / LCC Statcan
49
+ <42311> +proj=lcc +lat_1=49 +lat_2=77 +lat_0=63.390675 +lon_0=-91.86666700000001 +x_0=6200000 +y_0=3000000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs no_defs <>
data/data/proj_def.dat ADDED
@@ -0,0 +1,17 @@
1
+ # Projection library defaults file
2
+ # SCCSID--- @(#)proj_def.dat 4.3 94/02/23 GIE REL"
3
+ # very preliminary version
4
+ <general>
5
+ ellps=WGS84
6
+ <>
7
+ <aea> # Conterminous U.S. map
8
+ lat_1=29.5
9
+ lat_2=45.5
10
+ <>
11
+ <lcc> # Conterminous U.S. map
12
+ lat_1=33
13
+ lat_2=45
14
+ <>
15
+ <lagrng>
16
+ W=2
17
+ <>
data/data/prvi ADDED
Binary file
data/data/stgeorge ADDED
Binary file
data/data/stlrnc ADDED
Binary file
data/data/stpaul ADDED
Binary file
data/data/world ADDED
@@ -0,0 +1,212 @@
1
+ # SCCSID @(#)world 1.2 95/08/05 GIE REL
2
+ # proj +init files for various non-U.S. coordinate systems.
3
+ #
4
+ <CH1903> # Swiss Coordinate System
5
+ +proj=somerc +lat_0=46d57'8.660"N +lon_0=7d26'22.500"E
6
+ +ellps=bessel +x_0=600000 +y_0=200000
7
+ +k_0=1. no_defs <>
8
+ <madagascar> # Laborde grid for Madagascar
9
+ proj=labrd ellps=intl lon_0=46d26'13.95E lat_0=18d54S
10
+ azi=18d54 k_0=.9995 x_0=400000 y_0=800000
11
+ no_defs <>
12
+ <new_zealand> # New Zealand Map Grid (NZMG)
13
+ proj=nzmg # Projection unique to N.Z. so all factors fixed
14
+ no_defs <>
15
+ # Secondary grids DMA TM8358.1, p. 4.3
16
+ <bwi> # British West Indies
17
+ proj=tmerc ellps=clrk80 lon_0=62W
18
+ x_0=400000 k_0=0.9995
19
+ no_defs <>
20
+ <costa-n> # Costa Rica Norte
21
+ proj=lcc ellps=clrk66 lat_1=10d28N lon_0=84d20W
22
+ x_0=500000 y_0=217820.522 k_0=0.99995696
23
+ no_defs <>
24
+ <costa-s> # Costa Rica Sud
25
+ proj=lcc ellps=clrk66 lat_1=9dN lon_0=83d40W
26
+ x_0=500000 y_0=327987.436 k_0=0.99995696
27
+ no_defs <>
28
+ <cuba-n> # Cuba Norte
29
+ proj=lcc ellps=clrk66 lat_1=22d21N lon_0=81dW
30
+ x_0=500000 y_0=280296.016 k_0=0.99993602
31
+ no_defs <>
32
+ <cuba-s> # Cuba Sud
33
+ proj=lcc ellps=clrk66 lat_1=20d43'N lon_0=76d50'W
34
+ x_0=500000 y_0=229126.939 k_0=0.99994848
35
+ no_defs <>
36
+ <domin_rep> # Dominican Republic
37
+ proj=lcc ellps=clrk66 lat_1=18d49'N lon_0=71d30'W
38
+ x_0=500000 y_0=277063.657 k_0=0.99991102
39
+ no_defs <>
40
+ <egypt-1> # Egypt
41
+ proj=tmerc ellps=intl lon_0=25d30'E x_0=300000 k_0=0.99985
42
+ no_defs <>
43
+ <egypt-2> # Egypt
44
+ proj=tmerc ellps=intl lon_0=28d30'E x_0=300000 k_0=0.99985
45
+ no_defs <>
46
+ <egypt-3> # Egypt
47
+ proj=tmerc ellps=intl lon_0=31d30'E x_0=300000 k_0=0.99985
48
+ no_defs <>
49
+ <egypt-4> # Egypt
50
+ proj=tmerc ellps=intl lon_0=34d30'E x_0=300000 k_0=0.99985
51
+ no_defs <>
52
+ <egypt-5> # Egypt
53
+ proj=tmerc ellps=intl lon_0=37d30'E x_0=300000 k_0=0.99985
54
+ no_defs <>
55
+ <el_sal> # El Salvador
56
+ proj=lcc ellps=clrk66 lat_1=13d47'N lon_0=89dW
57
+ x_0=500000 y_0=295809.184 k_0=0.99996704
58
+ no_defs <>
59
+ <guat-n> # Guatemala Norte
60
+ proj=lcc ellps=clrk66 lat_1=16d49'N lon_0=90d20'W
61
+ x_0=500000 y_0=292209.579 k_0=0.99992226
62
+ no_defs <>
63
+ <guat-s> # Guatemala Sud
64
+ proj=lcc ellps=clrk66 lat_1=14d54'N lon_0=90d20'W
65
+ x_0=500000 y_0=325992.681 k_0=0.99989906
66
+ no_defs <>
67
+ <haiti> # Haiti
68
+ proj=lcc ellps=clrk66 lat_1=18d49'N lon_0=71d30'W
69
+ x_0=500000 y_0=277063.657 k_0=0.99991102
70
+ no_defs <>
71
+ <hond-n> # Honduras Norte
72
+ proj=lcc ellps=clrk66 lat_1=15d30'N lon_0=86d10'W
73
+ x_0=500000 y_0=296917.439 k_0=0.99993273
74
+ no_defs <>
75
+ <hond-s> # Honduras Sud
76
+ proj=lcc ellps=clrk66 lat_1=13d47'N lon_0=87d10'W
77
+ x_0=500000 y_0=296215.903 k_0=0.99995140
78
+ no_defs <>
79
+ <levant> # Levant
80
+ proj=lcc ellps=clrk66 lat_1=34d39'N lon_0=37d21'E
81
+ x_0=500000 y_0=300000 k_0=0.9996256
82
+ no_defs <>
83
+ <nica-n> # Nicaragua Norte
84
+ proj=lcc ellps=clrk66 lat_1=13d52'N lon_0=85d30'W
85
+ x_0=500000 y_0=359891.816 k_0=0.99990314
86
+ no_defs <>
87
+ <nica-s> # Nicaragua Sud
88
+ proj=lcc ellps=clrk66 lat_1=11d40'N lon_0=85d30'W
89
+ x_0=500000 y_0=288876.327 k_0=0.99992228
90
+ no_defs <>
91
+ <nw-africa> # Northwest Africa
92
+ proj=lcc ellps=clrk80 lat_1=34dN lon_0=0dE
93
+ x_0=1000000 y_0=500000 k_0=0.99908
94
+ no_defs <>
95
+ <palestine> # Palestine
96
+ proj=tmerc a=6378300.79 rf=293.488307656
97
+ lat_0=31d44'2.749"N lon_0=35d12'43.490"E
98
+ x_0=170251.555 y_0=126867.909 k_0=1
99
+ no_defs <>
100
+ <panama> # Panama
101
+ proj=lcc ellps=clrk66 lat_1=8d25'N lon_0=80dW
102
+ x_0=500000 y_0=294865.303 k_0=0.99989909
103
+ no_defs <>
104
+ # other grids in DMA TM8358.1
105
+ <bng> # British National Grid
106
+ proj=tmerc ellps=airy lat_0=49dN lon_0=2dW
107
+ k_0=0.9996012717 x_0=400000 y_0=-100000
108
+ no_defs <>
109
+ <malay> # West Malaysian RSO Grid
110
+ proj=omerc a=6377295.66402 rf=300.8017 alpha=323d01'32.846"
111
+ no_uoff rot_conv lonc=102d15E lat_0=4dN k_0=0.99984 x_0=804670.240 y_0=0
112
+ no_defs <>
113
+ <india-I> # India Zone I
114
+ proj=lcc ellps=everest lon_0=68E lat_1=32d30'N
115
+ x_0=2743185.69 y_0=914395.23 k_0=.998786408
116
+ no_defs <>
117
+ <india-IIA> # India Zone IIA
118
+ proj=lcc ellps=everest lon_0=74E lat_1=26N
119
+ x_0=2743185.69 y_0=914395.23 k_0=.998786408
120
+ no_defs <>
121
+ <india-IIB> # India Zone IIB
122
+ proj=lcc ellps=everest lon_0=90E lat_1=26N
123
+ x_0=2743185.69 y_0=914395.23 k_0=.998786408
124
+ no_defs <>
125
+ <india-IIIA> # India Zone IIIA
126
+ proj=lcc ellps=everest lon_0=80E lat_1=19N
127
+ x_0=2743185.69 y_0=914395.23 k_0=.998786408
128
+ no_defs <>
129
+ <india-IIIB> # India Zone IIIB
130
+ proj=lcc ellps=everest lon_0=100E lat_1=19N
131
+ x_0=2743185.69 y_0=914395.23 k_0=.998786408
132
+ no_defs <>
133
+ <india-IVA> # India Zone IVA
134
+ proj=lcc ellps=everest lon_0=80E lat_1=12N
135
+ x_0=2743185.69 y_0=914395.23 k_0=.998786408
136
+ no_defs <>
137
+ <india-IVB> # India Zone IVB
138
+ proj=lcc ellps=everest lon_0=104E lat_1=12N
139
+ x_0=2743185.69 y_0=914395.23 k_0=.998786408
140
+ no_defs <>
141
+ <ceylon> # Ceylon Belt
142
+ proj=tmerc ellps=everest lon_0=80d46'18.160"E lat_0=7d0'1.729"N
143
+ x_0=160933.56048 y_0=160933.56048 k_0=1.
144
+ no_defs <>
145
+ <irish> # Irish Transverse Mercator Grid
146
+ proj=tmerx ellps=mod_airy lat_0=53d30'N lon_0=8W
147
+ x_0=200000 y_0=-250000 k_0=1.000035
148
+ no_defs <>
149
+ <neiez> # Netherlands East Indies Equitorial Zone
150
+ proj=merc ellps=bessel lon_0=110E
151
+ x_0=3900000 y_0=900000 k_0=0.997
152
+ no_defs <>
153
+ <n-alger> # Nord Algerie Grid
154
+ proj=lcc ellps=clrk80 lon_0=2d42E lat_0=36N
155
+ x_0=500000 y_0=300000 k_0=0.999625544
156
+ no_defs <>
157
+ <n-maroc> # Nord Maroc Grid
158
+ proj=lcc ellps=clrk80 lon_0=5d24'W lat_0=33d18'N
159
+ x_0=500000 y_0=300000 k_0=0.999625769
160
+ no_defs <>
161
+ <n-tunis> # Nord Tunisie Grid
162
+ proj=lcc ellps=clrk80 lon_0=9d54E lat_0=36N
163
+ x_0=500000 y_0=300000 k_0=0.999625544
164
+ no_defs <>
165
+ <s-alger> # Sud Algerie Grid
166
+ proj=lcc ellps=clrk80 lon_0=2d42E lat_0=33d18'N
167
+ x_0=500000 y_0=300000 k_0=0.999625769
168
+ no_defs <>
169
+ <s-maroc> # Sud Maroc Grid
170
+ proj=lcc ellps=clrk80 lon_0=5d24W lat_0=29d42'N
171
+ x_0=500000 y_0=300000 k_0=0.999615596
172
+ no_defs <>
173
+ <s-tunis> # Sud Tunisie Grid
174
+ proj=lcc ellps=clrk80 lon_0=9d54'E lat_0=33d18'N
175
+ x_0=500000 y_0=300000 k_0=0.999625769
176
+ no_defs <>
177
+ # Gauss Krueger Grid for Germany
178
+ #
179
+ # The first figure of the easting is lon_0 devided by 3
180
+ # ( 2 for 6d0E, 3 for 9d0E, 4 for 12d0E)
181
+ # For translations you have to remove this first figure
182
+ # and convert northings and eastings from km to meter .
183
+ # The other way round, devide by 1000 and add the figure.
184
+ # I made 3 entrys for the officially used grids in Germany
185
+ #
186
+ #
187
+ # Und nochmal in deutsch :
188
+ # Die erste Ziffer des Rechtswerts beschreibt den Hauptmeridian
189
+ # und ist dessen Gradzahl geteilt durch 3.
190
+ # Zum Umrechnen in Grad muss daher die erste Ziffer des Rechtswertes
191
+ # entfernt werden und evt. von km auf Metern umgerechnet werden.
192
+ # Zur Umrechnung in Gauss Krueger Koordinaten entsprechend die
193
+ # Ziffer fuer den Hauptmeridian vor dem Rechtswert ergaenzen.
194
+ # Ich hab fuer alle drei in Deutschland ueblichen Hauptmeridiane
195
+ # jeweils einen Eintrag ergaenzt.
196
+ #
197
+ #
198
+ # added by Michael Goepel <goepel@ffm.plusline.de>
199
+ #
200
+ <gk2-d> # Gauss Krueger Grid for Germany
201
+ proj=tmerc ellps=bessel lon_0=6d0E lat_0=0
202
+ x_0=500000
203
+ no_defs<>
204
+ <gk3-d> # Gauss Krueger Grid for Germany
205
+ proj=tmerc ellps=bessel lon_0=9d0E lat_0=0
206
+ x_0=500000
207
+ no_defs<>
208
+ <gk4-d> # Gauss Krueger Grid for Germany
209
+ proj=tmerc ellps=bessel lon_0=12d0E lat_0=0
210
+ x_0=500000
211
+ no_defs<>
212
+
@@ -0,0 +1,5 @@
1
+
2
+ module Proj4
3
+ class Point < Struct.new(:x, :y, :z)
4
+ end
5
+ end
@@ -0,0 +1,189 @@
1
+
2
+ module Proj4
3
+ class ProjectionParseError < RuntimeError; end
4
+ class TransformError < RuntimeError; end
5
+
6
+ class Projection
7
+ include Tools
8
+
9
+ attr_reader :ptr
10
+
11
+ def initialize(arg, auto_free = true)
12
+ args = case arg
13
+ when Array
14
+ arg.collect { |a| a.sub(/^\+/, '') }
15
+ when String
16
+ arg.strip.split(/ /).collect { |a| a.sub(/^\+/, '') }
17
+ when Hash
18
+ arg.collect { |k, v|
19
+ if v.nil?
20
+ k.to_s
21
+ else
22
+ "#{k.to_s.strip}=#{v.to_s.strip}"
23
+ end
24
+ }
25
+ when Proj4::Projection
26
+ arg.definition.strip.split(/ /).collect { |a| a.sub(/^\+/, '') }
27
+ else
28
+ raise ArgumentError.new("Unknown type #{arg.class} for projection definition")
29
+ end
30
+
31
+ params = args.collect(&:strip).collect { |a|
32
+ if !(a =~ /^\+/)
33
+ "+#{a}"
34
+ else
35
+ a
36
+ end
37
+ }.join(' ')
38
+
39
+ ptr = FFIProj4.pj_init_plus(params)
40
+
41
+ if ptr.null?
42
+ errno = FFIProj4.pj_get_errno_ref.read_int
43
+ raise ProjectionParseError.new(FFIProj4.pj_strerrno(errno))
44
+ else
45
+ @ptr = FFI::AutoPointer.new(
46
+ ptr,
47
+ auto_free ? self.class.method(:release) : self.class.method(:no_release)
48
+ )
49
+ end
50
+ end
51
+
52
+ def self.no_release(ptr) #:nodoc:
53
+ end
54
+
55
+ def self.release(ptr) #:nodoc:
56
+ FFIProj4.pj_free(ptr)
57
+ end
58
+
59
+ def lat_long?
60
+ bool_result(FFIProj4.pj_is_latlong(self.ptr))
61
+ end
62
+
63
+ def geocentric?
64
+ bool_result(FFIProj4.pj_is_geocent(self.ptr))
65
+ end
66
+
67
+ def definition
68
+ @definition ||= FFIProj4.pj_get_def(self.ptr, 0).strip
69
+ end
70
+
71
+ def definition_as_hash
72
+ self.definition.split(/ /).inject({}) { |memo, opt|
73
+ memo.tap {
74
+ k, v = opt.split(/=/)
75
+ k.sub!(/^\+/, '')
76
+ v = true if v.nil?
77
+ memo[k.to_sym] = v
78
+ }
79
+ }
80
+ end
81
+
82
+ #def to_s
83
+ #"#<Proj4::Projection #{definition}>"
84
+ #end
85
+ #alias :inspect :to_s
86
+
87
+ def forward(x, y)
88
+ xy = ProjXY.new(x, y)
89
+ ret = FFIProj4.pj_fwd(xy, self.ptr)
90
+ errno = FFIProj4.pj_get_errno_ref.read_int
91
+ if errno == 0
92
+ Point.new(ret.x, ret.y)
93
+ else
94
+ raise TransformError.new(FFIProj4.pj_strerrno(errno))
95
+ end
96
+ end
97
+ alias :forward_deg :forward
98
+
99
+ def forward_rad(x, y)
100
+ self.forward(deg_to_rad(x), deg_to_rad(y))
101
+ end
102
+
103
+ def inverse(x, y)
104
+ xy = ProjXY.new(x, y)
105
+ ret = FFIProj4.pj_inv(xy, self.ptr)
106
+ errno = FFIProj4.pj_get_errno_ref.read_int
107
+ if errno == 0
108
+ Point.new(ret.x, ret.y)
109
+ else
110
+ raise TransformError.new(FFIProj4.pj_strerrno(errno))
111
+ end
112
+ end
113
+ alias :inverse_deg :inverse
114
+
115
+ def inverse_rad(x, y)
116
+ self.inverse(deg_to_rad(x), deg_to_rad(y))
117
+ end
118
+
119
+ def transform(proj, x, y, z = nil)
120
+ if !proj.is_a?(Proj4::Projection)
121
+ raise ArgumentError.new("Expected a Proj4::Projection")
122
+ end
123
+
124
+ x_ptr = FFI::MemoryPointer.new(:double)
125
+ y_ptr = FFI::MemoryPointer.new(:double)
126
+ z_ptr = FFI::MemoryPointer.new(:double) unless z.nil?
127
+
128
+ x_ptr.write_double(x)
129
+ y_ptr.write_double(y)
130
+ z_ptr.write_double(z) unless z.nil?
131
+
132
+ result = FFIProj4.pj_transform(self.ptr, proj.ptr, 1, 1, x_ptr, y_ptr, z_ptr)
133
+
134
+ if result >= 0 && !bool_result(result)
135
+ Point.new(
136
+ x_ptr.read_double,
137
+ y_ptr.read_double,
138
+ z_ptr.read_double
139
+ )
140
+ else
141
+ raise TransformError.new(FFIProj4.pj_strerrno(result))
142
+ end
143
+ end
144
+ alias :transform_rad :transform
145
+
146
+ def transform_deg(proj, x, y, z = nil)
147
+ self.transform(proj, x, y, z).tap { |ret|
148
+ ret.x = rad_to_deg(ret.x)
149
+ ret.y = rad_to_deg(ret.y)
150
+ ret.z = rad_to_deg(ret.z)
151
+ }
152
+ end
153
+
154
+ def datum_transform(proj, x, y, z = nil)
155
+ if !proj.is_a?(Proj4::Projection)
156
+ raise ArgumentError.new("Expected a Proj4::Projection")
157
+ end
158
+
159
+ x_ptr = FFI::MemoryPointer.new(:double)
160
+ y_ptr = FFI::MemoryPointer.new(:double)
161
+ z_ptr = FFI::MemoryPointer.new(:double) unless z.nil?
162
+
163
+ x_ptr.write_double(x)
164
+ y_ptr.write_double(y)
165
+ z_ptr.write_double(z) unless z.nil?
166
+
167
+ result = FFIProj4.pj_transform(self.ptr, proj.ptr, 1, 1, x_ptr, y_ptr, z_ptr)
168
+
169
+ if result >= 0 && !bool_result(result)
170
+ Point.new(
171
+ x_ptr.read_double,
172
+ y_ptr.read_double,
173
+ z_ptr.read_double
174
+ )
175
+ else
176
+ raise TransformError.new(FFIProj4.pj_strerrno(result))
177
+ end
178
+ end
179
+ alias :datum_transform_rad :datum_transform
180
+
181
+ def datum_transform_deg(proj, x, y, z = nil)
182
+ self.datum_transform(proj, x, y, z).tap { |ret|
183
+ ret.x = rad_to_deg(ret.x)
184
+ ret.y = rad_to_deg(ret.y)
185
+ ret.z = rad_to_deg(ret.z)
186
+ }
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,43 @@
1
+
2
+ module Proj4
3
+ class ProjXY < FFI::Struct
4
+ layout(
5
+ :x, :double,
6
+ :y, :double
7
+ )
8
+
9
+ def initialize(*args)
10
+ if args.first.is_a?(FFI::Pointer)
11
+ super(*args)
12
+ else
13
+ self[:x] = if args.first.respond_to?(:read_double)
14
+ args.first.read_double
15
+ else
16
+ args.first.to_f
17
+ end
18
+
19
+ self[:y] = if args[1].respond_to?(:read_double)
20
+ args.first.read_double
21
+ else
22
+ args[1].to_f
23
+ end
24
+ end
25
+ end
26
+
27
+ def x=(v)
28
+ self[:x] = v
29
+ end
30
+
31
+ def y=(v)
32
+ self[:y] = v
33
+ end
34
+
35
+ def x
36
+ self[:x]
37
+ end
38
+
39
+ def y
40
+ self[:y]
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+
2
+ module Proj4
3
+ module Tools
4
+ def bool_result(r)
5
+ case r
6
+ when 1
7
+ true
8
+ when 0
9
+ false
10
+ else
11
+ raise RuntimeError.new("Unexpected boolean result: #{r}")
12
+ end
13
+ end
14
+
15
+ def rad_to_deg(rad)
16
+ rad * Proj4::RAD_TO_DEG
17
+ end
18
+
19
+ def deg_to_rad(deg)
20
+ deg * Proj4::DEG_TO_RAD
21
+ end
22
+
23
+ class << self
24
+ include Proj4::Tools
25
+ end
26
+ end
27
+ end