rgeo 2.3.1 → 3.0.1

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 +23 -14
  4. data/ext/geos_c_impl/analysis.c +30 -25
  5. data/ext/geos_c_impl/analysis.h +8 -7
  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 +42 -28
  11. data/ext/geos_c_impl/factory.c +540 -451
  12. data/ext/geos_c_impl/factory.h +105 -95
  13. data/ext/geos_c_impl/geometry.c +593 -387
  14. data/ext/geos_c_impl/geometry.h +10 -5
  15. data/ext/geos_c_impl/geometry_collection.c +306 -339
  16. data/ext/geos_c_impl/geometry_collection.h +6 -20
  17. data/ext/geos_c_impl/globals.c +169 -0
  18. data/ext/geos_c_impl/globals.h +46 -0
  19. data/ext/geos_c_impl/line_string.c +271 -231
  20. data/ext/geos_c_impl/line_string.h +5 -8
  21. data/ext/geos_c_impl/main.c +16 -16
  22. data/ext/geos_c_impl/point.c +65 -67
  23. data/ext/geos_c_impl/point.h +4 -7
  24. data/ext/geos_c_impl/polygon.c +137 -135
  25. data/ext/geos_c_impl/polygon.h +11 -11
  26. data/ext/geos_c_impl/preface.h +16 -10
  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 +303 -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 +69 -85
  58. data/lib/rgeo/geographic/factory.rb +98 -125
  59. data/lib/rgeo/geographic/interface.rb +69 -166
  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 +105 -173
  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 +53 -95
  77. data/lib/rgeo/geos/zm_feature_methods.rb +30 -33
  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 +50 -13
  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
@@ -5,64 +5,19 @@
5
5
  #ifndef RGEO_GEOS_FACTORY_INCLUDED
6
6
  #define RGEO_GEOS_FACTORY_INCLUDED
7
7
 
8
- #include <ruby.h>
9
8
  #include <geos_c.h>
9
+ #include <ruby.h>
10
10
 
11
11
  RGEO_BEGIN_C
12
12
 
13
- /*
14
- Per-interpreter globals.
15
- Most of these are cached references to commonly used classes, modules,
16
- and symbols so we don't have to do a lot of constant lookups and calls
17
- to rb_intern.
18
- */
19
- typedef struct {
20
- VALUE feature_module;
21
- VALUE feature_geometry;
22
- VALUE feature_point;
23
- VALUE feature_line_string;
24
- VALUE feature_linear_ring;
25
- VALUE feature_line;
26
- VALUE feature_polygon;
27
- VALUE feature_geometry_collection;
28
- VALUE feature_multi_point;
29
- VALUE feature_multi_line_string;
30
- VALUE feature_multi_polygon;
31
- VALUE geos_module;
32
- VALUE geos_geometry;
33
- VALUE geos_point;
34
- VALUE geos_line_string;
35
- VALUE geos_linear_ring;
36
- VALUE geos_line;
37
- VALUE geos_polygon;
38
- VALUE geos_geometry_collection;
39
- VALUE geos_multi_point;
40
- VALUE geos_multi_line_string;
41
- VALUE geos_multi_polygon;
42
- ID id_cast;
43
- ID id_eql;
44
- ID id_generate;
45
- ID id_enum_for;
46
- ID id_hash;
47
- VALUE sym_force_new;
48
- VALUE sym_keep_subtype;
49
- #ifndef RGEO_GEOS_SUPPORTS_SETOUTPUTDIMENSION
50
- VALUE psych_wkt_generator;
51
- VALUE marshal_wkb_generator;
52
- #endif
53
- } RGeo_Globals;
54
-
55
-
56
13
  /*
57
14
  Wrapped structure for Factory objects.
58
- A factory encapsulates the GEOS context, and GEOS serializer settings.
15
+ A factory encapsulates GEOS serializer settings.
59
16
  It also stores the SRID for all geometries created by this factory,
60
17
  and the resolution for buffers created for this factory's geometries.
61
- Finally, it provides easy access to the globals.
62
18
  */
