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