rgeo 2.1.1 → 2.4.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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +160 -0
  3. data/ext/geos_c_impl/analysis.c +80 -0
  4. data/ext/geos_c_impl/analysis.h +40 -0
  5. data/ext/geos_c_impl/errors.c +35 -0
  6. data/ext/geos_c_impl/errors.h +22 -0
  7. data/ext/geos_c_impl/extconf.rb +2 -0
  8. data/ext/geos_c_impl/factory.c +179 -174
  9. data/ext/geos_c_impl/factory.h +20 -49
  10. data/ext/geos_c_impl/geometry.c +17 -16
  11. data/ext/geos_c_impl/geometry.h +1 -3
  12. data/ext/geos_c_impl/geometry_collection.c +39 -44
  13. data/ext/geos_c_impl/geometry_collection.h +1 -3
  14. data/ext/geos_c_impl/globals.c +91 -0
  15. data/ext/geos_c_impl/globals.h +45 -0
  16. data/ext/geos_c_impl/line_string.c +27 -28
  17. data/ext/geos_c_impl/line_string.h +1 -3
  18. data/ext/geos_c_impl/main.c +14 -10
  19. data/ext/geos_c_impl/point.c +8 -7
  20. data/ext/geos_c_impl/point.h +1 -3
  21. data/ext/geos_c_impl/polygon.c +14 -14
  22. data/ext/geos_c_impl/polygon.h +1 -3
  23. data/ext/geos_c_impl/preface.h +8 -0
  24. data/lib/rgeo/cartesian/analysis.rb +22 -0
  25. data/lib/rgeo/cartesian/feature_methods.rb +6 -1
  26. data/lib/rgeo/cartesian.rb +7 -7
  27. data/lib/rgeo/coord_sys.rb +6 -6
  28. data/lib/rgeo/error.rb +4 -0
  29. data/lib/rgeo/feature/curve.rb +12 -2
  30. data/lib/rgeo/feature/geometry.rb +12 -2
  31. data/lib/rgeo/feature/linear_ring.rb +10 -0
  32. data/lib/rgeo/feature/multi_curve.rb +6 -1
  33. data/lib/rgeo/feature.rb +17 -17
  34. data/lib/rgeo/geographic/interface.rb +2 -1
  35. data/lib/rgeo/geographic/projected_feature_methods.rb +12 -2
  36. data/lib/rgeo/geographic/spherical_feature_classes.rb +1 -0
  37. data/lib/rgeo/geographic/spherical_feature_methods.rb +29 -1
  38. data/lib/rgeo/geographic.rb +10 -10
  39. data/lib/rgeo/geos/capi_factory.rb +3 -3
  40. data/lib/rgeo/geos/capi_feature_classes.rb +33 -0
  41. data/lib/rgeo/geos/ffi_feature_methods.rb +34 -5
  42. data/lib/rgeo/geos/interface.rb +18 -4
  43. data/lib/rgeo/geos/zm_feature_methods.rb +30 -5
  44. data/lib/rgeo/geos.rb +11 -11
  45. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +33 -5
  46. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +62 -8
  47. data/lib/rgeo/impl_helper/basic_point_methods.rb +12 -2
  48. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +44 -2
  49. data/lib/rgeo/impl_helper.rb +7 -7
  50. data/lib/rgeo/version.rb +1 -1
  51. data/lib/rgeo/wkrep/wkb_generator.rb +1 -1
  52. data/lib/rgeo/wkrep/wkt_generator.rb +6 -6
  53. data/lib/rgeo/wkrep.rb +4 -4
  54. data/lib/rgeo.rb +9 -9
  55. metadata +26 -14
@@ -11,6 +11,8 @@
11
11
  #include <ruby.h>
12
12
  #include <geos_c.h>
13
13
 
14
+ #include "globals.h"
15
+
14
16
  #include "factory.h"
15
17
  #include "geometry.h"
16
18
  #include "point.h"
@@ -29,7 +31,7 @@ static VALUE method_line_string_geometry_type(VALUE self)
29
31
  result = Qnil;
30
32
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
31
33
  if (self_data->geom) {
32
- result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_line_string;
34
+ result = rgeo_feature_line_string_module;
33
35
  }
34
36
  return result;
35
37
  }
@@ -43,7 +45,7 @@ static VALUE method_linear_ring_geometry_type(VALUE self)
43
45
  result = Qnil;
44
46
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
45
47
  if (self_data->geom) {
46
- result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_linear_ring;
48
+ result = rgeo_feature_linear_ring_module;
47
49
  }
48
50
  return result;
