rgeo 2.3.1 → 3.0.0.pre.rc.2

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.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +6 -0
  3. data/README.md +11 -10
  4. data/ext/geos_c_impl/analysis.c +8 -6
  5. data/ext/geos_c_impl/analysis.h +1 -3
  6. data/ext/geos_c_impl/errors.c +10 -8
  7. data/ext/geos_c_impl/errors.h +7 -3
  8. data/ext/geos_c_impl/extconf.rb +3 -0
  9. data/ext/geos_c_impl/factory.c +273 -202
  10. data/ext/geos_c_impl/factory.h +51 -63
  11. data/ext/geos_c_impl/geometry.c +124 -22
  12. data/ext/geos_c_impl/geometry.h +8 -3
  13. data/ext/geos_c_impl/geometry_collection.c +81 -185
  14. data/ext/geos_c_impl/geometry_collection.h +1 -14
  15. data/ext/geos_c_impl/globals.c +91 -0
  16. data/ext/geos_c_impl/globals.h +45 -0
  17. data/ext/geos_c_impl/line_string.c +28 -29
  18. data/ext/geos_c_impl/line_string.h +1 -3
  19. data/ext/geos_c_impl/main.c +10 -9
  20. data/ext/geos_c_impl/point.c +9 -8
  21. data/ext/geos_c_impl/point.h +1 -3
  22. data/ext/geos_c_impl/polygon.c +43 -72
  23. data/ext/geos_c_impl/polygon.h +1 -3
  24. data/ext/geos_c_impl/preface.h +12 -0
  25. data/ext/geos_c_impl/ruby_more.c +65 -0
  26. data/ext/geos_c_impl/ruby_more.h +16 -0
  27. data/lib/rgeo/cartesian/calculations.rb +54 -17
  28. data/lib/rgeo/cartesian/factory.rb +6 -14
  29. data/lib/rgeo/cartesian/feature_classes.rb +68 -46
  30. data/lib/rgeo/cartesian/feature_methods.rb +67 -20
  31. data/lib/rgeo/cartesian/interface.rb +0 -36
  32. data/lib/rgeo/cartesian/planar_graph.rb +379 -0
  33. data/lib/rgeo/cartesian/sweepline_intersector.rb +149 -0
  34. data/lib/rgeo/cartesian/valid_op.rb +71 -0
  35. data/lib/rgeo/cartesian.rb +3 -0
  36. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +6 -6
  37. data/lib/rgeo/coord_sys.rb +0 -11
  38. data/lib/rgeo/error.rb +15 -0
  39. data/lib/rgeo/feature/factory_generator.rb +0 -3
  40. data/lib/rgeo/feature/geometry.rb +107 -28
  41. data/lib/rgeo/feature/geometry_collection.rb +13 -5
  42. data/lib/rgeo/feature/line_string.rb +3 -3
  43. data/lib/rgeo/feature/multi_surface.rb +3 -3
  44. data/lib/rgeo/feature/point.rb +4 -4
  45. data/lib/rgeo/feature/surface.rb +3 -3
  46. data/lib/rgeo/geographic/factory.rb +6 -7
  47. data/lib/rgeo/geographic/interface.rb +6 -49
  48. data/lib/rgeo/geographic/proj4_projector.rb +0 -2
  49. data/lib/rgeo/geographic/projected_feature_classes.rb +21 -9
  50. data/lib/rgeo/geographic/projected_feature_methods.rb +67 -28
  51. data/lib/rgeo/geographic/simple_mercator_projector.rb +0 -2
  52. data/lib/rgeo/geographic/spherical_feature_classes.rb +29 -9
  53. data/lib/rgeo/geographic/spherical_feature_methods.rb +79 -2
  54. data/lib/rgeo/geos/capi_factory.rb +21 -38
  55. data/lib/rgeo/geos/capi_feature_classes.rb +54 -11
  56. data/lib/rgeo/geos/ffi_factory.rb +6 -35
  57. data/lib/rgeo/geos/ffi_feature_classes.rb +34 -10
  58. data/lib/rgeo/geos/ffi_feature_methods.rb +39 -5
  59. data/lib/rgeo/geos/interface.rb +0 -24
  60. data/lib/rgeo/geos/zm_factory.rb +0 -19
  61. data/lib/rgeo/geos/zm_feature_methods.rb +16 -0
  62. data/lib/rgeo/geos.rb +6 -3
  63. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +4 -4
  64. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +1 -1
  65. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +15 -19
  66. data/lib/rgeo/impl_helper/basic_point_methods.rb +1 -1
  67. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +1 -1
  68. data/lib/rgeo/impl_helper/valid_op.rb +354 -0
  69. data/lib/rgeo/impl_helper/validity_check.rb +139 -0
  70. data/lib/rgeo/impl_helper.rb +1 -0
  71. data/lib/rgeo/version.rb +1 -1
  72. metadata +45 -9
  73. data/lib/rgeo/coord_sys/srs_database/entry.rb +0 -107
  74. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +0 -64
  75. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +0 -65
