rgeo 2.4.0 → 3.1.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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +6 -0
  3. data/README.md +23 -14
  4. data/ext/geos_c_impl/analysis.c +29 -26
  5. data/ext/geos_c_impl/analysis.h +8 -5
  6. data/ext/geos_c_impl/coordinates.c +27 -21
  7. data/ext/geos_c_impl/coordinates.h +5 -2
  8. data/ext/geos_c_impl/errors.c +19 -10
  9. data/ext/geos_c_impl/errors.h +11 -4
  10. data/ext/geos_c_impl/extconf.rb +43 -29
  11. data/ext/geos_c_impl/factory.c +443 -351
  12. data/ext/geos_c_impl/factory.h +98 -55
  13. data/ext/geos_c_impl/geometry.c +589 -383
  14. data/ext/geos_c_impl/geometry.h +10 -3
  15. data/ext/geos_c_impl/geometry_collection.c +288 -316
  16. data/ext/geos_c_impl/geometry_collection.h +6 -18
  17. data/ext/geos_c_impl/globals.c +98 -21
  18. data/ext/geos_c_impl/globals.h +3 -2
  19. data/ext/geos_c_impl/line_string.c +263 -222
  20. data/ext/geos_c_impl/line_string.h +5 -6
  21. data/ext/geos_c_impl/main.c +8 -9
  22. data/ext/geos_c_impl/point.c +63 -65
  23. data/ext/geos_c_impl/point.h +4 -5
  24. data/ext/geos_c_impl/polygon.c +168 -131
  25. data/ext/geos_c_impl/polygon.h +11 -9
  26. data/ext/geos_c_impl/preface.h +15 -11
  27. data/ext/geos_c_impl/ruby_more.c +67 -0
  28. data/ext/geos_c_impl/ruby_more.h +25 -0
  29. data/lib/rgeo/cartesian/analysis.rb +5 -3
  30. data/lib/rgeo/cartesian/bounding_box.rb +74 -79
  31. data/lib/rgeo/cartesian/calculations.rb +64 -33
  32. data/lib/rgeo/cartesian/factory.rb +59 -104
  33. data/lib/rgeo/cartesian/feature_classes.rb +68 -46
  34. data/lib/rgeo/cartesian/feature_methods.rb +67 -25
  35. data/lib/rgeo/cartesian/interface.rb +6 -41
  36. data/lib/rgeo/cartesian/planar_graph.rb +373 -0
  37. data/lib/rgeo/cartesian/sweepline_intersector.rb +147 -0
  38. data/lib/rgeo/cartesian/valid_op.rb +69 -0
  39. data/lib/rgeo/cartesian.rb +3 -0
  40. data/lib/rgeo/coord_sys/cs/entities.rb +305 -101
  41. data/lib/rgeo/coord_sys/cs/factories.rb +0 -2
  42. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +90 -42
  43. data/lib/rgeo/coord_sys.rb +1 -20
  44. data/lib/rgeo/error.rb +15 -0
  45. data/lib/rgeo/feature/curve.rb +0 -11
  46. data/lib/rgeo/feature/factory.rb +26 -36
  47. data/lib/rgeo/feature/factory_generator.rb +6 -14
  48. data/lib/rgeo/feature/geometry.rb +146 -66
  49. data/lib/rgeo/feature/geometry_collection.rb +16 -9
  50. data/lib/rgeo/feature/line_string.rb +4 -5
  51. data/lib/rgeo/feature/linear_ring.rb +0 -1
  52. data/lib/rgeo/feature/multi_curve.rb +0 -6
  53. data/lib/rgeo/feature/multi_surface.rb +3 -4
  54. data/lib/rgeo/feature/point.rb +4 -5
  55. data/lib/rgeo/feature/polygon.rb +1 -2
  56. data/lib/rgeo/feature/surface.rb +3 -4
  57. data/lib/rgeo/feature/types.rb +71 -87
  58. data/lib/rgeo/geographic/factory.rb +100 -127
  59. data/lib/rgeo/geographic/interface.rb +71 -168
  60. data/lib/rgeo/geographic/projected_feature_classes.rb +21 -9
  61. data/lib/rgeo/geographic/projected_feature_methods.rb +67 -42
  62. data/lib/rgeo/geographic/projected_window.rb +36 -22
  63. data/lib/rgeo/geographic/{proj4_projector.rb → projector.rb} +3 -5
  64. data/lib/rgeo/geographic/simple_mercator_projector.rb +26 -25
  65. data/lib/rgeo/geographic/spherical_feature_classes.rb +29 -9
  66. data/lib/rgeo/geographic/spherical_feature_methods.rb +86 -9
  67. data/lib/rgeo/geographic/spherical_math.rb +17 -20
  68. data/lib/rgeo/geographic.rb +1 -1
  69. data/lib/rgeo/geos/capi_factory.rb +87 -158
  70. data/lib/rgeo/geos/capi_feature_classes.rb +50 -36
  71. data/lib/rgeo/geos/ffi_factory.rb +107 -175
  72. data/lib/rgeo/geos/ffi_feature_classes.rb +34 -10
  73. data/lib/rgeo/geos/ffi_feature_methods.rb +105 -127
  74. data/lib/rgeo/geos/interface.rb +20 -59
  75. data/lib/rgeo/geos/utils.rb +5 -5
  76. data/lib/rgeo/geos/zm_factory.rb +55 -97
  77. data/lib/rgeo/geos/zm_feature_methods.rb +30 -33
  78. data/lib/rgeo/geos.rb +15 -9
  79. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +11 -24
  80. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +1 -2
  81. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +28 -56
  82. data/lib/rgeo/impl_helper/basic_point_methods.rb +2 -14
  83. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +17 -26
  84. data/lib/rgeo/impl_helper/utils.rb +21 -0
  85. data/lib/rgeo/impl_helper/valid_op.rb +350 -0
  86. data/lib/rgeo/impl_helper/validity_check.rb +139 -0
  87. data/lib/rgeo/impl_helper.rb +1 -0
  88. data/lib/rgeo/version.rb +1 -1
  89. data/lib/rgeo/wkrep/wkb_generator.rb +73 -63
  90. data/lib/rgeo/wkrep/wkb_parser.rb +33 -31
  91. data/lib/rgeo/wkrep/wkt_generator.rb +52 -45
  92. data/lib/rgeo/wkrep/wkt_parser.rb +48 -35
  93. data/lib/rgeo.rb +1 -3
  94. metadata +63 -16
  95. data/lib/rgeo/coord_sys/srs_database/entry.rb +0 -107
  96. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +0 -64
  97. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +0 -65
