rgeo 3.0.0.pre.rc.1 → 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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -12
  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 +391 -410
  11. data/ext/geos_c_impl/factory.h +66 -48
  12. data/ext/geos_c_impl/geometry.c +417 -299
  13. data/ext/geos_c_impl/geometry.h +5 -5
  14. data/ext/geos_c_impl/geometry_collection.c +289 -213
  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 +231 -200
  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 +133 -94
  24. data/ext/geos_c_impl/polygon.h +10 -8
  25. data/ext/geos_c_impl/preface.h +8 -13
  26. data/ext/geos_c_impl/ruby_more.c +60 -0
  27. data/ext/geos_c_impl/ruby_more.h +17 -0
  28. data/lib/rgeo/cartesian/bounding_box.rb +1 -1
  29. data/lib/rgeo/cartesian/factory.rb +14 -50
  30. data/lib/rgeo/cartesian/feature_classes.rb +2 -0
  31. data/lib/rgeo/cartesian/feature_methods.rb +16 -5
  32. data/lib/rgeo/cartesian/interface.rb +6 -35
  33. data/lib/rgeo/coord_sys/cs/entities.rb +214 -0
  34. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +15 -8
  35. data/lib/rgeo/coord_sys.rb +1 -20
  36. data/lib/rgeo/feature/curve.rb +0 -10
  37. data/lib/rgeo/feature/factory.rb +1 -9
  38. data/lib/rgeo/feature/factory_generator.rb +3 -10
  39. data/lib/rgeo/feature/geometry.rb +77 -8
  40. data/lib/rgeo/feature/multi_curve.rb +0 -5
  41. data/lib/rgeo/feature/types.rb +5 -5
  42. data/lib/rgeo/geographic/factory.rb +15 -42
  43. data/lib/rgeo/geographic/interface.rb +28 -127
  44. data/lib/rgeo/geographic/projected_feature_methods.rb +16 -10
  45. data/lib/rgeo/geographic/projected_window.rb +1 -1
  46. data/lib/rgeo/geographic/{proj4_projector.rb → projector.rb} +3 -3
  47. data/lib/rgeo/geographic/simple_mercator_projector.rb +1 -10
  48. data/lib/rgeo/geographic/spherical_feature_methods.rb +17 -6
  49. data/lib/rgeo/geographic.rb +1 -1
  50. data/lib/rgeo/geos/capi_factory.rb +37 -98
  51. data/lib/rgeo/geos/capi_feature_classes.rb +15 -25
  52. data/lib/rgeo/geos/ffi_factory.rb +58 -99
  53. data/lib/rgeo/geos/ffi_feature_methods.rb +15 -29
  54. data/lib/rgeo/geos/interface.rb +5 -37
  55. data/lib/rgeo/geos/zm_factory.rb +5 -43
  56. data/lib/rgeo/geos/zm_feature_methods.rb +15 -24
  57. data/lib/rgeo/geos.rb +8 -8
  58. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +1 -14
  59. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +1 -19
  60. data/lib/rgeo/impl_helper/basic_point_methods.rb +0 -10
  61. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +1 -9
  62. data/lib/rgeo/impl_helper/utils.rb +27 -0
  63. data/lib/rgeo/impl_helper/validity_check.rb +6 -5
  64. data/lib/rgeo/version.rb +1 -1
  65. data/lib/rgeo/wkrep/wkb_generator.rb +68 -53
  66. data/lib/rgeo/wkrep/wkb_parser.rb +19 -16
  67. data/lib/rgeo/wkrep/wkt_generator.rb +34 -34
  68. data/lib/rgeo/wkrep/wkt_parser.rb +26 -23
  69. data/lib/rgeo.rb +1 -3
  70. metadata +23 -9
  71. data/lib/rgeo/coord_sys/srs_database/entry.rb +0 -107
  72. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +0 -64
  73. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +0 -65
@@ -2,28 +2,25 @@
2
2
  Line string methods for GEOS wrapper
3
3
  */
4
4
 
5
-
6
5
  #include "preface.h"
7
6
 
8
7
  #ifdef RGEO_GEOS_SUPPORTED
9
8
 
10
- #include <string.h>
11
- #include <ruby.h>
12
9
  #include <geos_c.h>
10
+ #include <ruby.h>
11
+ #include <string.h>
13
12
 
14
- #include "globals.h"
15
-
13
+ #include "coordinates.h"
16
14
  #include "factory.h"
17
15
  #include "geometry.h"
18
- #include "point.h"
16
+ #include "globals.h"
19
17
  #include "line_string.h"
20
-
21
- #include "coordinates.h"
18
+ #include "point.h"
22
19
 
23
20
  RGEO_BEGIN_C
24
21
 
25
-
26
- static VALUE method_line_string_geometry_type(VALUE self)
22
+ static VALUE
23
+ method_line_string_geometry_type(VALUE self)
27
24
  {
28
25
  VALUE result;
29
26
  RGeo_GeometryData* self_data;
@@ -36,8 +33,8 @@ static VALUE method_line_string_geometry_type(VALUE self)
36
33
  return result;
37
34
  }
38
35
 
39
-
40
- static VALUE method_linear_ring_geometry_type(VALUE self)
36
+ static VALUE
37
+ method_linear_ring_geometry_type(VALUE self)
41
38
  {
42
39
  VALUE result;
43
40
  RGeo_GeometryData* self_data;
@@ -50,8 +47,8 @@ static VALUE method_linear_ring_geometry_type(VALUE self)
50
47
  return result;
51
48
  }
52
49
 
53
-
54
- static VALUE method_line_geometry_type(VALUE self)
50
+ static VALUE
51
+ method_line_geometry_type(VALUE self)
55
52
  {
56
53
  VALUE result;
57
54
  RGeo_GeometryData* self_data;
@@ -64,8 +61,8 @@ static VALUE method_line_geometry_type(VALUE self)
64
61
  return result;
65
62
  }
