rgeo-proj4 2.0.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05e81871744567d55f6b9d11e115954040f5262e9d3317b9792973f1806f655a
4
- data.tar.gz: 0a3f2943bf7c80eb4c9d0680b382ab0c9eed83543ef1f4383326e4bdfb6da250
3
+ metadata.gz: 62f84fd831d1035bdd65d52dcfdcf03c46ee0dc99c3ca74ce3e2051faa53c66a
4
+ data.tar.gz: cd095e159586c6e57ae4e8f2eb0c5f84719adf6c7bf521c6b86b34e78ae7b824
5
5
  SHA512:
6
- metadata.gz: 74ad26d2f7f983b9415b1b301180fe0352a09d4df7425227c2d012220468e147d9b1787c41de2b13f2db9cb5bf9e8a35038beee362393427911854cbff4c49f8
7
- data.tar.gz: bcd150775bfa449dad65dd8035f9ceb4e23192dac1f258de2c0b3edf58362e6c48a4b7da7c710bcf3b43de61c92ca64b159f7b6eec2cdaa1ca0cda7a1a1a5ff0
6
+ metadata.gz: 8c982a9cda985160dbc50d62ca5d5798da685d98a63be3df1fb9c4687e7bc42ab5e651e6245e55757d948f4717496b2c178b881e2072292b19ca9530b7db1663
7
+ data.tar.gz: 4d30068d4ddaaed6372e42cce1fdcba32be62e8dd8bbe8891556df03f7a6e821cbf0481e4f580eaaaa4efaf1fa7ed0c64da251062b8873673bf69b7d7e6f07dc
@@ -45,15 +45,19 @@ else
45
45
 
46
46
  found_proj_ = false
47
47
  header_dirs_, lib_dirs_ = dir_config("proj", header_dirs_, lib_dirs_)
48
- dflag = "-DACCEPT_USE_OF_DEPRECATED_PROJ_API_H"
49
- if have_header("proj_api.h", nil, dflag)
48
+ if have_header("proj.h")
50
49
  $libs << " -lproj"
51
- if have_func("pj_init_plus", "proj_api.h", dflag)
50
+
51
+ if have_func("proj_create", "proj.h")
52
52
  found_proj_ = true
53
+ have_func("proj_create_crs_to_crs_from_pj", "proj.h")
54
+ have_func("proj_normalize_for_visualization", "proj.h")
53
55
  else
54
56
  $libs.gsub!(" -lproj", "")
55
57
  end
56
58
  end
59
+ have_func("rb_gc_mark_movable")
60
+
57
61
  unless found_proj_
58
62
  puts "**** WARNING: Unable to find Proj headers or Proj version is too old."
59
63
  puts "**** Compiling without Proj support."
@@ -1,12 +1,21 @@
1
1
  /*
2
2
  Main initializer for Proj4 wrapper
3
3
  */
4
- #ifdef HAVE_PROJ_API_H
5
- #ifdef HAVE_PJ_INIT_PLUS
6
- #define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
4
+ #ifdef HAVE_PROJ_H
5
+ #ifdef HAVE_PROJ_CREATE
6
+ #ifdef HAVE_PROJ_CREATE_CRS_TO_CRS_FROM_PJ
7
+ #ifdef HAVE_PROJ_NORMALIZE_FOR_VISUALIZATION
7
8
  #define RGEO_PROJ4_SUPPORTED
8
9
  #endif
9
10
  #endif
11
+ #endif
12
+ #endif
13
+
14
+ #ifdef HAVE_RB_GC_MARK_MOVABLE
15
+ #define mark rb_gc_mark_movable
16
+ #else
17
+ #define mark rb_gc_mark
18
+ #endif
10
19
 
11
20
  #ifdef __cplusplus
12
21
  #define RGEO_BEGIN_C extern "C" {
@@ -20,7 +29,7 @@
20
29
  #ifdef RGEO_PROJ4_SUPPORTED
21
30
 