@@ -2,42 +2,30 @@
2
2
  Geometry collection methods for GEOS wrapper
3
3
  */
4
4
 
5
-
6
5
  #ifndef RGEO_GEOS_GEOMETRY_COLLECTION_INCLUDED
7
6
  #define RGEO_GEOS_GEOMETRY_COLLECTION_INCLUDED
8
7
 
9
- #include <ruby.h>
10
8
  #include <geos_c.h>
9
+ #include <ruby.h>
11
10
 
12
11
  RGEO_BEGIN_C
13
12
 
14
-
15
13
  /*
16
14
  Initializes the geometry collection module. This should be called after
17
15
  the geometry module is initialized.
18
16
  */
19
- void rgeo_init_geos_geometry_collection();
20
-
21
- /*
22
- Comopares the contents of two geometry collections. Does not test the
23
- types of the collections themselves, but tests the types, values, and
24
- contents of all the contents. The two given geometries MUST be
25
- collection types-- i.e. GeometryCollection, MultiPoint, MultiLineString,
26
- or MultiPolygon.
27
- Returns Qtrue if the contents of the two geometry collections are equal,
28
- Qfalse if they are inequal, or Qnil if an error occurs.
29
- */
30
- VALUE rgeo_geos_geometry_collections_eql(GEOSContextHandle_t context, const GEOSGeometry* geom1, const GEOSGeometry* geom2, char check_z);
17
+ void
18
+ rgeo_init_geos_geometry_collection();
31
19
 
32
20
  /*
33
21
  A tool for building up hash values.
34
- You must pass in the context, a geos geometry, and a seed hash.
22
+ You must pass in a geos geometry and a seed hash.
35
23
  Returns an updated hash.
36
24
  This call is useful in sequence, and should be bracketed by calls to
37
25
  rb_hash_start and rb_hash_end.
38
26
  */
39
- st_index_t rgeo_geos_geometry_collection_hash(GEOSContextHandle_t context, const GEOSGeometry* geom, st_index_t hash);
40
-
27
+ st_index_t
28
+ rgeo_geos_geometry_collection_hash(const GEOSGeometry* geom, st_index_t hash);
41
29
 
42
30
  RGEO_END_C
43
31
 
@@ -2,8 +2,13 @@
2
2
 
3
3
  #ifdef RGEO_GEOS_SUPPORTED
4
4
 
