rgeo 2.4.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +6 -0
  3. data/README.md +21 -11
  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 +41 -29
  11. data/ext/geos_c_impl/factory.c +441 -351
  12. data/ext/geos_c_impl/factory.h +98 -55
  13. data/ext/geos_c_impl/geometry.c +563 -384
  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 +99 -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 +62 -65
  23. data/ext/geos_c_impl/point.h +4 -5
  24. data/ext/geos_c_impl/polygon.c +134 -132
  25. data/ext/geos_c_impl/polygon.h +11 -9
  26. data/ext/geos_c_impl/preface.h +10 -12
  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 +57 -102
  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 +299 -99
  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 +73 -83
  58. data/lib/rgeo/geographic/factory.rb +98 -125
  59. data/lib/rgeo/geographic/interface.rb +66 -163
  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 +24 -23
  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 +95 -165
  72. data/lib/rgeo/geos/ffi_feature_classes.rb +34 -10
  73. data/lib/rgeo/geos/ffi_feature_methods.rb +105 -126
  74. data/lib/rgeo/geos/interface.rb +20 -59
  75. data/lib/rgeo/geos/utils.rb +3 -3
  76. data/lib/rgeo/geos/zm_factory.rb +53 -95
  77. data/lib/rgeo/geos/zm_feature_methods.rb +30 -32
  78. data/lib/rgeo/geos.rb +8 -8
  79. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +9 -22
  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 +51 -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,128 @@ 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
+ static void
60
+ error_handler(const char* fmt, ...)
61
+ {
62
+ // See https://en.cppreference.com/w/c/io/vfprintf
63
+ va_list args1;
64
+ va_start(args1, fmt);
65
+ va_list args2;
66
+ va_copy(args2, args1);
67
+ int size = 1 + vsnprintf(NULL, 0, fmt, args1);
68
+ va_end(args1);
69
+ char geos_full_error[size];
70
+ vsnprintf(geos_full_error, sizeof geos_full_error, fmt, args2);
71
+ va_end(args2);
72
+
73
+ // NOTE: strtok is destructive, geos_full_error is not to be used afterwards.
74
+ char* geos_error = strtok(geos_full_error, ":");
75
+ char* geos_message = strtok(NULL, ":");
76
+ while (isspace(*geos_message))
77
+ geos_message++;
78
+
79
+ if (streq(geos_error, "UnsupportedOperationException")) {
80
+ rb_raise(rb_eRGeoUnsupportedOperation, "%s", geos_message);
81
+ } else if (streq(geos_error, "IllegalArgumentException")) {
82
+ rb_raise(rb_eRGeoInvalidGeometry, "%s", geos_message);
83
+ } else if (streq(geos_error, "ParseException")) {
84
+ rb_raise(rb_eRGeoParseError, "%s", geos_message);
85
+ } else if (geos_message) {
86
+ rb_raise(rb_eGeosError, "%s: %s", geos_error, geos_message);
87
+ } else {
88
+ rb_raise(rb_eGeosError, "%s", geos_error);
89
+ }
90
+ }
91
+
92
+ void
93
+ rgeo_init_geos_globals()
94
+ {
95
+ initGEOS(notice_handler, error_handler);
96
+
39
97
  rgeo_module = rb_define_module("RGeo");
40
98
  rb_gc_register_mark_object(rgeo_module);
41
99
 
42
100
  rgeo_feature_module = rb_define_module_under(rgeo_module, "Feature");
43
101
  rb_gc_register_mark_object(rgeo_feature_module);
44
- rgeo_feature_geometry_module = rb_const_get_at(rgeo_feature_module, rb_intern("Geometry"));
102
+ rgeo_feature_geometry_module =
103
+ rb_const_get_at(rgeo_feature_module, rb_intern("Geometry"));
45
104
  rb_gc_register_mark_object(rgeo_feature_geometry_module);
46
- rgeo_feature_point_module = rb_const_get_at(rgeo_feature_module, rb_intern("Point"));
105
+ rgeo_feature_point_module =
106
+ rb_const_get_at(rgeo_feature_module, rb_intern("Point"));
47
107
  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"));
108
+ rgeo_feature_line_string_module =
109
+ rb_const_get_at(rgeo_feature_module, rb_intern("LineString"));
49
110
  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"));
111
+ rgeo_feature_linear_ring_module =
112
+ rb_const_get_at(rgeo_feature_module, rb_intern("LinearRing"));
51
113
  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"));
114
+ rgeo_feature_line_module =
115
+ rb_const_get_at(rgeo_feature_module, rb_intern("Line"));
53
116
  rb_gc_register_mark_object(rgeo_feature_line_module);
54
- rgeo_feature_polygon_module = rb_const_get_at(rgeo_feature_module, rb_intern("Polygon"));
117
+ rgeo_feature_polygon_module =
118
+ rb_const_get_at(rgeo_feature_module, rb_intern("Polygon"));
55
119
  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"));
120
+ rgeo_feature_geometry_collection_module =
121
+ rb_const_get_at(rgeo_feature_module, rb_intern("GeometryCollection"));
57
122
  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"));
123
+ rgeo_feature_multi_point_module =
124
+ rb_const_get_at(rgeo_feature_module, rb_intern("MultiPoint"));
59
125
  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"));
126
+ rgeo_feature_multi_line_string_module =
127
+ rb_const_get_at(rgeo_feature_module, rb_intern("MultiLineString"));
61
128
  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"));
129
+ rgeo_feature_multi_polygon_module =
130
+ rb_const_get_at(rgeo_feature_module, rb_intern("MultiPolygon"));
63
131
  rb_gc_register_mark_object(rgeo_feature_multi_polygon_module);
64
132
 
65
133
  rgeo_geos_module = rb_define_module_under(rgeo_module, "Geos");
66
134
  rb_gc_register_mark_object(rgeo_geos_module);
67
- rgeo_geos_geometry_class = rb_define_class_under(rgeo_geos_module, "CAPIGeometryImpl", rb_cObject);
135
+ rgeo_geos_geometry_class =
136
+ rb_define_class_under(rgeo_geos_module, "CAPIGeometryImpl", rb_cObject);
68
137
  rb_gc_register_mark_object(rgeo_geos_geometry_class);
69
- rgeo_geos_point_class = rb_define_class_under(rgeo_geos_module, "CAPIPointImpl", rb_cObject);
138
+ rgeo_geos_point_class =
139
+ rb_define_class_under(rgeo_geos_module, "CAPIPointImpl", rb_cObject);
70
140
  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);