22
31
  #include <ruby.h>
23
- #include <proj_api.h>
32
+ #include <proj.h>
24
33
 
25
34
  #endif
26
35
 
@@ -32,76 +41,105 @@ RGEO_BEGIN_C
32
41
 
33
42
 
34
43
  typedef struct {
35
- projPJ pj;
44
+ PJ *pj;
36
45
  VALUE original_str;
37
46
  char uses_radians;
38
47
  } RGeo_Proj4Data;
39
48
 
40
49
 
41
- #define RGEO_PROJ4_DATA_PTR(obj) ((RGeo_Proj4Data*)DATA_PTR(obj))
50
+ // Destroy function for proj data.
51
+ static void rgeo_proj4_free(void *ptr)
52
+ {
53
+ RGeo_Proj4Data *data = (RGeo_Proj4Data *)ptr;
54
+ if(data->pj){
55
+ proj_destroy(data->pj);
56
+ }
57
+ free(data);
58
+ }
42
59
 
60
+ static size_t rgeo_proj4_memsize(const void *ptr)
61
+ {
62
+ size_t size = 0;
63
+ const RGeo_Proj4Data *data = (const RGeo_Proj4Data *)ptr;
43
64
 
44
- // Destroy function for proj data.
65
+ size += sizeof(*data);
66
+ if(data->pj){
67
+ size += sizeof(data->pj);
68
+ }
69
+ return size;
70
+ }
45
71
 