@@ -10,13 +10,16 @@
10
10
  #include <ruby.h>
11
11
  #include <geos_c.h>
12
12
 
13
+
14
+ #include "coordinates.h"
15
+ #include "errors.h"
13
16
  #include "factory.h"
14
17
  #include "geometry.h"
18
+ #include "geometry_collection.h"
19
+ #include "globals.h"
15
20
  #include "line_string.h"
16
21
  #include "polygon.h"
17
- #include "geometry_collection.h"
18
22
 
19
- #include "coordinates.h"
20
23
 
21
24
  RGEO_BEGIN_C
22
25
 
@@ -41,95 +44,69 @@ static VALUE create_geometry_collection(VALUE module, int type, VALUE factory, V
41
44
  VALUE cast_type;
42
45
  GEOSGeometry* geom;
43
46
  GEOSGeometry* collection;
44
- char problem;
45
- GEOSGeometry* igeom;
46
- GEOSGeometry* jgeom;
47
+ int state = 0;
47
48
 
48
49
  result = Qnil;
49
50
  Check_Type(array, T_ARRAY);
50
51
  len = (unsigned int)RARRAY_LEN(array);
51
52
  geoms = ALLOC_N(GEOSGeometry*, len == 0 ? 1 : len);
52
- if (geoms) {
53
- factory_data = RGEO_FACTORY_DATA_PTR(factory);
54
- geos_context = factory_data->geos_context;
55
- klasses = Qnil;
56
- cast_type = Qnil;
57
- switch (type) {
53
+ if (!geoms) { rb_raise(rb_eRGeoError, "not enough memory available"); }
54
+
55
+ factory_data = RGEO_FACTORY_DATA_PTR(factory);
56
+ geos_context = factory_data->geos_context;
57
+ klasses = Qnil;
58
+ cast_type = Qnil;
59
+ switch (type) {
58
60
  case GEOS_MULTIPOINT:
59
- cast_type = factory_data->globals->feature_point;
61
+ cast_type = rgeo_feature_point_module;
60
62
  break;
61
63
  case GEOS_MULTILINESTRING:
62
- cast_type = factory_data->globals->feature_line_string;
64
+ cast_type = rgeo_feature_line_string_module;
63
65
  break;
64
66
  case GEOS_MULTIPOLYGON:
65
- cast_type = factory_data->globals->feature_polygon;
67
+ cast_type = rgeo_feature_polygon_module;
68
+ break;
69
+ }
70
+ for (i=0; i<len; ++i) {
71
+ geom = rgeo_convert_to_detached_geos_geometry(rb_ary_entry(array, i), factory, cast_type, &klass, &state);
72
+ if (state || !geom) {
66
73
  break;
67
74
  }
68
- for (i=0; i<len; ++i) {
69
- geom = rgeo_convert_to_detached_geos_geometry(rb_ary_entry(array, i), factory, cast_type, &klass);
70
- if (!geom) {
71
- break;
72
- }
73
- geoms[i] = geom;
74
- if (!NIL_P(klass) && NIL_P(klasses)) {
75
- klasses = rb_ary_new2(len);
76
- for (j=0; j<i; ++j) {
77
- rb_ary_push(klasses, Qnil);
78
- }
79
- }
80
- if (!NIL_P(klasses)) {
81
- rb_ary_push(klasses, klass);
82
- }
83
- }
84
- if (i != len) {
75
+ geoms[i] = geom;
76
+ if (!NIL_P(klass) && NIL_P(klasses)) {
77
+ klasses = rb_ary_new2(len);
85
78
  for (j=0; j<i; ++j) {
86
- GEOSGeom_destroy_r(geos_context, geoms[j]);
79
+ rb_ary_push(klasses, Qnil);
87
80
  }
88
81
  }
89
- else {
90
- collection = GEOSGeom_createCollection_r(geos_context, type, geoms, len);
91
- // Due to a limitation of GEOS, the MultiPolygon assertions are not checked.
92
- // We do that manually here.
93
- if (collection && type == GEOS_MULTIPOLYGON && (factory_data->flags & 1) == 0) {
94
- problem = 0;
95
- for (i=1; i<len; ++i) {
96
- for (j=0; j<i; ++j) {
97
- igeom = geoms[i];
98
- jgeom = geoms[j];
99
- problem = GEOSRelatePattern_r(geos_context, igeom, jgeom, "2********");
100
- if (problem) {
101
- break;
102
- }
103
- problem = GEOSRelatePattern_r(geos_context, igeom, jgeom, "****1****");
104
- if (problem) {
105
- break;
106
- }
107
- }
108
- if (problem) {
109
- break;
110
- }
111
- }
112
- if (problem) {
113
- GEOSGeom_destroy_r(geos_context, collection);
114
- collection = NULL;
115
- }
116
- }
117
- if (collection) {
118
- result = rgeo_wrap_geos_geometry(factory, collection, module);
119
- RGEO_GEOMETRY_DATA_PTR(result)->klasses = klasses;
120
- }
121
- // NOTE: We are assuming that GEOS will do its own cleanup of the
122
- // element geometries if it fails to create the collection, so we
123
- // are not doing that ourselves. If that turns out not to be the
124
- // case, this will be a memory leak.
82
+ if (!NIL_P(klasses)) {
83
+ rb_ary_push(klasses, klass);
84
+ }
85
+ }
86
+ if (i != len) {
87
+ for (j=0; j<i; ++j) {
88
+ GEOSGeom_destroy_r(geos_context, geoms[j]);
89
+ }
90
+ }
91
+ else {
92
+ collection = GEOSGeom_createCollection_r(geos_context, type, geoms, len);
93
+ if (collection) {
94
+ result = rgeo_wrap_geos_geometry(factory, collection, module);
95
+ RGEO_GEOMETRY_DATA_PTR(result)->klasses = klasses;
125
96
  }
126
- free(geoms);
97
+ // NOTE: We are assuming that GEOS will do its own cleanup of the
98
+ // element geometries if it fails to create the collection, so we
99
+ // are not doing that ourselves. If that turns out not to be the
100
+ // case, this will be a memory leak.
101
+ }
102
+ FREE(geoms);
103
+ if (state) {
104
+ rb_exc_raise(rb_errinfo()); // raise $!
127
105
  }
128
106
 
129
107
  return result;
130
108
  }
131
109
 
132
-
133
110
  /**** RUBY METHOD DEFINITIONS ****/
134
111
 
135
112
 
@@ -141,7 +118,7 @@ static VALUE method_geometry_collection_eql(VALUE self, VALUE rhs)
141
118
  result = rgeo_geos_klasses_and_factories_eql(self, rhs);
142
119
  if (RTEST(result)) {
143
120
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
144
- result = rgeo_geos_geometry_collections_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom, RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
121
+ result = rgeo_geos_geometries_strict_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom);
145
122
  }
146
123
  return result;
147
124
  }
@@ -156,8 +133,7 @@ static VALUE method_geometry_collection_hash(VALUE self)
156
133
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
157
134
  factory = self_data->factory;
158
135
  hash = rb_hash_start(0);
159
- hash = rgeo_geos_objbase_hash(factory,
160
- RGEO_FACTORY_DATA_PTR(factory)->globals->feature_geometry_collection, hash);
136
+ hash = rgeo_geos_objbase_hash(factory, rgeo_feature_geometry_collection_module, hash);
161
137
  hash = rgeo_geos_geometry_collection_hash(self_data->geos_context, self_data->geom, hash);
162
138
  return LONG2FIX(rb_hash_end(hash));
163
139
  }
@@ -171,7 +147,7 @@ static VALUE method_geometry_collection_geometry_type(VALUE self)
171
147
  result = Qnil;
172
148
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
173
149
  if (self_data->geom) {
174
- result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_geometry_collection;
150
+ result = rgeo_feature_geometry_collection_module;
175
151
  }
176
152
  return result;
177
153
  }