63
- typedef struct {
64
- RGeo_Globals* globals;
65
- GEOSContextHandle_t geos_context;
19
+ typedef struct
20
+ {
66
21
  GEOSWKTReader* wkt_reader;
67
22
  GEOSWKBReader* wkb_reader;
68
23
  GEOSWKTWriter* wkt_writer;
@@ -75,19 +30,46 @@ typedef struct {
75
30
  GEOSWKBReader* marshal_wkb_reader;
76
31
  GEOSWKTWriter* psych_wkt_writer;
77
32
  GEOSWKBWriter* marshal_wkb_writer;
78
- VALUE proj4_obj;
79
33
  VALUE coord_sys_obj;
80
34
  int flags;
81
35
  int srid;
82
36
  int buffer_resolution;
83
37
  } RGeo_FactoryData;
84
38
 
85
- #define RGEO_FACTORYFLAGS_LENIENT_MULTIPOLYGON 1
86
- #define RGEO_FACTORYFLAGS_SUPPORTS_Z 2
87
- #define RGEO_FACTORYFLAGS_SUPPORTS_M 4
88
- #define RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M 6
89
- #define RGEO_FACTORYFLAGS_PREPARE_HEURISTIC 8
90
-
39
+ /*
40
+ Flags that are used to pass options when creating a factory.
41
+ They are available in ruby under RGeo::Geos::CAPIFactory::FLAG_name
42
+ where name is the name below without the RGEO_FACTORYFLAGS_ prefix.
43
+ */
44
+ #define RGEO_FACTORYFLAGS_SUPPORTS_Z 0b0010
45
+ #define RGEO_FACTORYFLAGS_SUPPORTS_M 0b0100
46
+ #define RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M \
47
+ (RGEO_FACTORYFLAGS_SUPPORTS_Z | RGEO_FACTORYFLAGS_SUPPORTS_M)
48
+ #define RGEO_FACTORYFLAGS_PREPARE_HEURISTIC 0b1000
49
+
50
+ /* call-seq:
51
+ * RGeo::Geos::CAPIFactory.supports_z? -> true or false
52
+ */
53
+ VALUE
54
+ method_factory_supports_z_p(VALUE self);
55
+
56
+ /* call-seq:
57
+ * RGeo::Geos::CAPIFactory.supports_m? -> true or false
58
+ */
59
+ VALUE
60
+ method_factory_supports_m_p(VALUE self);
61
+
62
+ /* call-seq:
63
+ * RGeo::Geos::CAPIFactory.supports_z_or_m? -> true or false
64
+ */
65
+ VALUE
66
+ method_factory_supports_z_or_m_p(VALUE self);
67
+
68
+ /* call-seq:
69
+ * RGeo::Geos::CAPIFactory.prepare_heuristic? -> true or false
70
+ */
71
+ VALUE
72
+ method_factory_prepare_heuristic_p(VALUE self);
91
73
 
92
74
  /*
93
75
  Wrapped structure for Geometry objects.
@@ -102,35 +84,44 @@ typedef struct {
102
84
  in Line objects, which have no GEOS type). Any array element, or the
103
85
  array itself, could be Qnil, indicating fall back to the default
104
86
  inferred from the GEOS type.
105
-
106
- The GEOS context handle is also included here. Ideally, it would be
107
- available by following the factory reference and getting it from the
108
- factory data. However, one use case is in the destroy_geometry_func
109
- in factory.c, and Rubinius 1.1.1 seems to crash when you try to
110
- evaluate a DATA_PTR from that function, so we copy the context handle
111
- here so the destroy_geometry_func can get to it.
112
87
  */
113
- typedef struct {
114
- GEOSContextHandle_t geos_context;
88
+ typedef struct
89
+ {
115
90
  GEOSGeometry* geom;
116
91
  const GEOSPreparedGeometry* prep;
117
92
  VALUE factory;
118
93
  VALUE klasses;
119
94
  } RGeo_GeometryData;
120
95
 
96
+ // Data types which indicate how RGeo types should be managed by Ruby.
97
+ extern const rb_data_type_t rgeo_factory_type;
98
+
99
+ extern const rb_data_type_t rgeo_geometry_type;
100
+
101
+ // Convenient macros for checking the type of data from Ruby
102
+ #define RGEO_FACTORY_TYPEDDATA_P(object) \
103
+ (_RGEO_TYPEDDATA_P(object, &rgeo_factory_type))
104
+ #define RGEO_GEOMETRY_TYPEDDATA_P(object) \
105
+ (_RGEO_TYPEDDATA_P(object, &rgeo_geometry_type))
106
+
107
+ #define _RGEO_TYPEDDATA_P(object, data_type) \
108
+ (TYPE(object) == T_DATA && RTYPEDDATA(object)->typed_flag == 1 && \
109
+ RTYPEDDATA(object)->type == data_type)
121
110
 
122
111
  // Returns the RGeo_FactoryData* given a ruby Factory object
123
- #define RGEO_FACTORY_DATA_PTR(factory) ((RGeo_FactoryData*)DATA_PTR(factory))
112
+ #define RGEO_FACTORY_DATA_PTR(factory) \
113
+ ((RGeo_FactoryData*)RTYPEDDATA_DATA(factory))
124
114
 
125
115
  // Returns the RGeo_GeometryData* given a ruby Geometry object
126
- #define RGEO_GEOMETRY_DATA_PTR(geometry) ((RGeo_GeometryData*)DATA_PTR(geometry))
127
-
116
+ #define RGEO_GEOMETRY_DATA_PTR(geometry) \
117
+ ((RGeo_GeometryData*)RTYPEDDATA_DATA(geometry))
128
118
 
129
119
  /*
130
120
  Initializes the factory module. This should be called first in the
131
121
  initialization process.
132
122
  */
133
- RGeo_Globals* rgeo_init_geos_factory();
123
+ void
124
+ rgeo_init_geos_factory();
134
125
 
135
126
  /*
136
127
  Given a GEOS geometry handle, wraps it in a ruby Geometry object of the
@@ -144,13 +135,17 @@ RGeo_Globals* rgeo_init_geos_factory();
144
135
  classes for the elements of the collection.
145
136
  Returns Qnil if the wrapping failed for any reason.
146
137
  */
147
- VALUE rgeo_wrap_geos_geometry(VALUE factory, GEOSGeometry* geom, VALUE klass);
138
+ VALUE
139
+ rgeo_wrap_geos_geometry(VALUE factory, GEOSGeometry* geom, VALUE klass);
148
140
 
149
141
  /*
150
142
  Same as rgeo_wrap_geos_geometry except that it wraps a clone of the
151
143
  given geom, so the original geom doesn't change ownership.
152
144
  */
153
- VALUE rgeo_wrap_geos_geometry_clone(VALUE factory, const GEOSGeometry* geom, VALUE klass);
145
+ VALUE
146
+ rgeo_wrap_geos_geometry_clone(VALUE factory,
147
+ const GEOSGeometry* geom,
148
+ VALUE klass);
154
149
 
155
150
  /*
156
151
  Gets the GEOS geometry for a given ruby Geometry object. If the given
@@ -159,8 +154,18 @@ VALUE rgeo_wrap_geos_geometry_clone(VALUE factory, const GEOSGeometry* geom, VAL
159
154
  specified by an appropriate feature module. Passing Qnil for the type
160
155
  disables this auto-cast. The returned GEOS geometry is owned by rgeo,
161
156
  and you should not dispose it or take ownership of it yourself.
157
+
158
+ The state parameter is given to follow `rb_protect*` ruby methods: this
159
+ method calls `#cast`, and this call may raise. if it does raise, state
160
+ will be set to a non-zero value, and you'll have access to the error
161
+ in `rb_errinfo()`. IT IS THE CALLER'S RESPONSIBILITY TO PROPAGATE THE
162
+ ERROR. You could also discard the error with `rb_set_errinfo(Qnil)`,
163
+ this will just ignore the error altogether. The error can be raised
164
+ with `rb_jump_tag(state)` which is helpful if you need to free data
165
+ before you raise the error.
162
166
  */
163
- const GEOSGeometry* rgeo_convert_to_geos_geometry(VALUE factory, VALUE obj, VALUE type);
167
+ const GEOSGeometry*
168
+ rgeo_convert_to_geos_geometry(VALUE factory, VALUE obj, VALUE type, int* state);
164
169
 
165
170
  /*
166
171
  Gets a GEOS geometry for a given ruby Geometry object. You must provide
@@ -177,50 +182,60 @@ const GEOSGeometry* rgeo_convert_to_geos_geometry(VALUE factory, VALUE obj, VALU
177
182
  result of this function to build a GEOS-backed clone of the original
178
183
  geometry, or to include the given geometry in a collection while keeping
179
184
  the klasses intact.
185
+
186
+ The state parameter is given to follow `rb_protect*` ruby methods: this
187
+ method calls `#cast`, and this call may raise. if it does raise, state
188
+ will be set to a non-zero value, and you'll have access to the error
189
+ in `rb_errinfo()`. IT IS THE CALLER'S RESPONSIBILITY TO PROPAGATE THE
190
+ ERROR. You could also discard the error with `rb_set_errinfo(Qnil)`,
191
+ this will just ignore the error altogether. The error can be raised
192
+ with `rb_jump_tag(state)` which is helpful if you need to free data
193
+ before you raise the error.
180
194
  */
181
- GEOSGeometry* rgeo_convert_to_detached_geos_geometry(VALUE obj, VALUE factory, VALUE type, VALUE* klasses);
195
+ GEOSGeometry*
196
+ rgeo_convert_to_detached_geos_geometry(VALUE obj,
197
+ VALUE factory,
198
+ VALUE type,
199
+ VALUE* klasses,
200
+ int* state);
182
201
 
183
202
  /*
184
203
  Returns 1 if the given ruby object is a GEOS Geometry implementation,
185
204
  or 0 if not.
186
205
  */
187
- char rgeo_is_geos_object(VALUE obj);
206
+ char
207
+ rgeo_is_geos_object(VALUE obj);
188
208
 
189
209
  /*
190
210
  Raises a rgeo error if the object is not a GEOS Geometry implementation.
191
211
  */
192
- void rgeo_check_geos_object(VALUE obj);
212
+ void
213
+ rgeo_check_geos_object(VALUE obj);
193
214
 
194
215
  /*
195
216
  Gets the underlying GEOS geometry for a given ruby object. Returns NULL
196
217
  if the given ruby object is not a GEOS geometry wrapper.
197
218
  */
198
- const GEOSGeometry* rgeo_get_geos_geometry_safe(VALUE obj);
199
-
200
- /*
201
- Compares the coordinate sequences for two given GEOS geometries.
202
- The two given geometries MUST be of types backed directly by
203
- coordinate sequences-- i.e. points or line strings.
204
- Returns Qtrue if the two coordinate sequences are equal, Qfalse
205
- if they are inequal, or Qnil if an error occurs.
206
- */
207
- VALUE rgeo_geos_coordseqs_eql(GEOSContextHandle_t context, const GEOSGeometry* geom1, const GEOSGeometry* geom2, char check_z);
219
+ const GEOSGeometry*
220
+ rgeo_get_geos_geometry_safe(VALUE obj);
208
221
 
209
222
  /*
210
223
  Compares the ruby classes and geometry factories of the two given ruby
211
224
  objects. Returns Qtrue if everything is equal (that is, the two objects
212
225
  are of the same type and factory), or Qfalse otherwise.
213
226
  */
214
- VALUE rgeo_geos_klasses_and_factories_eql(VALUE obj1, VALUE obj2);
227
+ VALUE
228
+ rgeo_geos_klasses_and_factories_eql(VALUE obj1, VALUE obj2);
215
229
 
216
230
  /*
217
231
  A tool for building up hash values.
218
- You must pass in the context, a geos geometry, and a seed hash.
232
+ You must pass a geos geometry and a seed hash.
219
233
  Returns an updated hash.
220
234
  This call is useful in sequence, and should be bracketed by calls to
221
235
  rb_hash_start and rb_hash_end.
222
236
  */
223
- st_index_t rgeo_geos_coordseq_hash(GEOSContextHandle_t context, const GEOSGeometry* geom, st_index_t hash);
237
+ st_index_t
238
+ rgeo_geos_coordseq_hash(const GEOSGeometry* geom, st_index_t hash);
224
239
 
225
240
  /*
226
241
  A tool for building up hash values.
@@ -229,13 +244,8 @@ st_index_t rgeo_geos_coordseq_hash(GEOSContextHandle_t context, const GEOSGeomet
229
244
  This call is useful in sequence, and should be bracketed by calls to
230
245
  rb_hash_start and rb_hash_end.
231
246
  */
232
- st_index_t rgeo_geos_objbase_hash(VALUE factory, VALUE type_module, st_index_t hash);
233
-
234
- /*
235
- Internal tool for creating simple (FNV-1A 32 bit) hashes.
236
- */
237
- st_index_t rgeo_internal_memhash(const void* ptr, long len);
238
-
247
+ st_index_t
248
+ rgeo_geos_objbase_hash(VALUE factory, VALUE type_module, st_index_t hash);
239
249
 
240
250
  RGEO_END_C
241
251