46
- static void destroy_proj4_func(RGeo_Proj4Data* data)
72
+ static void rgeo_proj4_mark(void *ptr)
47
73
  {
48
- if (data->pj) {
49
- pj_free(data->pj);
74
+ RGeo_Proj4Data *data = (RGeo_Proj4Data *)ptr;
75
+ if(!NIL_P(data->original_str)){
76
+ mark(data->original_str);
50
77
  }
51
- free(data);
52
78
  }
53
79
 
80
+ #ifdef HAVE_RB_GC_MARK_MOVABLE
81
+ static void rgeo_proj4_compact(void *ptr)
82
+ {
83
+ RGeo_Proj4Data *data = (RGeo_Proj4Data *)ptr;
84
+ if(data && !NIL_P(data->original_str)){
85
+ data->original_str = rb_gc_location(data->original_str);
86
+ }
87
+ }
88
+ #endif
54
89
 
55
- static void mark_proj4_func(RGeo_Proj4Data* data)
90
+ static void rgeo_proj4_clear_struct(RGeo_Proj4Data *data)
56
91
  {
57
- if (!NIL_P(data->original_str)) {
58
- rb_gc_mark(data->original_str);
92
+ if(data->pj){
93
+ proj_destroy(data->pj);
94
+ data->pj = NULL;
95
+ data->original_str = Qnil;
59
96
  }
60
97
  }
61
98
 
99
+ static const rb_data_type_t rgeo_proj4_data_type = {
100
+ "RGeo::CoordSys::Proj4",
101
+ {rgeo_proj4_mark, rgeo_proj4_free, rgeo_proj4_memsize,
102
+ #ifdef HAVE_RB_GC_MARK_MOVABLE
103
+ rgeo_proj4_compact
104
+ #endif
105
+ },
106
+ 0, 0,
107
+ RUBY_TYPED_FREE_IMMEDIATELY};
62
108
 
63
- static VALUE alloc_proj4(VALUE klass)
109
+ static VALUE rgeo_proj4_data_alloc(VALUE self)
64
110
  {
65
111
  VALUE result;
66
- RGeo_Proj4Data* data;
112
+ RGeo_Proj4Data *data = ALLOC(RGeo_Proj4Data);
67
113
 
68
114
  result = Qnil;
69
- data = ALLOC(RGeo_Proj4Data);
70
- if (data) {
115
+
116
+ if(data){
71
117
  data->pj = NULL;
72
118
  data->original_str = Qnil;
73
119
  data->uses_radians = 0;
74
- result = Data_Wrap_Struct(klass, mark_proj4_func, destroy_proj4_func, data);
120
+ result = TypedData_Wrap_Struct(self, &rgeo_proj4_data_type, data);
75
121
  }
76
122
  return result;
77
123
  }
78
124
 
79
-
80
125
  static VALUE method_proj4_initialize_copy(VALUE self, VALUE orig)
81
126
  {
82
- RGeo_Proj4Data* self_data;
83
- projPJ pj;
84
- RGeo_Proj4Data* orig_data;
85
- char* str;
127
+ RGeo_Proj4Data *self_data;
128
+ RGeo_Proj4Data *orig_data;
129
+ const char* str;
86
130
 
87
131
  // Clear out any existing value
88
- self_data = RGEO_PROJ4_DATA_PTR(self);
89
- pj = self_data->pj;
90
- if (pj) {
91
- pj_free(pj);
92
- self_data->pj = NULL;
93
- self_data->original_str = Qnil;
94
- }
132
+ TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, self_data);
133
+ rgeo_proj4_clear_struct(self_data);
95
134
 
96
135
  // Copy value from orig
97
- orig_data = RGEO_PROJ4_DATA_PTR(orig);
136
+ TypedData_Get_Struct(orig, RGeo_Proj4Data, &rgeo_proj4_data_type, orig_data);
98
137
  if (!NIL_P(orig_data->original_str)) {
99
- self_data->pj = pj_init_plus(RSTRING_PTR(orig_data->original_str));
138
+ self_data->pj = proj_create(PJ_DEFAULT_CTX, StringValuePtr(orig_data->original_str));
100
139
  }
101
140
  else {
102
- str = pj_get_def(orig_data->pj, 0);
103
- self_data->pj = pj_init_plus(str);
104
- pj_dalloc(str);
141
+ str = proj_as_proj_string(PJ_DEFAULT_CTX, orig_data->pj, PJ_PROJ_4, NULL);
142
+ self_data->pj = proj_create(PJ_DEFAULT_CTX, str);
105
143
  }
106
144
  self_data->original_str = orig_data->original_str;
107
145
  self_data->uses_radians = orig_data->uses_radians;
@@ -112,22 +150,16 @@ static VALUE method_proj4_initialize_copy(VALUE self, VALUE orig)
112
150
 
113
151
  static VALUE method_proj4_set_value(VALUE self, VALUE str, VALUE uses_radians)
114
152
  {
115
- RGeo_Proj4Data* self_data;
116
- projPJ pj;
153
+ RGeo_Proj4Data *self_data;
117
154
 
118
155
  Check_Type(str, T_STRING);
119
156
 
120
157
  // Clear out any existing value
121
- self_data = RGEO_PROJ4_DATA_PTR(self);
122
- pj = self_data->pj;
123
- if (pj) {
124
- pj_free(pj);
125
- self_data->pj = NULL;
126
- self_data->original_str = Qnil;
127
- }
158
+ TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, self_data);
159
+ rgeo_proj4_clear_struct(self_data);
128
160
 
129
161
  // Set new data
130
- self_data->pj = pj_init_plus(RSTRING_PTR(str));
162
+ self_data->pj = proj_create(PJ_DEFAULT_CTX, StringValuePtr(str));
131
163
  self_data->original_str = str;
132
164
  self_data->uses_radians = RTEST(uses_radians) ? 1 : 0;
133
165
 
@@ -138,17 +170,18 @@ static VALUE method_proj4_set_value(VALUE self, VALUE str, VALUE uses_radians)
138
170
  static VALUE method_proj4_get_geographic(VALUE self)
139
171
  {
140
172
  VALUE result;
141
- RGeo_Proj4Data* new_data;
142
- RGeo_Proj4Data* self_data;
173
+ RGeo_Proj4Data *new_data;
174
+ RGeo_Proj4Data *self_data;
143
175
 
144
176
  result = Qnil;
145
177
  new_data = ALLOC(RGeo_Proj4Data);
146
178
  if (new_data) {
147
- self_data = RGEO_PROJ4_DATA_PTR(self);
148
- new_data->pj = pj_latlong_from_proj(self_data->pj);
179
+ TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, self_data);
180
+
181
+ new_data->pj = proj_crs_get_geodetic_crs(PJ_DEFAULT_CTX, self_data->pj);
149
182
  new_data->original_str = Qnil;
150
183
  new_data->uses_radians = self_data->uses_radians;
151
- result = Data_Wrap_Struct(CLASS_OF(self), mark_proj4_func, destroy_proj4_func, new_data);
184
+ result = TypedData_Wrap_Struct(CLASS_OF(self), &rgeo_proj4_data_type, new_data);
152
185
  }
153
186
  return result;
154
187
  }
@@ -156,44 +189,97 @@ static VALUE method_proj4_get_geographic(VALUE self)
156
189
 
157
190
  static VALUE method_proj4_original_str(VALUE self)
158
191
  {
159
- return RGEO_PROJ4_DATA_PTR(self)->original_str;
192
+ RGeo_Proj4Data *data;
193
+ TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data);
194
+ return data->original_str;
160
195
  }
161
196
 
162
197
 
163
198
  static VALUE method_proj4_uses_radians(VALUE self)
164
199
  {
165
- return RGEO_PROJ4_DATA_PTR(self)->uses_radians ? Qtrue : Qfalse;
200
+ RGeo_Proj4Data *data;
201
+ TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data);
202
+ return data->uses_radians ? Qtrue : Qfalse;
166
203
  }
