proj4r 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/rb_proj.c ADDED
@@ -0,0 +1,357 @@
1
+ #include "ruby.h"
2
+ #include "rb_proj4r.h"
3
+
4
+ VALUE rb_cProj;
5
+
6
+ static void
7
+ free_proj (Proj *proj)
8
+ {
9
+ if ( proj->ref )
10
+ pj_free(proj->ref);
11
+ free(proj);
12
+ }
13
+
14
+ static VALUE
15
+ rb_proj_s_allocate (VALUE klass)
16
+ {
17
+ Proj *proj;
18
+ return Data_Make_Struct(klass, Proj, 0, free_proj, proj);
19
+ }
20
+
21
+ static VALUE
22
+ rb_proj_initialize (VALUE self, VALUE args)
23
+ {
24
+ Proj *proj;
25
+ PJ *ref;
26
+
27
+ Check_Type(args, T_STRING);
28
+
29
+ if ( ! ( ref = pj_init_plus(StringValuePtr(args)) ) )
30
+ rb_raise(rb_eRuntimeError, "%s", pj_strerrno(pj_errno));
31
+
32
+ Data_Get_Struct(self, Proj, proj);
33
+ proj->ref = ref;
34
+
35
+ /* rb_ivar_set(self, rb_intern("@definition"), args); */
36
+
37
+ return Qnil;
38
+ }
39
+
40
+ static VALUE
41
+ rb_proj_definition (VALUE self)
42
+ {
43
+ Proj *proj;
44
+ char *def;
45
+ Data_Get_Struct(self, Proj, proj);
46
+ def = pj_get_def(proj->ref, 0);
47
+ if ( def ) {
48
+ return rb_str_new2(def);
49
+ }
50
+ else {
51
+ return Qnil;
52
+ }
53
+ }
54
+
55
+ static VALUE
56
+ rb_proj_descr (VALUE self)
57
+ {
58
+ Proj *proj;
59
+ Data_Get_Struct(self, Proj, proj);
60
+ if ( proj->ref->descr ) {
61
+ return rb_str_new2(proj->ref->descr);
62
+ }
63
+ else {
64
+ return Qnil;
65
+ }
66
+ }
67
+
68
+ static VALUE
69
+ rb_proj_catalog_name (VALUE self)
70
+ {
71
+ Proj *proj;
72
+ Data_Get_Struct(self, Proj, proj);
73
+ if ( proj->ref->catalog_name ) {
74
+ return rb_str_new2(proj->ref->catalog_name);
75
+ }
76
+ else {
77
+ return Qnil;
78
+ }
79
+ }
80
+
81
+ static VALUE
82
+ rb_proj_def_size (VALUE self)
83
+ {
84
+ Proj *proj;
85
+ Data_Get_Struct(self, Proj, proj);
86
+ if ( proj->ref->def_size ) {
87
+ return rb_str_new2(proj->ref->def_size);
88
+ }
89
+ else {
90
+ return Qnil;
91
+ }
92
+ }
93
+
94
+ static VALUE
95
+ rb_proj_def_shape (VALUE self)
96
+ {
97
+ Proj *proj;
98
+ Data_Get_Struct(self, Proj, proj);
99
+ if ( proj->ref->def_shape ) {
100
+ return rb_str_new2(proj->ref->def_shape);
101
+ }
102
+ else {
103
+ return Qnil;
104
+ }
105
+ }
106
+
107
+ static VALUE
108
+ rb_proj_a (VALUE self)
109
+ {
110
+ Proj *proj;
111
+ Data_Get_Struct(self, Proj, proj);
112
+ return rb_float_new(proj->ref->a);
113
+ }
114
+
115
+ static VALUE
116
+ rb_proj_f (VALUE self)
117
+ {
118
+ Proj *proj;
119
+ double es;
120
+ Data_Get_Struct(self, Proj, proj);
121
+ es = proj->ref->es;
122
+ return rb_float_new(es/(1 + sqrt(1 - es)));
123
+ }
124
+
125
+ static VALUE
126
+ rb_proj_fr_meter (VALUE self)
127
+ {
128
+ Proj *proj;
129
+ Data_Get_Struct(self, Proj, proj);
130
+ return rb_float_new(proj->ref->fr_meter);
131
+ }
132
+
133
+ static VALUE
134
+ rb_proj_is_latlong (VALUE self)
135
+ {
136
+ Proj *proj;
137
+ Data_Get_Struct(self, Proj, proj);
138
+ if ( pj_is_latlong(proj->ref) ) {
139
+ return Qtrue;
140
+ }
141
+ else {
142
+ return Qfalse;
143
+ }
144
+ }
145
+
146
+ static VALUE
147
+ rb_proj_is_geocent (VALUE self)
148
+ {
149
+ Proj *proj;
150
+ Data_Get_Struct(self, Proj, proj);
151
+ if ( pj_is_geocent(proj->ref) ) {
152
+ return Qtrue;
153
+ }
154
+ else {
155
+ return Qfalse;
156
+ }
157
+ }
158
+
159
+ static VALUE
160
+ rb_proj_to_latlong (VALUE self)
161
+ {
162
+ volatile VALUE obj;
163
+ Proj *src, *dst;
164
+ obj = rb_proj_s_allocate(rb_cProj);
165
+ Data_Get_Struct(obj, Proj, dst);
166
+ Data_Get_Struct(self, Proj, src);
167
+ dst->ref = pj_latlong_from_proj(src->ref);
168
+ return obj;
169
+ }
170
+
171
+ static VALUE
172
+ rb_proj_fwd (VALUE self, VALUE vlon, VALUE vlat)
173
+ {
174
+ Proj *proj;
175
+ LP data;
176
+ Data_Get_Struct(self, Proj, proj);
177
+ data.u = NUM2DBL(vlon) * DEG_TO_RAD;
178
+ data.v = NUM2DBL(vlat) * DEG_TO_RAD;
179
+ data = pj_fwd(data, proj->ref);
180
+ if ( data.u == HUGE_VAL )
181
+ rb_raise(rb_eRuntimeError, "%s", pj_strerrno(pj_errno));
182
+ return rb_assoc_new(rb_float_new(data.u), rb_float_new(data.v));
183
+ }
184
+
185
+ static VALUE
186
+ rb_proj_inv (VALUE self, VALUE vx, VALUE vy)
187
+ {
188
+ Proj *proj;
189
+ XY data;
190
+ Data_Get_Struct(self, Proj, proj);
191
+ data.u = NUM2DBL(vx);
192
+ data.v = NUM2DBL(vy);
193
+ data = pj_inv(data, proj->ref);
194
+ if ( data.u == HUGE_VAL )
195
+ rb_raise(rb_eRuntimeError, "%s", pj_strerrno(pj_errno));
196
+ return rb_assoc_new(rb_float_new(data.u*RAD_TO_DEG),
197
+ rb_float_new(data.v*RAD_TO_DEG));
198
+ }
199
+
200
+ #ifdef HAVE_CARRAY_H
201
+
202
+ #include "carray.h"
203
+
204
+ static VALUE
205
+ rb_proj_fwd_ca (VALUE self, volatile VALUE vlon, volatile VALUE vlat,
206
+ volatile VALUE vx, volatile VALUE vy)
207
+ {
208
+ Proj *proj;
209
+ LP data;
210
+ CArray *clon, *clat, *cx, *cy;
211
+ double *p1, *p2, *p3, *p4;
212
+ ca_size_t s1, s2, s3, s4;
213
+ int8_t *m, *mp;
214
+ ca_size_t count, err_count, i;
215
+
216
+ Data_Get_Struct(self, Proj, proj);
217
+
218
+ clon = ca_wrap_readonly(vlon, CA_DOUBLE);
219
+ clat = ca_wrap_readonly(vlat, CA_DOUBLE);
220
+ cx = ca_wrap_writable(vx, CA_DOUBLE);
221
+ cy = ca_wrap_writable(vy, CA_DOUBLE);
222
+
223
+ ca_attach_n(4, clon, clat, cx, cy);
224
+
225
+ count = ca_set_iterator(4,
226
+ clon, &p1, &s1,
227
+ clat, &p2, &s2,
228
+ cx, &p3, &s3,
229
+ cy, &p4, &s4);
230
+
231
+ m = ca_allocate_mask_iterator(2, clon, clat);
232
+
233
+ mp = m;
234
+ err_count = 0;
235
+ for (i=0; i<count; i++) {
236
+ if ( *mp ) {
237
+ err_count += 1;
238
+ *p3 = 0.0/0.0;
239
+ *p4 = 0.0/0.0;
240
+ }
241
+ else {
242
+ data.u = (*p1) * DEG_TO_RAD;
243
+ data.v = (*p2) * DEG_TO_RAD;
244
+ data = pj_fwd(data, proj->ref);
245
+ if ( data.u == HUGE_VAL ) {
246
+ err_count += 1;
247
+ *p3 = 0.0/0.0;
248
+ *p4 = 0.0/0.0;
249
+ }
250
+ else {
251
+ *p3 = data.u;
252
+ *p4 = data.v;
253
+ }
254
+ }
255
+ p1+=s1; p2+=s2; p3+=s3; p4+=s4; mp++;
256
+ }
257
+
258
+ free(m);
259
+
260
+ ca_sync_n(2, cx, cy);
261
+ ca_detach_n(4, clon, clat, cx, cy);
262
+
263
+ return SIZE2NUM(err_count);
264
+ }
265
+
266
+ static VALUE
267
+ rb_proj_inv_ca (VALUE self, volatile VALUE vx, volatile VALUE vy,
268
+ volatile VALUE vlon, volatile VALUE vlat)
269
+ {
270
+ Proj *proj;
271
+ LP data;
272
+ CArray *cx, *cy, *clon, *clat;
273
+ double *p1, *p2, *p3, *p4;
274
+ ca_size_t s1, s2, s3, s4;
275
+ int8_t *m, *mp;
276
+ ca_size_t count, err_count, i;
277
+
278
+ Data_Get_Struct(self, Proj, proj);
279
+
280
+ cx = ca_wrap_readonly(vx, CA_DOUBLE);
281
+ cy = ca_wrap_readonly(vy, CA_DOUBLE);
282
+ clon = ca_wrap_writable(vlon, CA_DOUBLE);
283
+ clat = ca_wrap_writable(vlat, CA_DOUBLE);
284
+
285
+ ca_attach_n(4, cx, cy, clon, clat);
286
+
287
+ count = ca_set_iterator(4,
288
+ cx, &p1, &s1,
289
+ cy, &p2, &s2,
290
+ clon, &p3, &s3,
291
+ clat, &p4, &s4);
292
+
293
+ m = ca_allocate_mask_iterator(2, clon, clat);
294
+
295
+ mp = m;
296
+ err_count = 0;
297
+ for (i=0; i<count; i++) {
298
+ if ( *mp ) {
299
+ err_count += 1;
300
+ *p3 = 0.0/0.0;
301
+ *p4 = 0.0/0.0;
302
+ }
303
+ else {
304
+ data.u = (*p1);
305
+ data.v = (*p2);
306
+ data = pj_inv(data, proj->ref);
307
+ if ( data.u == HUGE_VAL ) {
308
+ err_count += 1;
309
+ *p3 = 0.0/0.0;
310
+ *p4 = 0.0/0.0;
311
+ }
312
+ else {
313
+ *p3 = data.u * RAD_TO_DEG;
314
+ *p4 = data.v * RAD_TO_DEG;
315
+ }
316
+ }
317
+ p1+=s1; p2+=s2; p3+=s3; p4+=s4;
318
+ mp++;
319
+ }
320
+
321
+ free(m);
322
+
323
+ ca_sync_n(2, clon, clat);
324
+ ca_detach_n(4, cx, cy, clon, clat);
325
+
326
+ return SIZE2NUM(err_count);
327
+ }
328
+
329
+ #endif
330
+
331
+
332
+ void
333
+ Init_proj ()
334
+ {
335
+ rb_cProj = rb_define_class_under(rb_mPROJ4, "Proj", rb_cObject);
336
+
337
+ rb_define_alloc_func(rb_cProj, rb_proj_s_allocate);
338
+ rb_define_method(rb_cProj, "initialize", rb_proj_initialize, 1);
339
+ rb_define_method(rb_cProj, "definition", rb_proj_definition, 0);
340
+ rb_define_method(rb_cProj, "descr", rb_proj_descr, 0);
341
+ rb_define_method(rb_cProj, "catalog_name", rb_proj_catalog_name, 0);
342
+ rb_define_method(rb_cProj, "def_size", rb_proj_def_size, 0);
343
+ rb_define_method(rb_cProj, "def_shape", rb_proj_def_shape, 0);
344
+ rb_define_method(rb_cProj, "a", rb_proj_a, 0);
345
+ rb_define_method(rb_cProj, "f", rb_proj_f, 0);
346
+ rb_define_method(rb_cProj, "fr_meter", rb_proj_fr_meter, 0);
347
+ rb_define_method(rb_cProj, "latlong?", rb_proj_is_latlong, 0);
348
+ rb_define_method(rb_cProj, "geocent?", rb_proj_is_geocent, 0);
349
+ rb_define_method(rb_cProj, "to_latlong", rb_proj_to_latlong, 0);
350
+ rb_define_private_method(rb_cProj, "_forward", rb_proj_fwd, 2);
351
+ rb_define_private_method(rb_cProj, "_inverse", rb_proj_inv, 2);
352
+ #ifdef HAVE_CARRAY_H
353
+ rb_define_private_method(rb_cProj, "_forward_ca", rb_proj_fwd_ca, 4);
354
+ rb_define_private_method(rb_cProj, "_inverse_ca", rb_proj_inv_ca, 4);
355
+ #endif
356
+ }
357
+
data/rb_proj4r.c ADDED
@@ -0,0 +1,232 @@
1
+ #include "ruby.h"
2
+ #include "rb_proj4r.h"
3
+
4
+ VALUE rb_mPROJ4;
5
+
6
+ static VALUE
7
+ rb_proj_s_dmstor (VALUE mod, VALUE str)
8
+ {
9
+ char *cdms;
10
+ double r;
11
+
12
+ Check_Type(str, T_STRING);
13
+
14
+ cdms = StringValuePtr(str);
15
+
16
+ r = dmstor(cdms, NULL);
17
+
18
+ return rb_float_new(r);
19
+ }
20
+
21
+ static VALUE
22
+ rb_proj_s_dmstod (VALUE mod, VALUE str)
23
+ {
24
+ char *cdms;
25
+ double r;
26
+
27
+ Check_Type(str, T_STRING);
28
+
29
+ cdms = StringValuePtr(str);
30
+
31
+ r = dmstor(cdms, NULL);
32
+
33
+ return rb_float_new(r * RAD_TO_DEG);
34
+ }
35
+
36
+ static VALUE
37
+ rb_proj_s_rtodms (int argc, VALUE *argv, VALUE mod)
38
+ {
39
+ VALUE vr, vpos, vneg;
40
+ char cdms[50];
41
+ int pos, neg;
42
+ double r;
43
+
44
+ rb_scan_args(argc, argv, "12", &vr, &vpos, &vneg);
45
+
46
+ r = NUM2DBL(vr);
47
+ pos = ( NIL_P(vpos) ) ? 0 : StringValuePtr(vpos)[0];
48
+ neg = ( NIL_P(vneg) ) ? 0 : StringValuePtr(vneg)[0];
49
+
50
+ rtodms(cdms, r, pos, neg);
51
+
52
+ return rb_str_new2(cdms);
53
+ }
54
+
55
+ static VALUE
56
+ rb_proj_s_dtodms (int argc, VALUE *argv, VALUE mod)
57
+ {
58
+ VALUE vr, vpos, vneg;
59
+ char cdms[50];
60
+ int pos, neg;
61
+ double r;
62
+
63
+ rb_scan_args(argc, argv, "12", &vr, &vpos, &vneg);
64
+
65
+ r = NUM2DBL(vr) * DEG_TO_RAD;
66
+ pos = ( NIL_P(vpos) ) ? 0 : StringValuePtr(vpos)[0];
67
+ neg = ( NIL_P(vneg) ) ? 0 : StringValuePtr(vneg)[0];
68
+
69
+ rtodms(cdms, r, pos, neg);
70
+
71
+ return rb_str_new2(cdms);
72
+ }
73
+
74
+ static VALUE
75
+ rb_proj_s_transform (int argc, VALUE *argv, VALUE klass)
76
+ {
77
+ VALUE vsrc, vdst, vx, vy, vz;
78
+ Proj *proj, *proj_dest;
79
+ double x, y, z;
80
+ int status;
81
+
82
+ rb_scan_args(argc, argv, "41", &vsrc, &vdst, &vx, &vy, &vz);
83
+
84
+ Data_Get_Struct(vsrc, Proj, proj);
85
+ Data_Get_Struct(vdst, Proj, proj_dest);
86
+
87
+ if ( pj_is_latlong(proj->ref) ) {
88
+ x = NUM2DBL(vx) * DEG_TO_RAD;
89
+ y = NUM2DBL(vy) * DEG_TO_RAD;
90
+ z = NIL_P(vz) ? 0.0 : NUM2DBL(vz);
91
+ }
92
+ else {
93
+ x = NUM2DBL(vx);
94
+ y = NUM2DBL(vy);
95
+ z = NIL_P(vz) ? 0.0 : NUM2DBL(vz);
96
+ }
97
+
98
+ status = pj_transform(proj->ref, proj_dest->ref, 1, 0, &x, &y, &z);
99
+
100
+ if ( status < 0 )
101
+ rb_raise(rb_eRuntimeError, "%s", pj_strerrno(pj_errno));
102
+
103
+ if ( pj_is_latlong(proj_dest->ref) ) {
104
+ if ( NIL_P(vz) ) {
105
+ return rb_ary_new3(3,
106
+ rb_float_new(x * RAD_TO_DEG),
107
+ rb_float_new(y * RAD_TO_DEG),
108
+ rb_float_new(z));
109
+ }
110
+ else {
111
+ return rb_ary_new3(2,
112
+ rb_float_new(x * RAD_TO_DEG),
113
+ rb_float_new(y * RAD_TO_DEG));
114
+ }
115
+ }
116
+ else {
117
+ if ( NIL_P(vz) ) {
118
+ return rb_ary_new3(3,
119
+ rb_float_new(x),
120
+ rb_float_new(y),
121
+ rb_float_new(z));
122
+ }
123
+ else {
124
+ return rb_ary_new3(2,
125
+ rb_float_new(x),
126
+ rb_float_new(y));
127
+ }
128
+ }
129
+ }
130
+
131
+ #ifdef HAVE_CARRAY_H
132
+
133
+ #include "carray.h"
134
+
135
+ static VALUE
136
+ rb_proj_s_transform_ca (int argc, VALUE *argv, VALUE self)
137
+ {
138
+ volatile VALUE vsrc, vdst, vx, vy, vz;
139
+ Proj *psrc, *pdst;
140
+ int isll_src, isll_dst;
141
+ CArray *cx, *cy, *cz;
142
+ double *p1, *p2, *p3;
143
+ ca_size_t s1, s2, s3;
144
+ int8_t *m, *mp;
145
+ ca_size_t count, err_count, status, i;
146
+
147
+ rb_scan_args(argc, argv, "5", &vsrc, &vdst, &vx, &vy, &vz);
148
+
149
+ Data_Get_Struct(vsrc, Proj, psrc);
150
+ Data_Get_Struct(vdst, Proj, pdst);
151
+
152
+ isll_src = pj_is_latlong(psrc->ref);
153
+ isll_dst = pj_is_latlong(pdst->ref);
154
+
155
+ cx = ca_wrap_writable(vx, CA_DOUBLE);
156
+ cy = ca_wrap_writable(vy, CA_DOUBLE);
157
+ cz = ca_wrap_writable(vz, CA_DOUBLE);
158
+
159
+ count = ca_get_loop_count(3, cx, cy, cz);
160
+ if ( count == -1 )
161
+ rb_raise(rb_eRuntimeError, "invalid data_num");
162
+
163
+ ca_attach_n(3, cx, cy, cz);
164
+
165
+ ca_set_iterator(3,
166
+ cx, &p1, &s1,
167
+ cy, &p2, &s2,
168
+ cz, &p3, &s3);
169
+
170
+ m = ca_allocate_mask_iterator(3, cx, cy, cz);
171
+
172
+ mp = m;
173
+ err_count = 0;
174
+ for (i=0; i<count; i++) {
175
+ if ( *mp ) {
176
+ err_count += 1;
177
+ }
178
+ else {
179
+ if ( isll_src ) {
180
+ (*p1) *= DEG_TO_RAD;
181
+ (*p2) *= DEG_TO_RAD;
182
+ }
183
+ status = pj_transform(psrc->ref, pdst->ref, 1, 0, p1, p2, p3);
184
+ if ( isll_dst ) {
185
+ (*p1) *= RAD_TO_DEG;
186
+ (*p2) *= RAD_TO_DEG;
187
+ }
188
+ if ( status < 0 ) {
189
+ err_count += 1;
190
+ }
191
+ }
192
+ p1+=s1; p2+=s2; p3+=s3;
193
+ mp++;
194
+ }
195
+
196
+ free(m);
197
+
198
+ ca_sync_n(3, cx, cy, cz);
199
+ ca_detach_n(3, cx, cy, cz);
200
+
201
+ return SIZE2NUM(err_count);
202
+ }
203
+
204
+
205
+ #endif
206
+
207
+ void Init_proj ();
208
+ void Init_geod ();
209
+
210
+ void
211
+ Init_proj4r ()
212
+ {
213
+ rb_mPROJ4 = rb_define_module("PROJ4");
214
+
215
+ rb_define_const(rb_mPROJ4, "RAD_TO_DEG", rb_float_new(RAD_TO_DEG));
216
+ rb_define_const(rb_mPROJ4, "DEG_TO_RAD", rb_float_new(DEG_TO_RAD));
217
+
218
+ set_rtodms(6, 1);
219
+ rb_define_singleton_method(rb_mPROJ4, "dmstor", rb_proj_s_dmstor, 1);
220
+ rb_define_singleton_method(rb_mPROJ4, "rtodms", rb_proj_s_rtodms, -1);
221
+ rb_define_singleton_method(rb_mPROJ4, "dmstod", rb_proj_s_dmstod, 1);
222
+ rb_define_singleton_method(rb_mPROJ4, "dtodms", rb_proj_s_dtodms, -1);
223
+
224
+ rb_define_singleton_method(rb_mPROJ4, "_transform", rb_proj_s_transform, -1);
225
+ #ifdef HAVE_CARRAY_H
226
+ rb_define_singleton_method(rb_mPROJ4, "_transform_ca", rb_proj_s_transform_ca, -1);
227
+ #endif
228
+
229
+ Init_proj();
230
+ Init_geod();
231
+ }
232
+
data/rb_proj4r.h ADDED
@@ -0,0 +1,46 @@
1
+ #ifndef RB_PROJ_H
2
+ #define RB_PROJ_H
3
+
4
+ #include <ctype.h>
5
+ #include <stdio.h>
6
+ #include <string.h>
7
+
8
+ #include "projects.h"
9
+ #define projCtx_t int
10
+ #include "proj_api.h"
11
+ #include "geodesic.h"
12
+
13
+ typedef struct {
14
+ PJ *ref;
15
+ } Proj;
16
+
17
+ typedef struct {
18
+ struct geod_geodesic *ref;
19
+ } Geod;
20
+
21
+ /*
22
+ void
23
+ proj4_geod_init (struct geodesic *geod, char *param);
24
+
25
+ void
26
+ proj4_geod_inverse (struct geodesic *geod,
27
+ double l1, double p1, double l2, double p2,
28
+ double *az12, double *az21, double *dist);
29
+
30
+ double
31
+ proj4_geod_distance (struct geodesic *geod,
32
+ double l1, double p1, double l2, double p2);
33
+
34
+ void
35
+ proj4_geod_forward (struct geodesic *geod,
36
+ double l1, double p1, double a, double d,
37
+ double *l2, double *p2, double *az21);
38
+ */
39
+
40
+ extern VALUE rb_mPROJ4;
41
+ extern VALUE rb_cProj;
42
+ extern VALUE rb_cGeod;
43
+ extern VALUE rb_cProj4;
44
+ extern VALUE rb_mGeod;
45
+
46
+ #endif
data/test/TEST.txt ADDED
@@ -0,0 +1,5 @@
1
+ # x y
2
+ 110503 5.059 2.667
3
+ 110506 5.132 2.750
4
+ 110509 5.174 2.806
5
+ 110512 5.277 2.950
@@ -0,0 +1,13 @@
1
+ require "proj4r"
2
+
3
+ pj = PROJ4::Proj.new("+proj=merc +lat_0=0 +ellps=WGS84 +units=km")
4
+
5
+ p pj.descr
6
+ p pj.definition
7
+ p pj.def_size
8
+ p pj.def_shape
9
+ p pj.latlong?
10
+ p pj.geocent?
11
+ p pj.catalog_name
12
+
13
+ p pj.to_latlong.definition
data/test/tenkizu.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "proj4r"
2
+
3
+ include PROJ4
4
+
5
+ scy = 1316.360971/2.097
6
+ scx = scy*1.076
7
+
8
+ ps = Proj.new("+ellps=WGS84 +units=km +proj=stere +lat_ts=60 +lat_0=90 +lon_0=140")
9
+ ll = Proj.new("+proj=lonlat")
10
+
11
+ xoff = 5.708
12
+ yoff = 9399.152289/scy
13
+
14
+ #p PROJ4.transform(ll, ps, 140*DEG_TO_RAD, 30*DEG_TO_RAD, 0)
15
+ #p PROJ4.transform(ll, ps, 140*DEG_TO_RAD, 40*DEG_TO_RAD, 0)
16
+ #p PROJ4.transform(ps, ll, 0.0, -5555.5289096419965, 0).map{|s| s*RAD_TO_DEG}
17
+ #p PROJ4.transform(ps, ll, 0.0, -6871.88988083827, 0).map{|s| s*RAD_TO_DEG}
18
+
19
+ while line = gets
20
+ case line
21
+ when /^#/
22
+ else
23
+ index, x, y = line.chomp.split(/\s+/)
24
+ x = x.to_f
25
+ y = y.to_f
26
+ lon, lat, hgt = *PROJ4.transform(ps, ll, (x-xoff)*scx, (y-yoff)*scy, 0).map{|s| s*RAD_TO_DEG}
27
+ printf("%s,%g,%g\n", index, lon, lat)
28
+ end
29
+ end
data/test/test.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "proj4r"
2
+
3
+ #
4
+ # PROJ4::Geod.new(a = 6378137, f = 1.0/298.257223563)
5
+ #
6
+ # PROJ4::Geod.inverse(lat1, lon1, lat2, lon2)
7
+ #
8
+ # -> distance, azi1, azi2
9
+ #
10
+
11
+ geod = PROJ4::Geod.new("+ellps=WGS84 +units=km")
12
+ p geod.inverse(30,100,-30,-100)
13
+ # => [18101709.587288667, 94.90534751023246, 94.90534751023246]
14
+
15
+ geod2 = PROJ4::Geod.new()
16
+ p geod2.inverse(30,100,-30,-100)
17
+ # => [18101709.587288667, 94.90534751023246, 94.90534751023246]
18
+
19
+ p geod.inverse(30,100,-30,-120)
20
+ # => [18101709.587288667, 94.90534751023246, 94.90534751023246]
21
+
22
+
23
+ p geod.inverse(42.25, -71.11666666666666, 45.516, -123.68)
24
+ p geod.inverse(CA_DOUBLE(42.25), CA_DOUBLE(-71.11666666666666),
25
+ CA_DOUBLE(45.516), CA_DOUBLE(-123.68))