5
+ #include <ctype.h>
6
+ #include <geos_c.h>
5
7
  #include <ruby.h>
8
+ #include <stdarg.h>
9
+ #include <stdio.h>
6
10
 
11
+ #include "errors.h"
7
12
  #include "globals.h"
8
13
 
9
14
  RGEO_BEGIN_C
@@ -34,55 +39,127 @@ VALUE rgeo_geos_multi_point_class;
34
39
  VALUE rgeo_geos_multi_line_string_class;
35
40
  VALUE rgeo_geos_multi_polygon_class;
36
41
 
37
- void rgeo_init_geos_globals()
42
+ // The notice handler is very rarely used by GEOS, only in
43
+ // GEOSIsValid_r (check for NOTICE_MESSAGE in GEOS codebase).
44
+ // We still set it to make sure we do not miss any implementation
45
+ // change. Use `DEBUG=1 rake` to show notice.
46
+ static void
47
+ notice_handler(const char* fmt, ...)
38
48
  {
49
+ #ifdef DEBUG
50
+ va_list args;
51
+ va_start(args, fmt);
52
+ fprintf(stderr, "GEOS Notice -- ");
53
+ vfprintf(stderr, fmt, args);
54
+ fprintf(stderr, "\n");
55
+ va_end(args);
56
+ #endif
57
+ }
58
+
59
+ NORETURN(static void error_handler(const char* fmt, ...))
60
+ {
61
+ // See https://en.cppreference.com/w/c/io/vfprintf
62
+ va_list args1;
63
+ va_start(args1, fmt);
64
+ va_list args2;
65
+ va_copy(args2, args1);
66
+ int size = 1 + vsnprintf(NULL, 0, fmt, args1);
67
+ va_end(args1);
68
+ char geos_full_error[size];
69
+ vsnprintf(geos_full_error, sizeof geos_full_error, fmt, args2);
70
+ va_end(args2);
71
+
72
+ // NOTE: strtok is destructive, geos_full_error is not to be used afterwards.
73
+ char* geos_error = strtok(geos_full_error, ":");
74
+ char* geos_message = strtok(NULL, ":");
75
+ while (isspace(*geos_message))
76
+ geos_message++;
77
+
78
+ if (streq(geos_error, "UnsupportedOperationException")) {
79
+ rb_raise(rb_eRGeoUnsupportedOperation, "%s", geos_message);
80
+ } else if (streq(geos_error, "IllegalArgumentException")) {
81
+ rb_raise(rb_eRGeoInvalidGeometry, "%s", geos_message);
82
+ } else if (streq(geos_error, "ParseException")) {
83
+ rb_raise(rb_eRGeoParseError, "%s", geos_message);
84
+ } else if (geos_message) {
85
+ rb_raise(rb_eGeosError, "%s: %s", geos_error, geos_message);
86
+ } else {
87
+ rb_raise(rb_eGeosError, "%s", geos_error);
88
+ }
89
+ }
90
+
91
+ void
92
+ rgeo_init_geos_globals()
93
+ {
94
+ initGEOS(notice_handler, error_handler);
95
+
39
96
  rgeo_module = rb_define_module("RGeo");
40
97
  rb_gc_register_mark_object(rgeo_module);
41
98
 
42
99
  rgeo_feature_module = rb_define_module_under(rgeo_module, "Feature");
43
100
  rb_gc_register_mark_object(rgeo_feature_module);
44
- rgeo_feature_geometry_module = rb_const_get_at(rgeo_feature_module, rb_intern("Geometry"));
101
+ rgeo_feature_geometry_module =
102
+ rb_const_get_at(rgeo_feature_module, rb_intern("Geometry"));
45
103
  rb_gc_register_mark_object(rgeo_feature_geometry_module);
46
- rgeo_feature_point_module = rb_const_get_at(rgeo_feature_module, rb_intern("Point"));
104
+ rgeo_feature_point_module =
105
+ rb_const_get_at(rgeo_feature_module, rb_intern("Point"));
47
106
  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"));
107
+ rgeo_feature_line_string_module =
108
+ rb_const_get_at(rgeo_feature_module, rb_intern("LineString"));
49
109
  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"));
110
+ rgeo_feature_linear_ring_module =
111
+ rb_const_get_at(rgeo_feature_module, rb_intern("LinearRing"));
51
112
  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"));
113
+ rgeo_feature_line_module =
114
+ rb_const_get_at(rgeo_feature_module, rb_intern("Line"));
53
115
  rb_gc_register_mark_object(rgeo_feature_line_module);
54
- rgeo_feature_polygon_module = rb_const_get_at(rgeo_feature_module, rb_intern("Polygon"));
116
+ rgeo_feature_polygon_module =
117
+ rb_const_get_at(rgeo_feature_module, rb_intern("Polygon"));
55
118
  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"));
119
+ rgeo_feature_geometry_collection_module =
120
+ rb_const_get_at(rgeo_feature_module, rb_intern("GeometryCollection"));
57
121
  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"));
122
+ rgeo_feature_multi_point_module =
123
+ rb_const_get_at(rgeo_feature_module, rb_intern("MultiPoint"));
59
124
  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"));
125
+ rgeo_feature_multi_line_string_module =
126
+ rb_const_get_at(rgeo_feature_module, rb_intern("MultiLineString"));
61
127
  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"));
128
+ rgeo_feature_multi_polygon_module =
129
+ rb_const_get_at(rgeo_feature_module, rb_intern("MultiPolygon"));
63
130
  rb_gc_register_mark_object(rgeo_feature_multi_polygon_module);
64
131
 
65
132
  rgeo_geos_module = rb_define_module_under(rgeo_module, "Geos");
66
133
  rb_gc_register_mark_object(rgeo_geos_module);
67
- rgeo_geos_geometry_class = rb_define_class_under(rgeo_geos_module, "CAPIGeometryImpl", rb_cObject);
134
+ rgeo_geos_geometry_class =
135
+ rb_define_class_under(rgeo_geos_module, "CAPIGeometryImpl", rb_cObject);
68
136
  rb_gc_register_mark_object(rgeo_geos_geometry_class);
69
- rgeo_geos_point_class = rb_define_class_under(rgeo_geos_module, "CAPIPointImpl", rb_cObject);
137
+ rgeo_geos_point_class =
138
+ rb_define_class_under(rgeo_geos_module, "CAPIPointImpl", rb_cObject);
70
139
  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);