49
51
  }
@@ -57,7 +59,7 @@ static VALUE method_line_geometry_type(VALUE self)
57
59
  result = Qnil;
58
60
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
59
61
  if (self_data->geom) {
60
- result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_line;
62
+ result = rgeo_feature_line_module;
61
63
  }
62
64
  return result;
63
65
  }
@@ -264,7 +266,7 @@ static VALUE method_line_string_project_point(VALUE self, VALUE point)
264
266
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
265
267
 
266
268
  if(self_geom && point) {
267
- geos_point = rgeo_convert_to_geos_geometry(factory, point, factory_data->globals->geos_point);
269
+ geos_point = rgeo_convert_to_geos_geometry(factory, point, rgeo_geos_point_class);
268
270
  location = GEOSProject_r(self_data->geos_context, self_geom, geos_point);
269
271
  result = DBL2NUM(location);
270
272
  }
@@ -290,7 +292,7 @@ static VALUE method_line_string_interpolate_point(VALUE self, VALUE loc_num)
290
292
 
291
293
  if(self_geom) {
292
294
  geos_point = GEOSInterpolate_r(self_data->geos_context, self_geom, location);
293
- result = rgeo_wrap_geos_geometry(factory, geos_point, factory_data->globals->geos_point);
295
+ result = rgeo_wrap_geos_geometry(factory, geos_point, rgeo_geos_point_class);
294
296
  }
295
297
 
296
298
  return result;
@@ -358,8 +360,7 @@ static VALUE method_line_string_hash(VALUE self)
358
360
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
359
361
  factory = self_data->factory;
360
362
  hash = rb_hash_start(0);
361
- hash = rgeo_geos_objbase_hash(factory,
362
- RGEO_FACTORY_DATA_PTR(factory)->globals->feature_line_string, hash);
363
+ hash = rgeo_geos_objbase_hash(factory, rgeo_feature_line_string_module, hash);
363
364
  hash = rgeo_geos_coordseq_hash(self_data->geos_context, self_data->geom, hash);
364
365
  return LONG2FIX(rb_hash_end(hash));
365
366
  }
@@ -374,8 +375,7 @@ static VALUE method_linear_ring_hash(VALUE self)
374
375
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
375
376
  factory = self_data->factory;
376
377
  hash = rb_hash_start(0);
377
- hash = rgeo_geos_objbase_hash(factory,
378
- RGEO_FACTORY_DATA_PTR(factory)->globals->feature_linear_ring, hash);
378
+ hash = rgeo_geos_objbase_hash(factory, rgeo_feature_linear_ring_module, hash);
379
379
  hash = rgeo_geos_coordseq_hash(self_data->geos_context, self_data->geom, hash);
380
380
  return LONG2FIX(rb_hash_end(hash));
381
381
  }
@@ -390,8 +390,7 @@ static VALUE method_line_hash(VALUE self)
390
390
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
391
391
  factory = self_data->factory;
392
392
  hash = rb_hash_start(0);
393
- hash = rgeo_geos_objbase_hash(factory,
394
- RGEO_FACTORY_DATA_PTR(factory)->globals->feature_line, hash);
393
+ hash = rgeo_geos_objbase_hash(factory, rgeo_feature_line_module, hash);
395
394
  hash = rgeo_geos_coordseq_hash(self_data->geos_context, self_data->geom, hash);
396
395
  return LONG2FIX(rb_hash_end(hash));
397
396
  }
