proj4rb 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +5 -5
  2. data/ChangeLog +46 -0
  3. data/Gemfile +4 -0
  4. data/README.rdoc +158 -148
  5. data/Rakefile +26 -41
  6. data/lib/area.rb +32 -0
  7. data/lib/config.rb +70 -0
  8. data/lib/context.rb +103 -0
  9. data/lib/coordinate.rb +197 -0
  10. data/lib/crs.rb +206 -0
  11. data/lib/ellipsoid.rb +42 -0
  12. data/lib/error.rb +18 -0
  13. data/lib/operation.rb +43 -0
  14. data/lib/pj_object.rb +82 -0
  15. data/lib/point.rb +72 -0
  16. data/lib/prime_meridian.rb +40 -0
  17. data/lib/proj.rb +31 -0
  18. data/lib/proj4.rb +3 -469
  19. data/lib/projection.rb +207 -0
  20. data/lib/transformation.rb +61 -0
  21. data/lib/unit.rb +54 -0
  22. data/proj4rb.gemspec +31 -0
  23. data/test/abstract_test.rb +7 -0
  24. data/test/context_test.rb +82 -0
  25. data/test/coordinate_test.rb +35 -0
  26. data/test/crs_test.rb +373 -0
  27. data/test/ellipsoid_test.rb +34 -0
  28. data/test/operation_test.rb +29 -0
  29. data/test/prime_meridians_test.rb +33 -0
  30. data/test/proj_test.rb +17 -0
  31. data/test/projection_test.rb +224 -0
  32. data/test/transformation_test.rb +68 -0
  33. data/test/unit_test.rb +47 -0
  34. metadata +82 -77
  35. data/data/GL27 +0 -22
  36. data/data/MD +0 -0
  37. data/data/TN +0 -0
  38. data/data/WI +0 -0
  39. data/data/WO +0 -0
  40. data/data/conus +0 -0
  41. data/data/epsg +0 -5443
  42. data/data/epsg-deprecated +0 -2
  43. data/data/esri +0 -5937
  44. data/data/esri.extra +0 -948
  45. data/data/hawaii +0 -0
  46. data/data/nad.lst +0 -142
  47. data/data/nad27 +0 -809
  48. data/data/nad83 +0 -744
  49. data/data/ntv1_can.dat +0 -0
  50. data/data/null +0 -0
  51. data/data/other.extra +0 -49
  52. data/data/proj_def.dat +0 -17
  53. data/data/prvi +0 -0
  54. data/data/stgeorge +0 -0
  55. data/data/stlrnc +0 -0
  56. data/data/stpaul +0 -0
  57. data/data/world +0 -212
  58. data/example/basic.rb +0 -18
  59. data/example/list-datums.rb +0 -17
  60. data/example/list-ellipsoids.rb +0 -17
  61. data/example/list-errors.rb +0 -11
  62. data/example/list-prime-meridians.rb +0 -17
  63. data/example/list-projection-types.rb +0 -17
  64. data/example/list-units.rb +0 -17
  65. data/example/version.rb +0 -8
  66. data/ext/Makefile +0 -238
  67. data/ext/extconf.rb +0 -16
  68. data/ext/mkmf.log +0 -103
  69. data/ext/out.log +0 -0
  70. data/ext/proj4_ruby-x64-mingw32.def +0 -2
  71. data/ext/proj4_ruby.so +0 -0
  72. data/ext/projrb.c +0 -566
  73. data/ext/projrb.o +0 -0
  74. data/ext/vc/proj4_ruby.sln +0 -19
  75. data/ext/vc/proj4_ruby.vcproj +0 -208
  76. data/test/test_constants.rb +0 -18
  77. data/test/test_create_projection.rb +0 -63
  78. data/test/test_datums.rb +0 -45
  79. data/test/test_ellipsoids.rb +0 -46
  80. data/test/test_errors.rb +0 -66
  81. data/test/test_init_projection.rb +0 -109
  82. data/test/test_prime_meridians.rb +0 -45
  83. data/test/test_projection_type.rb +0 -44
  84. data/test/test_simple_projection.rb +0 -58
  85. data/test/test_suite.rb +0 -14
  86. data/test/test_transform.rb +0 -115
  87. data/test/test_units.rb +0 -46