66
63
 
67
-
68
- static VALUE method_line_string_length(VALUE self)
64
+ static VALUE
65
+ method_line_string_length(VALUE self)
69
66
  {
70
67
  VALUE result;
71
68
  RGeo_GeometryData* self_data;
@@ -76,15 +73,15 @@ static VALUE method_line_string_length(VALUE self)
76
73
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
77
74
  self_geom = self_data->geom;
78
75
  if (self_geom) {
79
- if (GEOSLength_r(self_data->geos_context, self_geom, &len)) {
76
+ if (GEOSLength(self_geom, &len)) {
80
77
  result = rb_float_new(len);
81
78
  }
82
79
  }
83
80
  return result;
84
81
  }
85
82
 
86
-
87
- static VALUE method_line_string_num_points(VALUE self)
83
+ static VALUE
84
+ method_line_string_num_points(VALUE self)
88
85
  {
89
86
  VALUE result;
90
87
  RGeo_GeometryData* self_data;
@@ -94,13 +91,13 @@ static VALUE method_line_string_num_points(VALUE self)
94
91
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
95
92
  self_geom = self_data->geom;
96
93
  if (self_geom) {
97
- result = INT2NUM(GEOSGetNumCoordinates_r(self_data->geos_context, self_geom));
94
+ result = INT2NUM(GEOSGetNumCoordinates(self_geom));
98
95
  }
99
96
  return result;
100
97
  }
101
98
 
102
-
103
- static VALUE method_line_string_coordinates(VALUE self)
99
+ static VALUE
100
+ method_line_string_coordinates(VALUE self)
104
101
  {
105
102
  VALUE result;
106
103
  RGeo_GeometryData* self_data;
@@ -108,43 +105,41 @@ static VALUE method_line_string_coordinates(VALUE self)
108
105
  const GEOSCoordSequence* coord_sequence;
109
106
  int zCoordinate;
110
107
 
111
- GEOSContextHandle_t context;
112
-
113
108
  result = Qnil;
114
109
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
115
110
  self_geom = self_data->geom;
116
111
 
117
112
  if (self_geom) {
118
- zCoordinate = RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M;
119
- context = self_data->geos_context;
120
- coord_sequence = GEOSGeom_getCoordSeq_r(context, self_geom);
121
- if(coord_sequence) {
122
- result = extract_points_from_coordinate_sequence(context, coord_sequence, zCoordinate);
113
+ zCoordinate = RGEO_FACTORY_DATA_PTR(self_data->factory)->flags &
114
+ RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M;
115
+ coord_sequence = GEOSGeom_getCoordSeq(self_geom);
116
+ if (coord_sequence) {
117
+ result =
118
+ extract_points_from_coordinate_sequence(coord_sequence, zCoordinate);
123
119
  }
124
120
  }
125
121
  return result;
126
122
  }
127
123
 
128
-
129
-
130
- static VALUE get_point_from_coordseq(VALUE self, const GEOSCoordSequence* coord_seq, unsigned int i, char has_z)
124
+ static VALUE
125
+ get_point_from_coordseq(VALUE self,
126
+ const GEOSCoordSequence* coord_seq,
127
+ unsigned int i,
128
+ char has_z)
131
129
  {
132
130
  VALUE result;
133
131
  RGeo_GeometryData* self_data;
134
- GEOSContextHandle_t self_context;
135
132
  double x, y, z;
136
133
 
137
134
  result = Qnil;
138
135
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
139
- self_context = self_data->geos_context;
140
- if (GEOSCoordSeq_getX_r(self_context, coord_seq, i, &x)) {
141
- if (GEOSCoordSeq_getY_r(self_context, coord_seq, i, &y)) {
136
+ if (GEOSCoordSeq_getX(coord_seq, i, &x)) {
137
+ if (GEOSCoordSeq_getY(coord_seq, i, &y)) {
142
138
  if (has_z) {
143
- if (!GEOSCoordSeq_getZ_r(self_context, coord_seq, i, &z)) {
139
+ if (!GEOSCoordSeq_getZ(coord_seq, i, &z)) {
144
140
  z = 0.0;
145
141
  }
146
- }
147
- else {
142
+ } else {
148
143
  z = 0.0;
149
144
  }
150
145
  result = rgeo_create_geos_point(self_data->factory, x, y, z);
@@ -153,13 +148,12 @@ static VALUE get_point_from_coordseq(VALUE self, const GEOSCoordSequence* coord_
153
148
  return result;
154
149
  }
155
150
 
156
-
157
- static VALUE method_line_string_point_n(VALUE self, VALUE n)
151
+ static VALUE
152
+ method_line_string_point_n(VALUE self, VALUE n)
158
153
  {
159
154
  VALUE result;
160
155
  RGeo_GeometryData* self_data;
161
156
  const GEOSGeometry* self_geom;
162
- GEOSContextHandle_t self_context;
163
157
  const GEOSCoordSequence* coord_seq;
164
158
  char has_z;
165
159
  int si;
@@ -170,14 +164,14 @@ static VALUE method_line_string_point_n(VALUE self, VALUE n)
170
164
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
171
165
  self_geom = self_data->geom;
172
166
  if (self_geom) {
173
- self_context = self_data->geos_context;
174
- coord_seq = GEOSGeom_getCoordSeq_r(self_context, self_geom);
167
+ coord_seq = GEOSGeom_getCoordSeq(self_geom);
175
168
  if (coord_seq) {
176
- has_z = (char)(RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
177
- si = NUM2INT(n);
169
+ has_z = (char)(RGEO_FACTORY_DATA_PTR(self_data->factory)->flags &
170
+ RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
171
+ si = RB_NUM2INT(n);
178
172
  if (si >= 0) {
179
173
  i = si;
180
- if (GEOSCoordSeq_getSize_r(self_context, coord_seq, &size)) {
174
+ if (GEOSCoordSeq_getSize(coord_seq, &size)) {
181
175
  if (i < size) {
182
176
  result = get_point_from_coordseq(self, coord_seq, i, has_z);
183
177
  }
@@ -188,13 +182,12 @@ static VALUE method_line_string_point_n(VALUE self, VALUE n)
188
182
  return result;
189
183
  }
190
184
 
191
-
192
- static VALUE method_line_string_points(VALUE self)
185
+ static VALUE
186
+ method_line_string_points(VALUE self)
193
187
  {
194
188
  VALUE result;
195
189
  RGeo_GeometryData* self_data;
196
190
  const GEOSGeometry* self_geom;
197
- GEOSContextHandle_t self_context;
198
191
  const GEOSCoordSequence* coord_seq;
199
192
  char has_z;
200
193
  unsigned int size;
@@ -205,13 +198,13 @@ static VALUE method_line_string_points(VALUE self)
205
198
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
206
199
  self_geom = self_data->geom;
207
200
  if (self_geom) {
208
- self_context = self_data->geos_context;
209
- coord_seq = GEOSGeom_getCoordSeq_r(self_context, self_geom);
201
+ coord_seq = GEOSGeom_getCoordSeq(self_geom);
210
202
  if (coord_seq) {
211
- has_z = (char)(RGEO_FACTORY_DATA_PTR(self_data->factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
212
- if (GEOSCoordSeq_getSize_r(self_context, coord_seq, &size)) {
203
+ has_z = (char)(RGEO_FACTORY_DATA_PTR(self_data->factory)->flags &
204
+ RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
205
+ if (GEOSCoordSeq_getSize(coord_seq, &size)) {
213
206
  result = rb_ary_new2(size);
214
- for (i=0; i<size; ++i) {
207
+ for (i = 0; i < size; ++i) {
215
208
  point = get_point_from_coordseq(self, coord_seq, i, has_z);
216
209
  if (!NIL_P(point)) {
217
210
  rb_ary_store(result, i, point);
@@ -223,14 +216,14 @@ static VALUE method_line_string_points(VALUE self)
223
216
  return result;
224
217
  }
225
218
 
226
-
227
- static VALUE method_line_string_start_point(VALUE self)
219
+ static VALUE
220
+ method_line_string_start_point(VALUE self)
228
221
  {
229
222
  return method_line_string_point_n(self, INT2NUM(0));
230
223
  }
231
224
 
232
-
233
- static VALUE method_line_string_end_point(VALUE self)
225
+ static VALUE
226
+ method_line_string_end_point(VALUE self)
234
227
  {
235
228
  VALUE result;
236
229
  RGeo_GeometryData* self_data;
@@ -241,41 +234,41 @@ static VALUE method_line_string_end_point(VALUE self)
241
234
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
242
235
  self_geom = self_data->geom;
243
236
  if (self_geom) {
244
- n = GEOSGetNumCoordinates_r(self_data->geos_context, self_geom);
237
+ n = GEOSGetNumCoordinates(self_geom);
245
238
  if (n > 0) {
246
- result = method_line_string_point_n(self, INT2NUM(n-1));
239
+ result = method_line_string_point_n(self, INT2NUM(n - 1));
247
240
  }
248
241
  }
249
242
  return result;
250
243
  }
251
244
 
252
- static VALUE method_line_string_project_point(VALUE self, VALUE point)
245
+ static VALUE
246
+ method_line_string_project_point(VALUE self, VALUE point)
253
247
  {
254
- RGeo_FactoryData* factory_data;
255
248
  VALUE result = Qnil;
256
249
  VALUE factory;
257
250
  RGeo_GeometryData* self_data;
258
251
  const GEOSGeometry* self_geom;
259
- const GEOSGeometry *geos_point;
252
+ const GEOSGeometry* geos_point;
260
253
 
261
254
  double location;
262
255
 
263
256
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
264
257
  factory = self_data->factory;
265
258
  self_geom = self_data->geom;
266
- factory_data = RGEO_FACTORY_DATA_PTR(factory);
267
259
 
268
- if(self_geom && point) {
269
- geos_point = rgeo_convert_to_geos_geometry(factory, point, rgeo_geos_point_class);
270
- location = GEOSProject_r(self_data->geos_context, self_geom, geos_point);
260
+ if (self_geom && point) {
261
+ geos_point =
262
+ rgeo_convert_to_geos_geometry(factory, point, rgeo_geos_point_class);
263
+ location = GEOSProject(self_geom, geos_point);
271
264
  result = DBL2NUM(location);
272
265
  }
273
266
  return result;
274
267
  }
275
268
 
276
- static VALUE method_line_string_interpolate_point(VALUE self, VALUE loc_num)
269
+ static VALUE
270
+ method_line_string_interpolate_point(VALUE self, VALUE loc_num)
277
271
  {
278
- RGeo_FactoryData* factory_data;
279
272
  VALUE result = Qnil;
280
273
  VALUE factory;
281
274
  RGeo_GeometryData* self_data;
@@ -287,18 +280,19 @@ static VALUE method_line_string_interpolate_point(VALUE self, VALUE loc_num)
287
280
  location = NUM2DBL(loc_num);
288
281
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
289
282
  factory = self_data->factory;
290
- factory_data = RGEO_FACTORY_DATA_PTR(factory);
291
283
  self_geom = self_data->geom;
292
284
 
293
- if(self_geom) {
294
- geos_point = GEOSInterpolate_r(self_data->geos_context, self_geom, location);
295
- result = rgeo_wrap_geos_geometry(factory, geos_point, rgeo_geos_point_class);
285
+ if (self_geom) {
286
+ geos_point = GEOSInterpolate(self_geom, location);
287
+ result =
288
+ rgeo_wrap_geos_geometry(factory, geos_point, rgeo_geos_point_class);
296
289
  }
297
290
 
298
291
  return result;
299
292
  }
300
293
 
301
- static VALUE method_line_string_is_closed(VALUE self)
294
+ static VALUE
295
+ method_line_string_is_closed(VALUE self)
302
296
  {
303
297
  VALUE result;
304
298
  RGeo_GeometryData* self_data;
@@ -308,13 +302,13 @@ static VALUE method_line_string_is_closed(VALUE self)
308
302
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
309
303
  self_geom = self_data->geom;
310
304
  if (self_geom) {
311
- result = rgeo_is_geos_line_string_closed(self_data->geos_context, self_geom);
305
+ result = rgeo_is_geos_line_string_closed(self_geom);
312
306
  }
313
307
  return result;
314
308
  }
315
309
 
316
-
317
- static VALUE method_line_string_is_ring(VALUE self)
310
+ static VALUE
311
+ method_line_string_is_ring(VALUE self)
318
312
  {
319
313
  VALUE result;
320
314
  RGeo_GeometryData* self_data;
@@ -325,19 +319,18 @@ static VALUE method_line_string_is_ring(VALUE self)
325
319
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
326
320
  self_geom = self_data->geom;
327
321
  if (self_geom) {
328
- val = GEOSisRing_r(self_data->geos_context, self_geom);
322
+ val = GEOSisRing(self_geom);
329
323
  if (val == 0) {
330
324
  result = Qfalse;
331
- }
332
- else if (val == 1) {
325
+ } else if (val == 1) {
333
326
  result = Qtrue;
334
327
  }
335
328
  }
336
329
  return result;
337
330
  }
338
331
 
339
-
340
- static VALUE method_line_string_eql(VALUE self, VALUE rhs)
332
+ static VALUE
333
+ method_line_string_eql(VALUE self, VALUE rhs)
341
334
  {
342
335
  VALUE result;
343
336
  RGeo_GeometryData* self_data;
@@ -345,13 +338,14 @@ static VALUE method_line_string_eql(VALUE self, VALUE rhs)
345
338
  result = rgeo_geos_klasses_and_factories_eql(self, rhs);
346
339
  if (RTEST(result)) {
347
340
  self_data = RGEO_GEOMETRY_DATA_PTR(self);
348
- result = rgeo_geos_geometries_strict_eql(self_data->geos_context, self_data->geom, RGEO_GEOMETRY_DATA_PTR(rhs)->geom);
341
+ result = rgeo_geos_geometries_strict_eql(self_data->geom,
342
+ RGEO_GEOMETRY_DATA_PTR(rhs)->geom);
349
343
  }
350
344
  return result;
351
345
  }
352
346
 
353
-
354
- static VALUE method_line_string_hash(VALUE self)
347
+ static VALUE
348
+ method_line_string_hash(VALUE self)
355
349
  {
356
350
  st_index_t hash;
357
351
  RGeo_GeometryData* self_data;
@@ -361,12 +355,12 @@ static VALUE method_line_string_hash(VALUE self)
361
355
  factory = self_data->factory;
362
356
  hash = rb_hash_start(0);
363
357
  hash = rgeo_geos_objbase_hash(factory, rgeo_feature_line_string_module, hash);
364
- hash = rgeo_geos_coordseq_hash(self_data->geos_context, self_data->geom, hash);
358
+ hash = rgeo_geos_coordseq_hash(self_data->geom, hash);
365
359
  return LONG2FIX(rb_hash_end(hash));
366
360
  }
367
361
 
368
-
369
- static VALUE method_linear_ring_hash(VALUE self)
362
+ static VALUE
363
+ method_linear_ring_hash(VALUE self)
370
364
  {
371
365
  st_index_t hash;
372
366
  RGeo_GeometryData* self_data;
@@ -376,12 +370,12 @@ static VALUE method_linear_ring_hash(VALUE self)
376
370
  factory = self_data->factory;
377
371
  hash = rb_hash_start(0);
378
372
  hash = rgeo_geos_objbase_hash(factory, rgeo_feature_linear_ring_module, hash);
379
- hash = rgeo_geos_coordseq_hash(self_data->geos_context, self_data->geom, hash);
373
+ hash = rgeo_geos_coordseq_hash(self_data->geom, hash);
380
374
  return LONG2FIX(rb_hash_end(hash));
381
375
  }
382
376
 
383
-
384
- static VALUE method_line_hash(VALUE self)
377
+ static VALUE
378
+ method_line_hash(VALUE self)
385
379
  {
386
380
  st_index_t hash;
387
381
  RGeo_GeometryData* self_data;
@@ -391,12 +385,12 @@ static VALUE method_line_hash(VALUE self)
391
385
  factory = self_data->factory;
392
386
  hash = rb_hash_start(0);
393
387
  hash = rgeo_geos_objbase_hash(factory, rgeo_feature_line_module, hash);
394
- hash = rgeo_geos_coordseq_hash(self_data->geos_context, self_data->geom, hash);
388
+ hash = rgeo_geos_coordseq_hash(self_data->geom, hash);
395
389
  return LONG2FIX(rb_hash_end(hash));
396
390
  }
397
391
 
398
-
399
- static GEOSCoordSequence* coord_seq_from_array(VALUE factory, VALUE array, char close)
392
+ static GEOSCoordSequence*
393
+ coord_seq_from_array(VALUE factory, VALUE array, char close)
400
394
  {
401
395
  RGeo_FactoryData* factory_data;
402
396
  VALUE point_type;
@@ -404,7 +398,6 @@ static GEOSCoordSequence* coord_seq_from_array(VALUE factory, VALUE array, char
404
398
  char has_z;
405
399
  unsigned int dims;
406
400
  double* coords;
407
- GEOSContextHandle_t context;
408
401
  unsigned int i;
409
402
  char good;
410
403
  const GEOSGeometry* entry_geom;
@@ -416,29 +409,29 @@ static GEOSCoordSequence* coord_seq_from_array(VALUE factory, VALUE array, char
416
409
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
417
410
  point_type = rgeo_feature_point_module;
418
411
  len = (unsigned int)RARRAY_LEN(array);
419
- has_z = (char)(RGEO_FACTORY_DATA_PTR(factory)->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
412
+ has_z = (char)(RGEO_FACTORY_DATA_PTR(factory)->flags &
413
+ RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
420
414
  dims = has_z ? 3 : 2;
421
415
  coords = ALLOC_N(double, len == 0 ? 1 : len * dims);
422
416
  if (!coords) {
423
417
  return NULL;
424
418
  }
425
- context = factory_data->geos_context;
426
- for (i=0; i<len; ++i) {
419
+ for (i = 0; i < len; ++i) {
427
420
  good = 0;
428
- entry_geom = rgeo_convert_to_geos_geometry(factory, rb_ary_entry(array, i), point_type);
421
+ entry_geom = rgeo_convert_to_geos_geometry(
422
+ factory, rb_ary_entry(array, i), point_type);
429
423
  if (entry_geom) {
430
- entry_cs = GEOSGeom_getCoordSeq_r(context, entry_geom);
424
+ entry_cs = GEOSGeom_getCoordSeq(entry_geom);
431
425
  if (entry_cs) {
432
- if (GEOSCoordSeq_getX_r(context, entry_cs, 0, &x)) {
433
- coords[i*dims] = x;
434
- if (GEOSCoordSeq_getY_r(context, entry_cs, 0, &x)) {
435
- coords[i*dims+1] = x;
426
+ if (GEOSCoordSeq_getX(entry_cs, 0, &x)) {
427
+ coords[i * dims] = x;
428
+ if (GEOSCoordSeq_getY(entry_cs, 0, &x)) {
429
+ coords[i * dims + 1] = x;
436
430
  good = 1;
437
431
  if (has_z) {
438
- if (GEOSCoordSeq_getZ_r(context, entry_cs, 0, &x)) {
439
- coords[i*dims+2] = x;
440
- }
441
- else {
432
+ if (GEOSCoordSeq_getZ(entry_cs, 0, &x)) {
433
+ coords[i * dims + 2] = x;
434
+ } else {
442
435
  good = 0;
443
436
  }
444
437
  }
@@ -447,37 +440,37 @@ static GEOSCoordSequence* coord_seq_from_array(VALUE factory, VALUE array, char
447
440
  }
448
441
  }
449
442
  if (!good) {
450
- free(coords);
443
+ FREE(coords);
451
444
  return NULL;
452
445
  }
453
446
  }
454
447
  if (len > 0 && close) {
455
- if (coords[0] == coords[(len-1)*dims] && coords[1] == coords[(len-1)*dims+1]) {
448
+ if (coords[0] == coords[(len - 1) * dims] &&
449
+ coords[1] == coords[(len - 1) * dims + 1]) {
456
450
  close = 0;
457
451
  }
458
- }
459
- else {
452
+ } else {
460
453
  close = 0;
461
454
  }
462
- coord_seq = GEOSCoordSeq_create_r(context, len + close, 3);
455
+ coord_seq = GEOSCoordSeq_create(len + close, 3);
463
456
  if (coord_seq) {
464
- for (i=0; i<len; ++i) {
465
- GEOSCoordSeq_setX_r(context, coord_seq, i, coords[i*dims]);
466
- GEOSCoordSeq_setY_r(context, coord_seq, i, coords[i*dims+1]);
467
- GEOSCoordSeq_setZ_r(context, coord_seq, i, has_z ? coords[i*dims+2] : 0);
457
+ for (i = 0; i < len; ++i) {
458
+ GEOSCoordSeq_setX(coord_seq, i, coords[i * dims]);
459
+ GEOSCoordSeq_setY(coord_seq, i, coords[i * dims + 1]);
460
+ GEOSCoordSeq_setZ(coord_seq, i, has_z ? coords[i * dims + 2] : 0);
468
461
  }
469
462
  if (close) {
470
- GEOSCoordSeq_setX_r(context, coord_seq, len, coords[0]);
471
- GEOSCoordSeq_setY_r(context, coord_seq, len, coords[1]);
472
- GEOSCoordSeq_setZ_r(context, coord_seq, len, has_z ? coords[2] : 0);
463
+ GEOSCoordSeq_setX(coord_seq, len, coords[0]);
464
+ GEOSCoordSeq_setY(coord_seq, len, coords[1]);
465
+ GEOSCoordSeq_setZ(coord_seq, len, has_z ? coords[2] : 0);
473
466
  }
474
467
  }
475
- free(coords);
468
+ FREE(coords);
476
469
  return coord_seq;
477
470
  }
478
471
 
479
-
480
- static VALUE cmethod_create_line_string(VALUE module, VALUE factory, VALUE array)
472
+ static VALUE
473
+ cmethod_create_line_string(VALUE module, VALUE factory, VALUE array)
481
474
  {
482
475
  VALUE result;
483
476
  GEOSCoordSequence* coord_seq;
@@ -488,16 +481,17 @@ static VALUE cmethod_create_line_string(VALUE module, VALUE factory, VALUE array
488
481
  coord_seq = coord_seq_from_array(factory, array, 0);
489
482
  if (coord_seq) {
490
483
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
491
- geom = GEOSGeom_createLineString_r(factory_data->geos_context, coord_seq);
484
+ geom = GEOSGeom_createLineString(coord_seq);
492
485
  if (geom) {
493
- result = rgeo_wrap_geos_geometry(factory, geom, rgeo_geos_line_string_class);
486
+ result =
487
+ rgeo_wrap_geos_geometry(factory, geom, rgeo_geos_line_string_class);
494
488
  }
495
489
  }
496
490
  return result;
497
491
  }
498
492
 
499
-
500
- static VALUE cmethod_create_linear_ring(VALUE module, VALUE factory, VALUE array)
493
+ static VALUE
494
+ cmethod_create_linear_ring(VALUE module, VALUE factory, VALUE array)
501
495
  {
502
496
  VALUE result;
503
497
  GEOSCoordSequence* coord_seq;
@@ -508,46 +502,49 @@ static VALUE cmethod_create_linear_ring(VALUE module, VALUE factory, VALUE array
508
502
  coord_seq = coord_seq_from_array(factory, array, 1);
509
503
  if (coord_seq) {
510
504
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
511
- geom = GEOSGeom_createLinearRing_r(factory_data->geos_context, coord_seq);
505
+ geom = GEOSGeom_createLinearRing(coord_seq);
512
506
  if (geom) {
513
- result = rgeo_wrap_geos_geometry(factory, geom, rgeo_geos_linear_ring_class);
507
+ result =
508
+ rgeo_wrap_geos_geometry(factory, geom, rgeo_geos_linear_ring_class);
514
509
  }
515
510
  }
516
511
  return result;
517
512
  }
518
513
 
519
-
520
- static void populate_geom_into_coord_seq(GEOSContextHandle_t context, const GEOSGeometry* geom, GEOSCoordSequence* coord_seq, unsigned int i, char has_z)
514
+ static void
515
+ populate_geom_into_coord_seq(const GEOSGeometry* geom,
516
+ GEOSCoordSequence* coord_seq,
517
+ unsigned int i,
518
+ char has_z)
521
519
  {
522
520
  const GEOSCoordSequence* cs;
523
521
  double x;
524
522
 
525
- cs = GEOSGeom_getCoordSeq_r(context, geom);
523
+ cs = GEOSGeom_getCoordSeq(geom);
526
524
  x = 0;
527
525
  if (cs) {
528
- GEOSCoordSeq_getX_r(context, cs, 0, &x);
526
+ GEOSCoordSeq_getX(cs, 0, &x);
529
527
  }
530
- GEOSCoordSeq_setX_r(context, coord_seq, i, x);
528
+ GEOSCoordSeq_setX(coord_seq, i, x);
531
529
  x = 0;
532
530
  if (cs) {
533
- GEOSCoordSeq_getY_r(context, cs, 0, &x);
531
+ GEOSCoordSeq_getY(cs, 0, &x);
534
532
  }
535
- GEOSCoordSeq_setY_r(context, coord_seq, i, x);
533
+ GEOSCoordSeq_setY(coord_seq, i, x);
536
534
  x = 0;
537
535
  if (has_z && cs) {
538
- GEOSCoordSeq_getZ_r(context, cs, 0, &x);
536
+ GEOSCoordSeq_getZ(cs, 0, &x);
539
537
  }
540
- GEOSCoordSeq_setZ_r(context, coord_seq, i, x);
538
+ GEOSCoordSeq_setZ(coord_seq, i, x);
541
539
  }
542
540
 
543
-
544
- static VALUE cmethod_create_line(VALUE module, VALUE factory, VALUE start, VALUE end)
541
+ static VALUE
542
+ cmethod_create_line(VALUE module, VALUE factory, VALUE start, VALUE end)
545
543
  {
546
544
  VALUE result;
547
545
  RGeo_FactoryData* factory_data;
548
546
  char has_z;
549
547
  VALUE point_type;
550
- GEOSContextHandle_t context;
551
548
  const GEOSGeometry* start_geom;
552
549
  const GEOSGeometry* end_geom;
553
550
  GEOSCoordSequence* coord_seq;
@@ -557,17 +554,16 @@ static VALUE cmethod_create_line(VALUE module, VALUE factory, VALUE start, VALUE
557
554
  factory_data = RGEO_FACTORY_DATA_PTR(factory);
558
555
  has_z = (char)(factory_data->flags & RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M);
559
556
  point_type = rgeo_feature_point_module;
560
- context = factory_data->geos_context;
561
557
 
562
558
  start_geom = rgeo_convert_to_geos_geometry(factory, start, point_type);
563
559
  if (start_geom) {
564
560
  end_geom = rgeo_convert_to_geos_geometry(factory, end, point_type);
565
561
  if (end_geom) {
566
- coord_seq = GEOSCoordSeq_create_r(context, 2, 3);
562
+ coord_seq = GEOSCoordSeq_create(2, 3);
567
563
  if (coord_seq) {
568
- populate_geom_into_coord_seq(context, start_geom, coord_seq, 0, has_z);
569
- populate_geom_into_coord_seq(context, end_geom, coord_seq, 1, has_z);
570
- geom = GEOSGeom_createLineString_r(context, coord_seq);
564
+ populate_geom_into_coord_seq(start_geom, coord_seq, 0, has_z);
565
+ populate_geom_into_coord_seq(end_geom, coord_seq, 1, has_z);
566
+ geom = GEOSGeom_createLineString(coord_seq);
571
567
  if (geom) {
572
568
  result = rgeo_wrap_geos_geometry(factory, geom, rgeo_geos_line_class);
573
569
  }
@@ -578,12 +574,11 @@ static VALUE cmethod_create_line(VALUE module, VALUE factory, VALUE start, VALUE
578
574
  return result;
579
575
  }
580
576
 
581
-
582
- static VALUE impl_copy_from(VALUE klass, VALUE factory, VALUE original, char subtype)
577
+ static VALUE
578
+ impl_copy_from(VALUE klass, VALUE factory, VALUE original, char subtype)
583
579
  {
584
580
  VALUE result;
585
581
  const GEOSGeometry* original_geom;
586
- GEOSContextHandle_t context;
587
582
  const GEOSCoordSequence* original_coord_seq;
588
583
  GEOSCoordSequence* coord_seq;
589
584
  GEOSGeometry* geom;
@@ -591,16 +586,16 @@ static VALUE impl_copy_from(VALUE klass, VALUE factory, VALUE original, char sub
591
586
  result = Qnil;
592
587
  original_geom = RGEO_GEOMETRY_DATA_PTR(original)->geom;
593
588
  if (original_geom) {
594
- context = RGEO_FACTORY_DATA_PTR(factory)->geos_context;
595
- if (subtype == 1 && GEOSGetNumCoordinates_r(context, original_geom) != 2) {
589
+ if (subtype == 1 && GEOSGetNumCoordinates(original_geom) != 2) {
596
590
  original_geom = NULL;
597
591
  }
598
592
  if (original_geom) {
599
- original_coord_seq = GEOSGeom_getCoordSeq_r(context, original_geom);
593
+ original_coord_seq = GEOSGeom_getCoordSeq(original_geom);
600
594
  if (original_coord_seq) {
601
- coord_seq = GEOSCoordSeq_clone_r(context, original_coord_seq);
595
+ coord_seq = GEOSCoordSeq_clone(original_coord_seq);
602
596
  if (coord_seq) {
603
- geom = subtype == 2 ? GEOSGeom_createLinearRing_r(context, coord_seq) : GEOSGeom_createLineString_r(context, coord_seq);
597
+ geom = subtype == 2 ? GEOSGeom_createLinearRing(coord_seq)
598
+ : GEOSGeom_createLineString(coord_seq);
604
599
  if (geom) {
605
600
  result = rgeo_wrap_geos_geometry(factory, geom, klass);
606
601
  }
@@ -611,74 +606,112 @@ static VALUE impl_copy_from(VALUE klass, VALUE factory, VALUE original, char sub
611
606
  return result;
612
607
  }
613
608
 
614
-
615
- static VALUE cmethod_line_string_copy_from(VALUE klass, VALUE factory, VALUE original)
609
+ static VALUE
610
+ cmethod_line_string_copy_from(VALUE klass, VALUE factory, VALUE original)
616
611
  {
617
612
  return impl_copy_from(klass, factory, original, 0);
618
613
  }
619
614
 
620
-
621
- static VALUE cmethod_line_copy_from(VALUE klass, VALUE factory, VALUE original)
615
+ static VALUE
616
+ cmethod_line_copy_from(VALUE klass, VALUE factory, VALUE original)
622
617
  {
623
618
  return impl_copy_from(klass, factory, original, 1);
624
619
  }
625
620
 
626
-
627
- static VALUE cmethod_linear_ring_copy_from(VALUE klass, VALUE factory, VALUE original)
621
+ static VALUE
622
+ cmethod_linear_ring_copy_from(VALUE klass, VALUE factory, VALUE original)
628
623
  {
629
624
  return impl_copy_from(klass, factory, original, 2);
630
625
  }
631
626
 
632
-
633
- void rgeo_init_geos_line_string()
627
+ void
628
+ rgeo_init_geos_line_string()
634
629
  {
635
630
  VALUE geos_line_string_methods;
636
631
  VALUE geos_linear_ring_methods;
637
632
  VALUE geos_line_methods;
638
633
 
639
634
  // Class methods for CAPILineStringImpl
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);
635
+ rb_define_module_function(
636
+ rgeo_geos_line_string_class, "create", cmethod_create_line_string, 2);
637
+ rb_define_module_function(rgeo_geos_line_string_class,
638
+ "_copy_from",
639
+ cmethod_line_string_copy_from,
640
+ 2);
642
641
 
643
642
  // Class methods for CAPILinearRingImpl
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);
643
+ rb_define_module_function(
644
+ rgeo_geos_linear_ring_class, "create", cmethod_create_linear_ring, 2);
645
+ rb_define_module_function(rgeo_geos_linear_ring_class,
646
+ "_copy_from",
647
+ cmethod_linear_ring_copy_from,
648
+ 2);
646
649
 
647
650
  // Class methods for CAPILineImpl
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
+ rb_define_module_function(
652
+ rgeo_geos_line_class, "create", cmethod_create_line, 3);
653
+ rb_define_module_function(
654
+ rgeo_geos_line_class, "_copy_from", cmethod_line_copy_from, 2);
650
655
 
651
656
  // CAPILineStringMethods module
652
- geos_line_string_methods = rb_define_module_under(rgeo_geos_module, "CAPILineStringMethods");
653
- rb_define_method(geos_line_string_methods, "rep_equals?", method_line_string_eql, 1);
657
+ geos_line_string_methods =
658
+ rb_define_module_under(rgeo_geos_module, "CAPILineStringMethods");
659
+ rb_define_method(
660
+ geos_line_string_methods, "rep_equals?", method_line_string_eql, 1);
654
661
  rb_define_method(geos_line_string_methods, "eql?", method_line_string_eql, 1);
655
- rb_define_method(geos_line_string_methods, "hash", method_line_string_hash, 0);
656
- rb_define_method(geos_line_string_methods, "geometry_type", method_line_string_geometry_type, 0);
657
- rb_define_method(geos_line_string_methods, "length", method_line_string_length, 0);
658
- rb_define_method(geos_line_string_methods, "num_points", method_line_string_num_points, 0);
659
- rb_define_method(geos_line_string_methods, "point_n", method_line_string_point_n, 1);
660
- rb_define_method(geos_line_string_methods, "points", method_line_string_points, 0);
661
- rb_define_method(geos_line_string_methods, "start_point", method_line_string_start_point, 0);
662
- rb_define_method(geos_line_string_methods, "end_point", method_line_string_end_point, 0);
663
- rb_define_method(geos_line_string_methods, "project_point", method_line_string_project_point, 1);
664
- rb_define_method(geos_line_string_methods, "interpolate_point", method_line_string_interpolate_point, 1);
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);
667
- rb_define_method(geos_line_string_methods, "coordinates", method_line_string_coordinates, 0);
662
+ rb_define_method(
663
+ geos_line_string_methods, "hash", method_line_string_hash, 0);
664
+ rb_define_method(geos_line_string_methods,
665
+ "geometry_type",
666
+ method_line_string_geometry_type,
667
+ 0);
668
+ rb_define_method(
669
+ geos_line_string_methods, "length", method_line_string_length, 0);
670
+ rb_define_method(
671
+ geos_line_string_methods, "num_points", method_line_string_num_points, 0);
672
+ rb_define_method(
673
+ geos_line_string_methods, "point_n", method_line_string_point_n, 1);
674
+ rb_define_method(
675
+ geos_line_string_methods, "points", method_line_string_points, 0);
676
+ rb_define_method(
677
+ geos_line_string_methods, "start_point", method_line_string_start_point, 0);
678
+ rb_define_method(
679
+ geos_line_string_methods, "end_point", method_line_string_end_point, 0);
680
+ rb_define_method(geos_line_string_methods,
681
+ "project_point",
682
+ method_line_string_project_point,
683
+ 1);
684
+ rb_define_method(geos_line_string_methods,
685
+ "interpolate_point",
686
+ method_line_string_interpolate_point,
687
+ 1);
688
+ rb_define_method(
689
+ geos_line_string_methods, "closed?", method_line_string_is_closed, 0);
690
+ rb_define_method(
691
+ geos_line_string_methods, "ring?", method_line_string_is_ring, 0);
692
+ rb_define_method(
693
+ geos_line_string_methods, "coordinates", method_line_string_coordinates, 0);
668
694
 
669
695
  // CAPILinearRingMethods module
670
- geos_linear_ring_methods = rb_define_module_under(rgeo_geos_module, "CAPILinearRingMethods");
671
- rb_define_method(geos_linear_ring_methods, "geometry_type", method_linear_ring_geometry_type, 0);
672
- rb_define_method(geos_linear_ring_methods, "hash", method_linear_ring_hash, 0);
696
+ geos_linear_ring_methods =
697
+ rb_define_module_under(rgeo_geos_module, "CAPILinearRingMethods");
698
+ rb_define_method(geos_linear_ring_methods,
699
+ "geometry_type",
700
+ method_linear_ring_geometry_type,
701
+ 0);
702
+ rb_define_method(
703
+ geos_linear_ring_methods, "hash", method_linear_ring_hash, 0);
673
704
 
674
705
  // CAPILineMethods module
675
- geos_line_methods = rb_define_module_under(rgeo_geos_module, "CAPILineMethods");
676
- rb_define_method(geos_line_methods, "geometry_type", method_line_geometry_type, 0);
706
+ geos_line_methods =
707
+ rb_define_module_under(rgeo_geos_module, "CAPILineMethods");
708
+ rb_define_method(
709
+ geos_line_methods, "geometry_type", method_line_geometry_type, 0);
677
710
  rb_define_method(geos_line_methods, "hash", method_line_hash, 0);
678
711
  }
679
712
 
680
-
681
- VALUE rgeo_is_geos_line_string_closed(GEOSContextHandle_t context, const GEOSGeometry* geom)
713
+ VALUE
714
+ rgeo_is_geos_line_string_closed(const GEOSGeometry* geom)
682
715
  {
683
716
  VALUE result;
684
717
  unsigned int n;
@@ -686,19 +719,18 @@ VALUE rgeo_is_geos_line_string_closed(GEOSContextHandle_t context, const GEOSGeo
686
719
  const GEOSCoordSequence* coord_seq;
687
720
 
688
721
  result = Qnil;
689
- n = GEOSGetNumCoordinates_r(context, geom);
722
+ n = GEOSGetNumCoordinates(geom);
690
723
  if (n > 0) {
691
- coord_seq = GEOSGeom_getCoordSeq_r(context, geom);
692
- if (GEOSCoordSeq_getX_r(context, coord_seq, 0, &x1)) {
693
- if (GEOSCoordSeq_getX_r(context, coord_seq, n-1, &x2)) {
724
+ coord_seq = GEOSGeom_getCoordSeq(geom);
725
+ if (GEOSCoordSeq_getX(coord_seq, 0, &x1)) {
726
+ if (GEOSCoordSeq_getX(coord_seq, n - 1, &x2)) {
694
727
  if (x1 == x2) {
695
- if (GEOSCoordSeq_getY_r(context, coord_seq, 0, &y1)) {
696
- if (GEOSCoordSeq_getY_r(context, coord_seq, n-1, &y2)) {
728
+ if (GEOSCoordSeq_getY(coord_seq, 0, &y1)) {
729
+ if (GEOSCoordSeq_getY(coord_seq, n - 1, &y2)) {
697
730
  result = y1 == y2 ? Qtrue : Qfalse;
698
731
  }
699
732
  }
700
- }
701
- else {
733
+ } else {
702
734
  result = Qfalse;
703
735
  }
704
736
  }
@@ -707,7 +739,6 @@ VALUE rgeo_is_geos_line_string_closed(GEOSContextHandle_t context, const GEOSGeo
707
739
  return result;
708
740
  }
709
741
 
710
-
711
742
  RGEO_END_C
712
743
 
713
744
  #endif