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.
- checksums.yaml +4 -4
- data/README.md +12 -12
- data/ext/geos_c_impl/analysis.c +26 -23
- data/ext/geos_c_impl/analysis.h +8 -5
- data/ext/geos_c_impl/coordinates.c +27 -21
- data/ext/geos_c_impl/coordinates.h +5 -2
- data/ext/geos_c_impl/errors.c +15 -8
- data/ext/geos_c_impl/errors.h +4 -1
- data/ext/geos_c_impl/extconf.rb +40 -30
- data/ext/geos_c_impl/factory.c +391 -410
- data/ext/geos_c_impl/factory.h +66 -48
- data/ext/geos_c_impl/geometry.c +417 -299
- data/ext/geos_c_impl/geometry.h +5 -5
- data/ext/geos_c_impl/geometry_collection.c +289 -213
- data/ext/geos_c_impl/geometry_collection.h +6 -7
- data/ext/geos_c_impl/globals.c +99 -21
- data/ext/geos_c_impl/globals.h +3 -2
- data/ext/geos_c_impl/line_string.c +231 -200
- data/ext/geos_c_impl/line_string.h +5 -6
- data/ext/geos_c_impl/main.c +8 -9
- data/ext/geos_c_impl/point.c +62 -63
- data/ext/geos_c_impl/point.h +4 -5
- data/ext/geos_c_impl/polygon.c +133 -94
- data/ext/geos_c_impl/polygon.h +10 -8
- data/ext/geos_c_impl/preface.h +8 -13
- data/ext/geos_c_impl/ruby_more.c +60 -0
- data/ext/geos_c_impl/ruby_more.h +17 -0
- data/lib/rgeo/cartesian/bounding_box.rb +1 -1
- data/lib/rgeo/cartesian/factory.rb +14 -50
- data/lib/rgeo/cartesian/feature_classes.rb +2 -0
- data/lib/rgeo/cartesian/feature_methods.rb +16 -5
- data/lib/rgeo/cartesian/interface.rb +6 -35
- data/lib/rgeo/coord_sys/cs/entities.rb +214 -0
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +15 -8
- data/lib/rgeo/coord_sys.rb +1 -20
- data/lib/rgeo/feature/curve.rb +0 -10
- data/lib/rgeo/feature/factory.rb +1 -9
- data/lib/rgeo/feature/factory_generator.rb +3 -10
- data/lib/rgeo/feature/geometry.rb +77 -8
- data/lib/rgeo/feature/multi_curve.rb +0 -5
- data/lib/rgeo/feature/types.rb +5 -5
- data/lib/rgeo/geographic/factory.rb +15 -42
- data/lib/rgeo/geographic/interface.rb +28 -127
- data/lib/rgeo/geographic/projected_feature_methods.rb +16 -10
- data/lib/rgeo/geographic/projected_window.rb +1 -1
- data/lib/rgeo/geographic/{proj4_projector.rb → projector.rb} +3 -3
- data/lib/rgeo/geographic/simple_mercator_projector.rb +1 -10
- data/lib/rgeo/geographic/spherical_feature_methods.rb +17 -6
- data/lib/rgeo/geographic.rb +1 -1
- data/lib/rgeo/geos/capi_factory.rb +37 -98
- data/lib/rgeo/geos/capi_feature_classes.rb +15 -25
- data/lib/rgeo/geos/ffi_factory.rb +58 -99
- data/lib/rgeo/geos/ffi_feature_methods.rb +15 -29
- data/lib/rgeo/geos/interface.rb +5 -37
- data/lib/rgeo/geos/zm_factory.rb +5 -43
- data/lib/rgeo/geos/zm_feature_methods.rb +15 -24
- data/lib/rgeo/geos.rb +8 -8
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +1 -14
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +1 -19
- data/lib/rgeo/impl_helper/basic_point_methods.rb +0 -10
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +1 -9
- data/lib/rgeo/impl_helper/utils.rb +27 -0
- data/lib/rgeo/impl_helper/validity_check.rb +6 -5
- data/lib/rgeo/version.rb +1 -1
- data/lib/rgeo/wkrep/wkb_generator.rb +68 -53
- data/lib/rgeo/wkrep/wkb_parser.rb +19 -16
- data/lib/rgeo/wkrep/wkt_generator.rb +34 -34
- data/lib/rgeo/wkrep/wkt_parser.rb +26 -23
- data/lib/rgeo.rb +1 -3
- metadata +23 -9
- data/lib/rgeo/coord_sys/srs_database/entry.rb +0 -107
- data/lib/rgeo/coord_sys/srs_database/sr_org.rb +0 -64
- data/lib/rgeo/coord_sys/srs_database/url_reader.rb +0 -65
@@ -2,41 +2,36 @@
|
|
2
2
|
Geometry collection 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 <ruby.h>
|
11
9
|
#include <geos_c.h>
|
10
|
+
#include <ruby.h>
|
12
11
|
|
13
|
-
#include "
|
14
|
-
|
12
|
+
#include "coordinates.h"
|
13
|
+
#include "errors.h"
|
15
14
|
#include "factory.h"
|
16
15
|
#include "geometry.h"
|
16
|
+
#include "geometry_collection.h"
|
17
|
+
#include "globals.h"
|
17
18
|
#include "line_string.h"
|
18
19
|
#include "polygon.h"
|
19
|
-
#include "geometry.h"
|
20
|
-
#include "geometry_collection.h"
|
21
|
-
|
22
|
-
#include "coordinates.h"
|
23
20
|
|
24
21
|
RGEO_BEGIN_C
|
25
22
|
|
26
|
-
|
27
23
|
/**** INTERNAL IMPLEMENTATION OF CREATE ****/
|
28
24
|
|
29
|
-
|
30
25
|
// Main implementation of the "create" class method for geometry collections.
|
31
26
|
// You must pass in the correct GEOS geometry type ID.
|
32
27
|
|
33
|
-
static VALUE
|
28
|
+
static VALUE
|
29
|
+
create_geometry_collection(VALUE module, int type, VALUE factory, VALUE array)
|
34
30
|
{
|
35
31
|
VALUE result;
|
36
32
|
unsigned int len;
|
37
33
|
GEOSGeometry** geoms;
|
38
34
|
RGeo_FactoryData* factory_data;
|
39
|
-
GEOSContextHandle_t geos_context;
|
40
35
|
VALUE klass;
|
41
36
|
unsigned int i;
|
42
37
|
unsigned int j;
|
@@ -44,17 +39,20 @@ static VALUE create_geometry_collection(VALUE module, int type, VALUE factory, V
|
|
44
39
|
VALUE cast_type;
|
45
40
|
GEOSGeometry* geom;
|
46
41
|
GEOSGeometry* collection;
|
42
|
+
int state = 0;
|
47
43
|
|
48
44
|
result = Qnil;
|
49
45
|
Check_Type(array, T_ARRAY);
|
50
46
|
len = (unsigned int)RARRAY_LEN(array);
|
51
47
|
geoms = ALLOC_N(GEOSGeometry*, len == 0 ? 1 : len);
|
52
|
-
if (geoms) {
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
48
|
+
if (!geoms) {
|
49
|
+
rb_raise(rb_eRGeoError, "not enough memory available");
|
50
|
+
}
|
51
|
+
|
52
|
+
factory_data = RGEO_FACTORY_DATA_PTR(factory);
|
53
|
+
klasses = Qnil;
|
54
|
+
cast_type = Qnil;
|
55
|
+
switch (type) {
|
58
56
|
case GEOS_MULTIPOINT:
|
59
57
|
cast_type = rgeo_feature_point_module;
|
60
58
|
break;
|
@@ -64,50 +62,51 @@ static VALUE create_geometry_collection(VALUE module, int type, VALUE factory, V
|
|
64
62
|
case GEOS_MULTIPOLYGON:
|
65
63
|
cast_type = rgeo_feature_polygon_module;
|
66
64
|
break;
|
65
|
+
}
|
66
|
+
for (i = 0; i < len; ++i) {
|
67
|
+
geom = rgeo_convert_to_detached_geos_geometry(
|
68
|
+
rb_ary_entry(array, i), factory, cast_type, &klass, &state);
|
69
|
+
if (state || !geom) {
|
70
|
+
break;
|
67
71
|
}
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
geoms[i] = geom;
|
74
|
-
if (!NIL_P(klass) && NIL_P(klasses)) {
|
75
|
-
klasses = rb_ary_new2(len);
|
76
|
-
for (j=0; j<i; ++j) {
|
77
|
-
rb_ary_push(klasses, Qnil);
|
78
|
-
}
|
79
|
-
}
|
80
|
-
if (!NIL_P(klasses)) {
|
81
|
-
rb_ary_push(klasses, klass);
|
72
|
+
geoms[i] = geom;
|
73
|
+
if (!NIL_P(klass) && NIL_P(klasses)) {
|
74
|
+
klasses = rb_ary_new2(len);
|
75
|
+
for (j = 0; j < i; ++j) {
|
76
|
+
rb_ary_push(klasses, Qnil);
|
82
77
|
}
|
83
78
|
}
|
84
|
-
if (
|
85
|
-
|
86
|
-
GEOSGeom_destroy_r(geos_context, geoms[j]);
|
87
|
-
}
|
79
|
+
if (!NIL_P(klasses)) {
|
80
|
+
rb_ary_push(klasses, klass);
|
88
81
|
}
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
RGEO_GEOMETRY_DATA_PTR(result)->klasses = klasses;
|
94
|
-
}
|
95
|
-
// NOTE: We are assuming that GEOS will do its own cleanup of the
|
96
|
-
// element geometries if it fails to create the collection, so we
|
97
|
-
// are not doing that ourselves. If that turns out not to be the
|
98
|
-
// case, this will be a memory leak.
|
82
|
+
}
|
83
|
+
if (i != len) {
|
84
|
+
for (j = 0; j < i; ++j) {
|
85
|
+
GEOSGeom_destroy(geoms[j]);
|
99
86
|
}
|
100
|
-
|
87
|
+
} else {
|
88
|
+
collection = GEOSGeom_createCollection(type, geoms, len);
|
89
|
+
if (collection) {
|
90
|
+
result = rgeo_wrap_geos_geometry(factory, collection, module);
|
91
|
+
RGEO_GEOMETRY_DATA_PTR(result)->klasses = klasses;
|
92
|
+
}
|
93
|
+
// NOTE: We are assuming that GEOS will do its own cleanup of the
|
94
|
+
// element geometries if it fails to create the collection, so we
|
95
|
+
// are not doing that ourselves. If that turns out not to be the
|
96
|
+
// case, this will be a memory leak.
|
97
|
+
}
|
98
|
+
FREE(geoms);
|
99
|
+
if (state) {
|
100
|
+
rb_exc_raise(rb_errinfo()); // raise $!
|
101
101
|
}
|
102
102
|
|
103
103
|
return result;
|
104
104
|
}
|
105
105
|
|
106
|
-
|
107
106
|
/**** RUBY METHOD DEFINITIONS ****/
|
108
107
|
|
109
|
-
|
110
|
-
|
108
|
+
static VALUE
|
109
|
+
method_geometry_collection_eql(VALUE self, VALUE rhs)
|
111
110
|
{
|
112
111
|
VALUE result;
|
113
112
|
RGeo_GeometryData* self_data;
|
@@ -115,13 +114,14 @@ static VALUE method_geometry_collection_eql(VALUE self, VALUE rhs)
|
|
115
114
|
result = rgeo_geos_klasses_and_factories_eql(self, rhs);
|
116
115
|
if (RTEST(result)) {
|
117
116
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
118
|
-
result = rgeo_geos_geometries_strict_eql(self_data->
|
117
|
+
result = rgeo_geos_geometries_strict_eql(self_data->geom,
|
118
|
+
RGEO_GEOMETRY_DATA_PTR(rhs)->geom);
|
119
119
|
}
|
120
120
|
return result;
|
121
121
|
}
|
122
122
|
|
123
|
-
|
124
|
-
|
123
|
+
static VALUE
|
124
|
+
method_geometry_collection_hash(VALUE self)
|
125
125
|
{
|
126
126
|
st_index_t hash;
|
127
127
|
RGeo_GeometryData* self_data;
|
@@ -130,13 +130,14 @@ static VALUE method_geometry_collection_hash(VALUE self)
|
|
130
130
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
131
131
|
factory = self_data->factory;
|
132
132
|
hash = rb_hash_start(0);
|
133
|
-
hash = rgeo_geos_objbase_hash(
|
134
|
-
|
133
|
+
hash = rgeo_geos_objbase_hash(
|
134
|
+
factory, rgeo_feature_geometry_collection_module, hash);
|
135
|
+
hash = rgeo_geos_geometry_collection_hash(self_data->geom, hash);
|
135
136
|
return LONG2FIX(rb_hash_end(hash));
|
136
137
|
}
|
137
138
|
|
138
|
-
|
139
|
-
|
139
|
+
static VALUE
|
140
|
+
method_geometry_collection_geometry_type(VALUE self)
|
140
141
|
{
|
141
142
|
VALUE result;
|
142
143
|
RGeo_GeometryData* self_data;
|
@@ -149,8 +150,8 @@ static VALUE method_geometry_collection_geometry_type(VALUE self)
|
|
149
150
|
return result;
|
150
151
|
}
|
151
152
|
|
152
|
-
|
153
|
-
|
153
|
+
static VALUE
|
154
|
+
method_geometry_collection_num_geometries(VALUE self)
|
154
155
|
{
|
155
156
|
VALUE result;
|
156
157
|
RGeo_GeometryData* self_data;
|
@@ -160,13 +161,13 @@ static VALUE method_geometry_collection_num_geometries(VALUE self)
|
|
160
161
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
161
162
|
self_geom = self_data->geom;
|
162
163
|
if (self_geom) {
|
163
|
-
result = INT2NUM(
|
164
|
+
result = INT2NUM(GEOSGetNumGeometries(self_geom));
|
164
165
|
}
|
165
166
|
return result;
|
166
167
|
}
|
167
168
|
|
168
|
-
|
169
|
-
|
169
|
+
static VALUE
|
170
|
+
impl_geometry_n(VALUE self, VALUE n, char allow_negatives)
|
170
171
|
{
|
171
172
|
VALUE result;
|
172
173
|
RGeo_GeometryData* self_data;
|
@@ -180,16 +181,16 @@ static VALUE impl_geometry_n(VALUE self, VALUE n, char allow_negatives)
|
|
180
181
|
self_geom = self_data->geom;
|
181
182
|
if (self_geom) {
|
182
183
|
klasses = self_data->klasses;
|
183
|
-
i =
|
184
|
+
i = RB_NUM2INT(n);
|
184
185
|
if (allow_negatives || i >= 0) {
|
185
|
-
|
186
|
-
len = GEOSGetNumGeometries_r(self_context, self_geom);
|
186
|
+
len = GEOSGetNumGeometries(self_geom);
|
187
187
|
if (i < 0) {
|
188
188
|
i += len;
|
189
189
|
}
|
190
190
|
if (i >= 0 && i < len) {
|
191
|
-
result = rgeo_wrap_geos_geometry_clone(
|
192
|
-
|
191
|
+
result = rgeo_wrap_geos_geometry_clone(
|
192
|
+
self_data->factory,
|
193
|
+
GEOSGetGeometryN(self_geom, i),
|
193
194
|
NIL_P(klasses) ? Qnil : rb_ary_entry(klasses, i));
|
194
195
|
}
|
195
196
|
}
|
@@ -197,22 +198,23 @@ static VALUE impl_geometry_n(VALUE self, VALUE n, char allow_negatives)
|
|
197
198
|
return result;
|
198
199
|
}
|
199
200
|
|
200
|
-
|
201
|
-
|
201
|
+
static VALUE
|
202
|
+
method_geometry_collection_geometry_n(VALUE self, VALUE n)
|
202
203
|
{
|
203
204
|
return impl_geometry_n(self, n, 0);
|
204
205
|
}
|
205
206
|
|
206
|
-
|
207
|
-
|
207
|
+
static VALUE
|
208
|
+
method_geometry_collection_brackets(VALUE self, VALUE n)
|
208
209
|
{
|
209
210
|
return impl_geometry_n(self, n, 1);
|
210
211
|
}
|
211
212
|
|
212
|
-
|
213
|
-
|
213
|
+
static VALUE
|
214
|
+
method_geometry_collection_each(VALUE self)
|
214
215
|
{
|
215
|
-
RETURN_ENUMERATOR(
|
216
|
+
RETURN_ENUMERATOR(
|
217
|
+
self, 0, 0); /* return enum_for(__callee__) unless block_given? */
|
216
218
|
|
217
219
|
RGeo_GeometryData* self_data;
|
218
220
|
const GEOSGeometry* self_geom;
|
@@ -226,13 +228,15 @@ static VALUE method_geometry_collection_each(VALUE self)
|
|
226
228
|
|
227
229
|
self_geom = self_data->geom;
|
228
230
|
if (self_geom) {
|
229
|
-
|
230
|
-
len = GEOSGetNumGeometries_r(self_context, self_geom);
|
231
|
+
len = GEOSGetNumGeometries(self_geom);
|
231
232
|
if (len > 0) {
|
232
233
|
klasses = self_data->klasses;
|
233
|
-
for (i=0; i<len; ++i) {
|
234
|
-
elem_geom =
|
235
|
-
elem = rgeo_wrap_geos_geometry_clone(
|
234
|
+
for (i = 0; i < len; ++i) {
|
235
|
+
elem_geom = GEOSGetGeometryN(self_geom, i);
|
236
|
+
elem = rgeo_wrap_geos_geometry_clone(
|
237
|
+
self_data->factory,
|
238
|
+
elem_geom,
|
239
|
+
NIL_P(klasses) ? Qnil : rb_ary_entry(klasses, i));
|
236
240
|
if (!NIL_P(elem)) {
|
237
241
|
rb_yield(elem);
|
238
242
|
}
|
@@ -242,7 +246,8 @@ static VALUE method_geometry_collection_each(VALUE self)
|
|
242
246
|
return self;
|
243
247
|
}
|
244
248
|
|
245
|
-
static VALUE
|
249
|
+
static VALUE
|
250
|
+
method_multi_point_geometry_type(VALUE self)
|
246
251
|
{
|
247
252
|
VALUE result;
|
248
253
|
RGeo_GeometryData* self_data;
|
@@ -255,8 +260,8 @@ static VALUE method_multi_point_geometry_type(VALUE self)
|
|
255
260
|
return result;
|
256
261
|
}
|
257
262
|
|
258
|
-
|
259
|
-
|
263
|
+
static VALUE
|
264
|
+
method_multi_point_hash(VALUE self)
|
260
265
|
{
|
261
266
|
st_index_t hash;
|
262
267
|
RGeo_GeometryData* self_data;
|
@@ -266,17 +271,16 @@ static VALUE method_multi_point_hash(VALUE self)
|
|
266
271
|
factory = self_data->factory;
|
267
272
|
hash = rb_hash_start(0);
|
268
273
|
hash = rgeo_geos_objbase_hash(factory, rgeo_feature_multi_point_module, hash);
|
269
|
-
hash = rgeo_geos_geometry_collection_hash(self_data->
|
274
|
+
hash = rgeo_geos_geometry_collection_hash(self_data->geom, hash);
|
270
275
|
return LONG2FIX(rb_hash_end(hash));
|
271
276
|
}
|
272
277
|
|
273
|
-
|
274
|
-
|
278
|
+
static VALUE
|
279
|
+
method_multi_point_coordinates(VALUE self)
|
275
280
|
{
|
276
281
|
VALUE result = Qnil;
|
277
282
|
RGeo_GeometryData* self_data;
|
278
283
|
const GEOSGeometry* self_geom;
|
279
|
-
GEOSContextHandle_t context;
|
280
284
|
const GEOSCoordSequence* coord_sequence;
|
281
285
|
|
282
286
|
const GEOSGeometry* point;
|
@@ -287,23 +291,26 @@ static VALUE method_multi_point_coordinates(VALUE self)
|
|
287
291
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
288
292
|
self_geom = self_data->geom;
|
289
293
|
|
290
|
-
if(self_geom) {
|
291
|
-
zCoordinate = RGEO_FACTORY_DATA_PTR(self_data->factory)->flags &
|
292
|
-
|
293
|
-
|
294
|
+
if (self_geom) {
|
295
|
+
zCoordinate = RGEO_FACTORY_DATA_PTR(self_data->factory)->flags &
|
296
|
+
RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M;
|
297
|
+
|
298
|
+
count = GEOSGetNumGeometries(self_geom);
|
294
299
|
result = rb_ary_new2(count);
|
295
|
-
for(i = 0; i < count; ++i) {
|
296
|
-
point =
|
297
|
-
coord_sequence =
|
298
|
-
rb_ary_push(result,
|
300
|
+
for (i = 0; i < count; ++i) {
|
301
|
+
point = GEOSGetGeometryN(self_geom, i);
|
302
|
+
coord_sequence = GEOSGeom_getCoordSeq(point);
|
303
|
+
rb_ary_push(result,
|
304
|
+
rb_ary_pop(extract_points_from_coordinate_sequence(
|
305
|
+
coord_sequence, zCoordinate)));
|
299
306
|
}
|
300
307
|
}
|
301
308
|
|
302
309
|
return result;
|
303
310
|
}
|
304
311
|
|
305
|
-
|
306
|
-
|
312
|
+
static VALUE
|
313
|
+
method_multi_line_string_geometry_type(VALUE self)
|
307
314
|
{
|
308
315
|
VALUE result;
|
309
316
|
RGeo_GeometryData* self_data;
|
@@ -316,8 +323,8 @@ static VALUE method_multi_line_string_geometry_type(VALUE self)
|
|
316
323
|
return result;
|
317
324
|
}
|
318
325
|
|
319
|
-
|
320
|
-
|
326
|
+
static VALUE
|
327
|
+
method_multi_line_string_hash(VALUE self)
|
321
328
|
{
|
322
329
|
st_index_t hash;
|
323
330
|
RGeo_GeometryData* self_data;
|
@@ -326,35 +333,35 @@ static VALUE method_multi_line_string_hash(VALUE self)
|
|
326
333
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
327
334
|
factory = self_data->factory;
|
328
335
|
hash = rb_hash_start(0);
|
329
|
-
hash = rgeo_geos_objbase_hash(
|
330
|
-
|
336
|
+
hash = rgeo_geos_objbase_hash(
|
337
|
+
factory, rgeo_feature_multi_line_string_module, hash);
|
338
|
+
hash = rgeo_geos_geometry_collection_hash(self_data->geom, hash);
|
331
339
|
return LONG2FIX(rb_hash_end(hash));
|
332
340
|
}
|
333
341
|
|
334
|
-
static VALUE
|
342
|
+
static VALUE
|
343
|
+
method_geometry_collection_node(VALUE self)
|
335
344
|
{
|
336
345
|
VALUE result = Qnil;
|
337
346
|
RGeo_GeometryData* self_data;
|
338
347
|
const GEOSGeometry* self_geom;
|
339
348
|
GEOSGeometry* noded;
|
340
|
-
GEOSContextHandle_t context;
|
341
349
|
|
342
350
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
343
351
|
self_geom = self_data->geom;
|
344
|
-
context = self_data->geos_context;
|
345
352
|
|
346
|
-
noded =
|
353
|
+
noded = GEOSNode(self_geom);
|
347
354
|
result = rgeo_wrap_geos_geometry(self_data->factory, noded, Qnil);
|
348
355
|
|
349
356
|
return result;
|
350
357
|
}
|
351
358
|
|
352
|
-
static VALUE
|
359
|
+
static VALUE
|
360
|
+
method_multi_line_string_coordinates(VALUE self)
|
353
361
|
{
|
354
362
|
VALUE result = Qnil;
|
355
363
|
RGeo_GeometryData* self_data;
|
356
364
|
const GEOSGeometry* self_geom;
|
357
|
-
GEOSContextHandle_t context;
|
358
365
|
const GEOSCoordSequence* coord_sequence;
|
359
366
|
|
360
367
|
const GEOSGeometry* line_string;
|
@@ -365,22 +372,25 @@ static VALUE method_multi_line_string_coordinates(VALUE self)
|
|
365
372
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
366
373
|
self_geom = self_data->geom;
|
367
374
|
|
368
|
-
if(self_geom) {
|
369
|
-
zCoordinate = RGEO_FACTORY_DATA_PTR(self_data->factory)->flags &
|
370
|
-
|
371
|
-
count =
|
375
|
+
if (self_geom) {
|
376
|
+
zCoordinate = RGEO_FACTORY_DATA_PTR(self_data->factory)->flags &
|
377
|
+
RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M;
|
378
|
+
count = GEOSGetNumGeometries(self_geom);
|
372
379
|
result = rb_ary_new2(count);
|
373
|
-
for(i = 0; i < count; ++i) {
|
374
|
-
line_string =
|
375
|
-
coord_sequence =
|
376
|
-
rb_ary_push(
|
380
|
+
for (i = 0; i < count; ++i) {
|
381
|
+
line_string = GEOSGetGeometryN(self_geom, i);
|
382
|
+
coord_sequence = GEOSGeom_getCoordSeq(line_string);
|
383
|
+
rb_ary_push(
|
384
|
+
result,
|
385
|
+
extract_points_from_coordinate_sequence(coord_sequence, zCoordinate));
|
377
386
|
}
|
378
387
|
}
|
379
388
|
|
380
389
|
return result;
|
381
390
|
}
|
382
391
|
|
383
|
-
static VALUE
|
392
|
+
static VALUE
|
393
|
+
method_multi_line_string_length(VALUE self)
|
384
394
|
{
|
385
395
|
VALUE result;
|
386
396
|
RGeo_GeometryData* self_data;
|
@@ -391,20 +401,19 @@ static VALUE method_multi_line_string_length(VALUE self)
|
|
391
401
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
392
402
|
self_geom = self_data->geom;
|
393
403
|
if (self_geom) {
|
394
|
-
if (
|
404
|
+
if (GEOSLength(self_geom, &len)) {
|
395
405
|
result = rb_float_new(len);
|
396
406
|
}
|
397
407
|
}
|
398
408
|
return result;
|
399
409
|
}
|
400
410
|
|
401
|
-
|
402
|
-
|
411
|
+
static VALUE
|
412
|
+
method_multi_line_string_is_closed(VALUE self)
|
403
413
|
{
|
404
414
|
VALUE result;
|
405
415
|
RGeo_GeometryData* self_data;
|
406
416
|
const GEOSGeometry* self_geom;
|
407
|
-
GEOSContextHandle_t self_context;
|
408
417
|
int len;
|
409
418
|
int i;
|
410
419
|
const GEOSGeometry* geom;
|
@@ -413,14 +422,13 @@ static VALUE method_multi_line_string_is_closed(VALUE self)
|
|
413
422
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
414
423
|
self_geom = self_data->geom;
|
415
424
|
if (self_geom) {
|
416
|
-
self_context = self_data->geos_context;
|
417
425
|
result = Qtrue;
|
418
|
-
len =
|
426
|
+
len = GEOSGetNumGeometries(self_geom);
|
419
427
|
if (len > 0) {
|
420
|
-
for (i=0; i<len; ++i) {
|
421
|
-
geom =
|
428
|
+
for (i = 0; i < len; ++i) {
|
429
|
+
geom = GEOSGetGeometryN(self_geom, i);
|
422
430
|
if (geom) {
|
423
|
-
result = rgeo_is_geos_line_string_closed(
|
431
|
+
result = rgeo_is_geos_line_string_closed(self_geom);
|
424
432
|
if (result != Qtrue) {
|
425
433
|
break;
|
426
434
|
}
|
@@ -431,8 +439,8 @@ static VALUE method_multi_line_string_is_closed(VALUE self)
|
|
431
439
|
return result;
|
432
440
|
}
|
433
441
|
|
434
|
-
|
435
|
-
|
442
|
+
static VALUE
|
443
|
+
method_multi_polygon_geometry_type(VALUE self)
|
436
444
|
{
|
437
445
|
VALUE result;
|
438
446
|
RGeo_GeometryData* self_data;
|
@@ -445,8 +453,8 @@ static VALUE method_multi_polygon_geometry_type(VALUE self)
|
|
445
453
|
return result;
|
446
454
|
}
|
447
455
|
|
448
|
-
|
449
|
-
|
456
|
+
static VALUE
|
457
|
+
method_multi_polygon_hash(VALUE self)
|
450
458
|
{
|
451
459
|
st_index_t hash;
|
452
460
|
RGeo_GeometryData* self_data;
|
@@ -455,18 +463,18 @@ static VALUE method_multi_polygon_hash(VALUE self)
|
|
455
463
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
456
464
|
factory = self_data->factory;
|
457
465
|
hash = rb_hash_start(0);
|
458
|
-
hash =
|
459
|
-
|
466
|
+
hash =
|
467
|
+
rgeo_geos_objbase_hash(factory, rgeo_feature_multi_polygon_module, hash);
|
468
|
+
hash = rgeo_geos_geometry_collection_hash(self_data->geom, hash);
|
460
469
|
return LONG2FIX(rb_hash_end(hash));
|
461
470
|
}
|
462
471
|
|
463
|
-
|
464
|
-
|
472
|
+
static VALUE
|
473
|
+
method_multi_polygon_coordinates(VALUE self)
|
465
474
|
{
|
466
475
|
VALUE result = Qnil;
|
467
476
|
RGeo_GeometryData* self_data;
|
468
477
|
const GEOSGeometry* self_geom;
|
469
|
-
GEOSContextHandle_t context;
|
470
478
|
|
471
479
|
const GEOSGeometry* poly;
|
472
480
|
unsigned int count;
|
@@ -476,22 +484,22 @@ static VALUE method_multi_polygon_coordinates(VALUE self)
|
|
476
484
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
477
485
|
self_geom = self_data->geom;
|
478
486
|
|
479
|
-
if(self_geom) {
|
480
|
-
zCoordinate = RGEO_FACTORY_DATA_PTR(self_data->factory)->flags &
|
481
|
-
|
482
|
-
count =
|
487
|
+
if (self_geom) {
|
488
|
+
zCoordinate = RGEO_FACTORY_DATA_PTR(self_data->factory)->flags &
|
489
|
+
RGEO_FACTORYFLAGS_SUPPORTS_Z_OR_M;
|
490
|
+
count = GEOSGetNumGeometries(self_geom);
|
483
491
|
result = rb_ary_new2(count);
|
484
|
-
for(i = 0; i < count; ++i) {
|
485
|
-
poly =
|
486
|
-
rb_ary_push(result, extract_points_from_polygon(
|
492
|
+
for (i = 0; i < count; ++i) {
|
493
|
+
poly = GEOSGetGeometryN(self_geom, i);
|
494
|
+
rb_ary_push(result, extract_points_from_polygon(poly, zCoordinate));
|
487
495
|
}
|
488
496
|
}
|
489
497
|
|
490
498
|
return result;
|
491
499
|
}
|
492
500
|
|
493
|
-
|
494
|
-
|
501
|
+
static VALUE
|
502
|
+
method_multi_polygon_area(VALUE self)
|
495
503
|
{
|
496
504
|
VALUE result;
|
497
505
|
RGeo_GeometryData* self_data;
|
@@ -502,15 +510,15 @@ static VALUE method_multi_polygon_area(VALUE self)
|
|
502
510
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
503
511
|
self_geom = self_data->geom;
|
504
512
|
if (self_geom) {
|
505
|
-
if (
|
513
|
+
if (GEOSArea(self_geom, &area)) {
|
506
514
|
result = rb_float_new(area);
|
507
515
|
}
|
508
516
|
}
|
509
517
|
return result;
|
510
518
|
}
|
511
519
|
|
512
|
-
|
513
|
-
|
520
|
+
static VALUE
|
521
|
+
method_multi_polygon_centroid(VALUE self)
|
514
522
|
{
|
515
523
|
VALUE result;
|
516
524
|
RGeo_GeometryData* self_data;
|
@@ -520,40 +528,42 @@ static VALUE method_multi_polygon_centroid(VALUE self)
|
|
520
528
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
521
529
|
self_geom = self_data->geom;
|
522
530
|
if (self_geom) {
|
523
|
-
result = rgeo_wrap_geos_geometry(
|
531
|
+
result = rgeo_wrap_geos_geometry(
|
532
|
+
self_data->factory, GEOSGetCentroid(self_geom), Qnil);
|
524
533
|
}
|
525
534
|
return result;
|
526
535
|
}
|
527
536
|
|
528
|
-
|
529
|
-
|
537
|
+
static VALUE
|
538
|
+
cmethod_geometry_collection_create(VALUE module, VALUE factory, VALUE array)
|
530
539
|
{
|
531
|
-
return create_geometry_collection(
|
540
|
+
return create_geometry_collection(
|
541
|
+
module, GEOS_GEOMETRYCOLLECTION, factory, array);
|
532
542
|
}
|
533
543
|
|
534
|
-
|
535
|
-
|
544
|
+
static VALUE
|
545
|
+
cmethod_multi_point_create(VALUE module, VALUE factory, VALUE array)
|
536
546
|
{
|
537
547
|
return create_geometry_collection(module, GEOS_MULTIPOINT, factory, array);
|
538
548
|
}
|
539
549
|
|
540
|
-
|
541
|
-
|
550
|
+
static VALUE
|
551
|
+
cmethod_multi_line_string_create(VALUE module, VALUE factory, VALUE array)
|
542
552
|
{
|
543
|
-
return create_geometry_collection(
|
553
|
+
return create_geometry_collection(
|
554
|
+
module, GEOS_MULTILINESTRING, factory, array);
|
544
555
|
}
|
545
556
|
|
546
|
-
|
547
|
-
|
557
|
+
static VALUE
|
558
|
+
cmethod_multi_polygon_create(VALUE module, VALUE factory, VALUE array)
|
548
559
|
{
|
549
560
|
return create_geometry_collection(module, GEOS_MULTIPOLYGON, factory, array);
|
550
561
|
}
|
551
562
|
|
552
|
-
|
553
563
|
/**** INITIALIZATION FUNCTION ****/
|
554
564
|
|
555
|
-
|
556
|
-
|
565
|
+
void
|
566
|
+
rgeo_init_geos_geometry_collection()
|
557
567
|
{
|
558
568
|
VALUE geos_geometry_collection_methods;
|
559
569
|
VALUE geos_multi_point_methods;
|
@@ -561,53 +571,120 @@ void rgeo_init_geos_geometry_collection()
|
|
561
571
|
VALUE geos_multi_polygon_methods;
|
562
572
|
|
563
573
|
// Class methods for geometry collection classes
|
564
|
-
rb_define_module_function(rgeo_geos_geometry_collection_class,
|
565
|
-
|
566
|
-
|
567
|
-
|
574
|
+
rb_define_module_function(rgeo_geos_geometry_collection_class,
|
575
|
+
"create",
|
576
|
+
cmethod_geometry_collection_create,
|
577
|
+
2);
|
578
|
+
rb_define_module_function(
|
579
|
+
rgeo_geos_multi_point_class, "create", cmethod_multi_point_create, 2);
|
580
|
+
rb_define_module_function(rgeo_geos_multi_line_string_class,
|
581
|
+
"create",
|
582
|
+
cmethod_multi_line_string_create,
|
583
|
+
2);
|
584
|
+
rb_define_module_function(
|
585
|
+
rgeo_geos_multi_polygon_class, "create", cmethod_multi_polygon_create, 2);
|
568
586
|
|
569
587
|
// Methods for GeometryCollectionImpl
|
570
|
-
geos_geometry_collection_methods =
|
571
|
-
|
572
|
-
rb_define_method(geos_geometry_collection_methods,
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
rb_define_method(geos_geometry_collection_methods,
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
rb_define_method(geos_geometry_collection_methods,
|
581
|
-
|
588
|
+
geos_geometry_collection_methods =
|
589
|
+
rb_define_module_under(rgeo_geos_module, "CAPIGeometryCollectionMethods");
|
590
|
+
rb_define_method(geos_geometry_collection_methods,
|
591
|
+
"rep_equals?",
|
592
|
+
method_geometry_collection_eql,
|
593
|
+
1);
|
594
|
+
rb_define_method(geos_geometry_collection_methods,
|
595
|
+
"eql?",
|
596
|
+
method_geometry_collection_eql,
|
597
|
+
1);
|
598
|
+
rb_define_method(geos_geometry_collection_methods,
|
599
|
+
"hash",
|
600
|
+
method_geometry_collection_hash,
|
601
|
+
0);
|
602
|
+
rb_define_method(geos_geometry_collection_methods,
|
603
|
+
"geometry_type",
|
604
|
+
method_geometry_collection_geometry_type,
|
605
|
+
0);
|
606
|
+
rb_define_method(geos_geometry_collection_methods,
|
607
|
+
"num_geometries",
|
608
|
+
method_geometry_collection_num_geometries,
|
609
|
+
0);
|
610
|
+
rb_define_method(geos_geometry_collection_methods,
|
611
|
+
"size",
|
612
|
+
method_geometry_collection_num_geometries,
|
613
|
+
0);
|
614
|
+
rb_define_method(geos_geometry_collection_methods,
|
615
|
+
"geometry_n",
|
616
|
+
method_geometry_collection_geometry_n,
|
617
|
+
1);
|
618
|
+
rb_define_method(geos_geometry_collection_methods,
|
619
|
+
"[]",
|
620
|
+
method_geometry_collection_brackets,
|
621
|
+
1);
|
622
|
+
rb_define_method(geos_geometry_collection_methods,
|
623
|
+
"each",
|
624
|
+
method_geometry_collection_each,
|
625
|
+
0);
|
626
|
+
rb_define_method(geos_geometry_collection_methods,
|
627
|
+
"node",
|
628
|
+
method_geometry_collection_node,
|
629
|
+
0);
|
582
630
|
|
583
631
|
// Methods for MultiPointImpl
|
584
|
-
geos_multi_point_methods =
|
585
|
-
|
586
|
-
rb_define_method(geos_multi_point_methods,
|
587
|
-
|
632
|
+
geos_multi_point_methods =
|
633
|
+
rb_define_module_under(rgeo_geos_module, "CAPIMultiPointMethods");
|
634
|
+
rb_define_method(geos_multi_point_methods,
|
635
|
+
"geometry_type",
|
636
|
+
method_multi_point_geometry_type,
|
637
|
+
0);
|
638
|
+
rb_define_method(
|
639
|
+
geos_multi_point_methods, "hash", method_multi_point_hash, 0);
|
640
|
+
rb_define_method(
|
641
|
+
geos_multi_point_methods, "coordinates", method_multi_point_coordinates, 0);
|
588
642
|
|
589
643
|
// Methods for MultiLineStringImpl
|
590
|
-
geos_multi_line_string_methods =
|
591
|
-
|
592
|
-
rb_define_method(geos_multi_line_string_methods,
|
593
|
-
|
594
|
-
|
595
|
-
|
644
|
+
geos_multi_line_string_methods =
|
645
|
+
rb_define_module_under(rgeo_geos_module, "CAPIMultiLineStringMethods");
|
646
|
+
rb_define_method(geos_multi_line_string_methods,
|
647
|
+
"geometry_type",
|
648
|
+
method_multi_line_string_geometry_type,
|
649
|
+
0);
|
650
|
+
rb_define_method(geos_multi_line_string_methods,
|
651
|
+
"length",
|
652
|
+
method_multi_line_string_length,
|
653
|
+
0);
|
654
|
+
rb_define_method(geos_multi_line_string_methods,
|
655
|
+
"closed?",
|
656
|
+
method_multi_line_string_is_closed,
|
657
|
+
0);
|
658
|
+
rb_define_method(
|
659
|
+
geos_multi_line_string_methods, "hash", method_multi_line_string_hash, 0);
|
660
|
+
rb_define_method(geos_multi_line_string_methods,
|
661
|
+
"coordinates",
|
662
|
+
method_multi_line_string_coordinates,
|
663
|
+
0);
|
596
664
|
|
597
665
|
// Methods for MultiPolygonImpl
|
598
|
-
geos_multi_polygon_methods =
|
599
|
-
|
600
|
-
rb_define_method(geos_multi_polygon_methods,
|
601
|
-
|
602
|
-
|
603
|
-
|
666
|
+
geos_multi_polygon_methods =
|
667
|
+
rb_define_module_under(rgeo_geos_module, "CAPIMultiPolygonMethods");
|
668
|
+
rb_define_method(geos_multi_polygon_methods,
|
669
|
+
"geometry_type",
|
670
|
+
method_multi_polygon_geometry_type,
|
671
|
+
0);
|
672
|
+
rb_define_method(
|
673
|
+
geos_multi_polygon_methods, "area", method_multi_polygon_area, 0);
|
674
|
+
rb_define_method(
|
675
|
+
geos_multi_polygon_methods, "centroid", method_multi_polygon_centroid, 0);
|
676
|
+
rb_define_method(
|
677
|
+
geos_multi_polygon_methods, "hash", method_multi_polygon_hash, 0);
|
678
|
+
rb_define_method(geos_multi_polygon_methods,
|
679
|
+
"coordinates",
|
680
|
+
method_multi_polygon_coordinates,
|
681
|
+
0);
|
604
682
|
}
|
605
683
|
|
606
|
-
|
607
684
|
/**** OTHER PUBLIC FUNCTIONS ****/
|
608
685
|
|
609
|
-
|
610
|
-
|
686
|
+
st_index_t
|
687
|
+
rgeo_geos_geometry_collection_hash(const GEOSGeometry* geom, st_index_t hash)
|
611
688
|
{
|
612
689
|
const GEOSGeometry* sub_geom;
|
613
690
|
int type;
|
@@ -615,28 +692,28 @@ st_index_t rgeo_geos_geometry_collection_hash(GEOSContextHandle_t context, const
|
|
615
692
|
unsigned int i;
|
616
693
|
|
617
694
|
if (geom) {
|
618
|
-
len =
|
619
|
-
for (i=0; i<len; ++i) {
|
620
|
-
sub_geom =
|
695
|
+
len = GEOSGetNumGeometries(geom);
|
696
|
+
for (i = 0; i < len; ++i) {
|
697
|
+
sub_geom = GEOSGetGeometryN(geom, i);
|
621
698
|
if (sub_geom) {
|
622
|
-
type =
|
699
|
+
type = GEOSGeomTypeId(sub_geom);
|
623
700
|
if (type >= 0) {
|
624
701
|
hash = hash ^ type;
|
625
702
|
switch (type) {
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
703
|
+
case GEOS_POINT:
|
704
|
+
case GEOS_LINESTRING:
|
705
|
+
case GEOS_LINEARRING:
|
706
|
+
hash = rgeo_geos_coordseq_hash(sub_geom, hash);
|
707
|
+
break;
|
708
|
+
case GEOS_POLYGON:
|
709
|
+
hash = rgeo_geos_polygon_hash(sub_geom, hash);
|
710
|
+
break;
|
711
|
+
case GEOS_GEOMETRYCOLLECTION:
|
712
|
+
case GEOS_MULTIPOINT:
|
713
|
+
case GEOS_MULTILINESTRING:
|
714
|
+
case GEOS_MULTIPOLYGON:
|
715
|
+
hash = rgeo_geos_geometry_collection_hash(sub_geom, hash);
|
716
|
+
break;
|
640
717
|
}
|
641
718
|
}
|
642
719
|
}
|
@@ -645,7 +722,6 @@ st_index_t rgeo_geos_geometry_collection_hash(GEOSContextHandle_t context, const
|
|
645
722
|
return hash;
|
646
723
|
}
|
647
724
|
|
648
|
-
|
649
725
|
RGEO_END_C
|
650
726
|
|
651
727
|
#endif
|