167
204
 
168
205
 
169
206
  static VALUE method_proj4_canonical_str(VALUE self)
170
207
  {
171
208
  VALUE result;
172
- projPJ pj;
173
- char* str;
209
+ PJ *pj;
210
+ const char *str;
211
+ RGeo_Proj4Data *data;
174
212
 
175
213
  result = Qnil;
176
- pj = RGEO_PROJ4_DATA_PTR(self)->pj;
214
+ TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data);
215
+ pj = data->pj;
177
216
  if (pj) {
178
- str = pj_get_def(pj, 0);
217
+ str = proj_as_proj_string(PJ_DEFAULT_CTX, pj, PJ_PROJ_4, NULL);
179
218
  if (str) {
180
219
  result = rb_str_new2(str);
181
- pj_dalloc(str);
182
220
  }
183
221
  }
184
222
  return result;
185
223
  }
186
224
 
225
+ static VALUE method_proj4_wkt_str(VALUE self)
226
+ {
227
+ VALUE result;
228
+ PJ *pj;
229
+ const char *str;
230
+ RGeo_Proj4Data *data;
231
+
232
+ result = Qnil;
233
+ TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data);
234
+ pj = data->pj;
235
+ if (pj) {
236
+ const char *const options[] = {"MULTILINE=NO", NULL};
237
+ str = proj_as_wkt(PJ_DEFAULT_CTX, pj, PJ_WKT2_2019, options);
238
+ if(str){
239
+ result = rb_str_new2(str);
240
+ }
241
+ }
242
+ return result;
243
+ }
244
+
245
+ static VALUE method_proj4_auth_name_str(VALUE self)
246
+ {
247
+ VALUE result;
248
+ PJ *pj;
249
+ const char *id;
250
+ const char *auth;
251
+ RGeo_Proj4Data *data;
252
+
253
+ result = Qnil;
254
+ TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data);
255
+ pj = data->pj;
256
+ if (pj) {
257
+ auth = proj_get_id_auth_name(pj, 0);
258
+ id = proj_get_id_code(pj, 0);
259
+ if(id && auth){
260
+ result = rb_sprintf("%s:%s", auth, id);
261
+ }
262
+ }
263
+ return result;
264
+ }
187
265
 
188
266
  static VALUE method_proj4_is_geographic(VALUE self)