@@ -239,6 +215,8 @@ static VALUE method_geometry_collection_brackets(VALUE self, VALUE n)
239
215
 
240
216
  static VALUE method_geometry_collection_each(VALUE self)
241
217
  {
218
+ RETURN_ENUMERATOR(self, 0, 0); /* return enum_for(__callee__) unless block_given? */
219
+
242
220
  RGeo_GeometryData* self_data;
243
221
  const GEOSGeometry* self_geom;
244
222
  int len;
@@ -249,27 +227,22 @@ static VALUE method_geometry_collection_each(VALUE self)
249
227
 
250
228
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
251
229
 
252
- if (rb_block_given_p()) {
253
- self_geom = self_data->geom;
254
- if (self_geom) {
255
- GEOSContextHandle_t self_context = self_data->geos_context;
256
- len = GEOSGetNumGeometries_r(self_context, self_geom);
257
- if (len > 0) {
258
- klasses = self_data->klasses;
259
- for (i=0; i<len; ++i) {
260
- elem_geom = GEOSGetGeometryN_r(self_context, self_geom, i);
261
- elem = rgeo_wrap_geos_geometry_clone(self_data->factory, elem_geom, NIL_P(klasses) ? Qnil : rb_ary_entry(klasses, i));
262
- if (!NIL_P(elem)) {
263
- rb_yield(elem);
264
- }
230
+ self_geom = self_data->geom;
231
+ if (self_geom) {
232
+ GEOSContextHandle_t self_context = self_data->geos_context;
233
+ len = GEOSGetNumGeometries_r(self_context, self_geom);
234
+ if (len > 0) {
235
+ klasses = self_data->klasses;
236
+ for (i=0; i<len; ++i) {
237
+ elem_geom = GEOSGetGeometryN_r(self_context, self_geom, i);
238
+ elem = rgeo_wrap_geos_geometry_clone(self_data->factory, elem_geom, NIL_P(klasses) ? Qnil : rb_ary_entry(klasses, i));
239
+ if (!NIL_P(elem)) {
240
+ rb_yield(elem);
265
241
  }
266
242
  }
267
243
  }
268
- return self;
269
- }
270
- else {
271
- return rb_funcall(self, RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->id_enum_for, 0);
272
244
  }
245
+ return self;
273
246
  }
274
247
 
275
248
  static VALUE method_multi_point_geometry_type(VALUE self)
@@ -280,7 +253,7 @@ static VALUE method_multi_point_geometry_type(VALUE self)
280
253
  result = Qnil;
281
254
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
282
255
  if (self_data->geom) {
283
- result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_multi_point;
256
+ result = rgeo_feature_multi_point_module;
284
257
  }
285
258
  return result;
286
259
  }
@@ -295,8 +268,7 @@ static VALUE method_multi_point_hash(VALUE self)
295
268
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
296
269
  factory = self_data->factory;
297
270
  hash = rb_hash_start(0);
298
- hash = rgeo_geos_objbase_hash(factory,
299
- RGEO_FACTORY_DATA_PTR(factory)->globals->feature_multi_point, hash);
271
+ hash = rgeo_geos_objbase_hash(factory, rgeo_feature_multi_point_module, hash);
300
272
  hash = rgeo_geos_geometry_collection_hash(self_data->geos_context, self_data->geom, hash);
301
273
  return LONG2FIX(rb_hash_end(hash));
302
274
  }
@@ -342,7 +314,7 @@ static VALUE method_multi_line_string_geometry_type(VALUE self)
342
314
  result = Qnil;
343
315
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
344
316
  if (self_data->geom) {
345
- result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_multi_line_string;
317
+ result = rgeo_feature_multi_line_string_module;
346
318
  }
347
319
  return result;
348
320
  }
@@ -357,8 +329,7 @@ static VALUE method_multi_line_string_hash(VALUE self)
357
329
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
358
330
  factory = self_data->factory;
359
331
  hash = rb_hash_start(0);
360
- hash = rgeo_geos_objbase_hash(factory,
361
- RGEO_FACTORY_DATA_PTR(factory)->globals->feature_multi_line_string, hash);
332
+ hash = rgeo_geos_objbase_hash(factory, rgeo_feature_multi_line_string_module, hash);
362
333
  hash = rgeo_geos_geometry_collection_hash(self_data->geos_context, self_data->geom, hash);
363
334
  return LONG2FIX(rb_hash_end(hash));
364
335
  }