140
+ rgeo_geos_line_string_class =
141
+ rb_define_class_under(rgeo_geos_module, "CAPILineStringImpl", rb_cObject);
72
142
  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);
143
+ rgeo_geos_linear_ring_class =
144
+ rb_define_class_under(rgeo_geos_module, "CAPILinearRingImpl", rb_cObject);
74
145
  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);
146
+ rgeo_geos_line_class =
147
+ rb_define_class_under(rgeo_geos_module, "CAPILineImpl", rb_cObject);
76
148
  rb_gc_register_mark_object(rgeo_geos_line_class);
77
- rgeo_geos_polygon_class = rb_define_class_under(rgeo_geos_module, "CAPIPolygonImpl", rb_cObject);
149
+ rgeo_geos_polygon_class =
150
+ rb_define_class_under(rgeo_geos_module, "CAPIPolygonImpl", rb_cObject);
78
151
  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);
152
+ rgeo_geos_geometry_collection_class = rb_define_class_under(
153
+ rgeo_geos_module, "CAPIGeometryCollectionImpl", rb_cObject);
80
154
  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);
155
+ rgeo_geos_multi_point_class =
156
+ rb_define_class_under(rgeo_geos_module, "CAPIMultiPointImpl", rb_cObject);
82
157
  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);
158
+ rgeo_geos_multi_line_string_class = rb_define_class_under(
159
+ rgeo_geos_module, "CAPIMultiLineStringImpl", rb_cObject);
84
160
  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);
161
+ rgeo_geos_multi_polygon_class =
162
+ rb_define_class_under(rgeo_geos_module, "CAPIMultiPolygonImpl", rb_cObject);
86
163
  rb_gc_register_mark_object(rgeo_geos_multi_polygon_class);
87
164
  }
88
165
 
@@ -8,7 +8,7 @@
8
8
  #ifndef RGEO_GEOS_GLOBALS_INCLUDED
9
9
  #define RGEO_GEOS_GLOBALS_INCLUDED
10
10
 
11
- #include <ruby.h>
11
+ #include <geos_c.h>
12
12
 
13
13
  RGEO_BEGIN_C
14
14
 
@@ -38,7 +38,8 @@ extern VALUE rgeo_geos_multi_point_class;
38
38
  extern VALUE rgeo_geos_multi_line_string_class;
39
39
  extern VALUE rgeo_geos_multi_polygon_class;
40
40
 
41
- void rgeo_init_geos_globals();
41
+ void
42
+ rgeo_init_geos_globals();
42
43
 
43
44
  RGEO_END_C
44
45