rgeo 3.0.0.pre.rc.2 → 3.0.0.pre.rc.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/ext/geos_c_impl/analysis.c +26 -23
  4. data/ext/geos_c_impl/analysis.h +8 -5
  5. data/ext/geos_c_impl/coordinates.c +27 -21
  6. data/ext/geos_c_impl/coordinates.h +5 -2
  7. data/ext/geos_c_impl/errors.c +15 -8
  8. data/ext/geos_c_impl/errors.h +4 -1
  9. data/ext/geos_c_impl/extconf.rb +40 -30
  10. data/ext/geos_c_impl/factory.c +367 -387
  11. data/ext/geos_c_impl/factory.h +59 -48
  12. data/ext/geos_c_impl/geometry.c +368 -320
  13. data/ext/geos_c_impl/geometry.h +5 -5
  14. data/ext/geos_c_impl/geometry_collection.c +256 -183
  15. data/ext/geos_c_impl/geometry_collection.h +6 -7
  16. data/ext/geos_c_impl/globals.c +99 -21
  17. data/ext/geos_c_impl/globals.h +3 -2
  18. data/ext/geos_c_impl/line_string.c +229 -198
  19. data/ext/geos_c_impl/line_string.h +5 -6
  20. data/ext/geos_c_impl/main.c +8 -9
  21. data/ext/geos_c_impl/point.c +62 -63
  22. data/ext/geos_c_impl/point.h +4 -5
  23. data/ext/geos_c_impl/polygon.c +116 -84
  24. data/ext/geos_c_impl/polygon.h +10 -8
  25. data/ext/geos_c_impl/preface.h +4 -13
  26. data/ext/geos_c_impl/ruby_more.c +35 -40
  27. data/ext/geos_c_impl/ruby_more.h +3 -2
  28. data/lib/rgeo/cartesian/bounding_box.rb +1 -1
  29. data/lib/rgeo/cartesian/factory.rb +8 -43
  30. data/lib/rgeo/cartesian/feature_methods.rb +0 -5
  31. data/lib/rgeo/cartesian/interface.rb +6 -5
  32. data/lib/rgeo/coord_sys/cs/entities.rb +214 -0
  33. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +15 -8
  34. data/lib/rgeo/coord_sys.rb +1 -9
  35. data/lib/rgeo/feature/curve.rb +0 -10
  36. data/lib/rgeo/feature/factory.rb +1 -9
  37. data/lib/rgeo/feature/factory_generator.rb +3 -7
  38. data/lib/rgeo/feature/geometry.rb +0 -10
  39. data/lib/rgeo/feature/multi_curve.rb +0 -5
  40. data/lib/rgeo/feature/types.rb +5 -5
  41. data/lib/rgeo/geographic/factory.rb +9 -42
  42. data/lib/rgeo/geographic/interface.rb +28 -99
  43. data/lib/rgeo/geographic/projected_feature_methods.rb +0 -10
  44. data/lib/rgeo/geographic/projected_window.rb +1 -1
  45. data/lib/rgeo/geographic/{proj4_projector.rb → projector.rb} +3 -3
  46. data/lib/rgeo/geographic/simple_mercator_projector.rb +1 -10
  47. data/lib/rgeo/geographic/spherical_feature_methods.rb +0 -5
  48. data/lib/rgeo/geographic.rb +1 -1
  49. data/lib/rgeo/geos/capi_factory.rb +37 -91
  50. data/lib/rgeo/geos/capi_feature_classes.rb +0 -29
  51. data/lib/rgeo/geos/ffi_factory.rb +52 -92
  52. data/lib/rgeo/geos/ffi_feature_methods.rb +1 -31
  53. data/lib/rgeo/geos/interface.rb +5 -20
  54. data/lib/rgeo/geos/zm_factory.rb +5 -36
  55. data/lib/rgeo/geos/zm_feature_methods.rb +1 -26
  56. data/lib/rgeo/geos.rb +2 -5
  57. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +1 -14
  58. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +1 -19
  59. data/lib/rgeo/impl_helper/basic_point_methods.rb +0 -10
  60. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +1 -9
  61. data/lib/rgeo/impl_helper/utils.rb +27 -0
  62. data/lib/rgeo/impl_helper/validity_check.rb +3 -3
  63. data/lib/rgeo/version.rb +1 -1
  64. data/lib/rgeo/wkrep/wkb_generator.rb +68 -53
  65. data/lib/rgeo/wkrep/wkb_parser.rb +19 -16
  66. data/lib/rgeo/wkrep/wkt_generator.rb +34 -34
  67. data/lib/rgeo/wkrep/wkt_parser.rb +26 -23
  68. data/lib/rgeo.rb +1 -3
  69. metadata +7 -6
@@ -2,31 +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();
17
+ void
18
+ rgeo_init_geos_geometry_collection();
20
19
 
21
20
  /*
22
21
  A tool for building up hash values.
23
- 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.
24
23
  Returns an updated hash.
25
24
  This call is useful in sequence, and should be bracketed by calls to
26
25
  rb_hash_start and rb_hash_end.
27
26
  */
28
- st_index_t rgeo_geos_geometry_collection_hash(GEOSContextHandle_t context, const GEOSGeometry* geom, st_index_t hash);
29
-
27
+ st_index_t
28
+ rgeo_geos_geometry_collection_hash(const GEOSGeometry* geom, st_index_t hash);
30
29
 
31
30
  RGEO_END_C
32
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