189
267
  {
190
268
  VALUE result;
191
- projPJ pj;
269
+ PJ *pj;
270
+ PJ_TYPE proj_type;
271
+ RGeo_Proj4Data *data;
192
272
 
193
273
  result = Qnil;
194
- pj = RGEO_PROJ4_DATA_PTR(self)->pj;
274
+ TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data);
275
+ pj = data->pj;
195
276
  if (pj) {
196
- result = pj_is_latlong(pj) ? Qtrue : Qfalse;
277
+ proj_type = proj_get_type(pj);
278
+ if(proj_type == PJ_TYPE_GEOGRAPHIC_2D_CRS || proj_type == PJ_TYPE_GEOGRAPHIC_3D_CRS){
279
+ result = Qtrue;
280
+ } else {
281
+ result = Qfalse;
282
+ }
197
283
  }
198
284
  return result;
199
285
  }
@@ -202,12 +288,16 @@ static VALUE method_proj4_is_geographic(VALUE self)
202
288
  static VALUE method_proj4_is_geocentric(VALUE self)
203
289
  {
204
290
  VALUE result;
205
- projPJ pj;
291
+ PJ *pj;
292
+ PJ_TYPE proj_type;
293
+ RGeo_Proj4Data *data;
206
294
 
207
295
  result = Qnil;
208
- pj = RGEO_PROJ4_DATA_PTR(self)->pj;
296
+ TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data);
297
+ pj = data->pj;
209
298
  if (pj) {
210
- result = pj_is_geocent(pj) ? Qtrue : Qfalse;
299
+ proj_type = proj_get_type(pj);
300
+ result = proj_type == PJ_TYPE_GEOCENTRIC_CRS ? Qtrue : Qfalse;
211
301
  }
212
302
  return result;
213
303
  }
@@ -215,42 +305,62 @@ static VALUE method_proj4_is_geocentric(VALUE self)
215
305
 
216
306
  static VALUE method_proj4_is_valid(VALUE self)
217
307
  {
218
- return RGEO_PROJ4_DATA_PTR(self)->pj ? Qtrue : Qfalse;
308
+ RGeo_Proj4Data *data;
309
+ TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data);
310
+ return data->pj ? Qtrue : Qfalse;
219
311
  }
220
312
 
221
313
 
222
314
  static VALUE cmethod_proj4_version(VALUE module)
223
315
  {
224
- return INT2NUM(PJ_VERSION);
316
+ return rb_sprintf("%d.%d.%d", PROJ_VERSION_MAJOR, PROJ_VERSION_MINOR, PROJ_VERSION_PATCH);
225
317
  }
226
318
 
227
319
 
228
320
  static VALUE cmethod_proj4_transform(VALUE module, VALUE from, VALUE to, VALUE x, VALUE y, VALUE z)