@@ -396,7 +367,7 @@ static VALUE method_multi_line_string_coordinates(VALUE self)
396
367
 
397
368
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
398
369
  self_geom = self_data->geom;
399
-
370
+
400
371
  if(self_geom) {
401
372
  zCoordinate = RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M;
402
373
  context = self_data->geos_context;
@@ -472,7 +443,7 @@ static VALUE method_multi_polygon_geometry_type(VALUE self)
472
443
  result = Qnil;
473
444
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
474
445
  if (self_data->geom) {
475
- result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_multi_polygon;
446
+ result = rgeo_feature_multi_polygon_module;
476
447
  }
477
448
  return result;
478
449
  }
@@ -487,8 +458,7 @@ static VALUE method_multi_polygon_hash(VALUE self)
487
458
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
488
459
  factory = self_data->factory;
489
460
  hash = rb_hash_start(0);
490
- hash = rgeo_geos_objbase_hash(factory,
491
- RGEO_FACTORY_DATA_PTR(factory)->globals->feature_multi_polygon, hash);
461
+ hash = rgeo_geos_objbase_hash(factory, rgeo_feature_multi_polygon_module, hash);
492
462
  hash = rgeo_geos_geometry_collection_hash(self_data->geos_context, self_data->geom, hash);
493
463
  return LONG2FIX(rb_hash_end(hash));