141
+ rgeo_geos_line_string_class =
142
+ rb_define_class_under(rgeo_geos_module, "CAPILineStringImpl", rb_cObject);
72
143
  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);
144
+ rgeo_geos_linear_ring_class =
145
+ rb_define_class_under(rgeo_geos_module, "CAPILinearRingImpl", rb_cObject);
74
146
  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);
147
+ rgeo_geos_line_class =
148
+ rb_define_class_under(rgeo_geos_module, "CAPILineImpl", rb_cObject);
76
149
  rb_gc_register_mark_object(rgeo_geos_line_class);
77
- rgeo_geos_polygon_class = rb_define_class_under(rgeo_geos_module, "CAPIPolygonImpl", rb_cObject);
150
+ rgeo_geos_polygon_class =
151
+ rb_define_class_under(rgeo_geos_module, "CAPIPolygonImpl", rb_cObject);
78
152
  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);
153
+ rgeo_geos_geometry_collection_class = rb_define_class_under(
154
+ rgeo_geos_module, "CAPIGeometryCollectionImpl", rb_cObject);
80
155
  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);
156
+ rgeo_geos_multi_point_class =
157
+ rb_define_class_under(rgeo_geos_module, "CAPIMultiPointImpl", rb_cObject);
82
158
  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);
159
+ rgeo_geos_multi_line_string_class = rb_define_class_under(
160
+ rgeo_geos_module, "CAPIMultiLineStringImpl", rb_cObject);
84
161
  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);
162
+ rgeo_geos_multi_polygon_class =
163
+ rb_define_class_under(rgeo_geos_module, "CAPIMultiPolygonImpl", rb_cObject);
86
164
  rb_gc_register_mark_object(rgeo_geos_multi_polygon_class);
87
165
  }
88
166
 
@@ -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