@@ -415,7 +414,7 @@ static GEOSCoordSequence* coord_seq_from_array(VALUE factory, VALUE array, char
415
414
 
416
415
  Check_Type(array, T_ARRAY);
417
416
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
418
- point_type = factory_data->globals->feature_point;
417
+ point_type = rgeo_feature_point_module;
419
418
  len = (unsigned int)RARRAY_LEN(array);
420
419
  has_z = (char)(RGEO_FACTORY_DATA_PTR(factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
421
420
  dims = has_z ? 3 : 2;
@@ -491,7 +490,7 @@ static VALUE cmethod_create_line_string(VALUE module, VALUE factory, VALUE array
491
490
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
492
491
  geom = GEOSGeom_createLineString_r(factory_data->geos_context, coord_seq);
493
492
  if (geom) {
494
- result = rgeo_wrap_geos_geometry(factory, geom, factory_data->globals->geos_line_string);
493
+ result = rgeo_wrap_geos_geometry(factory, geom, rgeo_geos_line_string_class);
495
494
  }
496
495
  }
497
496
  return result;
@@ -511,7 +510,7 @@ static VALUE cmethod_create_linear_ring(VALUE module, VALUE factory, VALUE array
511
510
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
512
511
  geom = GEOSGeom_createLinearRing_r(factory_data->geos_context, coord_seq);
513
512
  if (geom) {
514
- result = rgeo_wrap_geos_geometry(factory, geom, factory_data->globals->geos_linear_ring);
513
+ result = rgeo_wrap_geos_geometry(factory, geom, rgeo_geos_linear_ring_class);
515
514
  }
516
515
  }
517
516
  return result;
@@ -557,7 +556,7 @@ static VALUE cmethod_create_line(VALUE module, VALUE factory, VALUE start, VALUE
557
556
  result = Qnil;
558
557
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
559
558
  has_z = (char)(factory_data->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
560
- point_type = factory_data->globals->feature_point;
559
+ point_type = rgeo_feature_point_module;
561
560
  context = factory_data->geos_context;
562
561
 
563
562
  start_geom = rgeo_convert_to_geos_geometry(factory, start, point_type);
@@ -570,7 +569,7 @@ static VALUE cmethod_create_line(VALUE module, VALUE factory, VALUE start, VALUE
570
569
  populate_geom_into_coord_seq(context, end_geom, coord_seq, 1, has_z);
571
570
  geom = GEOSGeom_createLineString_r(context, coord_seq);
572
571
  if (geom) {
573
- result = rgeo_wrap_geos_geometry(factory, geom, factory_data->globals->geos_line);
572
+ result = rgeo_wrap_geos_geometry(factory, geom, rgeo_geos_line_class);
574
573
  }
575
574
  }
576
575
  }
@@ -631,26 +630,26 @@ static VALUE cmethod_linear_ring_copy_from(VALUE klass, VALUE factory, VALUE ori
631
630
  }
632
631
 
633
632
 
634
- void rgeo_init_geos_line_string(RGeo_Globals* globals)
633
+ void rgeo_init_geos_line_string()
635
634
  {
636
635
  VALUE geos_line_string_methods;
637
636
  VALUE geos_linear_ring_methods;
638
637
  VALUE geos_line_methods;
639
638
 
640
639
  // Class methods for CAPILineStringImpl
641
- rb_define_module_function(globals->geos_line_string, "create", cmethod_create_line_string, 2);
642
- rb_define_module_function(globals->geos_line_string, "_copy_from", cmethod_line_string_copy_from, 2);
640
+ rb_define_module_function(rgeo_geos_line_string_class, "create", cmethod_create_line_string, 2);
641
+ rb_define_module_function(rgeo_geos_line_string_class, "_copy_from", cmethod_line_string_copy_from, 2);
643
642
 
644
643
  // Class methods for CAPILinearRingImpl
645
- rb_define_module_function(globals->geos_linear_ring, "create", cmethod_create_linear_ring, 2);
646
- rb_define_module_function(globals->geos_linear_ring, "_copy_from", cmethod_linear_ring_copy_from, 2);
644
+ rb_define_module_function(rgeo_geos_linear_ring_class, "create", cmethod_create_linear_ring, 2);
645
+ rb_define_module_function(rgeo_geos_linear_ring_class, "_copy_from", cmethod_linear_ring_copy_from, 2);
647
646
 
648
647
  // Class methods for CAPILineImpl
649
- rb_define_module_function(globals->geos_line, "create", cmethod_create_line, 3);
650
- rb_define_module_function(globals->geos_line, "_copy_from", cmethod_line_copy_from, 2);
648
+ rb_define_module_function(rgeo_geos_line_class, "create", cmethod_create_line, 3);
649
+ rb_define_module_function(rgeo_geos_line_class, "_copy_from", cmethod_line_copy_from, 2);
651
650
 
652
651
  // CAPILineStringMethods module
653
- geos_line_string_methods = rb_define_module_under(globals->geos_module, "CAPILineStringMethods");
652
+ geos_line_string_methods = rb_define_module_under(rgeo_geos_module, "CAPILineStringMethods");
654
653
  rb_define_method(geos_line_string_methods, "rep_equals?", method_line_string_eql, 1);
655
654
  rb_define_method(geos_line_string_methods, "eql?", method_line_string_eql, 1);
656
655
  rb_define_method(geos_line_string_methods, "hash", method_line_string_hash, 0);
@@ -663,17 +662,17 @@ void rgeo_init_geos_line_string(RGeo_Globals* globals)
663
662
  rb_define_method(geos_line_string_methods, "end_point", method_line_string_end_point, 0);
664
663
  rb_define_method(geos_line_string_methods, "project_point", method_line_string_project_point, 1);
665
664
  rb_define_method(geos_line_string_methods, "interpolate_point", method_line_string_interpolate_point, 1);
666
- rb_define_method(geos_line_string_methods, "is_closed?", method_line_string_is_closed, 0);
667
- rb_define_method(geos_line_string_methods, "is_ring?", method_line_string_is_ring, 0);
665
+ rb_define_method(geos_line_string_methods, "closed?", method_line_string_is_closed, 0);
666
+ rb_define_method(geos_line_string_methods, "ring?", method_line_string_is_ring, 0);
668
667
  rb_define_method(geos_line_string_methods, "coordinates", method_line_string_coordinates, 0);
669
668
 
670
669
  // CAPILinearRingMethods module
671
- geos_linear_ring_methods = rb_define_module_under(globals->geos_module, "CAPILinearRingMethods");
670
+ geos_linear_ring_methods = rb_define_module_under(rgeo_geos_module, "CAPILinearRingMethods");
672
671
  rb_define_method(geos_linear_ring_methods, "geometry_type", method_linear_ring_geometry_type, 0);
673
672
  rb_define_method(geos_linear_ring_methods, "hash", method_linear_ring_hash, 0);
674
673
 
675
674
  // CAPILineMethods module
676
- geos_line_methods = rb_define_module_under(globals->geos_module, "CAPILineMethods");
675
+ geos_line_methods = rb_define_module_under(rgeo_geos_module, "CAPILineMethods");
677
676
  rb_define_method(geos_line_methods, "geometry_type", method_line_geometry_type, 0);
678
677
  rb_define_method(geos_line_methods, "hash", method_line_hash, 0);
679
678
  }
@@ -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,7 +16,7 @@ RGEO_BEGIN_C
18
16
  Initializes the line string module. This should be called after
19
17
  the geometry module is initialized.
20
18
  */
21
- void rgeo_init_geos_line_string(RGeo_Globals* globals);
19
+ void rgeo_init_geos_line_string();
22
20
 
23
21
  /*
24
22
  Determines whether the given GEOS line string is closed.
@@ -2,7 +2,6 @@
2
2
  Main initializer for GEOS wrapper
3
3
  */
4
4
 
5
-
6
5
  #include "preface.h"
7
6
 
8
7
  #ifdef RGEO_GEOS_SUPPORTED
@@ -10,29 +9,34 @@
10
9
  #include <ruby.h>
11
10
  #include <geos_c.h>
12
11
 
12
+ #include "globals.h"
13
+
14
+ #include "errors.h"
15
+
13
16
  #include "factory.h"
14
17
  #include "geometry.h"
15
18
  #include "point.h"
16
19
  #include "line_string.h"
17
20
  #include "polygon.h"
18
21
  #include "geometry_collection.h"
22
+ #include "analysis.h"
19
23
 
20
24
  #endif
21
25
 
22
26
  RGEO_BEGIN_C
23
27
 
24
-
25
28
  void Init_geos_c_impl()
26
29
  {
27
30
  #ifdef RGEO_GEOS_SUPPORTED
28
- RGeo_Globals* globals;
29
-
30
- globals = rgeo_init_geos_factory();
31
- rgeo_init_geos_geometry(globals);
32
- rgeo_init_geos_point(globals);
33
- rgeo_init_geos_line_string(globals);
34
- rgeo_init_geos_polygon(globals);
35
- rgeo_init_geos_geometry_collection(globals);
31
+ rgeo_init_geos_globals();
32
+ rgeo_init_geos_factory();
33
+ rgeo_init_geos_geometry();
34
+ rgeo_init_geos_point();
35
+ rgeo_init_geos_line_string();
36
+ rgeo_init_geos_polygon();
37
+ rgeo_init_geos_geometry_collection();
38
+ rgeo_init_geos_analysis();
39
+ rgeo_init_geos_errors();
36
40
  #endif
37
41
  }
38
42
 
@@ -9,6 +9,8 @@
9
9
  #include <ruby.h>
10
10
  #include <geos_c.h>
11
11
 
12
+ #include "globals.h"
13
+
12
14
  #include "factory.h"
13
15
  #include "geometry.h"
14
16
  #include "point.h"
@@ -26,7 +28,7 @@ static VALUE method_point_geometry_type(VALUE self)
26
28
  result = Qnil;
27
29
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
28
30
  if (self_data->geom) {
29
- result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_point;
31
+ result = rgeo_feature_point_module;
30
32
  }
31
33
  return result;
32
34
  }
@@ -168,8 +170,7 @@ static VALUE method_point_hash(VALUE self)
168
170
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
169
171
  factory = self_data->factory;
170
172
  hash = rb_hash_start(0);
171
- hash = rgeo_geos_objbase_hash(factory,
172
- RGEO_FACTORY_DATA_PTR(factory)->globals->feature_point, hash);
173
+ hash = rgeo_geos_objbase_hash(factory, rgeo_feature_point_module, hash);
173
174
  hash = rgeo_geos_coordseq_hash(self_data->geos_context, self_data->geom, hash);
174
175
  return LONG2FIX(rb_hash_end(hash));
175
176
  }
@@ -182,15 +183,15 @@ static VALUE cmethod_create(VALUE module, VALUE factory, VALUE x, VALUE y, VALUE
182
183
  }
183
184
 
184
185
 
185
- void rgeo_init_geos_point(RGeo_Globals* globals)
186
+ void rgeo_init_geos_point()
186
187
  {
187
188
  VALUE geos_point_methods;
188
189
 
189
190
  // Class methods for CAPIPointImpl
190
- rb_define_module_function(globals->geos_point, "create", cmethod_create, 4);
191
+ rb_define_module_function(rgeo_geos_point_class, "create", cmethod_create, 4);
191
192
 
192
193
  // CAPIPointMethods module
193
- geos_point_methods = rb_define_module_under(globals->geos_module, "CAPIPointMethods");
194
+ geos_point_methods = rb_define_module_under(rgeo_geos_module, "CAPIPointMethods");
194
195
  rb_define_method(geos_point_methods, "rep_equals?", method_point_eql, 1);
195
196
  rb_define_method(geos_point_methods, "eql?", method_point_eql, 1);
196
197
  rb_define_method(geos_point_methods, "hash", method_point_hash, 0);
@@ -221,7 +222,7 @@ VALUE rgeo_create_geos_point(VALUE factory, double x, double y, double z)
221
222
  if (GEOSCoordSeq_setZ_r(context, coord_seq, 0, z)) {
222
223
  geom = GEOSGeom_createPoint_r(context, coord_seq);
223
224
  if (geom) {
224
- result = rgeo_wrap_geos_geometry(factory, geom, factory_data->globals->geos_point);
225
+ result = rgeo_wrap_geos_geometry(factory, geom, rgeo_geos_point_class);
225
226
  }
226
227
  }
227
228
  }
@@ -8,8 +8,6 @@
8
8
 
9
9
  #include <ruby.h>
10
10
 
11
- #include "factory.h"
12
-
13
11
  RGEO_BEGIN_C
14
12
 
15
13
 
@@ -17,7 +15,7 @@ RGEO_BEGIN_C
17
15
  Initializes the point module. This should be called after
18
16
  the geometry module is initialized.
19
17
  */
20
- void rgeo_init_geos_point(RGeo_Globals* globals);
18
+ void rgeo_init_geos_point();
21
19
 
22
20
  /*
23
21
  Creates a 3d point and returns the ruby object.
@@ -10,6 +10,8 @@
10
10
  #include <ruby.h>
11
11
  #include <geos_c.h>
12
12
 
13
+ #include "globals.h"
14
+
13
15
  #include "factory.h"
14
16
  #include "geometry.h"
15
17
  #include "line_string.h"
@@ -43,8 +45,7 @@ static VALUE method_polygon_hash(VALUE self)
43
45
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
44
46
  factory = self_data->factory;
45
47
  hash = rb_hash_start(0);
46
- hash = rgeo_geos_objbase_hash(factory,
47
- RGEO_FACTORY_DATA_PTR(factory)->globals->feature_polygon, hash);
48
+ hash = rgeo_geos_objbase_hash(factory, rgeo_feature_polygon_module, hash);
48
49
  hash = rgeo_geos_polygon_hash(self_data->geos_context, self_data->geom, hash);
49
50
  return LONG2FIX(rb_hash_end(hash));
50
51
  }
@@ -58,7 +59,7 @@ static VALUE method_polygon_geometry_type(VALUE self)
58
59
  result = Qnil;
59
60
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
60
61
  if (self_data->geom) {
61
- result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_polygon;
62
+ result = rgeo_feature_polygon_module;
62
63
  }
63
64
  return result;
64
65
  }
@@ -93,7 +94,7 @@ static VALUE method_polygon_centroid(VALUE self)
93
94
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
94
95
  self_geom = self_data->geom;
95
96
  if (self_geom) {
96
- result = rgeo_wrap_geos_geometry(self_data->factory, GEOSGetCentroid_r(self_data->geos_context, self_geom), RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_point);
97
+ result = rgeo_wrap_geos_geometry(self_data->factory, GEOSGetCentroid_r(self_data->geos_context, self_geom), rgeo_geos_point_class);
97
98
  }
98
99
  return result;
99
100
  }
@@ -109,7 +110,7 @@ static VALUE method_polygon_point_on_surface(VALUE self)
109
110
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
110
111
  self_geom = self_data->geom;
111
112
  if (self_geom) {
112
- result = rgeo_wrap_geos_geometry(self_data->factory, GEOSPointOnSurface_r(self_data->geos_context, self_geom), RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_point);
113
+ result = rgeo_wrap_geos_geometry(self_data->factory, GEOSPointOnSurface_r(self_data->geos_context, self_geom), rgeo_geos_point_class);
113
114
  }
114
115
  return result;
115
116
  }
@@ -145,7 +146,7 @@ static VALUE method_polygon_exterior_ring(VALUE self)
145
146
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
146
147
  self_geom = self_data->geom;
147
148
  if (self_geom) {
148
- result = rgeo_wrap_geos_geometry_clone(self_data->factory, GEOSGetExteriorRing_r(self_data->geos_context, self_geom), RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_linear_ring);
149
+ result = rgeo_wrap_geos_geometry_clone(self_data->factory, GEOSGetExteriorRing_r(self_data->geos_context, self_geom), rgeo_geos_linear_ring_class);
149
150
  }
150
151
  return result;
151
152
  }
@@ -191,7 +192,7 @@ static VALUE method_polygon_interior_ring_n(VALUE self, VALUE n)
191
192
  if (i < num) {
192
193
  result = rgeo_wrap_geos_geometry_clone(self_data->factory,
193
194
  GEOSGetInteriorRingN_r(self_context, self_geom, i),
194
- RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_linear_ring);
195
+ rgeo_geos_linear_ring_class);
195
196
  }
196
197
  }
197
198
  }
@@ -219,9 +220,8 @@ static VALUE method_polygon_interior_rings(VALUE self)
219
220
  if (count >= 0) {
220
221
  result = rb_ary_new2(count);
221
222
  factory = self_data->factory;
222
- linear_ring_class = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->geos_linear_ring;
223
223
  for (i=0; i<count; ++i) {
224
- rb_ary_store(result, i, rgeo_wrap_geos_geometry_clone(factory, GEOSGetInteriorRingN_r(self_context, self_geom, i), linear_ring_class));
224
+ rb_ary_store(result, i, rgeo_wrap_geos_geometry_clone(factory, GEOSGetInteriorRingN_r(self_context, self_geom, i), rgeo_geos_linear_ring_class));
225
225
  }
226
226
  }
227
227
  }
@@ -244,7 +244,7 @@ static VALUE cmethod_create(VALUE module, VALUE factory, VALUE exterior, VALUE i
244
244
 
245
245
  Check_Type(interior_array, T_ARRAY);
246
246
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
247
- linear_ring_type = factory_data->globals->feature_linear_ring;
247
+ linear_ring_type = rgeo_feature_linear_ring_module;
248
248
  exterior_geom = rgeo_convert_to_detached_geos_geometry(exterior, factory, linear_ring_type, NULL);
249
249
  if (exterior_geom) {
250
250
  context = factory_data->geos_context;
@@ -262,7 +262,7 @@ static VALUE cmethod_create(VALUE module, VALUE factory, VALUE exterior, VALUE i
262
262
  polygon = GEOSGeom_createPolygon_r(context, exterior_geom, interior_geoms, actual_len);
263
263
  if (polygon) {
264
264
  free(interior_geoms);
265
- return rgeo_wrap_geos_geometry(factory, polygon, factory_data->globals->geos_polygon);
265
+ return rgeo_wrap_geos_geometry(factory, polygon, rgeo_geos_polygon_class);
266
266
  }
267
267
  }
268
268
  for (i=0; i<actual_len; ++i) {
@@ -276,15 +276,15 @@ static VALUE cmethod_create(VALUE module, VALUE factory, VALUE exterior, VALUE i
276
276
  }
277
277
 
278
278
 
279
- void rgeo_init_geos_polygon(RGeo_Globals* globals)
279
+ void rgeo_init_geos_polygon()
280
280
  {
281
281
  VALUE geos_polygon_methods;
282
282
 
283
283
  // Class methods for CAPIPolygonImpl
284
- rb_define_module_function(globals->geos_polygon, "create", cmethod_create, 3);
284
+ rb_define_module_function(rgeo_geos_polygon_class, "create", cmethod_create, 3);
285
285
 
286
286
  // CAPIPolygonMethods module
287
- geos_polygon_methods = rb_define_module_under(globals->geos_module, "CAPIPolygonMethods");
287
+ geos_polygon_methods = rb_define_module_under(rgeo_geos_module, "CAPIPolygonMethods");
288
288
  rb_define_method(geos_polygon_methods, "rep_equals?", method_polygon_eql, 1);
289
289
  rb_define_method(geos_polygon_methods, "eql?", method_polygon_eql, 1);
290
290
  rb_define_method(geos_polygon_methods, "hash", method_polygon_hash, 0);
@@ -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,7 +16,7 @@ RGEO_BEGIN_C
18
16
  Initializes the polygon module. This should be called after
19
17
  the geometry module is initialized.
20
18
  */
21
- void rgeo_init_geos_polygon(RGeo_Globals* globals);
19
+ void rgeo_init_geos_polygon();
22
20
 
23
21
  /*
24
22
  Comopares the values of two GEOS polygons. The two given geometries MUST
@@ -21,9 +21,17 @@
21
21
  #ifdef HAVE_GEOSUNARYUNION_R
22
22
  #define RGEO_GEOS_SUPPORTS_UNARYUNION
23
23
  #endif
24
+ #ifdef HAVE_GEOSCOORDSEQ_ISCCW_R
25
+ #define RGEO_GEOS_SUPPORTS_ISCCW
26
+ #endif
24
27
  #ifdef HAVE_RB_MEMHASH
25
28
  #define RGEO_SUPPORTS_NEW_HASHING
26
29
  #endif
30
+ #ifdef HAVE_RB_GC_MARK_MOVABLE
31
+ #define mark rb_gc_mark_movable
32
+ #else
33
+ #define mark rb_gc_mark
34
+ #endif
27
35
 
28
36
  #ifndef RGEO_SUPPORTS_NEW_HASHING
29
37
  #define st_index_t int
@@ -13,6 +13,28 @@ module RGeo
13
13
 
14
14
  module Analysis
15
15
  class << self
16
+ # Check orientation of a ring, returns `true` if it is counter-clockwise
17
+ # and false otherwise.
18
+ #
19
+ # If the factory used is GEOS based, use the GEOS implementation to
20
+ # check that. Otherwise, this methods falls back to `ring_direction`.
21
+ #
22
+ # == Note
23
+ #
24
+ # This method does not ensure a correct result for an invalid geometry.
25
+ # You should make sure your ring is valid beforehand using `ring?`
26
+ # if you are using a LineString, or directly `valid?` for a
27
+ # `linear_ring?`.
28
+ # This will be subject to changes in v3.
29
+ def ccw?(ring)
30
+ if RGeo::Geos.capi_geos?(ring) && RGeo::Geos::Analysis.ccw_supported?
31
+ RGeo::Geos::Analysis.ccw?(ring)
32
+ else
33
+ RGeo::Cartesian::Analysis.ring_direction(ring) == 1
34
+ end
35
+ end
36
+ alias counter_clockwise? ccw?
37
+
16
38
  # Given a LineString, which must be a ring, determine whether the
17
39
  # ring proceeds clockwise or counterclockwise.
18
40
  # Returns 1 for counterclockwise, or -1 for clockwise.
@@ -49,7 +49,7 @@ module RGeo
49
49
  end
50
50
  end
51
51
 
52
- def is_simple?
52
+ def simple?
53
53
  len = segments.length
54
54
  return false if segments.any?(&:degenerate?)
55
55
  return true if len == 1
@@ -72,6 +72,11 @@ module RGeo
72
72
  true
73
73
  end
74
74
 
75
+ def is_simple?
76
+ warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
77
+ simple?
78
+ end
79
+
75
80
  def length
76
81
  segments.inject(0.0) { |sum, seg| sum + seg.length }
77
82
  end
@@ -6,10 +6,10 @@
6
6
  # the simple Cartesian implementation. It also provides a namespace
7
7
  # for Cartesian-specific analysis tools.
8
8
 
9
- require "rgeo/cartesian/calculations"
10
- require "rgeo/cartesian/feature_methods"
11
- require "rgeo/cartesian/feature_classes"
12
- require "rgeo/cartesian/factory"
13
- require "rgeo/cartesian/interface"
14
- require "rgeo/cartesian/bounding_box"
15
- require "rgeo/cartesian/analysis"
9
+ require_relative "cartesian/calculations"
10
+ require_relative "cartesian/feature_methods"
11
+ require_relative "cartesian/feature_classes"
12
+ require_relative "cartesian/factory"
13
+ require_relative "cartesian/interface"
14
+ require_relative "cartesian/bounding_box"
15
+ require_relative "cartesian/analysis"
@@ -6,12 +6,12 @@
6
6
  #
7
7
  # -----------------------------------------------------------------------------
8
8
 
9
- require "rgeo/coord_sys/cs/factories"
10
- require "rgeo/coord_sys/cs/entities"
11
- require "rgeo/coord_sys/cs/wkt_parser"
12
- require "rgeo/coord_sys/srs_database/entry"
13
- require "rgeo/coord_sys/srs_database/url_reader"
14
- require "rgeo/coord_sys/srs_database/sr_org"
9
+ require_relative "coord_sys/cs/factories"
10
+ require_relative "coord_sys/cs/entities"
11
+ require_relative "coord_sys/cs/wkt_parser"
12
+ require_relative "coord_sys/srs_database/entry"
13
+ require_relative "coord_sys/srs_database/url_reader"
14
+ require_relative "coord_sys/srs_database/sr_org"
15
15
 
16
16
  module RGeo
17
17
  # This module provides data structures and tools related to coordinate
data/lib/rgeo/error.rb CHANGED
@@ -14,6 +14,10 @@ module RGeo
14
14
  class RGeoError < RuntimeError
15
15
  end
16
16
 
17
+ # RGeo error specific to the GEOS implementation.
18
+ class GeosError < RGeoError
19
+ end
20
+
17
21
  # The specified geometry is invalid
18
22
  class InvalidGeometry < RGeoError
19
23
  end
@@ -90,8 +90,13 @@ module RGeo
90
90
  # Returns a boolean value. Note that this is different from the SFS
91
91
  # specification, which stipulates an integer return value.
92
92
 
93
+ def closed?
94
+ raise Error::UnsupportedOperation, "Method Curve#closed? not defined."
95
+ end
96
+
93
97
  def is_closed?
94
- raise Error::UnsupportedOperation, "Method Curve#is_closed? not defined."
98
+ warn "The is_closed? method is deprecated, please use the closed? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
99
+ closed?
95
100
  end
96
101
 
97
102
  # === SFS 1.1 Description
@@ -105,8 +110,13 @@ module RGeo
105
110
  # Returns a boolean value. Note that this is different from the SFS
106
111
  # specification, which stipulates an integer return value.
107
112
 
113
+ def ring?
114
+ raise Error::UnsupportedOperation, "Method Curve#ring? not defined."
115
+ end
116
+
108
117
  def is_ring?
109
- raise Error::UnsupportedOperation, "Method Curve#is_ring? not defined."
118
+ warn "The is_ring? method is deprecated, please use the ring? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
119
+ ring?
110
120
  end
111
121
  end
112
122
  end
@@ -191,8 +191,13 @@ module RGeo
191
191
  # Returns a boolean value. Note that this is different from the SFS
192
192
  # specification, which stipulates an integer return value.
193
193
 
194
+ def empty?
195
+ raise Error::UnsupportedOperation, "Method Geometry#empty? not defined."
196
+ end
197
+
194
198
  def is_empty?
195
- raise Error::UnsupportedOperation, "Method Geometry#is_empty? not defined."
199
+ warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
200
+ empty?
196
201
  end
197
202
 
198
203
  # === SFS 1.1 Description
@@ -208,8 +213,13 @@ module RGeo
208
213
  # Returns a boolean value. Note that this is different from the SFS
209
214
  # specification, which stipulates an integer return value.
210
215
 
216
+ def simple?
217
+ raise Error::UnsupportedOperation, "Method Geometry#simple? not defined."
218
+ end
219
+
211
220
  def is_simple?
212
- raise Error::UnsupportedOperation, "Method Geometry#is_simple? not defined."
221
+ warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
222
+ simple?
213
223
  end
214
224
 
215
225
  # === SFS 1.1 Description
@@ -23,6 +23,16 @@ module RGeo
23
23
  module LinearRing
24
24
  include LineString
25
25
  extend Type
26
+
27
+ # Returns +true+ if the ring is oriented in a counter clockwise direction
28
+ # otherwise returns +false+.
29
+ #
30
+ # == Notes
31
+ #
32
+ # Not a standard SFS method for linear rings, but added for convenience.
33
+ def ccw?
34
+ raise Error::UnsupportedOperation, "Method LinearRing#ccw? not defined."
35
+ end
26
36
  end
27
37
  end
28
38
  end