494
464
  }
@@ -508,7 +478,7 @@ static VALUE method_multi_polygon_coordinates(VALUE self)
508
478
 
509
479
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
510
480
  self_geom = self_data->geom;
511
-
481
+
512
482
  if(self_geom) {
513
483
  zCoordinate = RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M;
514
484
  context = self_data->geos_context;
@@ -586,7 +556,7 @@ static VALUE cmethod_multi_polygon_create(VALUE module, VALUE factory, VALUE arr
586
556
  /**** INITIALIZATION FUNCTION ****/
587
557
 
588
558
 
589
- void rgeo_init_geos_geometry_collection(RGeo_Globals* globals)
559
+ void rgeo_init_geos_geometry_collection()
590
560
  {
591
561
  VALUE geos_geometry_collection_methods;
592
562
  VALUE geos_multi_point_methods;
@@ -594,13 +564,13 @@ void rgeo_init_geos_geometry_collection(RGeo_Globals* globals)
594
564
  VALUE geos_multi_polygon_methods;
595
565
 
596
566
  // Class methods for geometry collection classes
597
- rb_define_module_function(globals->geos_geometry_collection, "create", cmethod_geometry_collection_create, 2);
598
- rb_define_module_function(globals->geos_multi_point, "create", cmethod_multi_point_create, 2);
599
- rb_define_module_function(globals->geos_multi_line_string, "create", cmethod_multi_line_string_create, 2);
600
- rb_define_module_function(globals->geos_multi_polygon, "create", cmethod_multi_polygon_create, 2);
567
+ rb_define_module_function(rgeo_geos_geometry_collection_class, "create", cmethod_geometry_collection_create, 2);
568
+ rb_define_module_function(rgeo_geos_multi_point_class, "create", cmethod_multi_point_create, 2);
569
+ rb_define_module_function(rgeo_geos_multi_line_string_class, "create", cmethod_multi_line_string_create, 2);
570
+ rb_define_module_function(rgeo_geos_multi_polygon_class, "create", cmethod_multi_polygon_create, 2);
601
571
 
602
572
  // Methods for GeometryCollectionImpl
603
- geos_geometry_collection_methods = rb_define_module_under(globals->geos_module, "CAPIGeometryCollectionMethods");
573
+ geos_geometry_collection_methods = rb_define_module_under(rgeo_geos_module, "CAPIGeometryCollectionMethods");
604
574
  rb_define_method(geos_geometry_collection_methods, "rep_equals?", method_geometry_collection_eql, 1);
605
575
  rb_define_method(geos_geometry_collection_methods, "eql?", method_geometry_collection_eql, 1);
606
576
  rb_define_method(geos_geometry_collection_methods, "hash", method_geometry_collection_hash, 0);
@@ -614,13 +584,13 @@ void rgeo_init_geos_geometry_collection(RGeo_Globals* globals)
614
584
 
615
585
 
616
586
  // Methods for MultiPointImpl
617
- geos_multi_point_methods = rb_define_module_under(globals->geos_module, "CAPIMultiPointMethods");
587
+ geos_multi_point_methods = rb_define_module_under(rgeo_geos_module, "CAPIMultiPointMethods");
618
588
  rb_define_method(geos_multi_point_methods, "geometry_type", method_multi_point_geometry_type, 0);
619
589
  rb_define_method(geos_multi_point_methods, "hash", method_multi_point_hash, 0);
620
590
  rb_define_method(geos_multi_point_methods, "coordinates", method_multi_point_coordinates, 0);
621
591
 
622
592
  // Methods for MultiLineStringImpl
623
- geos_multi_line_string_methods = rb_define_module_under(globals->geos_module, "CAPIMultiLineStringMethods");
593
+ geos_multi_line_string_methods = rb_define_module_under(rgeo_geos_module, "CAPIMultiLineStringMethods");
624
594
  rb_define_method(geos_multi_line_string_methods, "geometry_type", method_multi_line_string_geometry_type, 0);
625
595
  rb_define_method(geos_multi_line_string_methods, "length", method_multi_line_string_length, 0);
626
596
  rb_define_method(geos_multi_line_string_methods, "closed?", method_multi_line_string_is_closed, 0);
@@ -628,7 +598,7 @@ void rgeo_init_geos_geometry_collection(RGeo_Globals* globals)
628
598
  rb_define_method(geos_multi_line_string_methods, "coordinates", method_multi_line_string_coordinates, 0);
629
599
 
630
600
  // Methods for MultiPolygonImpl
631
- geos_multi_polygon_methods = rb_define_module_under(globals->geos_module, "CAPIMultiPolygonMethods");
601
+ geos_multi_polygon_methods = rb_define_module_under(rgeo_geos_module, "CAPIMultiPolygonMethods");
632
602
  rb_define_method(geos_multi_polygon_methods, "geometry_type", method_multi_polygon_geometry_type, 0);
633
603
  rb_define_method(geos_multi_polygon_methods, "area", method_multi_polygon_area, 0);
634
604
  rb_define_method(geos_multi_polygon_methods, "centroid", method_multi_polygon_centroid, 0);
@@ -640,80 +610,6 @@ void rgeo_init_geos_geometry_collection(RGeo_Globals* globals)
640
610
  /**** OTHER PUBLIC FUNCTIONS ****/
641
611
 
642
612
 
643
- VALUE rgeo_geos_geometry_collections_eql(GEOSContextHandle_t context, const GEOSGeometry* geom1, const GEOSGeometry* geom2, char check_z)
644
- {
645
- VALUE result;
646
- int len1;
647
- int len2;
648
- int i;
649
- const GEOSGeometry* sub_geom1;
650
- const GEOSGeometry* sub_geom2;
651
- int type1;
652
- int type2;
653
-
654
- result = Qnil;
655
- if (geom1 && geom2) {
656
- len1 = GEOSGetNumGeometries_r(context, geom1);
657
- len2 = GEOSGetNumGeometries_r(context, geom2);
658
- if (len1 >= 0 && len2 >= 0) {
659
- if (len1 == len2) {
660
- result = Qtrue;
661
- for (i=0; i<len1; ++i) {
662
- sub_geom1 = GEOSGetGeometryN_r(context, geom1, i);
663
- sub_geom2 = GEOSGetGeometryN_r(context, geom2, i);
664
- if (sub_geom1 && sub_geom2) {
665
- type1 = GEOSGeomTypeId_r(context, sub_geom1);
666
- type2 = GEOSGeomTypeId_r(context, sub_geom2);
667
- if (type1 >= 0 && type2 >= 0) {
668
- if (type1 == type2) {
669
- switch (type1) {
670
- case GEOS_POINT:
671
- case GEOS_LINESTRING:
672
- case GEOS_LINEARRING:
673
- result = rgeo_geos_coordseqs_eql(context, sub_geom1, sub_geom2, check_z);
674
- break;
675
- case GEOS_POLYGON:
676
- result = rgeo_geos_polygons_eql(context, sub_geom1, sub_geom2, check_z);
677
- break;
678
- case GEOS_GEOMETRYCOLLECTION:
679
- case GEOS_MULTIPOINT:
680
- case GEOS_MULTILINESTRING:
681
- case GEOS_MULTIPOLYGON:
682
- result = rgeo_geos_geometry_collections_eql(context, sub_geom1, sub_geom2, check_z);
683
- break;
684
- default:
685
- result = Qnil;
686
- break;
687
- }
688
- if (!RTEST(result)) {
689
- break;
690
- }
691
- }
692
- else {
693
- result = Qfalse;
694
- break;
695
- }
696
- }
697
- else {
698
- result = Qnil;
699
- break;
700
- }
701
- }
702
- else {
703
- result = Qnil;
704
- break;
705
- }
706
- }
707
- }
708
- else {
709
- result = Qfalse;
710
- }
711
- }
712
- }
713
- return result;
714
- }
715
-
716
-
717
613
  st_index_t rgeo_geos_geometry_collection_hash(GEOSContextHandle_t context, const GEOSGeometry* geom, st_index_t hash)
718
614
  {
719
615
  const GEOSGeometry* sub_geom;
@@ -9,8 +9,6 @@
9
9
  #include <ruby.h>
10
10
  #include <geos_c.h>
11
11
 
12
- #include "factory.h"
13
-
14
12
  RGEO_BEGIN_C
15
13
 
16
14
 
@@ -18,18 +16,7 @@ RGEO_BEGIN_C
18
16
  Initializes the geometry collection module. This should be called after
19
17
  the geometry module is initialized.
20
18
  */
21
- void rgeo_init_geos_geometry_collection(RGeo_Globals* globals);
22
-
23
- /*
24
- Comopares the contents of two geometry collections. Does not test the
25
- types of the collections themselves, but tests the types, values, and
26
- contents of all the contents. The two given geometries MUST be
27
- collection types-- i.e. GeometryCollection, MultiPoint, MultiLineString,
28
- or MultiPolygon.
29
- Returns Qtrue if the contents of the two geometry collections are equal,
30
- Qfalse if they are inequal, or Qnil if an error occurs.
31
- */
32
- VALUE rgeo_geos_geometry_collections_eql(GEOSContextHandle_t context, const GEOSGeometry* geom1, const GEOSGeometry* geom2, char check_z);
19
+ void rgeo_init_geos_geometry_collection();
33
20
 
34
21
  /*
35
22
  A tool for building up hash values.
@@ -0,0 +1,91 @@
1
+ #include "preface.h"
2
+
3
+ #ifdef RGEO_GEOS_SUPPORTED
4
+
5
+ #include <ruby.h>
6
+
7
+ #include "globals.h"
8
+
9
+ RGEO_BEGIN_C
10
+
11
+ VALUE rgeo_module;
12
+
13
+ VALUE rgeo_feature_module;
14
+ VALUE rgeo_feature_geometry_module;
15
+ VALUE rgeo_feature_point_module;
16
+ VALUE rgeo_feature_line_string_module;
17
+ VALUE rgeo_feature_linear_ring_module;
18
+ VALUE rgeo_feature_line_module;
19
+ VALUE rgeo_feature_polygon_module;
20
+ VALUE rgeo_feature_geometry_collection_module;
21
+ VALUE rgeo_feature_multi_point_module;
22
+ VALUE rgeo_feature_multi_line_string_module;
23
+ VALUE rgeo_feature_multi_polygon_module;
24
+
25
+ VALUE rgeo_geos_module;
26
+ VALUE rgeo_geos_geometry_class;
27
+ VALUE rgeo_geos_point_class;
28
+ VALUE rgeo_geos_line_string_class;
29
+ VALUE rgeo_geos_linear_ring_class;
30
+ VALUE rgeo_geos_line_class;
31
+ VALUE rgeo_geos_polygon_class;
32
+ VALUE rgeo_geos_geometry_collection_class;
33
+ VALUE rgeo_geos_multi_point_class;
34
+ VALUE rgeo_geos_multi_line_string_class;
35
+ VALUE rgeo_geos_multi_polygon_class;
36
+
37
+ void rgeo_init_geos_globals()
38
+ {
39
+ rgeo_module = rb_define_module("RGeo");
40
+ rb_gc_register_mark_object(rgeo_module);
41
+
42
+ rgeo_feature_module = rb_define_module_under(rgeo_module, "Feature");
43
+ rb_gc_register_mark_object(rgeo_feature_module);
44
+ rgeo_feature_geometry_module = rb_const_get_at(rgeo_feature_module, rb_intern("Geometry"));
45
+ rb_gc_register_mark_object(rgeo_feature_geometry_module);
46
+ rgeo_feature_point_module = rb_const_get_at(rgeo_feature_module, rb_intern("Point"));
47
+ rb_gc_register_mark_object(rgeo_feature_point_module);
48
+ rgeo_feature_line_string_module = rb_const_get_at(rgeo_feature_module, rb_intern("LineString"));
49
+ rb_gc_register_mark_object(rgeo_feature_line_string_module);
50
+ rgeo_feature_linear_ring_module = rb_const_get_at(rgeo_feature_module, rb_intern("LinearRing"));
51
+ rb_gc_register_mark_object(rgeo_feature_linear_ring_module);
52
+ rgeo_feature_line_module = rb_const_get_at(rgeo_feature_module, rb_intern("Line"));
53
+ rb_gc_register_mark_object(rgeo_feature_line_module);
54
+ rgeo_feature_polygon_module = rb_const_get_at(rgeo_feature_module, rb_intern("Polygon"));
55
+ rb_gc_register_mark_object(rgeo_feature_polygon_module);
56
+ rgeo_feature_geometry_collection_module = rb_const_get_at(rgeo_feature_module, rb_intern("GeometryCollection"));
57
+ rb_gc_register_mark_object(rgeo_feature_geometry_collection_module);
58
+ rgeo_feature_multi_point_module = rb_const_get_at(rgeo_feature_module, rb_intern("MultiPoint"));
59
+ rb_gc_register_mark_object(rgeo_feature_multi_point_module);
60
+ rgeo_feature_multi_line_string_module = rb_const_get_at(rgeo_feature_module, rb_intern("MultiLineString"));
61
+ rb_gc_register_mark_object(rgeo_feature_multi_line_string_module);
62
+ rgeo_feature_multi_polygon_module = rb_const_get_at(rgeo_feature_module, rb_intern("MultiPolygon"));
63
+ rb_gc_register_mark_object(rgeo_feature_multi_polygon_module);
64
+
65
+ rgeo_geos_module = rb_define_module_under(rgeo_module, "Geos");
66
+ rb_gc_register_mark_object(rgeo_geos_module);
67
+ rgeo_geos_geometry_class = rb_define_class_under(rgeo_geos_module, "CAPIGeometryImpl", rb_cObject);
68
+ rb_gc_register_mark_object(rgeo_geos_geometry_class);
69
+ rgeo_geos_point_class = rb_define_class_under(rgeo_geos_module, "CAPIPointImpl", rb_cObject);
70
+ rb_gc_register_mark_object(rgeo_geos_point_class);
71
+ rgeo_geos_line_string_class = rb_define_class_under(rgeo_geos_module, "CAPILineStringImpl", rb_cObject);
72
+ rb_gc_register_mark_object(rgeo_geos_line_string_class);
73
+ rgeo_geos_linear_ring_class = rb_define_class_under(rgeo_geos_module, "CAPILinearRingImpl", rb_cObject);
74
+ rb_gc_register_mark_object(rgeo_geos_linear_ring_class);
75
+ rgeo_geos_line_class = rb_define_class_under(rgeo_geos_module, "CAPILineImpl", rb_cObject);
76
+ rb_gc_register_mark_object(rgeo_geos_line_class);
77
+ rgeo_geos_polygon_class = rb_define_class_under(rgeo_geos_module, "CAPIPolygonImpl", rb_cObject);
78
+ rb_gc_register_mark_object(rgeo_geos_polygon_class);
79
+ rgeo_geos_geometry_collection_class = rb_define_class_under(rgeo_geos_module, "CAPIGeometryCollectionImpl", rb_cObject);
80
+ rb_gc_register_mark_object(rgeo_geos_geometry_collection_class);
81
+ rgeo_geos_multi_point_class = rb_define_class_under(rgeo_geos_module, "CAPIMultiPointImpl", rb_cObject);
82
+ rb_gc_register_mark_object(rgeo_geos_multi_point_class);
83
+ rgeo_geos_multi_line_string_class = rb_define_class_under(rgeo_geos_module, "CAPIMultiLineStringImpl", rb_cObject);
84
+ rb_gc_register_mark_object(rgeo_geos_multi_line_string_class);
85
+ rgeo_geos_multi_polygon_class = rb_define_class_under(rgeo_geos_module, "CAPIMultiPolygonImpl", rb_cObject);
86
+ rb_gc_register_mark_object(rgeo_geos_multi_polygon_class);
87
+ }
88
+
89
+ RGEO_END_C
90
+
91
+ #endif
@@ -0,0 +1,45 @@
1
+ /*
2
+ Per-interpreter globals.
3
+ Most of these are cached references to commonly used classes, modules,
4
+ and symbols so we don't have to do a lot of constant lookups and calls
5
+ to rb_intern.
6
+ */
7
+
8
+ #ifndef RGEO_GEOS_GLOBALS_INCLUDED
9
+ #define RGEO_GEOS_GLOBALS_INCLUDED
10
+
11
+ #include <ruby.h>
12
+
13
+ RGEO_BEGIN_C
14
+
15
+ extern VALUE rgeo_module;
16
+
17
+ extern VALUE rgeo_feature_module;
18
+ extern VALUE rgeo_feature_geometry_module;
19
+ extern VALUE rgeo_feature_point_module;
20
+ extern VALUE rgeo_feature_line_string_module;
21
+ extern VALUE rgeo_feature_linear_ring_module;
22
+ extern VALUE rgeo_feature_line_module;
23
+ extern VALUE rgeo_feature_polygon_module;
24
+ extern VALUE rgeo_feature_geometry_collection_module;
25
+ extern VALUE rgeo_feature_multi_point_module;
26
+ extern VALUE rgeo_feature_multi_line_string_module;
27
+ extern VALUE rgeo_feature_multi_polygon_module;
28
+
29
+ extern VALUE rgeo_geos_module;
30
+ extern VALUE rgeo_geos_geometry_class;
31
+ extern VALUE rgeo_geos_point_class;
32
+ extern VALUE rgeo_geos_line_string_class;
33
+ extern VALUE rgeo_geos_linear_ring_class;
34
+ extern VALUE rgeo_geos_line_class;
35
+ extern VALUE rgeo_geos_polygon_class;
36
+ extern VALUE rgeo_geos_geometry_collection_class;
37
+ extern VALUE rgeo_geos_multi_point_class;
38
+ extern VALUE rgeo_geos_multi_line_string_class;
39
+ extern VALUE rgeo_geos_multi_polygon_class;
40
+
41
+ void rgeo_init_geos_globals();
42
+
43
+ RGEO_END_C
44
+
45
+ #endif