@@ -1,16 +0,0 @@
1
- require 'mkmf'
2
-
3
- dir_config('proj')
4
-
5
- if not have_header('proj_api.h')
6
- raise('Cannot find proj_api.h header')
7
- end
8
-
9
- have_header('projects.h')
10
-
11
- unless have_library('proj', 'pj_init') or
12
- have_library('libproj', 'pj_init')
13
- raise('Cannot find proj4 library')
14
- end
15
-
16
- create_makefile 'proj4_ruby'
@@ -1,103 +0,0 @@
1
- have_header: checking for proj_api.h... -------------------- yes
2
-
3
- "x86_64-w64-mingw32-gcc -o conftest.exe -Ic:/mingw64/mingw64/local/ruby/include/ruby-2.1.0/x64-mingw32 -Ic:/mingw64/mingw64/local/ruby/include/ruby-2.1.0/ruby/backward -Ic:/mingw64/mingw64/local/ruby/include/ruby-2.1.0 -I. -Ic:/mingw64/mingw64/local/include -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c -L. -Lc:/mingw64/mingw64/local/ruby/lib -L. -Lc:/mingw64/mingw64/local/lib -lx64-msvcrt-ruby210 -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi "
4
- checked program was:
5
- /* begin */
6
- 1: #include "ruby.h"
7
- 2:
8
- 3: #include <winsock2.h>
9
- 4: #include <windows.h>
10
- 5: int main(int argc, char **argv)
11
- 6: {
12
- 7: return 0;
13
- 8: }
14
- /* end */
15
-
16
- "x86_64-w64-mingw32-gcc -E -Ic:/mingw64/mingw64/local/ruby/include/ruby-2.1.0/x64-mingw32 -Ic:/mingw64/mingw64/local/ruby/include/ruby-2.1.0/ruby/backward -Ic:/mingw64/mingw64/local/ruby/include/ruby-2.1.0 -I. -Ic:/mingw64/mingw64/local/include -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c -o conftest.i"
17
- checked program was:
18
- /* begin */
19
- 1: #include "ruby.h"
20
- 2:
21
- 3: #include <winsock2.h>
22
- 4: #include <windows.h>
23
- 5: #include <proj_api.h>
24
- /* end */
25
-
26
- --------------------
27
-
28
- have_header: checking for projects.h... -------------------- no
29
-
30
- "x86_64-w64-mingw32-gcc -E -Ic:/mingw64/mingw64/local/ruby/include/ruby-2.1.0/x64-mingw32 -Ic:/mingw64/mingw64/local/ruby/include/ruby-2.1.0/ruby/backward -Ic:/mingw64/mingw64/local/ruby/include/ruby-2.1.0 -I. -Ic:/mingw64/mingw64/local/include -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c -o conftest.i"
31
- conftest.c:5:22: fatal error: projects.h: No such file or directory
32
- #include <projects.h>
33
- ^
34
- compilation terminated.
35
- checked program was:
36
- /* begin */
37
- 1: #include "ruby.h"
38
- 2:
39
- 3: #include <winsock2.h>
40
- 4: #include <windows.h>
41
- 5: #include <projects.h>
42
- /* end */
43
-
44
- --------------------
45
-
46
- have_library: checking for pj_init() in -lproj... -------------------- yes
47
-
48
- "x86_64-w64-mingw32-gcc -o conftest.exe -Ic:/mingw64/mingw64/local/ruby/include/ruby-2.1.0/x64-mingw32 -Ic:/mingw64/mingw64/local/ruby/include/ruby-2.1.0/ruby/backward -Ic:/mingw64/mingw64/local/ruby/include/ruby-2.1.0 -I. -Ic:/mingw64/mingw64/local/include -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c -L. -Lc:/mingw64/mingw64/local/ruby/lib -L. -Lc:/mingw64/mingw64/local/lib -lx64-msvcrt-ruby210 -lproj -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi "
49
- conftest.c: In function 't':
50
- conftest.c:16:57: error: 'pj_init' undeclared (first use in this function)
51
- int t(void) { void ((*volatile p)()); p = (void ((*)()))pj_init; return 0; }
52
- ^
53
- conftest.c:16:57: note: each undeclared identifier is reported only once for each function it appears in
54
- conftest.c:16:32: warning: variable 'p' set but not used [-Wunused-but-set-variable]
55
- int t(void) { void ((*volatile p)()); p = (void ((*)()))pj_init; return 0; }
56
- ^
57
- checked program was:
58
- /* begin */
59
- 1: #include "ruby.h"
60
- 2:
61
- 3: #include <winsock2.h>
62
- 4: #include <windows.h>
63
- 5:
64
- 6: /*top*/
65
- 7: extern int t(void);
66
- 8: int main(int argc, char **argv)
67
- 9: {
68
- 10: if (argc > 1000000) {
69
- 11: printf("%p", &t);
70
- 12: }
71
- 13:
72
- 14: return 0;
73
- 15: }
74
- 16: int t(void) { void ((*volatile p)()); p = (void ((*)()))pj_init; return 0; }
75
- /* end */
76
-
77
- "x86_64-w64-mingw32-gcc -o conftest.exe -Ic:/mingw64/mingw64/local/ruby/include/ruby-2.1.0/x64-mingw32 -Ic:/mingw64/mingw64/local/ruby/include/ruby-2.1.0/ruby/backward -Ic:/mingw64/mingw64/local/ruby/include/ruby-2.1.0 -I. -Ic:/mingw64/mingw64/local/include -D_WIN32_WINNT=0x0501 -D__MINGW_USE_VC2005_COMPAT -D_FILE_OFFSET_BITS=64 -O3 -fno-omit-frame-pointer -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c -L. -Lc:/mingw64/mingw64/local/ruby/lib -L. -Lc:/mingw64/mingw64/local/lib -lx64-msvcrt-ruby210 -lproj -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi "
78
- conftest.c: In function 't':
79
- conftest.c:16:1: warning: implicit declaration of function 'pj_init' [-Wimplicit-function-declaration]
80
- int t(void) { pj_init(); return 0; }
81
- ^
82
- checked program was:
83
- /* begin */
84
- 1: #include "ruby.h"
85
- 2:
86
- 3: #include <winsock2.h>
87
- 4: #include <windows.h>
88
- 5:
89
- 6: /*top*/
90
- 7: extern int t(void);
91
- 8: int main(int argc, char **argv)
92
- 9: {
93
- 10: if (argc > 1000000) {
94
- 11: printf("%p", &t);
95
- 12: }
96
- 13:
97
- 14: return 0;
98
- 15: }
99
- 16: int t(void) { pj_init(); return 0; }
100
- /* end */
101
-
102
- --------------------
103
-
File without changes
@@ -1,2 +0,0 @@
1
- EXPORTS
2
- Init_proj4_ruby
Binary file
@@ -1,566 +0,0 @@
1
- #include <ruby.h>
2
- #ifdef HAVE_PROJECTS_H
3
- #include <projects.h>
4
- #endif
5
- #include <proj_api.h>
6
-
7
- static VALUE mProjrb;
8
-
9
- #ifdef HAVE_PROJECTS_H
10
- static VALUE cDef;
11
- static VALUE cDatum;
12
- static VALUE cEllipsoid;
13
- static VALUE cPrimeMeridian;
14
- static VALUE cProjectionType;
15
- static VALUE cUnit;
16
- #endif
17
-
18
- static VALUE cError;
19
- static VALUE cProjection;
20
-
21
- static ID idGetX;
22
- static ID idSetX;
23
- static ID idGetY;
24
- static ID idSetY;
25
- static ID idGetZ;
26
- static ID idSetZ;
27
- static ID idParseInitParameters;
28
- static ID idRaiseError;
29
-
30
- typedef struct {projPJ pj;} _wrap_pj;
31
-
32
-
33
- static void raise_error(int pj_errno_ref) {
34
- VALUE error_id = INT2NUM(pj_errno_ref);
35
- rb_funcall(cError, idRaiseError, 1, error_id);
36
- }
37
-
38
- static void proj_free(void* p){
39
- _wrap_pj * wpj = (_wrap_pj*) p;
40
- if(wpj->pj != 0)
41
- pj_free(wpj->pj);
42
- free(p);
43
- }
44
-
45
- static VALUE proj_alloc(VALUE klass){
46
- _wrap_pj* wpj;
47
- VALUE obj;
48
- wpj = (_wrap_pj*) malloc(sizeof(_wrap_pj));
49
- wpj->pj = 0; //at init the projection has not been defined
50
- obj = Data_Wrap_Struct(klass, 0, proj_free, wpj);
51
- return obj;
52
- }
53
-
54
-
55
- /** Returns the current error message.
56
-
57
- call-seq: Error.message(errno)
58
-
59
- */
60
- static VALUE proj_error_message(VALUE self, VALUE rerrno) {
61
- int error_id = NUM2INT(rerrno);
62
- char *msg = pj_strerrno(error_id);
63
- if (msg)
64
- return rb_str_new2(msg);
65
- else
66
- return rb_str_new2("unknown error");
67
- }
68
-
69
-
70
- /**Creates a new projection object. See the intro for details.
71
-
72
- call-seq: new(String) -> Proj4::Projection
73
- new(Array) -> Proj4::Projection
74
- new(Hash) -> Proj4::Projection
75
-
76
- */
77
- static VALUE proj_initialize(VALUE self, VALUE params){
78
- _wrap_pj* wpj;
79
- VALUE proj_params = rb_funcall(cProjection, idParseInitParameters, 1, params);
80
- int size = RARRAY_LEN(proj_params);
81
- char** c_params = (char **) malloc(size*sizeof(char *));
82
- int i;
83
-
84
- for (i=0; i < size; i++)
85
- {
86
- VALUE item = rb_ary_entry(proj_params, i);
87
- c_params[i]= StringValuePtr(item);
88
- }
89
-
90
- Data_Get_Struct(self,_wrap_pj,wpj);
91
- wpj->pj = pj_init(size,c_params);
92
- free(c_params);
93
- if(wpj->pj == 0) {
94
- int pj_errno_ref = *pj_get_errno_ref();
95
- if (pj_errno_ref > 0) {
96
- rb_raise(rb_eSystemCallError, "Unknown system call error");
97
- } else {
98
- raise_error(pj_errno_ref);
99
- }
100
- }
101
- return self;
102
- }
103
-
104
- #ifdef HAVE_PROJECTS_H
105
- /**Has this projection an inverse?
106
-
107
- call-seq: hasInverse? -> true or false
108
-
109
- */
110
- static VALUE proj_has_inverse(VALUE self){
111
- _wrap_pj* wpj;
112
- Data_Get_Struct(self,_wrap_pj,wpj);
113
- return wpj->pj->inv ? Qtrue : Qfalse;
114
- }
115
- #endif
116
-
117
- /**Is this projection a latlong projection?
118
-
119
- call-seq: isLatLong? -> true or false
120
-
121
- */
122
- static VALUE proj_is_latlong(VALUE self){
123
- _wrap_pj* wpj;
124
- Data_Get_Struct(self,_wrap_pj,wpj);
125
- return pj_is_latlong(wpj->pj) ? Qtrue : Qfalse;
126
- }
127
-
128
- /**Is this projection a geocentric projection?
129
-
130
- call-seq: isGeocentric? -> true or false
131
-
132
- */
133
- static VALUE proj_is_geocent(VALUE self){
134
- _wrap_pj* wpj;
135
- Data_Get_Struct(self,_wrap_pj,wpj);
136
- return pj_is_geocent(wpj->pj) ? Qtrue : Qfalse;
137
- }
138
-
139
- /**Get the expanded definition of this projection as a string.
140
-
141
- call-seq: getDef -> String
142
-
143
- */
144
- static VALUE proj_get_def(VALUE self){
145
- _wrap_pj* wpj;
146
- Data_Get_Struct(self,_wrap_pj,wpj);
147
- return rb_str_new2(pj_get_def(wpj->pj, 0));
148
- }
149
-
150
- /**Transforms a point in WGS84 LonLat in radians to projected coordinates.
151
- This version of the method changes the point in-place.
152
-
153
- call-seq: forward!(point) -> point
154
-
155
- */
156
- static VALUE proj_forward(VALUE self,VALUE point){
157
- _wrap_pj* wpj;
158
- int pj_errno_ref;
159
- projLP pj_point;
160
- projXY pj_result;
161
- Data_Get_Struct(self,_wrap_pj,wpj);
162
-
163
- pj_point.u = NUM2DBL( rb_funcall(point, idGetX, 0) );
164
- pj_point.v = NUM2DBL( rb_funcall(point, idGetY, 0) );
165
- pj_result = pj_fwd(pj_point, wpj->pj);
166
-
167
- pj_errno_ref = *pj_get_errno_ref();
168
- if (pj_errno_ref == 0) {
169
- rb_funcall(point, idSetX, 1, rb_float_new(pj_result.u) );
170
- rb_funcall(point, idSetY, 1, rb_float_new(pj_result.v) );
171
- return point;
172
- } else if (pj_errno_ref > 0) {
173
- rb_raise(rb_eSystemCallError, "Unknown system call error");
174
- } else {
175
- raise_error(pj_errno_ref);
176
- }
177
- return self; /* Makes gcc happy */
178
- }
179
-
180
- /**Transforms a point in the coordinate system defined at initialization of the Projection object to WGS84 LonLat in radians.
181
- This version of the method changes the point in-place.
182
-
183
- call-seq: inverse!(point) -> point
184
-
185
- */
186
- static VALUE proj_inverse(VALUE self,VALUE point){
187
- _wrap_pj* wpj;
188
- int pj_errno_ref;
189
- projXY pj_point;
190
- projLP pj_result;
191
-
192
- Data_Get_Struct(self,_wrap_pj,wpj);
193
-
194
- pj_point.u = NUM2DBL( rb_funcall(point, idGetX, 0) );
195
- pj_point.v = NUM2DBL( rb_funcall(point, idGetY, 0) );
196
- pj_result = pj_inv(pj_point, wpj->pj);
197
-
198
- pj_errno_ref = *pj_get_errno_ref();
199
- if (pj_errno_ref == 0) {
200
- rb_funcall(point, idSetX, 1, rb_float_new(pj_result.u) );
201
- rb_funcall(point, idSetY, 1, rb_float_new(pj_result.v) );
202
- return point;
203
- } else if (pj_errno_ref > 0) {
204
- rb_raise(rb_eSystemCallError, "Unknown system call error");
205
- } else {
206
- raise_error(pj_errno_ref);
207
- }
208
- return self; /* Makes gcc happy */
209
- }
210
-
211
- /**Transforms a point from one projection to another. The second parameter is
212
- either a Proj4::Point object or you can use any object which
213
- responds to the x, y, z read and write accessor methods. (In fact you
214
- don't even need the z accessor methods, 0 is assumed if they don't exist).
215
- This is the destructive variant of the method, i.e. it will overwrite your
216
- existing point coordinates but otherwise leave the point object alone.
217
-
218
- call-seq: transform!(destinationProjection, point) -> point
219
-
220
- */
221
- static VALUE proj_transform(VALUE self, VALUE dst, VALUE point){
222
- _wrap_pj* wpjsrc;
223
- _wrap_pj* wpjdst;
224
- double array_x[1];
225
- double array_y[1];
226
- double array_z[1];
227
- int result;
228
-
229
- Data_Get_Struct(self,_wrap_pj,wpjsrc);
230
- Data_Get_Struct(dst,_wrap_pj,wpjdst);
231
-
232
- array_x[0] = NUM2DBL( rb_funcall(point, idGetX, 0) );
233
- array_y[0] = NUM2DBL( rb_funcall(point, idGetY, 0) );
234
-
235
- /* if point objects has a method 'z' we get the z coordinate, otherwise we just assume 0 */
236
- if ( rb_respond_to(point, idGetZ) ) {
237
- array_z[0] = NUM2DBL( rb_funcall(point, idGetZ, 0) );
238
- } else {
239
- array_z[0] = 0.0;
240
- }
241
-
242
- result = pj_transform(wpjsrc->pj, wpjdst->pj, 1, 1, array_x, array_y, array_z);
243
- if (! result) {
244
- rb_funcall(point, idSetX, 1, rb_float_new(array_x[0]) );
245
- rb_funcall(point, idSetY, 1, rb_float_new(array_y[0]) );
246
- /* if point objects has a method 'z=' we set the z coordinate, otherwise we ignore it */
247
- if ( rb_respond_to(point, idSetZ) ) {
248
- rb_funcall(point, idSetZ, 1, rb_float_new(array_z[0]) );
249
- }
250
- return point;
251
- } else if (result > 0) {
252
- rb_raise(rb_eSystemCallError, "Unknown system call error");
253
- } else {
254
- raise_error(result);
255
- }
256
- return self; /* Makes gcc happy */
257
- }
258
-
259
- #if PJ_VERSION >= 449 && defined(HAVE_PROJECTS_H)
260
- /**Return list of all datums we know about.
261
-
262
- call-seq: list -> Array of Proj4::Datum
263
-
264
- */
265
- static VALUE datum_list(VALUE self){
266
- struct PJ_DATUMS *datum;
267
- VALUE list = rb_ary_new();
268
- for (datum = pj_get_datums_ref(); datum->id; datum++){
269
- rb_ary_push(list, Data_Wrap_Struct(cDatum, 0, 0, datum));
270
- }
271
- return list;
272
- }
273
- /**Get ID of the datum.
274
-
275
- call-seq: id -> String
276
-
277
- */
278
- static VALUE datum_get_id(VALUE self){
279
- struct PJ_DATUMS *datum;
280
- Data_Get_Struct(self,struct PJ_DATUMS,datum);
281
- return rb_str_new2(datum->id);
282
- }
283
- /**Get ID of the ellipse used by the datum.
284
-
285
- call-seq: ellipse_id -> String
286
-
287
- */
288
- static VALUE datum_get_ellipse_id(VALUE self){
289
- struct PJ_DATUMS *datum;
290
- Data_Get_Struct(self,struct PJ_DATUMS,datum);
291
- return rb_str_new2(datum->ellipse_id);
292
- }
293
- /**Get definition of the datum.
294
-
295
- call-seq: defn -> String
296
-
297
- */
298
- static VALUE datum_get_defn(VALUE self){
299
- struct PJ_DATUMS *datum;
300
- Data_Get_Struct(self,struct PJ_DATUMS,datum);
301
- return rb_str_new2(datum->defn);
302
- }
303
- /**Get comments about the datum.
304
-
305
- call-seq: comments -> String
306
-
307
- */
308
- static VALUE datum_get_comments(VALUE self){
309
- struct PJ_DATUMS *datum;
310
- Data_Get_Struct(self,struct PJ_DATUMS,datum);
311
- return rb_str_new2(datum->comments);
312
- }
313
-
314
- /**Return list of all reference ellipsoids we know about.
315
-
316
- call-seq: list -> Array of Proj4::Ellipsoid
317
-
318
- */
319
- static VALUE ellipsoid_list(VALUE self){
320
- struct PJ_ELLPS *el;
321
- VALUE list = rb_ary_new();
322
- for (el = pj_get_ellps_ref(); el->id; el++){
323
- rb_ary_push(list, Data_Wrap_Struct(cEllipsoid, 0, 0, el));
324
- }
325
- return list;
326
- }
327
- /**Get ID of the reference ellipsoid.
328
-
329
- call-seq: id -> String
330
-
331
- */
332
- static VALUE ellipsoid_get_id(VALUE self){
333
- struct PJ_ELLPS *el;
334
- Data_Get_Struct(self,struct PJ_ELLPS,el);
335
- return rb_str_new2(el->id);
336
- }
337
- /**Get equatorial radius (semi-major axis, a value) of the reference ellipsoid.
338
-
339
- call-seq: major -> String
340
-
341
- */
342
- static VALUE ellipsoid_get_major(VALUE self){
343
- struct PJ_ELLPS *el;
344
- Data_Get_Struct(self,struct PJ_ELLPS,el);
345
- return rb_str_new2(el->major);
346
- }
347
- /**Get elliptical parameter of the reference ellipsoid. This is either the polar radius (semi-minor axis, b value) or the inverse flattening (1/f, rf).
348
-
349
- call-seq: ell -> String
350
-
351
- */
352
- static VALUE ellipsoid_get_ell(VALUE self){
353
- struct PJ_ELLPS *el;
354
- Data_Get_Struct(self,struct PJ_ELLPS,el);
355
- return rb_str_new2(el->ell);
356
- }
357
- /**Get name of the reference ellipsoid.
358
-
359
- call-seq: name -> String
360
-
361
- */
362
- static VALUE ellipsoid_get_name(VALUE self){
363
- struct PJ_ELLPS *el;
364
- Data_Get_Struct(self,struct PJ_ELLPS,el);
365
- return rb_str_new2(el->name);
366
- }
367
-
368
- /**Return list of all prime meridians we know about.
369
-
370
- call-seq: list -> Array of Proj4::PrimeMeridian
371
-
372
- */
373
- static VALUE prime_meridian_list(VALUE self){
374
- struct PJ_PRIME_MERIDIANS *prime_meridian;
375
- VALUE list = rb_ary_new();
376
- for (prime_meridian = pj_get_prime_meridians_ref(); prime_meridian->id; prime_meridian++){
377
- rb_ary_push(list, Data_Wrap_Struct(cPrimeMeridian, 0, 0, prime_meridian));
378
- }
379
- return list;
380
- }
381
- /**Get ID of this prime_meridian.
382
-
383
- call-seq: id -> String
384
-
385
- */
386
- static VALUE prime_meridian_get_id(VALUE self){
387
- struct PJ_PRIME_MERIDIANS *prime_meridian;
388
- Data_Get_Struct(self,struct PJ_PRIME_MERIDIANS,prime_meridian);
389
- return rb_str_new2(prime_meridian->id);
390
- }
391
- /**Get definition of this prime_meridian.
392
-
393
- call-seq: defn -> String
394
-
395
- */
396
- static VALUE prime_meridian_get_defn(VALUE self){
397
- struct PJ_PRIME_MERIDIANS *prime_meridian;
398
- Data_Get_Struct(self,struct PJ_PRIME_MERIDIANS,prime_meridian);
399
- return rb_str_new2(prime_meridian->defn);
400
- }
401
-
402
- /**Return list of all projection types we know about.
403
-
404
- call-seq: list -> Array of Proj4::ProjectionType
405
-
406
- */
407
- static VALUE projection_type_list(VALUE self){
408
- struct PJ_LIST *pt;
409
- VALUE list = rb_ary_new();
410
- for (pt = pj_get_list_ref(); pt->id; pt++){
411
- rb_ary_push(list, Data_Wrap_Struct(cProjectionType, 0, 0, pt));
412
- }
413
- return list;
414
- }
415
- /**Get ID of this projection type.
416
-
417
- call-seq: id -> String
418
-
419
- */
420
- static VALUE projection_type_get_id(VALUE self){
421
- struct PJ_LIST *pt;
422
- Data_Get_Struct(self,struct PJ_LIST,pt);
423
- return rb_str_new2(pt->id);
424
- }
425
- /**Get description of this projection type as a multiline string.
426
-
427
- call-seq: descr -> String
428
-
429
- */
430
- static VALUE projection_type_get_descr(VALUE self){
431
- struct PJ_LIST *pt;
432
- Data_Get_Struct(self,struct PJ_LIST,pt);
433
- return rb_str_new2(*(pt->descr));
434
- }
435
-
436
- /**Return list of all units we know about.
437
-
438
- call-seq: list -> Array of Proj4::Unit
439
-
440
- */
441
- static VALUE unit_list(VALUE self){
442
- struct PJ_UNITS *unit;
443
- VALUE list = rb_ary_new();
444
- for (unit = pj_get_units_ref(); unit->id; unit++){
445
- rb_ary_push(list, Data_Wrap_Struct(cUnit, 0, 0, unit));
446
- }
447
- return list;
448
- }
449
- /**Get ID of the unit.
450
-
451
- call-seq: id -> String
452
-
453
- */
454
- static VALUE unit_get_id(VALUE self){
455
- struct PJ_UNITS *unit;
456
- Data_Get_Struct(self,struct PJ_UNITS,unit);
457
- return rb_str_new2(unit->id);
458
- }
459
- /**Get conversion factor of this unit to a meter. Note that this is a string, it can either contain a floating point number or it can be in the form numerator/denominator.
460
-
461
- call-seq: to_meter -> String
462
-
463
- */
464
- static VALUE unit_get_to_meter(VALUE self){
465
- struct PJ_UNITS *unit;
466
- Data_Get_Struct(self,struct PJ_UNITS,unit);
467
- return rb_str_new2(unit->to_meter);
468
- }
469
- /**Get name (description) of the unit.
470
-
471
- call-seq: name -> String
472
-
473
- */
474
- static VALUE unit_get_name(VALUE self){
475
- struct PJ_UNITS *unit;
476
- Data_Get_Struct(self,struct PJ_UNITS,unit);
477
- return rb_str_new2(unit->name);
478
- }
479
-
480
- #endif
481
-
482
- #if defined(_WIN32)
483
- __declspec(dllexport)
484
- #endif
485
- void Init_proj4_ruby(void) {
486
-
487
- idGetX = rb_intern("x");
488
- idSetX = rb_intern("x=");
489
- idGetY = rb_intern("y");
490
- idSetY = rb_intern("y=");
491
- idGetZ = rb_intern("z");
492
- idSetZ = rb_intern("z=");
493
- idParseInitParameters = rb_intern("_parse_init_parameters");
494
- idRaiseError = rb_intern("raise_error");
495
-
496
- mProjrb = rb_define_module("Proj4");
497
-
498
- /**
499
- Radians per degree
500
- */
501
- rb_define_const(mProjrb,"DEG_TO_RAD", rb_float_new(DEG_TO_RAD));
502
- /**
503
- Degrees per radian
504
- */
505
- rb_define_const(mProjrb,"RAD_TO_DEG", rb_float_new(RAD_TO_DEG));
506
- /**
507
- Version of C libproj
508
- */
509
- rb_define_const(mProjrb,"LIBVERSION", rb_float_new(PJ_VERSION));
510
-
511
- cError = rb_define_class_under(mProjrb,"Error",rb_path2class("StandardError"));
512
- rb_define_singleton_method(cError,"message",proj_error_message,1);
513
-
514
- cProjection = rb_define_class_under(mProjrb,"Projection",rb_cObject);
515
- rb_define_alloc_func(cProjection,proj_alloc);
516
- rb_define_method(cProjection,"initialize",proj_initialize,1);
517
- #ifdef HAVE_PROJECTS_H
518
- rb_define_method(cProjection,"hasInverse?",proj_has_inverse,0);
519
- #endif
520
- rb_define_method(cProjection,"isLatLong?",proj_is_latlong,0);
521
- rb_define_method(cProjection,"isGeocent?",proj_is_geocent,0);
522
- rb_define_alias(cProjection,"isGeocentric?","isGeocent?");
523
- rb_define_method(cProjection,"getDef",proj_get_def,0);
524
- rb_define_method(cProjection,"forward!",proj_forward,1);
525
- rb_define_method(cProjection,"inverse!",proj_inverse,1);
526
- rb_define_method(cProjection,"transform!",proj_transform,2);
527
-
528
- #if PJ_VERSION >= 449 && defined(HAVE_PROJECTS_H)
529
- cDef = rb_define_class_under(mProjrb,"Def",rb_cObject);
530
-
531
- /* The Datum class holds information about datums ('WGS84', 'potsdam', ...) known to Proj.4. */
532
- cDatum = rb_define_class_under(mProjrb,"Datum",cDef);
533
- rb_define_singleton_method(cDatum,"list",datum_list,0);
534
- rb_define_method(cDatum,"id",datum_get_id,0);
535
- rb_define_method(cDatum,"ellipse_id",datum_get_ellipse_id,0);
536
- rb_define_method(cDatum,"defn",datum_get_defn,0);
537
- rb_define_method(cDatum,"comments",datum_get_comments,0);
538
-
539
- /* The Ellipsoid class holds information about ellipsoids ('WGS84', 'bessel', ...) known to Proj.4. */
540
- cEllipsoid = rb_define_class_under(mProjrb,"Ellipsoid",cDef);
541
- rb_define_singleton_method(cEllipsoid,"list",ellipsoid_list,0);
542
- rb_define_method(cEllipsoid,"id",ellipsoid_get_id,0);
543
- rb_define_method(cEllipsoid,"major",ellipsoid_get_major,0);
544
- rb_define_method(cEllipsoid,"ell",ellipsoid_get_ell,0);
545
- rb_define_method(cEllipsoid,"name",ellipsoid_get_name,0);
546
-
547
- /* The PrimeMeridian class holds information about prime meridians ('greenwich', 'lisbon', ...) known to Proj.4. */
548
- cPrimeMeridian = rb_define_class_under(mProjrb,"PrimeMeridian",cDef);
549
- rb_define_singleton_method(cPrimeMeridian,"list",prime_meridian_list,0);
550
- rb_define_method(cPrimeMeridian,"id",prime_meridian_get_id,0);
551
- rb_define_method(cPrimeMeridian,"defn",prime_meridian_get_defn,0);
552
-
553
- /* The ProjectionType class holds information about projections types ('merc', 'aea', ...) known to Proj.4. */
554
- cProjectionType = rb_define_class_under(mProjrb,"ProjectionType",cDef);
555
- rb_define_singleton_method(cProjectionType,"list",projection_type_list,0);
556
- rb_define_method(cProjectionType,"id",projection_type_get_id,0);
557
- rb_define_method(cProjectionType,"descr",projection_type_get_descr,0);
558
-
559
- /* The Unit class holds information about the units ('m', 'km', 'mi', ...) known to Proj.4. */
560
- cUnit = rb_define_class_under(mProjrb,"Unit",cDef);
561
- rb_define_singleton_method(cUnit,"list",unit_list,0);
562
- rb_define_method(cUnit,"id",unit_get_id,0);
563
- rb_define_method(cUnit,"to_meter",unit_get_to_meter,0);
564
- rb_define_method(cUnit,"name",unit_get_name,0);
565
- #endif
566
- }