229
321
  {
230
322
  VALUE result;
231
- projPJ from_pj;
232
- projPJ to_pj;
323
+ RGeo_Proj4Data *from_data;
324
+ RGeo_Proj4Data *to_data;
325
+ PJ *from_pj;
326
+ PJ *to_pj;
327
+ PJ *crs_to_crs;
328
+ PJ *gis_pj;
233
329
  double xval, yval, zval;
234
- int err;
330
+ PJ_COORD input;
331
+ PJ_COORD output;
235
332
 
236
333
  result = Qnil;
237
- from_pj = RGEO_PROJ4_DATA_PTR(from)->pj;
238
- to_pj = RGEO_PROJ4_DATA_PTR(to)->pj;
334
+ TypedData_Get_Struct(from, RGeo_Proj4Data, &rgeo_proj4_data_type, from_data);
335
+ TypedData_Get_Struct(to, RGeo_Proj4Data, &rgeo_proj4_data_type, to_data);
336
+ from_pj = from_data->pj;
337
+ to_pj = to_data->pj;
239
338
  if (from_pj && to_pj) {
240
- xval = rb_num2dbl(x);
241
- yval = rb_num2dbl(y);
242
- zval = 0.0;
243
- if (!NIL_P(z)) {
244
- zval = rb_num2dbl(z);
245
- }
246
- err = pj_transform(from_pj, to_pj, 1, 1, &xval, &yval, NIL_P(z) ? NULL : &zval);
247
- if (!err && xval != HUGE_VAL && yval != HUGE_VAL && (NIL_P(z) || zval != HUGE_VAL)) {
248
- result = rb_ary_new2(NIL_P(z) ? 2 : 3);
249
- rb_ary_push(result, rb_float_new(xval));
250
- rb_ary_push(result, rb_float_new(yval));
251
- if (!NIL_P(z)) {
252
- rb_ary_push(result, rb_float_new(zval));
339
+ crs_to_crs = proj_create_crs_to_crs_from_pj(PJ_DEFAULT_CTX, from_pj, to_pj, 0, NULL);
340
+ if(crs_to_crs){
341
+ // necessary to use proj_normalize_for_visualization so that we
342
+ // do not have to worry about the order of coordinates in every
343
+ // coord system.
344
+ gis_pj = proj_normalize_for_visualization(PJ_DEFAULT_CTX, crs_to_crs);
345
+ if(gis_pj){
346
+ proj_destroy(crs_to_crs);
347
+ crs_to_crs = gis_pj;
348
+
349
+ xval = rb_num2dbl(x);
350
+ yval = rb_num2dbl(y);
351
+ zval = NIL_P(z) ? 0.0 : rb_num2dbl(z);
352
+
353
+ input = proj_coord(xval, yval, zval, HUGE_VAL);
354
+ output = proj_trans(crs_to_crs, PJ_FWD, input);
355
+
356
+ result = rb_ary_new2(NIL_P(z) ? 2 : 3);
357
+ rb_ary_push(result, DBL2NUM(output.xyz.x));
358
+ rb_ary_push(result, DBL2NUM(output.xyz.y));
359
+ if(!NIL_P(z)){
360
+ rb_ary_push(result, DBL2NUM(output.xyz.z));
361
+ }
253
362
  }
363
+ proj_destroy(crs_to_crs);
254
364
  }
255
365
  }
256
366
  return result;
@@ -266,10 +376,10 @@ static VALUE cmethod_proj4_create(VALUE klass, VALUE str, VALUE uses_radians)
266
376
  Check_Type(str, T_STRING);
267
377
  data = ALLOC(RGeo_Proj4Data);
268
378
  if (data) {
269
- data->pj = pj_init_plus(RSTRING_PTR(str));
379
+ data->pj = proj_create(PJ_DEFAULT_CTX, StringValuePtr(str));
270
380
  data->original_str = str;
271
381
  data->uses_radians = RTEST(uses_radians) ? 1 : 0;
272
- result = Data_Wrap_Struct(klass, mark_proj4_func, destroy_proj4_func, data);
382
+ result = TypedData_Wrap_Struct(klass, &rgeo_proj4_data_type, data);
273
383
  }
274
384
  return result;
275
385
  }
@@ -285,12 +395,14 @@ static void rgeo_init_proj4()
285
395
  coordsys_module = rb_define_module_under(rgeo_module, "CoordSys");
286
396
  proj4_class = rb_define_class_under(coordsys_module, "Proj4", rb_cObject);
287
397
 
288
- rb_define_alloc_func(proj4_class, alloc_proj4);
398
+ rb_define_alloc_func(proj4_class, rgeo_proj4_data_alloc);
289
399
  rb_define_module_function(proj4_class, "_create", cmethod_proj4_create, 2);
290
400
  rb_define_method(proj4_class, "initialize_copy", method_proj4_initialize_copy, 1);
291
401
  rb_define_method(proj4_class, "_set_value", method_proj4_set_value, 2);
292
402
  rb_define_method(proj4_class, "_original_str", method_proj4_original_str, 0);
293
403
  rb_define_method(proj4_class, "_canonical_str", method_proj4_canonical_str, 0);
404
+ rb_define_method(proj4_class, "_as_text", method_proj4_wkt_str, 0);
405
+ rb_define_method(proj4_class, "_auth_name", method_proj4_auth_name_str, 0);
294
406
  rb_define_method(proj4_class, "_valid?", method_proj4_is_valid, 0);
295
407
  rb_define_method(proj4_class, "_geographic?", method_proj4_is_geographic, 0);
296
408
  rb_define_method(proj4_class, "_geocentric?", method_proj4_is_geocentric, 0);
@@ -41,8 +41,8 @@ module RGeo
41
41
  # there are sometimes multiple ways to express a given coordinate
42
42
  # system.
43
43
 
44
- def eql?(rhs_)
45
- rhs_.class == self.class && rhs_.canonical_hash == canonical_hash && rhs_._radians? == _radians?
44
+ def eql?(other)
45
+ other.class == self.class && other.canonical_hash == canonical_hash && other._radians? == _radians?
46
46
  end
47
47
  alias == eql?
48
48
 
@@ -105,6 +105,21 @@ module RGeo
105
105
  _original_str
106
106
  end
107
107
 
108
+ # Returns the WKT representation of the CRS.
109
+
110
+ def as_text
111
+ _as_text
112
+ end
113
+
114
+ # Returns the string representing the authority and code of the
115
+ # CRS if it exists, nil otherwise.
116
+ #
117
+ # Ex. EPSG:4326
118
+
119
+ def auth_name
120
+ _auth_name
121
+ end
122
+
108
123
  # Returns true if this Proj4 object is a geographic (lat-long)
109
124
  # coordinate system.
110
125
 
@@ -172,7 +187,7 @@ module RGeo
172
187
  if defn_.is_a?(::Hash)
173
188
  defn_ = defn_.map { |k_, v_| v_ ? "+#{k_}=#{v_}" : "+#{k_}" }.join(" ")
174
189
  end
175
- defn_ = defn_.sub(/^(\s*)/, '\1+').gsub(/(\s+)([^+\s])/, '\1+\2') unless defn_ =~ /^\s*\+/
190
+
176
191
  result_ = _create(defn_, opts_[:radians])
177
192
  result_ = nil unless result_._valid?
178
193
  end
@@ -208,14 +223,15 @@ module RGeo
208
223
  # or three elements.
209
224
 
210
225
  def transform_coords(from_proj_, to_proj_, x_, y_, z_ = nil)
211
- if !from_proj_._radians? && from_proj_._geographic?
212
- x_ *= ImplHelper::Math::RADIANS_PER_DEGREE
213
- y_ *= ImplHelper::Math::RADIANS_PER_DEGREE
226
+ if from_proj_._radians? && from_proj_._geographic?
227
+ x_ *= ImplHelper::Math::DEGREES_PER_RADIAN
228
+ y_ *= ImplHelper::Math::DEGREES_PER_RADIAN
214
229
  end
230
+
215
231
  result_ = _transform_coords(from_proj_, to_proj_, x_, y_, z_)
216
- if result_ && !to_proj_._radians? && to_proj_._geographic?
217
- result_[0] *= ImplHelper::Math::DEGREES_PER_RADIAN
218
- result_[1] *= ImplHelper::Math::DEGREES_PER_RADIAN
232
+ if result_ && to_proj_._radians? && to_proj_._geographic?
233
+ result_[0] *= ImplHelper::Math::RADIANS_PER_DEGREE
234
+ result_[1] *= ImplHelper::Math::RADIANS_PER_DEGREE
219
235
  end
220
236
  result_
221
237
  end
@@ -259,15 +275,16 @@ module RGeo
259
275
  to_has_m_ = to_factory_.property(:has_m_coordinate)
260
276
  x_ = from_point_.x
261
277
  y_ = from_point_.y
262
- if !from_proj_._radians? && from_proj_._geographic?
263
- x_ *= ImplHelper::Math::RADIANS_PER_DEGREE
264
- y_ *= ImplHelper::Math::RADIANS_PER_DEGREE
278
+ if from_proj_._radians? && from_proj_._geographic?
279
+ x_ *= ImplHelper::Math::DEGREES_PER_RADIAN
280
+ y_ *= ImplHelper::Math::DEGREES_PER_RADIAN
265
281
  end
266
282
  coords_ = _transform_coords(from_proj_, to_proj_, x_, y_, from_has_z_ ? from_point_.z : nil)
267
283
  return unless coords_
268
- if !to_proj_._radians? && to_proj_._geographic?
269
- coords_[0] *= ImplHelper::Math::DEGREES_PER_RADIAN
270
- coords_[1] *= ImplHelper::Math::DEGREES_PER_RADIAN
284
+
285
+ if to_proj_._radians? && to_proj_._geographic?
286
+ coords_[0] *= ImplHelper::Math::RADIANS_PER_DEGREE
287
+ coords_[1] *= ImplHelper::Math::RADIANS_PER_DEGREE
271
288
  end
272
289
  extras_ = []
273
290
  extras_ << coords_[2].to_f if to_has_z_
@@ -81,11 +81,12 @@ module RGeo
81
81
  ident_ = ident_.to_s
82
82
  return @cache[ident_] if @cache&.include?(ident_)
83
83
  result_ = nil
84
- if @populate_state == 0
84
+ case @populate_state
85
+ when 0
85
86
  data_ = search_file(ident_)
86
87
  result_ = Entry.new(ident_, authority: @authority, authority_code: @authority ? ident_ : nil, name: data_[1], proj4: data_[2]) if data_
87
88
  @cache[ident_] = result_ if @cache
88
- elsif @populate_state == 1
89
+ when 1
89
90
  search_file(nil)
90
91
  result_ = @cache[ident_]
91
92
  @populate_state = 2
@@ -113,12 +114,10 @@ module RGeo
113
114
  cur_name_ = line_[comment_delim_ + 1..-1].strip
114
115
  line_ = line_[0..comment_delim_ - 1].strip
115
116
  end
116
- unless cur_ident_
117
- if line_ =~ /^<(\w+)>(.*)/
118
- cur_ident_ = Regexp.last_match(1)
119
- cur_text_ = []
120
- line_ = Regexp.last_match(2).strip
121
- end
117
+ if !cur_ident_ && (line_ =~ /^<(\w+)>(.*)/)
118
+ cur_ident_ = Regexp.last_match(1)
119
+ cur_text_ = []
120
+ line_ = Regexp.last_match(2).strip
122
121
  end
123
122
  next unless cur_ident_
124
123
  if line_[-2..-1] == "<>"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RGeo
4
4
  module Proj4
5
- VERSION = "2.0.1"
5
+ VERSION = "3.0.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgeo-proj4
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tee Parham, Daniel Azuma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-09 00:00:00.000000000 Z
11
+ date: 2021-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rgeo
@@ -30,28 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.11'
33
+ version: '5.14'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.11'
40
+ version: '5.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.9.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.9.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '12.0'
61
+ version: '13.0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '12.0'
68
+ version: '13.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake-compiler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.8.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.1
69
97
  description: Proj4 extension for rgeo.
70
98
  email:
71
99
  - parhameter@gmail.com, dazuma@gmail.com
@@ -93,14 +121,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
121
  requirements:
94
122
  - - ">="
95
123
  - !ruby/object:Gem::Version
96
- version: 2.3.0
124
+ version: 2.5.0
97
125
  required_rubygems_version: !ruby/object:Gem::Requirement
98
126
  requirements:
99
127
  - - ">="
100
128
  - !ruby/object:Gem::Version
101
129
  version: '0'
102
130
  requirements: []
103
- rubygems_version: 3.0.3
131
+ rubygems_version: 3.1.4
104
132
  signing_key:
105
133
  specification_version: 4
106
134
  summary: Proj4 extension for rgeo.