rgeo 2.3.1 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +6 -0
- data/README.md +23 -14
- data/ext/geos_c_impl/analysis.c +30 -25
- data/ext/geos_c_impl/analysis.h +8 -7
- 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 +19 -10
- data/ext/geos_c_impl/errors.h +11 -4
- data/ext/geos_c_impl/extconf.rb +42 -28
- data/ext/geos_c_impl/factory.c +540 -451
- data/ext/geos_c_impl/factory.h +105 -95
- data/ext/geos_c_impl/geometry.c +593 -387
- data/ext/geos_c_impl/geometry.h +10 -5
- data/ext/geos_c_impl/geometry_collection.c +306 -339
- data/ext/geos_c_impl/geometry_collection.h +6 -20
- data/ext/geos_c_impl/globals.c +169 -0
- data/ext/geos_c_impl/globals.h +46 -0
- data/ext/geos_c_impl/line_string.c +271 -231
- data/ext/geos_c_impl/line_string.h +5 -8
- data/ext/geos_c_impl/main.c +16 -16
- data/ext/geos_c_impl/point.c +65 -67
- data/ext/geos_c_impl/point.h +4 -7
- data/ext/geos_c_impl/polygon.c +137 -135
- data/ext/geos_c_impl/polygon.h +11 -11
- data/ext/geos_c_impl/preface.h +16 -10
- data/ext/geos_c_impl/ruby_more.c +67 -0
- data/ext/geos_c_impl/ruby_more.h +25 -0
- data/lib/rgeo/cartesian/analysis.rb +5 -3
- data/lib/rgeo/cartesian/bounding_box.rb +74 -79
- data/lib/rgeo/cartesian/calculations.rb +64 -33
- data/lib/rgeo/cartesian/factory.rb +57 -102
- data/lib/rgeo/cartesian/feature_classes.rb +68 -46
- data/lib/rgeo/cartesian/feature_methods.rb +67 -25
- data/lib/rgeo/cartesian/interface.rb +6 -41
- data/lib/rgeo/cartesian/planar_graph.rb +373 -0
- data/lib/rgeo/cartesian/sweepline_intersector.rb +147 -0
- data/lib/rgeo/cartesian/valid_op.rb +69 -0
- data/lib/rgeo/cartesian.rb +3 -0
- data/lib/rgeo/coord_sys/cs/entities.rb +303 -99
- data/lib/rgeo/coord_sys/cs/factories.rb +0 -2
- data/lib/rgeo/coord_sys/cs/wkt_parser.rb +90 -42
- data/lib/rgeo/coord_sys.rb +1 -20
- data/lib/rgeo/error.rb +15 -0
- data/lib/rgeo/feature/curve.rb +0 -11
- data/lib/rgeo/feature/factory.rb +26 -36
- data/lib/rgeo/feature/factory_generator.rb +6 -14
- data/lib/rgeo/feature/geometry.rb +146 -66
- data/lib/rgeo/feature/geometry_collection.rb +16 -9
- data/lib/rgeo/feature/line_string.rb +4 -5
- data/lib/rgeo/feature/linear_ring.rb +0 -1
- data/lib/rgeo/feature/multi_curve.rb +0 -6
- data/lib/rgeo/feature/multi_surface.rb +3 -4
- data/lib/rgeo/feature/point.rb +4 -5
- data/lib/rgeo/feature/polygon.rb +1 -2
- data/lib/rgeo/feature/surface.rb +3 -4
- data/lib/rgeo/feature/types.rb +69 -85
- data/lib/rgeo/geographic/factory.rb +98 -125
- data/lib/rgeo/geographic/interface.rb +69 -166
- data/lib/rgeo/geographic/projected_feature_classes.rb +21 -9
- data/lib/rgeo/geographic/projected_feature_methods.rb +67 -42
- data/lib/rgeo/geographic/projected_window.rb +36 -22
- data/lib/rgeo/geographic/{proj4_projector.rb → projector.rb} +3 -5
- data/lib/rgeo/geographic/simple_mercator_projector.rb +26 -25
- data/lib/rgeo/geographic/spherical_feature_classes.rb +29 -9
- data/lib/rgeo/geographic/spherical_feature_methods.rb +86 -9
- data/lib/rgeo/geographic/spherical_math.rb +17 -20
- data/lib/rgeo/geographic.rb +1 -1
- data/lib/rgeo/geos/capi_factory.rb +87 -158
- data/lib/rgeo/geos/capi_feature_classes.rb +50 -36
- data/lib/rgeo/geos/ffi_factory.rb +105 -173
- data/lib/rgeo/geos/ffi_feature_classes.rb +34 -10
- data/lib/rgeo/geos/ffi_feature_methods.rb +105 -127
- data/lib/rgeo/geos/interface.rb +20 -59
- data/lib/rgeo/geos/utils.rb +5 -5
- data/lib/rgeo/geos/zm_factory.rb +53 -95
- data/lib/rgeo/geos/zm_feature_methods.rb +30 -33
- data/lib/rgeo/geos.rb +8 -8
- data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +9 -22
- data/lib/rgeo/impl_helper/basic_geometry_methods.rb +1 -2
- data/lib/rgeo/impl_helper/basic_line_string_methods.rb +28 -56
- data/lib/rgeo/impl_helper/basic_point_methods.rb +2 -14
- data/lib/rgeo/impl_helper/basic_polygon_methods.rb +17 -26
- data/lib/rgeo/impl_helper/utils.rb +21 -0
- data/lib/rgeo/impl_helper/valid_op.rb +350 -0
- data/lib/rgeo/impl_helper/validity_check.rb +139 -0
- data/lib/rgeo/impl_helper.rb +1 -0
- data/lib/rgeo/version.rb +1 -1
- data/lib/rgeo/wkrep/wkb_generator.rb +73 -63
- data/lib/rgeo/wkrep/wkb_parser.rb +33 -31
- data/lib/rgeo/wkrep/wkt_generator.rb +52 -45
- data/lib/rgeo/wkrep/wkt_parser.rb +48 -35
- data/lib/rgeo.rb +1 -3
- metadata +50 -13
- 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
data/ext/geos_c_impl/geometry.c
CHANGED
@@ -2,28 +2,28 @@
|
|
2
2
|
Geometry base class 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
|
|
13
|
+
#include "errors.h"
|
14
14
|
#include "factory.h"
|
15
15
|
#include "geometry.h"
|
16
|
+
#include "globals.h"
|
16
17
|
|
17
18
|
RGEO_BEGIN_C
|
18
19
|
|
19
|
-
|
20
20
|
/**** INTERNAL UTILITY FUNCTIONS ****/
|
21
21
|
|
22
|
+
// Determine the dimension of the given geometry. Empty collections have
|
23
|
+
// dimension -1. Recursively checks collection elemenets.
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
static int compute_dimension(GEOSContextHandle_t context, const GEOSGeometry* geom)
|
25
|
+
static int
|
26
|
+
compute_dimension(const GEOSGeometry* geom)
|
27
27
|
{
|
28
28
|
int result;
|
29
29
|
int size;
|
@@ -32,50 +32,50 @@ static int compute_dimension(GEOSContextHandle_t context, const GEOSGeometry* ge
|
|
32
32
|
|
33
33
|
result = -1;
|
34
34
|
if (geom) {
|
35
|
-
switch (
|
36
|
-
|
37
|
-
result = 0;
|
38
|
-
break;
|
39
|
-
case GEOS_MULTIPOINT:
|
40
|
-
if (!GEOSisEmpty_r(context, geom)) {
|
35
|
+
switch (GEOSGeomTypeId(geom)) {
|
36
|
+
case GEOS_POINT:
|
41
37
|
result = 0;
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
38
|
+
break;
|
39
|
+
case GEOS_MULTIPOINT:
|
40
|
+
if (!GEOSisEmpty(geom)) {
|
41
|
+
result = 0;
|
42
|
+
}
|
43
|
+
break;
|
44
|
+
case GEOS_LINESTRING:
|
45
|
+
case GEOS_LINEARRING:
|
50
46
|
result = 1;
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
47
|
+
break;
|
48
|
+
case GEOS_MULTILINESTRING:
|
49
|
+
if (!GEOSisEmpty(geom)) {
|
50
|
+
result = 1;
|
51
|
+
}
|
52
|
+
break;
|
53
|
+
case GEOS_POLYGON:
|
58
54
|
result = 2;
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
for (i=0; i<size; ++i) {
|
64
|
-
dim = compute_dimension(context, GEOSGetGeometryN_r(context, geom, i));
|
65
|
-
if (dim > result) {
|
66
|
-
result = dim;
|
55
|
+
break;
|
56
|
+
case GEOS_MULTIPOLYGON:
|
57
|
+
if (!GEOSisEmpty(geom)) {
|
58
|
+
result = 2;
|
67
59
|
}
|
68
|
-
|
69
|
-
|
60
|
+
break;
|
61
|
+
case GEOS_GEOMETRYCOLLECTION:
|
62
|
+
size = GEOSGetNumGeometries(geom);
|
63
|
+
for (i = 0; i < size; ++i) {
|
64
|
+
dim = compute_dimension(GEOSGetGeometryN(geom, i));
|
65
|
+
if (dim > result) {
|
66
|
+
result = dim;
|
67
|
+
}
|
68
|
+
}
|
69
|
+
break;
|
70
70
|
}
|
71
71
|
}
|
72
72
|
return result;
|
73
73
|
}
|
74
74
|
|
75
|
-
|
76
75
|
// Returns a prepared geometry, honoring the preparation policy.
|
77
76
|
|
78
|
-
static const GEOSPreparedGeometry*
|
77
|
+
static const GEOSPreparedGeometry*
|
78
|
+
rgeo_request_prepared_geometry(RGeo_GeometryData* object_data)
|
79
79
|
{
|
80
80
|
const GEOSPreparedGeometry* prep;
|
81
81
|
|
@@ -83,62 +83,59 @@ static const GEOSPreparedGeometry* rgeo_request_prepared_geometry(RGeo_GeometryD
|
|
83
83
|
if (prep == (const GEOSPreparedGeometry*)1) {
|
84
84
|
object_data->prep = (GEOSPreparedGeometry*)2;
|
85
85
|
prep = NULL;
|
86
|
-
}
|
87
|
-
else if (prep == (const GEOSPreparedGeometry*)2) {
|
86
|
+
} else if (prep == (const GEOSPreparedGeometry*)2) {
|
88
87
|
if (object_data->geom) {
|
89
|
-
prep =
|
90
|
-
}
|
91
|
-
else {
|
88
|
+
prep = GEOSPrepare(object_data->geom);
|
89
|
+
} else {
|
92
90
|
prep = NULL;
|
93
91
|
}
|
94
92
|
if (prep) {
|
95
93
|
object_data->prep = prep;
|
96
|
-
}
|
97
|
-
else {
|
94
|
+
} else {
|
98
95
|
object_data->prep = (const GEOSPreparedGeometry*)3;
|
99
96
|
}
|
100
|
-
}
|
101
|
-
else if (prep == (const GEOSPreparedGeometry*)3) {
|
97
|
+
} else if (prep == (const GEOSPreparedGeometry*)3) {
|
102
98
|
prep = NULL;
|
103
99
|
}
|
104
100
|
return prep;
|
105
101
|
}
|
106
102
|
|
107
|
-
|
108
103
|
/**** RUBY METHOD DEFINITIONS ****/
|
109
104
|
|
110
|
-
|
111
|
-
|
105
|
+
static VALUE
|
106
|
+
method_geometry_initialized_p(VALUE self)
|
112
107
|
{
|
113
108
|
return RGEO_GEOMETRY_DATA_PTR(self)->geom ? Qtrue : Qfalse;
|
114
109
|
}
|
115
110
|
|
116
|
-
|
117
|
-
|
111
|
+
static VALUE
|
112
|
+
method_geometry_factory(VALUE self)
|
118
113
|
{
|
119
114
|
return RGEO_GEOMETRY_DATA_PTR(self)->factory;
|
120
115
|
}
|
121
116
|
|
122
|
-
|
123
|
-
|
117
|
+
static VALUE
|
118
|
+
method_geometry_set_factory(VALUE self, VALUE factory)
|
124
119
|
{
|
125
120
|
RGEO_GEOMETRY_DATA_PTR(self)->factory = factory;
|
126
121
|
return factory;
|
127
122
|
}
|
128
123
|
|
129
|
-
|
130
|
-
|
124
|
+
static VALUE
|
125
|
+
method_geometry_prepared_p(VALUE self)
|
131
126
|
{
|
132
127
|
const GEOSPreparedGeometry* prep;
|
133
128
|
|
134
129
|
prep = RGEO_GEOMETRY_DATA_PTR(self)->prep;
|
135
130
|
return (prep && prep != (const GEOSPreparedGeometry*)1 &&
|
136
|
-
|
137
|
-
|
131
|
+
prep != (const GEOSPreparedGeometry*)2 &&
|
132
|
+
prep != (GEOSPreparedGeometry*)3)
|
133
|
+
? Qtrue
|
134
|
+
: Qfalse;
|
138
135
|
}
|
139
136
|
|
140
|
-
|
141
|
-
|
137
|
+
static VALUE
|
138
|
+
method_geometry_prepare(VALUE self)
|
142
139
|
{
|
143
140
|
RGeo_GeometryData* self_data;
|
144
141
|
const GEOSPreparedGeometry* prep;
|
@@ -146,12 +143,12 @@ static VALUE method_geometry_prepare(VALUE self)
|
|
146
143
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
147
144
|
if (self_data->geom) {
|
148
145
|
prep = self_data->prep;
|
149
|
-
if (!prep || prep == (const GEOSPreparedGeometry*)1 ||
|
150
|
-
|
146
|
+
if (!prep || prep == (const GEOSPreparedGeometry*)1 ||
|
147
|
+
prep == (const GEOSPreparedGeometry*)2) {
|
148
|
+
prep = GEOSPrepare(self_data->geom);
|
151
149
|
if (prep) {
|
152
150
|
self_data->prep = prep;
|
153
|
-
}
|
154
|
-
else {
|
151
|
+
} else {
|
155
152
|
self_data->prep = (const GEOSPreparedGeometry*)3;
|
156
153
|
}
|
157
154
|
}
|
@@ -159,8 +156,8 @@ static VALUE method_geometry_prepare(VALUE self)
|
|
159
156
|
return self;
|
160
157
|
}
|
161
158
|
|
162
|
-
|
163
|
-
|
159
|
+
static VALUE
|
160
|
+
method_geometry_dimension(VALUE self)
|
164
161
|
{
|
165
162
|
VALUE result;
|
166
163
|
RGeo_GeometryData* self_data;
|
@@ -170,29 +167,27 @@ static VALUE method_geometry_dimension(VALUE self)
|
|
170
167
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
171
168
|
self_geom = self_data->geom;
|
172
169
|
if (self_geom) {
|
173
|
-
result = INT2NUM(compute_dimension(
|
170
|
+
result = INT2NUM(compute_dimension(self_geom));
|
174
171
|
}
|
175
172
|
return result;
|
176
173
|
}
|
177
174
|
|
178
|
-
|
179
|
-
|
175
|
+
static VALUE
|
176
|
+
method_geometry_geometry_type(VALUE self)
|
180
177
|
{
|
181
178
|
VALUE result;
|
182
179
|
RGeo_GeometryData* self_data;
|
183
|
-
const GEOSGeometry* self_geom;
|
184
180
|
|
185
181
|
result = Qnil;
|
186
182
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
187
|
-
|
188
|
-
|
189
|
-
result = RGEO_FACTORY_DATA_PTR(self_data->factory)->globals->feature_geometry;
|
183
|
+
if (self_data->geom) {
|
184
|
+
result = rgeo_feature_geometry_module;
|
190
185
|
}
|
191
186
|
return result;
|
192
187
|
}
|
193
188
|
|
194
|
-
|
195
|
-
|
189
|
+
static VALUE
|
190
|
+
method_geometry_srid(VALUE self)
|
196
191
|
{
|
197
192
|
VALUE result;
|
198
193
|
RGeo_GeometryData* self_data;
|
@@ -202,49 +197,45 @@ static VALUE method_geometry_srid(VALUE self)
|
|
202
197
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
203
198
|
self_geom = self_data->geom;
|
204
199
|
if (self_geom) {
|
205
|
-
result = INT2NUM(
|
200
|
+
result = INT2NUM(GEOSGetSRID(self_geom));
|
206
201
|
}
|
207
202
|
return result;
|
208
203
|
}
|
209
204
|
|
210
|
-
|
211
|
-
|
205
|
+
static VALUE
|
206
|
+
method_geometry_envelope(VALUE self)
|
212
207
|
{
|
213
208
|
VALUE result;
|
214
209
|
RGeo_GeometryData* self_data;
|
215
210
|
const GEOSGeometry* self_geom;
|
216
|
-
GEOSContextHandle_t geos_context;
|
217
211
|
GEOSGeometry* envelope;
|
218
212
|
|
219
213
|
result = Qnil;
|
220
214
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
221
215
|
self_geom = self_data->geom;
|
222
216
|
if (self_geom) {
|
223
|
-
|
224
|
-
envelope = GEOSEnvelope_r(geos_context, self_geom);
|
217
|
+
envelope = GEOSEnvelope(self_geom);
|
225
218
|
if (!envelope) {
|
226
|
-
envelope =
|
219
|
+
envelope = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, NULL, 0);
|
227
220
|
}
|
228
221
|
result = rgeo_wrap_geos_geometry(self_data->factory, envelope, Qnil);
|
229
222
|
}
|
230
223
|
return result;
|
231
224
|
}
|
232
225
|
|
233
|
-
|
234
|
-
|
226
|
+
static VALUE
|
227
|
+
method_geometry_boundary(VALUE self)
|
235
228
|
{
|
236
229
|
VALUE result;
|
237
230
|
RGeo_GeometryData* self_data;
|
238
231
|
const GEOSGeometry* self_geom;
|
239
|
-
GEOSContextHandle_t geos_context;
|
240
232
|
GEOSGeometry* boundary;
|
241
233
|
|
242
234
|
result = Qnil;
|
243
235
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
244
236
|
self_geom = self_data->geom;
|
245
237
|
if (self_geom) {
|
246
|
-
|
247
|
-
boundary = GEOSBoundary_r(geos_context, self_geom);
|
238
|
+
boundary = GEOSBoundary(self_geom);
|
248
239
|
if (boundary) {
|
249
240
|
result = rgeo_wrap_geos_geometry(self_data->factory, boundary, Qnil);
|
250
241
|
}
|
@@ -252,8 +243,8 @@ static VALUE method_geometry_boundary(VALUE self)
|
|
252
243
|
return result;
|
253
244
|
}
|
254
245
|
|
255
|
-
|
256
|
-
|
246
|
+
static VALUE
|
247
|
+
method_geometry_as_text(VALUE self)
|
257
248
|
{
|
258
249
|
VALUE result;
|
259
250
|
RGeo_GeometryData* self_data;
|
@@ -261,7 +252,6 @@ static VALUE method_geometry_as_text(VALUE self)
|
|
261
252
|
RGeo_FactoryData* factory_data;
|
262
253
|
VALUE wkt_generator;
|
263
254
|
GEOSWKTWriter* wkt_writer;
|
264
|
-
GEOSContextHandle_t geos_context;
|
265
255
|
char* str;
|
266
256
|
|
267
257
|
result = Qnil;
|
@@ -271,27 +261,27 @@ static VALUE method_geometry_as_text(VALUE self)
|
|
271
261
|
factory_data = RGEO_FACTORY_DATA_PTR(self_data->factory);
|
272
262
|
wkt_generator = factory_data->wkrep_wkt_generator;
|
273
263
|
if (!NIL_P(wkt_generator)) {
|
274
|
-
result = rb_funcall(wkt_generator,
|
275
|
-
}
|
276
|
-
else {
|
264
|
+
result = rb_funcall(wkt_generator, rb_intern("generate"), 1, self);
|
265
|
+
} else {
|
277
266
|
wkt_writer = factory_data->wkt_writer;
|
278
|
-
geos_context = self_data->geos_context;
|
279
267
|
if (!wkt_writer) {
|
280
|
-
wkt_writer =
|
268
|
+
wkt_writer = GEOSWKTWriter_create();
|
269
|
+
GEOSWKTWriter_setOutputDimension(wkt_writer, 2);
|
270
|
+
GEOSWKTWriter_setTrim(wkt_writer, 1);
|
281
271
|
factory_data->wkt_writer = wkt_writer;
|
282
272
|
}
|
283
|
-
str =
|
273
|
+
str = GEOSWKTWriter_write(wkt_writer, self_geom);
|
284
274
|
if (str) {
|
285
275
|
result = rb_str_new2(str);
|
286
|
-
|
276
|
+
GEOSFree(str);
|
287
277
|
}
|
288
278
|
}
|
289
279
|
}
|
290
280
|
return result;
|
291
281
|
}
|
292
282
|
|
293
|
-
|
294
|
-
|
283
|
+
static VALUE
|
284
|
+
method_geometry_as_binary(VALUE self)
|
295
285
|
{
|
296
286
|
VALUE result;
|
297
287
|
RGeo_GeometryData* self_data;
|
@@ -299,7 +289,6 @@ static VALUE method_geometry_as_binary(VALUE self)
|
|
299
289
|
RGeo_FactoryData* factory_data;
|
300
290
|
VALUE wkb_generator;
|
301
291
|
GEOSWKBWriter* wkb_writer;
|
302
|
-
GEOSContextHandle_t geos_context;
|
303
292
|
size_t size;
|
304
293
|
char* str;
|
305
294
|
|
@@ -310,27 +299,27 @@ static VALUE method_geometry_as_binary(VALUE self)
|
|
310
299
|
factory_data = RGEO_FACTORY_DATA_PTR(self_data->factory);
|
311
300
|
wkb_generator = factory_data->wkrep_wkb_generator;
|
312
301
|
if (!NIL_P(wkb_generator)) {
|
313
|
-
result = rb_funcall(wkb_generator,
|
314
|
-
}
|
315
|
-
else {
|
302
|
+
result = rb_funcall(wkb_generator, rb_intern("generate"), 1, self);
|
303
|
+
} else {
|
316
304
|
wkb_writer = factory_data->wkb_writer;
|
317
|
-
|
305
|
+
|
318
306
|
if (!wkb_writer) {
|
319
|
-
wkb_writer =
|
307
|
+
wkb_writer = GEOSWKBWriter_create();
|
308
|
+
GEOSWKBWriter_setOutputDimension(wkb_writer, 2);
|
320
309
|
factory_data->wkb_writer = wkb_writer;
|
321
310
|
}
|
322
|
-
str = (char*)
|
311
|
+
str = (char*)GEOSWKBWriter_write(wkb_writer, self_geom, &size);
|
323
312
|
if (str) {
|
324
313
|
result = rb_str_new(str, size);
|
325
|
-
|
314
|
+
GEOSFree(str);
|
326
315
|
}
|
327
316
|
}
|
328
317
|
}
|
329
318
|
return result;
|
330
319
|
}
|
331
320
|
|
332
|
-
|
333
|
-
|
321
|
+
static VALUE
|
322
|
+
method_geometry_is_empty(VALUE self)
|
334
323
|
{
|
335
324
|
VALUE result;
|
336
325
|
RGeo_GeometryData* self_data;
|
@@ -341,19 +330,18 @@ static VALUE method_geometry_is_empty(VALUE self)
|
|
341
330
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
342
331
|
self_geom = self_data->geom;
|
343
332
|
if (self_geom) {
|
344
|
-
val =
|
333
|
+
val = GEOSisEmpty(self_geom);
|
345
334
|
if (val == 0) {
|
346
335
|
result = Qfalse;
|
347
|
-
}
|
348
|
-
else if (val == 1) {
|
336
|
+
} else if (val == 1) {
|
349
337
|
result = Qtrue;
|
350
338
|
}
|
351
339
|
}
|
352
340
|
return result;
|
353
341
|
}
|
354
342
|
|
355
|
-
|
356
|
-
|
343
|
+
static VALUE
|
344
|
+
method_geometry_is_simple(VALUE self)
|
357
345
|
{
|
358
346
|
VALUE result;
|
359
347
|
RGeo_GeometryData* self_data;
|
@@ -364,26 +352,28 @@ static VALUE method_geometry_is_simple(VALUE self)
|
|
364
352
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
365
353
|
self_geom = self_data->geom;
|
366
354
|
if (self_geom) {
|
367
|
-
val =
|
355
|
+
val = GEOSisSimple(self_geom);
|
368
356
|
if (val == 0) {
|
369
357
|
result = Qfalse;
|
370
|
-
}
|
371
|
-
else if (val == 1) {
|
358
|
+
} else if (val == 1) {
|
372
359
|
result = Qtrue;
|
373
360
|
}
|
374
361
|
}
|
375
362
|
return result;
|
376
363
|
}
|
377
364
|
|
378
|
-
|
379
|
-
|
365
|
+
static VALUE
|
366
|
+
method_geometry_equals(VALUE self, VALUE rhs)
|
380
367
|
{
|
381
368
|
VALUE result;
|
382
369
|
RGeo_GeometryData* self_data;
|
383
370
|
const GEOSGeometry* self_geom;
|
384
371
|
const GEOSGeometry* rhs_geom;
|
385
|
-
|
386
|
-
|
372
|
+
|
373
|
+
// Shortcut when self and rhs are the same object.
|
374
|
+
if (self == rhs) {
|
375
|
+
return Qtrue;
|
376
|
+
}
|
387
377
|
|
388
378
|
result = Qnil;
|
389
379
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
@@ -391,42 +381,33 @@ static VALUE method_geometry_equals(VALUE self, VALUE rhs)
|
|
391
381
|
if (self_geom) {
|
392
382
|
rhs_geom = rgeo_get_geos_geometry_safe(rhs);
|
393
383
|
if (rhs_geom) {
|
394
|
-
self_context = self_data->geos_context;
|
395
384
|
// GEOS has a bug where empty geometries are not spatially equal
|
396
385
|
// to each other. Work around this case first.
|
397
|
-
if (
|
398
|
-
GEOSisEmpty_r(RGEO_GEOMETRY_DATA_PTR(rhs)->geos_context, rhs_geom) == 1) {
|
386
|
+
if (GEOSisEmpty(self_geom) == 1 && GEOSisEmpty(rhs_geom) == 1) {
|
399
387
|
result = Qtrue;
|
400
|
-
}
|
401
|
-
|
402
|
-
val = GEOSEquals_r(self_context, self_geom, rhs_geom);
|
403
|
-
if (val == 0) {
|
404
|
-
result = Qfalse;
|
405
|
-
}
|
406
|
-
else if (val == 1) {
|
407
|
-
result = Qtrue;
|
408
|
-
}
|
388
|
+
} else {
|
389
|
+
result = GEOSEquals(self_geom, rhs_geom) ? Qtrue : Qfalse;
|
409
390
|
}
|
410
391
|
}
|
411
392
|
}
|
412
393
|
return result;
|
413
394
|
}
|
414
395
|
|
415
|
-
|
416
|
-
|
396
|
+
static VALUE
|
397
|
+
method_geometry_eql(VALUE self, VALUE rhs)
|
417
398
|
{
|
418
399
|
// This should be overridden by the subclass.
|
419
400
|
return self == rhs ? Qtrue : Qfalse;
|
420
401
|
}
|
421
402
|
|
422
|
-
|
423
|
-
|
403
|
+
static VALUE
|
404
|
+
method_geometry_disjoint(VALUE self, VALUE rhs)
|
424
405
|
{
|
425
406
|
VALUE result;
|
426
407
|
RGeo_GeometryData* self_data;
|
427
408
|
const GEOSGeometry* self_geom;
|
428
409
|
const GEOSGeometry* rhs_geom;
|
429
|
-
|
410
|
+
int state = 0;
|
430
411
|
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
|
431
412
|
const GEOSPreparedGeometry* prep;
|
432
413
|
#endif
|
@@ -435,34 +416,31 @@ static VALUE method_geometry_disjoint(VALUE self, VALUE rhs)
|
|
435
416
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
436
417
|
self_geom = self_data->geom;
|
437
418
|
if (self_geom) {
|
438
|
-
rhs_geom =
|
439
|
-
|
419
|
+
rhs_geom =
|
420
|
+
rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil, &state);
|
421
|
+
if (state) {
|
422
|
+
rb_jump_tag(state);
|
423
|
+
}
|
440
424
|
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
425
|
+
prep = rgeo_request_prepared_geometry(self_data);
|
426
|
+
if (prep)
|
427
|
+
result = GEOSPreparedDisjoint(prep, rhs_geom) ? Qtrue : Qfalse;
|
428
|
+
else
|
445
429
|
#endif
|
446
|
-
|
447
|
-
if (val == 0) {
|
448
|
-
result = Qfalse;
|
449
|
-
}
|
450
|
-
else if (val == 1) {
|
451
|
-
result = Qtrue;
|
452
|
-
}
|
453
|
-
}
|
430
|
+
result = GEOSDisjoint(self_geom, rhs_geom) ? Qtrue : Qfalse;
|
454
431
|
}
|
455
432
|
return result;
|
456
433
|
}
|
457
434
|
|
458
|
-
|
459
|
-
|
435
|
+
static VALUE
|
436
|
+
method_geometry_intersects(VALUE self, VALUE rhs)
|
460
437
|
{
|
461
438
|
VALUE result;
|
462
439
|
RGeo_GeometryData* self_data;
|
463
440
|
const GEOSGeometry* self_geom;
|
464
441
|
const GEOSGeometry* rhs_geom;
|
465
442
|
char val;
|
443
|
+
int state = 0;
|
466
444
|
#ifdef RGEO_GEOS_SUPPORTS_PREPARED1
|
467
445
|
const GEOSPreparedGeometry* prep;
|
468
446
|
#endif
|
@@ -471,34 +449,36 @@ static VALUE method_geometry_intersects(VALUE self, VALUE rhs)
|
|
471
449
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
472
450
|
self_geom = self_data->geom;
|
473
451
|
if (self_geom) {
|
474
|
-
rhs_geom =
|
475
|
-
|
452
|
+
rhs_geom =
|
453
|
+
rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil, &state);
|
454
|
+
if (state) {
|
455
|
+
rb_jump_tag(state);
|
456
|
+
}
|
476
457
|
#ifdef RGEO_GEOS_SUPPORTS_PREPARED1
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
458
|
+
prep = rgeo_request_prepared_geometry(self_data);
|
459
|
+
if (prep)
|
460
|
+
val = GEOSPreparedIntersects(prep, rhs_geom);
|
461
|
+
else
|
481
462
|
#endif
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
result = Qtrue;
|
488
|
-
}
|
463
|
+
val = GEOSIntersects(self_geom, rhs_geom);
|
464
|
+
if (val == 0) {
|
465
|
+
result = Qfalse;
|
466
|
+
} else if (val == 1) {
|
467
|
+
result = Qtrue;
|
489
468
|
}
|
490
469
|
}
|
491
470
|
return result;
|
492
471
|
}
|
493
472
|
|
494
|
-
|
495
|
-
|
473
|
+
static VALUE
|
474
|
+
method_geometry_touches(VALUE self, VALUE rhs)
|
496
475
|
{
|
497
476
|
VALUE result;
|
498
477
|
RGeo_GeometryData* self_data;
|
499
478
|
const GEOSGeometry* self_geom;
|
500
479
|
const GEOSGeometry* rhs_geom;
|
501
480
|
char val;
|
481
|
+
int state = 0;
|
502
482
|
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
|
503
483
|
const GEOSPreparedGeometry* prep;
|
504
484
|
#endif
|
@@ -507,34 +487,36 @@ static VALUE method_geometry_touches(VALUE self, VALUE rhs)
|
|
507
487
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
508
488
|
self_geom = self_data->geom;
|
509
489
|
if (self_geom) {
|
510
|
-
rhs_geom =
|
511
|
-
|
490
|
+
rhs_geom =
|
491
|
+
rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil, &state);
|
492
|
+
if (state) {
|
493
|
+
rb_jump_tag(state);
|
494
|
+
}
|
512
495
|
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
496
|
+
prep = rgeo_request_prepared_geometry(self_data);
|
497
|
+
if (prep)
|
498
|
+
val = GEOSPreparedTouches(prep, rhs_geom);
|
499
|
+
else
|
517
500
|
#endif
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
result = Qtrue;
|
524
|
-
}
|
501
|
+
val = GEOSTouches(self_geom, rhs_geom);
|
502
|
+
if (val == 0) {
|
503
|
+
result = Qfalse;
|
504
|
+
} else if (val == 1) {
|
505
|
+
result = Qtrue;
|
525
506
|
}
|
526
507
|
}
|
527
508
|
return result;
|
528
509
|
}
|
529
510
|
|
530
|
-
|
531
|
-
|
511
|
+
static VALUE
|
512
|
+
method_geometry_crosses(VALUE self, VALUE rhs)
|
532
513
|
{
|
533
514
|
VALUE result;
|
534
515
|
RGeo_GeometryData* self_data;
|
535
516
|
const GEOSGeometry* self_geom;
|
536
517
|
const GEOSGeometry* rhs_geom;
|
537
518
|
char val;
|
519
|
+
int state = 0;
|
538
520
|
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
|
539
521
|
const GEOSPreparedGeometry* prep;
|
540
522
|
#endif
|
@@ -543,34 +525,36 @@ static VALUE method_geometry_crosses(VALUE self, VALUE rhs)
|
|
543
525
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
544
526
|
self_geom = self_data->geom;
|
545
527
|
if (self_geom) {
|
546
|
-
rhs_geom =
|
547
|
-
|
528
|
+
rhs_geom =
|
529
|
+
rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil, &state);
|
530
|
+
if (state) {
|
531
|
+
rb_jump_tag(state);
|
532
|
+
}
|
548
533
|
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
534
|
+
prep = rgeo_request_prepared_geometry(self_data);
|
535
|
+
if (prep)
|
536
|
+
val = GEOSPreparedCrosses(prep, rhs_geom);
|
537
|
+
else
|
553
538
|
#endif
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
result = Qtrue;
|
560
|
-
}
|
539
|
+
val = GEOSCrosses(self_geom, rhs_geom);
|
540
|
+
if (val == 0) {
|
541
|
+
result = Qfalse;
|
542
|
+
} else if (val == 1) {
|
543
|
+
result = Qtrue;
|
561
544
|
}
|
562
545
|
}
|
563
546
|
return result;
|
564
547
|
}
|
565
548
|
|
566
|
-
|
567
|
-
|
549
|
+
static VALUE
|
550
|
+
method_geometry_within(VALUE self, VALUE rhs)
|
568
551
|
{
|
569
552
|
VALUE result;
|
570
553
|
RGeo_GeometryData* self_data;
|
571
554
|
const GEOSGeometry* self_geom;
|
572
555
|
const GEOSGeometry* rhs_geom;
|
573
556
|
char val;
|
557
|
+
int state = 0;
|
574
558
|
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
|
575
559
|
const GEOSPreparedGeometry* prep;
|
576
560
|
#endif
|
@@ -579,34 +563,36 @@ static VALUE method_geometry_within(VALUE self, VALUE rhs)
|
|
579
563
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
580
564
|
self_geom = self_data->geom;
|
581
565
|
if (self_geom) {
|
582
|
-
rhs_geom =
|
583
|
-
|
566
|
+
rhs_geom =
|
567
|
+
rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil, &state);
|
568
|
+
if (state) {
|
569
|
+
rb_jump_tag(state);
|
570
|
+
}
|
584
571
|
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
572
|
+
prep = rgeo_request_prepared_geometry(self_data);
|
573
|
+
if (prep)
|
574
|
+
val = GEOSPreparedWithin(prep, rhs_geom);
|
575
|
+
else
|
589
576
|
#endif
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
result = Qtrue;
|
596
|
-
}
|
577
|
+
val = GEOSWithin(self_geom, rhs_geom);
|
578
|
+
if (val == 0) {
|
579
|
+
result = Qfalse;
|
580
|
+
} else if (val == 1) {
|
581
|
+
result = Qtrue;
|
597
582
|
}
|
598
583
|
}
|
599
584
|
return result;
|
600
585
|
}
|
601
586
|
|
602
|
-
|
603
|
-
|
587
|
+
static VALUE
|
588
|
+
method_geometry_contains(VALUE self, VALUE rhs)
|
604
589
|
{
|
605
590
|
VALUE result;
|
606
591
|
RGeo_GeometryData* self_data;
|
607
592
|
const GEOSGeometry* self_geom;
|
608
593
|
const GEOSGeometry* rhs_geom;
|
609
594
|
char val;
|
595
|
+
int state = 0;
|
610
596
|
#ifdef RGEO_GEOS_SUPPORTS_PREPARED1
|
611
597
|
const GEOSPreparedGeometry* prep;
|
612
598
|
#endif
|
@@ -615,34 +601,36 @@ static VALUE method_geometry_contains(VALUE self, VALUE rhs)
|
|
615
601
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
616
602
|
self_geom = self_data->geom;
|
617
603
|
if (self_geom) {
|
618
|
-
rhs_geom =
|
619
|
-
|
604
|
+
rhs_geom =
|
605
|
+
rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil, &state);
|
606
|
+
if (state) {
|
607
|
+
rb_jump_tag(state);
|
608
|
+
}
|
620
609
|
#ifdef RGEO_GEOS_SUPPORTS_PREPARED1
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
610
|
+
prep = rgeo_request_prepared_geometry(self_data);
|
611
|
+
if (prep)
|
612
|
+
val = GEOSPreparedContains(prep, rhs_geom);
|
613
|
+
else
|
625
614
|
#endif
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
result = Qtrue;
|
632
|
-
}
|
615
|
+
val = GEOSContains(self_geom, rhs_geom);
|
616
|
+
if (val == 0) {
|
617
|
+
result = Qfalse;
|
618
|
+
} else if (val == 1) {
|
619
|
+
result = Qtrue;
|
633
620
|
}
|
634
621
|
}
|
635
622
|
return result;
|
636
623
|
}
|
637
624
|
|
638
|
-
|
639
|
-
|
625
|
+
static VALUE
|
626
|
+
method_geometry_overlaps(VALUE self, VALUE rhs)
|
640
627
|
{
|
641
628
|
VALUE result;
|
642
629
|
RGeo_GeometryData* self_data;
|
643
630
|
const GEOSGeometry* self_geom;
|
644
631
|
const GEOSGeometry* rhs_geom;
|
645
632
|
char val;
|
633
|
+
int state = 0;
|
646
634
|
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
|
647
635
|
const GEOSPreparedGeometry* prep;
|
648
636
|
#endif
|
@@ -651,78 +639,86 @@ static VALUE method_geometry_overlaps(VALUE self, VALUE rhs)
|
|
651
639
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
652
640
|
self_geom = self_data->geom;
|
653
641
|
if (self_geom) {
|
654
|
-
rhs_geom =
|
655
|
-
|
642
|
+
rhs_geom =
|
643
|
+
rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil, &state);
|
644
|
+
if (state) {
|
645
|
+
rb_jump_tag(state);
|
646
|
+
}
|
656
647
|
#ifdef RGEO_GEOS_SUPPORTS_PREPARED2
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
648
|
+
prep = rgeo_request_prepared_geometry(self_data);
|
649
|
+
if (prep)
|
650
|
+
val = GEOSPreparedOverlaps(prep, rhs_geom);
|
651
|
+
else
|
661
652
|
#endif
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
result = Qtrue;
|
668
|
-
}
|
653
|
+
val = GEOSOverlaps(self_geom, rhs_geom);
|
654
|
+
if (val == 0) {
|
655
|
+
result = Qfalse;
|
656
|
+
} else if (val == 1) {
|
657
|
+
result = Qtrue;
|
669
658
|
}
|
670
659
|
}
|
671
660
|
return result;
|
672
661
|
}
|
673
662
|
|
674
|
-
|
675
|
-
|
663
|
+
static VALUE
|
664
|
+
method_geometry_relate(VALUE self, VALUE rhs, VALUE pattern)
|
676
665
|
{
|
677
666
|
VALUE result;
|
678
667
|
RGeo_GeometryData* self_data;
|
679
668
|
const GEOSGeometry* self_geom;
|
680
669
|
const GEOSGeometry* rhs_geom;
|
681
670
|
char val;
|
671
|
+
int state = 0;
|
682
672
|
|
683
673
|
result = Qnil;
|
684
674
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
685
675
|
self_geom = self_data->geom;
|
686
676
|
if (self_geom) {
|
687
|
-
rhs_geom =
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
677
|
+
rhs_geom =
|
678
|
+
rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil, &state);
|
679
|
+
if (state) {
|
680
|
+
rb_jump_tag(state);
|
681
|
+
}
|
682
|
+
|
683
|
+
val = GEOSRelatePattern(self_geom, rhs_geom, StringValuePtr(pattern));
|
684
|
+
if (val == 0) {
|
685
|
+
result = Qfalse;
|
686
|
+
} else if (val == 1) {
|
687
|
+
result = Qtrue;
|
696
688
|
}
|
697
689
|
}
|
698
690
|
return result;
|
699
691
|
}
|
700
692
|
|
701
|
-
|
702
|
-
|
693
|
+
static VALUE
|
694
|
+
method_geometry_distance(VALUE self, VALUE rhs)
|
703
695
|
{
|
704
696
|
VALUE result;
|
705
697
|
RGeo_GeometryData* self_data;
|
706
698
|
const GEOSGeometry* self_geom;
|
707
699
|
const GEOSGeometry* rhs_geom;
|
708
700
|
double dist;
|
701
|
+
int state = 0;
|
709
702
|
|
710
703
|
result = Qnil;
|
711
704
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
712
705
|
self_geom = self_data->geom;
|
713
706
|
if (self_geom) {
|
714
|
-
rhs_geom =
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
707
|
+
rhs_geom =
|
708
|
+
rgeo_convert_to_geos_geometry(self_data->factory, rhs, Qnil, &state);
|
709
|
+
if (state) {
|
710
|
+
rb_jump_tag(state);
|
711
|
+
}
|
712
|
+
|
713
|
+
if (GEOSDistance(self_geom, rhs_geom, &dist)) {
|
714
|
+
result = rb_float_new(dist);
|
719
715
|
}
|
720
716
|
}
|
721
717
|
return result;
|
722
718
|
}
|
723
719
|
|
724
|
-
|
725
|
-
|
720
|
+
static VALUE
|
721
|
+
method_geometry_buffer(VALUE self, VALUE distance)
|
726
722
|
{
|
727
723
|
VALUE result;
|
728
724
|
RGeo_GeometryData* self_data;
|
@@ -734,13 +730,19 @@ static VALUE method_geometry_buffer(VALUE self, VALUE distance)
|
|
734
730
|
self_geom = self_data->geom;
|
735
731
|
if (self_geom) {
|
736
732
|
factory = self_data->factory;
|
737
|
-
result = rgeo_wrap_geos_geometry(
|
738
|
-
|
733
|
+
result = rgeo_wrap_geos_geometry(
|
734
|
+
factory,
|
735
|
+
GEOSBuffer(self_geom,
|
736
|
+
rb_num2dbl(distance),
|
737
|
+
RGEO_FACTORY_DATA_PTR(factory)->buffer_resolution),
|
738
|
+
Qnil);
|
739
739
|
}
|
740
740
|
return result;
|
741
741
|
}
|
742
742
|
|
743
|
-
|
743
|
+
#ifdef RGEO_GEOS_SUPPORTS_DENSIFY
|
744
|
+
static VALUE
|
745
|
+
method_geometry_segmentize(VALUE self, VALUE max_segment_length)
|
744
746
|
{
|
745
747
|
VALUE result;
|
746
748
|
RGeo_GeometryData* self_data;
|
@@ -752,19 +754,19 @@ static VALUE method_geometry_buffer_with_style(VALUE self, VALUE distance, VALUE
|
|
752
754
|
self_geom = self_data->geom;
|
753
755
|
if (self_geom) {
|
754
756
|
factory = self_data->factory;
|
755
|
-
result = rgeo_wrap_geos_geometry(
|
756
|
-
|
757
|
-
rb_num2dbl(distance),
|
758
|
-
RGEO_FACTORY_DATA_PTR(factory)->buffer_resolution,
|
759
|
-
rb_num2int(endCapStyle),
|
760
|
-
rb_num2int(joinStyle),
|
761
|
-
rb_num2dbl(mitreLimit)),
|
762
|
-
Qnil);
|
757
|
+
result = rgeo_wrap_geos_geometry(
|
758
|
+
factory, GEOSDensify(self_geom, rb_num2dbl(max_segment_length)), Qnil);
|
763
759
|
}
|
764
760
|
return result;
|
765
761
|
}
|
762
|
+
#endif
|
766
763
|
|
767
|
-
static VALUE
|
764
|
+
static VALUE
|
765
|
+
method_geometry_buffer_with_style(VALUE self,
|
766
|
+
VALUE distance,
|
767
|
+
VALUE endCapStyle,
|
768
|
+
VALUE joinStyle,
|
769
|
+
VALUE mitreLimit)
|
768
770
|
{
|
769
771
|
VALUE result;
|
770
772
|
RGeo_GeometryData* self_data;
|
@@ -776,13 +778,21 @@ static VALUE method_geometry_simplify(VALUE self, VALUE tolerance)
|
|
776
778
|
self_geom = self_data->geom;
|
777
779
|
if (self_geom) {
|
778
780
|
factory = self_data->factory;
|
779
|
-
result = rgeo_wrap_geos_geometry(
|
780
|
-
|
781
|
+
result = rgeo_wrap_geos_geometry(
|
782
|
+
factory,
|
783
|
+
GEOSBufferWithStyle(self_geom,
|
784
|
+
rb_num2dbl(distance),
|
785
|
+
RGEO_FACTORY_DATA_PTR(factory)->buffer_resolution,
|
786
|
+
RB_NUM2INT(endCapStyle),
|
787
|
+
RB_NUM2INT(joinStyle),
|
788
|
+
rb_num2dbl(mitreLimit)),
|
789
|
+
Qnil);
|
781
790
|
}
|
782
791
|
return result;
|
783
792
|
}
|
784
793
|
|
785
|
-
static VALUE
|
794
|
+
static VALUE
|
795
|
+
method_geometry_simplify(VALUE self, VALUE tolerance)
|
786
796
|
{
|
787
797
|
VALUE result;
|
788
798
|
RGeo_GeometryData* self_data;
|
@@ -794,162 +804,194 @@ static VALUE method_geometry_simplify_preserve_topology(VALUE self, VALUE tolera
|
|
794
804
|
self_geom = self_data->geom;
|
795
805
|
if (self_geom) {
|
796
806
|
factory = self_data->factory;
|
797
|
-
result = rgeo_wrap_geos_geometry(
|
798
|
-
rb_num2dbl(tolerance)), Qnil);
|
807
|
+
result = rgeo_wrap_geos_geometry(
|
808
|
+
factory, GEOSSimplify(self_geom, rb_num2dbl(tolerance)), Qnil);
|
799
809
|
}
|
800
810
|
return result;
|
801
811
|
}
|
802
812
|
|
803
|
-
|
804
|
-
|
813
|
+
static VALUE
|
814
|
+
method_geometry_simplify_preserve_topology(VALUE self, VALUE tolerance)
|
805
815
|
{
|
806
816
|
VALUE result;
|
807
817
|
RGeo_GeometryData* self_data;
|
808
818
|
const GEOSGeometry* self_geom;
|
819
|
+
VALUE factory;
|
809
820
|
|
810
821
|
result = Qnil;
|
811
822
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
812
823
|
self_geom = self_data->geom;
|
813
824
|
if (self_geom) {
|
814
|
-
|
825
|
+
factory = self_data->factory;
|
826
|
+
result = rgeo_wrap_geos_geometry(
|
827
|
+
factory,
|
828
|
+
GEOSTopologyPreserveSimplify(self_geom, rb_num2dbl(tolerance)),
|
829
|
+
Qnil);
|
815
830
|
}
|
816
831
|
return result;
|
817
832
|
}
|
818
833
|
|
834
|
+
static VALUE
|
835
|
+
method_geometry_convex_hull(VALUE self)
|
836
|
+
{
|
837
|
+
VALUE result;
|
838
|
+
RGeo_GeometryData* self_data;
|
839
|
+
const GEOSGeometry* self_geom;
|
819
840
|
|
820
|
-
|
841
|
+
result = Qnil;
|
842
|
+
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
843
|
+
self_geom = self_data->geom;
|
844
|
+
if (self_geom) {
|
845
|
+
result = rgeo_wrap_geos_geometry(
|
846
|
+
self_data->factory, GEOSConvexHull(self_geom), Qnil);
|
847
|
+
}
|
848
|
+
return result;
|
849
|
+
}
|
850
|
+
|
851
|
+
static VALUE
|
852
|
+
method_geometry_intersection(VALUE self, VALUE rhs)
|
821
853
|
{
|
822
854
|
VALUE result;
|
823
855
|
RGeo_GeometryData* self_data;
|
824
856
|
const GEOSGeometry* self_geom;
|
825
857
|
VALUE factory;
|
826
858
|
const GEOSGeometry* rhs_geom;
|
859
|
+
int state = 0;
|
827
860
|
|
828
861
|
result = Qnil;
|
829
862
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
830
863
|
self_geom = self_data->geom;
|
831
864
|
if (self_geom) {
|
832
865
|
factory = self_data->factory;
|
833
|
-
rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil);
|
834
|
-
if (
|
835
|
-
|
866
|
+
rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil, &state);
|
867
|
+
if (state) {
|
868
|
+
rb_jump_tag(state);
|
836
869
|
}
|
870
|
+
|
871
|
+
result = rgeo_wrap_geos_geometry(
|
872
|
+
factory, GEOSIntersection(self_geom, rhs_geom), Qnil);
|
837
873
|
}
|
838
874
|
return result;
|
839
875
|
}
|
840
876
|
|
841
|
-
|
842
|
-
|
877
|
+
static VALUE
|
878
|
+
method_geometry_union(VALUE self, VALUE rhs)
|
843
879
|
{
|
844
880
|
VALUE result;
|
845
881
|
RGeo_GeometryData* self_data;
|
846
882
|
const GEOSGeometry* self_geom;
|
847
883
|
VALUE factory;
|
848
884
|
const GEOSGeometry* rhs_geom;
|
885
|
+
int state = 0;
|
849
886
|
|
850
887
|
result = Qnil;
|
851
888
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
852
889
|
self_geom = self_data->geom;
|
853
890
|
if (self_geom) {
|
854
891
|
factory = self_data->factory;
|
855
|
-
rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil);
|
856
|
-
if (
|
857
|
-
|
892
|
+
rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil, &state);
|
893
|
+
if (state) {
|
894
|
+
rb_jump_tag(state);
|
858
895
|
}
|
896
|
+
|
897
|
+
result =
|
898
|
+
rgeo_wrap_geos_geometry(factory, GEOSUnion(self_geom, rhs_geom), Qnil);
|
859
899
|
}
|
860
900
|
return result;
|
861
901
|
}
|
862
902
|
|
863
|
-
|
864
|
-
|
903
|
+
static VALUE
|
904
|
+
method_geometry_unary_union(VALUE self)
|
865
905
|
{
|
866
|
-
|
906
|
+
#ifdef RGEO_GEOS_SUPPORTS_UNARYUNION
|
867
907
|
RGeo_GeometryData* self_data;
|
868
908
|
const GEOSGeometry* self_geom;
|
869
909
|
|
870
|
-
result = Qnil;
|
871
|
-
|
872
|
-
#ifdef RGEO_GEOS_SUPPORTS_UNARYUNION
|
873
910
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
874
911
|
self_geom = self_data->geom;
|
875
912
|
if (self_geom) {
|
876
|
-
|
877
|
-
|
878
|
-
GEOSUnaryUnion_r(self_context, self_geom),
|
879
|
-
Qnil);
|
913
|
+
return rgeo_wrap_geos_geometry(
|
914
|
+
self_data->factory, GEOSUnaryUnion(self_geom), Qnil);
|
880
915
|
}
|
881
916
|
#endif
|
882
917
|
|
883
|
-
return
|
918
|
+
return Qnil;
|
884
919
|
}
|
885
920
|
|
886
|
-
|
887
|
-
|
921
|
+
static VALUE
|
922
|
+
method_geometry_difference(VALUE self, VALUE rhs)
|
888
923
|
{
|
889
924
|
VALUE result;
|
890
925
|
RGeo_GeometryData* self_data;
|
891
926
|
const GEOSGeometry* self_geom;
|
892
927
|
VALUE factory;
|
893
928
|
const GEOSGeometry* rhs_geom;
|
929
|
+
int state = 0;
|
894
930
|
|
895
931
|
result = Qnil;
|
896
932
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
897
933
|
self_geom = self_data->geom;
|
898
934
|
if (self_geom) {
|
899
935
|
factory = self_data->factory;
|
900
|
-
rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil);
|
901
|
-
if (
|
902
|
-
|
936
|
+
rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil, &state);
|
937
|
+
if (state) {
|
938
|
+
rb_jump_tag(state);
|
903
939
|
}
|
940
|
+
|
941
|
+
result = rgeo_wrap_geos_geometry(
|
942
|
+
factory, GEOSDifference(self_geom, rhs_geom), Qnil);
|
904
943
|
}
|
905
944
|
return result;
|
906
945
|
}
|
907
946
|
|
908
|
-
|
909
|
-
|
947
|
+
static VALUE
|
948
|
+
method_geometry_sym_difference(VALUE self, VALUE rhs)
|
910
949
|
{
|
911
950
|
VALUE result;
|
912
951
|
RGeo_GeometryData* self_data;
|
913
952
|
const GEOSGeometry* self_geom;
|
914
953
|
VALUE factory;
|
915
954
|
const GEOSGeometry* rhs_geom;
|
955
|
+
int state = 0;
|
916
956
|
|
917
957
|
result = Qnil;
|
918
958
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
919
959
|
self_geom = self_data->geom;
|
920
960
|
if (self_geom) {
|
921
961
|
factory = self_data->factory;
|
922
|
-
rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil);
|
923
|
-
if (
|
924
|
-
|
962
|
+
rhs_geom = rgeo_convert_to_geos_geometry(factory, rhs, Qnil, &state);
|
963
|
+
if (state) {
|
964
|
+
rb_jump_tag(state);
|
925
965
|
}
|
966
|
+
|
967
|
+
result = rgeo_wrap_geos_geometry(
|
968
|
+
factory, GEOSSymDifference(self_geom, rhs_geom), Qnil);
|
926
969
|
}
|
927
970
|
return result;
|
928
971
|
}
|
929
972
|
|
930
|
-
|
931
|
-
|
973
|
+
static VALUE
|
974
|
+
method_geometry_initialize_copy(VALUE self, VALUE orig)
|
932
975
|
{
|
933
976
|
RGeo_GeometryData* self_data;
|
934
977
|
const GEOSPreparedGeometry* prep;
|
935
978
|
const GEOSGeometry* geom;
|
936
979
|
RGeo_GeometryData* orig_data;
|
937
|
-
GEOSContextHandle_t orig_context;
|
938
980
|
GEOSGeometry* clone_geom;
|
939
981
|
RGeo_FactoryData* factory_data;
|
940
982
|
|
941
983
|
// Clear out any existing value
|
942
984
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
943
985
|
if (self_data->geom) {
|
944
|
-
|
986
|
+
GEOSGeom_destroy(self_data->geom);
|
945
987
|
self_data->geom = NULL;
|
946
988
|
}
|
947
989
|
prep = self_data->prep;
|
948
|
-
if (prep && prep != (GEOSPreparedGeometry*)1 &&
|
949
|
-
|
990
|
+
if (prep && prep != (GEOSPreparedGeometry*)1 &&
|
991
|
+
prep != (GEOSPreparedGeometry*)2) {
|
992
|
+
GEOSPreparedGeom_destroy(prep);
|
950
993
|
}
|
951
994
|
self_data->prep = NULL;
|
952
|
-
self_data->geos_context = NULL;
|
953
995
|
self_data->factory = Qnil;
|
954
996
|
self_data->klasses = Qnil;
|
955
997
|
|
@@ -957,15 +999,16 @@ static VALUE method_geometry_initialize_copy(VALUE self, VALUE orig)
|
|
957
999
|
geom = rgeo_get_geos_geometry_safe(orig);
|
958
1000
|
if (geom) {
|
959
1001
|
orig_data = RGEO_GEOMETRY_DATA_PTR(orig);
|
960
|
-
|
961
|
-
clone_geom = GEOSGeom_clone_r(orig_context, geom);
|
1002
|
+
clone_geom = GEOSGeom_clone(geom);
|
962
1003
|
if (clone_geom) {
|
963
1004
|
factory_data = RGEO_FACTORY_DATA_PTR(orig_data->factory);
|
964
|
-
|
1005
|
+
GEOSSetSRID(clone_geom, GEOSGetSRID(geom));
|
965
1006
|
self_data->geom = clone_geom;
|
966
|
-
self_data->
|
967
|
-
|
968
|
-
|
1007
|
+
self_data->prep =
|
1008
|
+
factory_data &&
|
1009
|
+
((factory_data->flags & RGEO_FACTORYFLAGS_PREPARE_HEURISTIC) != 0)
|
1010
|
+
? (GEOSPreparedGeometry*)1
|
1011
|
+
: NULL;
|
969
1012
|
self_data->factory = orig_data->factory;
|
970
1013
|
self_data->klasses = orig_data->klasses;
|
971
1014
|
}
|
@@ -973,8 +1016,8 @@ static VALUE method_geometry_initialize_copy(VALUE self, VALUE orig)
|
|
973
1016
|
return self;
|
974
1017
|
}
|
975
1018
|
|
976
|
-
|
977
|
-
|
1019
|
+
static VALUE
|
1020
|
+
method_geometry_steal(VALUE self, VALUE orig)
|
978
1021
|
{
|
979
1022
|
RGeo_GeometryData* self_data;
|
980
1023
|
const GEOSPreparedGeometry* prep;
|
@@ -986,32 +1029,32 @@ static VALUE method_geometry_steal(VALUE self, VALUE orig)
|
|
986
1029
|
// Clear out any existing value
|
987
1030
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
988
1031
|
if (self_data->geom) {
|
989
|
-
|
1032
|
+
GEOSGeom_destroy(self_data->geom);
|
990
1033
|
}
|
991
1034
|
prep = self_data->prep;
|
992
|
-
if (prep && prep != (GEOSPreparedGeometry*)1 &&
|
993
|
-
|
1035
|
+
if (prep && prep != (GEOSPreparedGeometry*)1 &&
|
1036
|
+
prep != (GEOSPreparedGeometry*)2) {
|
1037
|
+
GEOSPreparedGeom_destroy(prep);
|
994
1038
|
}
|
995
1039
|
|
996
1040
|
// Steal value from orig
|
997
1041
|
orig_data = RGEO_GEOMETRY_DATA_PTR(orig);
|
998
1042
|
self_data->geom = orig_data->geom;
|
999
1043
|
self_data->prep = orig_data->prep;
|
1000
|
-
self_data->geos_context = orig_data->geos_context;
|
1001
1044
|
self_data->factory = orig_data->factory;
|
1002
1045
|
self_data->klasses = orig_data->klasses;
|
1003
1046
|
|
1004
1047
|
// Clear out orig
|
1005
1048
|
orig_data->geom = NULL;
|
1006
1049
|
orig_data->prep = NULL;
|
1007
|
-
orig_data->geos_context = NULL;
|
1008
1050
|
orig_data->factory = Qnil;
|
1009
1051
|
orig_data->klasses = Qnil;
|
1010
1052
|
}
|
1011
1053
|
return self;
|
1012
1054
|
}
|
1013
1055
|
|
1014
|
-
static VALUE
|
1056
|
+
static VALUE
|
1057
|
+
method_geometry_is_valid(VALUE self)
|
1015
1058
|
{
|
1016
1059
|
VALUE result;
|
1017
1060
|
RGeo_GeometryData* self_data;
|
@@ -1022,18 +1065,18 @@ static VALUE method_geometry_is_valid(VALUE self)
|
|
1022
1065
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
1023
1066
|
self_geom = self_data->geom;
|
1024
1067
|
if (self_geom) {
|
1025
|
-
val =
|
1068
|
+
val = GEOSisValid(self_geom);
|
1026
1069
|
if (val == 0) {
|
1027
1070
|
result = Qfalse;
|
1028
|
-
}
|
1029
|
-
else if (val == 1) {
|
1071
|
+
} else if (val == 1) {
|
1030
1072
|
result = Qtrue;
|
1031
1073
|
}
|
1032
1074
|
}
|
1033
1075
|
return result;
|
1034
1076
|
}
|
1035
1077
|
|
1036
|
-
static VALUE
|
1078
|
+
static VALUE
|
1079
|
+
method_geometry_invalid_reason(VALUE self)
|
1037
1080
|
{
|
1038
1081
|
VALUE result;
|
1039
1082
|
RGeo_GeometryData* self_data;
|
@@ -1044,91 +1087,254 @@ static VALUE method_geometry_invalid_reason(VALUE self)
|
|
1044
1087
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
1045
1088
|
self_geom = self_data->geom;
|
1046
1089
|
if (self_geom) {
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1090
|
+
// We use NULL there to tell GEOS that we don't care about the position.
|
1091
|
+
switch (GEOSisValidDetail(self_geom, 0, &str, NULL)) {
|
1092
|
+
case 0: // invalid
|
1093
|
+
result = rb_utf8_str_new_cstr(str);
|
1094
|
+
case 1: // valid
|
1095
|
+
break;
|
1096
|
+
case 2: // exception
|
1097
|
+
default:
|
1098
|
+
result = rb_utf8_str_new_cstr("Exception");
|
1099
|
+
break;
|
1100
|
+
};
|
1101
|
+
if (str)
|
1102
|
+
GEOSFree(str);
|
1055
1103
|
}
|
1056
1104
|
return result;
|
1057
1105
|
}
|
1058
1106
|
|
1059
|
-
static VALUE
|
1107
|
+
static VALUE
|
1108
|
+
method_geometry_invalid_reason_location(VALUE self)
|
1060
1109
|
{
|
1061
1110
|
VALUE result;
|
1062
1111
|
RGeo_GeometryData* self_data;
|
1063
1112
|
const GEOSGeometry* self_geom;
|
1113
|
+
GEOSGeometry* location = NULL;
|
1064
1114
|
|
1065
1115
|
result = Qnil;
|
1066
1116
|
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
1067
1117
|
self_geom = self_data->geom;
|
1068
1118
|
if (self_geom) {
|
1069
|
-
|
1119
|
+
// We use NULL there to tell GEOS that we don't care about the reason.
|
1120
|
+
switch (GEOSisValidDetail(self_geom, 0, NULL, &location)) {
|
1121
|
+
case 0: // invalid
|
1122
|
+
result = rgeo_wrap_geos_geometry(self_data->factory, location, Qnil);
|
1123
|
+
case 1: // valid
|
1124
|
+
break;
|
1125
|
+
case 2: // exception
|
1126
|
+
break;
|
1127
|
+
default:
|
1128
|
+
break;
|
1129
|
+
};
|
1070
1130
|
}
|
1071
1131
|
return result;
|
1072
1132
|
}
|
1073
1133
|
|
1134
|
+
static VALUE
|
1135
|
+
method_geometry_make_valid(VALUE self)
|
1136
|
+
{
|
1137
|
+
RGeo_GeometryData* self_data;
|
1138
|
+
const GEOSGeometry* self_geom;
|
1139
|
+
GEOSGeometry* valid_geom;
|
1140
|
+
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
1141
|
+
self_geom = self_data->geom;
|
1142
|
+
if (!self_geom)
|
1143
|
+
return Qnil;
|
1144
|
+
|
1145
|
+
// According to GEOS implementation, MakeValid always returns.
|
1146
|
+
valid_geom = GEOSMakeValid(self_geom);
|
1147
|
+
if (!valid_geom) {
|
1148
|
+
rb_raise(rb_eRGeoInvalidGeometry,
|
1149
|
+
"%" PRIsVALUE,
|
1150
|
+
method_geometry_invalid_reason(self));
|
1151
|
+
}
|
1152
|
+
return rgeo_wrap_geos_geometry(self_data->factory, valid_geom, Qnil);
|
1153
|
+
}
|
1074
1154
|
|
1075
|
-
|
1155
|
+
static VALUE
|
1156
|
+
method_geometry_point_on_surface(VALUE self)
|
1157
|
+
{
|
1158
|
+
VALUE result;
|
1159
|
+
RGeo_GeometryData* self_data;
|
1160
|
+
const GEOSGeometry* self_geom;
|
1076
1161
|
|
1162
|
+
result = Qnil;
|
1163
|
+
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
1164
|
+
self_geom = self_data->geom;
|
1165
|
+
if (self_geom) {
|
1166
|
+
result = rgeo_wrap_geos_geometry(
|
1167
|
+
self_data->factory, GEOSPointOnSurface(self_geom), Qnil);
|
1168
|
+
}
|
1169
|
+
return result;
|
1170
|
+
}
|
1171
|
+
|
1172
|
+
/**
|
1173
|
+
* call-seq:
|
1174
|
+
* some.polygonize -> RGeo::Feature::GeometryCollection
|
1175
|
+
*
|
1176
|
+
* Polygonizes a set of Geometries which contain linework that
|
1177
|
+
* represents the edges of a planar graph.
|
1178
|
+
*
|
1179
|
+
* All types of Geometry are accepted as input;
|
1180
|
+
* the constituent linework is extracted as the edges to be polygonized.
|
1181
|
+
*
|
1182
|
+
* The edges must be correctly noded;
|
1183
|
+
* that is, they must only meet at their endpoints and not overlap anywhere.
|
1184
|
+
*
|
1185
|
+
* @see
|
1186
|
+
* https://libgeos.org/doxygen/geos__c_8h.html#a9d98e448d3b846d591c726d1c0000d25
|
1187
|
+
* GEOSPolygonize
|
1188
|
+
*/
|
1189
|
+
static VALUE
|
1190
|
+
method_geometry_polygonize(VALUE self)
|
1191
|
+
{
|
1192
|
+
VALUE result;
|
1193
|
+
RGeo_GeometryData* self_data;
|
1194
|
+
const GEOSGeometry* self_geom;
|
1195
|
+
GEOSGeometry* geos_polygon_collection;
|
1196
|
+
|
1197
|
+
result = Qnil;
|
1198
|
+
self_data = RGEO_GEOMETRY_DATA_PTR(self);
|
1199
|
+
self_geom = self_data->geom;
|
1200
|
+
if (self_geom) {
|
1201
|
+
geos_polygon_collection = GEOSPolygonize(&self_geom, 1);
|
1202
|
+
|
1203
|
+
if (geos_polygon_collection == NULL) {
|
1204
|
+
rb_raise(rb_eGeosError, "GEOS can't polygonize this geometry.");
|
1205
|
+
}
|
1077
1206
|
|
1078
|
-
|
1207
|
+
result = rgeo_wrap_geos_geometry(
|
1208
|
+
self_data->factory, geos_polygon_collection, Qnil);
|
1209
|
+
}
|
1210
|
+
return result;
|
1211
|
+
}
|
1212
|
+
|
1213
|
+
VALUE
|
1214
|
+
rgeo_geos_geometries_strict_eql(const GEOSGeometry* geom1,
|
1215
|
+
const GEOSGeometry* geom2)
|
1216
|
+
{
|
1217
|
+
switch (GEOSEqualsExact(geom1, geom2, 0.0)) {
|
1218
|
+
case 0:
|
1219
|
+
return Qfalse;
|
1220
|
+
case 1:
|
1221
|
+
return Qtrue;
|
1222
|
+
case 2:
|
1223
|
+
default:
|
1224
|
+
rb_raise(rb_eGeosError, "Cannot test equality.");
|
1225
|
+
}
|
1226
|
+
}
|
1227
|
+
|
1228
|
+
/**** INITIALIZATION FUNCTION ****/
|
1229
|
+
|
1230
|
+
void
|
1231
|
+
rgeo_init_geos_geometry()
|
1079
1232
|
{
|
1080
1233
|
VALUE geos_geometry_methods;
|
1081
1234
|
|
1082
|
-
geos_geometry_methods =
|
1235
|
+
geos_geometry_methods =
|
1236
|
+
rb_define_module_under(rgeo_geos_module, "CAPIGeometryMethods");
|
1083
1237
|
|
1084
|
-
rb_define_method(
|
1085
|
-
|
1238
|
+
rb_define_method(
|
1239
|
+
geos_geometry_methods, "factory=", method_geometry_set_factory, 1);
|
1240
|
+
rb_define_method(geos_geometry_methods,
|
1241
|
+
"initialize_copy",
|
1242
|
+
method_geometry_initialize_copy,
|
1243
|
+
1);
|
1086
1244
|
rb_define_method(geos_geometry_methods, "_steal", method_geometry_steal, 1);
|
1087
|
-
rb_define_method(
|
1088
|
-
|
1089
|
-
rb_define_method(
|
1090
|
-
|
1091
|
-
rb_define_method(
|
1092
|
-
|
1245
|
+
rb_define_method(
|
1246
|
+
geos_geometry_methods, "initialized?", method_geometry_initialized_p, 0);
|
1247
|
+
rb_define_method(
|
1248
|
+
geos_geometry_methods, "factory", method_geometry_factory, 0);
|
1249
|
+
rb_define_method(
|
1250
|
+
geos_geometry_methods, "prepared?", method_geometry_prepared_p, 0);
|
1251
|
+
rb_define_method(
|
1252
|
+
geos_geometry_methods, "prepare!", method_geometry_prepare, 0);
|
1253
|
+
rb_define_method(
|
1254
|
+
geos_geometry_methods, "dimension", method_geometry_dimension, 0);
|
1255
|
+
rb_define_method(
|
1256
|
+
geos_geometry_methods, "geometry_type", method_geometry_geometry_type, 0);
|
1093
1257
|
rb_define_method(geos_geometry_methods, "srid", method_geometry_srid, 0);
|
1094
|
-
rb_define_method(
|
1095
|
-
|
1096
|
-
rb_define_method(
|
1097
|
-
|
1098
|
-
rb_define_method(
|
1099
|
-
|
1258
|
+
rb_define_method(
|
1259
|
+
geos_geometry_methods, "envelope", method_geometry_envelope, 0);
|
1260
|
+
rb_define_method(
|
1261
|
+
geos_geometry_methods, "boundary", method_geometry_boundary, 0);
|
1262
|
+
rb_define_method(
|
1263
|
+
geos_geometry_methods, "_as_text", method_geometry_as_text, 0);
|
1264
|
+
rb_define_method(
|
1265
|
+
geos_geometry_methods, "as_binary", method_geometry_as_binary, 0);
|
1266
|
+
rb_define_method(
|
1267
|
+
geos_geometry_methods, "empty?", method_geometry_is_empty, 0);
|
1268
|
+
rb_define_method(
|
1269
|
+
geos_geometry_methods, "simple?", method_geometry_is_simple, 0);
|
1100
1270
|
rb_define_method(geos_geometry_methods, "equals?", method_geometry_equals, 1);
|
1101
1271
|
rb_define_method(geos_geometry_methods, "==", method_geometry_equals, 1);
|
1102
|
-
rb_define_method(
|
1272
|
+
rb_define_method(
|
1273
|
+
geos_geometry_methods, "rep_equals?", method_geometry_eql, 1);
|
1103
1274
|
rb_define_method(geos_geometry_methods, "eql?", method_geometry_eql, 1);
|
1104
|
-
rb_define_method(
|
1105
|
-
|
1106
|
-
rb_define_method(
|
1107
|
-
|
1275
|
+
rb_define_method(
|
1276
|
+
geos_geometry_methods, "disjoint?", method_geometry_disjoint, 1);
|
1277
|
+
rb_define_method(
|
1278
|
+
geos_geometry_methods, "intersects?", method_geometry_intersects, 1);
|
1279
|
+
rb_define_method(
|
1280
|
+
geos_geometry_methods, "touches?", method_geometry_touches, 1);
|
1281
|
+
rb_define_method(
|
1282
|
+
geos_geometry_methods, "crosses?", method_geometry_crosses, 1);
|
1108
1283
|
rb_define_method(geos_geometry_methods, "within?", method_geometry_within, 1);
|
1109
|
-
rb_define_method(
|
1110
|
-
|
1284
|
+
rb_define_method(
|
1285
|
+
geos_geometry_methods, "contains?", method_geometry_contains, 1);
|
1286
|
+
rb_define_method(
|
1287
|
+
geos_geometry_methods, "overlaps?", method_geometry_overlaps, 1);
|
1111
1288
|
rb_define_method(geos_geometry_methods, "relate?", method_geometry_relate, 2);
|
1112
|
-
rb_define_method(
|
1289
|
+
rb_define_method(
|
1290
|
+
geos_geometry_methods, "distance", method_geometry_distance, 1);
|
1113
1291
|
rb_define_method(geos_geometry_methods, "buffer", method_geometry_buffer, 1);
|
1114
|
-
rb_define_method(geos_geometry_methods,
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
rb_define_method(
|
1292
|
+
rb_define_method(geos_geometry_methods,
|
1293
|
+
"buffer_with_style",
|
1294
|
+
method_geometry_buffer_with_style,
|
1295
|
+
4);
|
1296
|
+
rb_define_method(
|
1297
|
+
geos_geometry_methods, "simplify", method_geometry_simplify, 1);
|
1298
|
+
rb_define_method(geos_geometry_methods,
|
1299
|
+
"simplify_preserve_topology",
|
1300
|
+
method_geometry_simplify_preserve_topology,
|
1301
|
+
1);
|
1302
|
+
rb_define_method(
|
1303
|
+
geos_geometry_methods, "convex_hull", method_geometry_convex_hull, 0);
|
1304
|
+
rb_define_method(
|
1305
|
+
geos_geometry_methods, "intersection", method_geometry_intersection, 1);
|
1119
1306
|
rb_define_method(geos_geometry_methods, "*", method_geometry_intersection, 1);
|
1120
1307
|
rb_define_method(geos_geometry_methods, "union", method_geometry_union, 1);
|
1121
|
-
rb_define_method(
|
1308
|
+
rb_define_method(
|
1309
|
+
geos_geometry_methods, "unary_union", method_geometry_unary_union, 0);
|
1122
1310
|
rb_define_method(geos_geometry_methods, "+", method_geometry_union, 1);
|
1123
|
-
rb_define_method(
|
1311
|
+
rb_define_method(
|
1312
|
+
geos_geometry_methods, "difference", method_geometry_difference, 1);
|
1124
1313
|
rb_define_method(geos_geometry_methods, "-", method_geometry_difference, 1);
|
1125
|
-
rb_define_method(
|
1126
|
-
|
1127
|
-
rb_define_method(
|
1128
|
-
|
1314
|
+
rb_define_method(
|
1315
|
+
geos_geometry_methods, "sym_difference", method_geometry_sym_difference, 1);
|
1316
|
+
rb_define_method(
|
1317
|
+
geos_geometry_methods, "valid?", method_geometry_is_valid, 0);
|
1318
|
+
rb_define_method(
|
1319
|
+
geos_geometry_methods, "invalid_reason", method_geometry_invalid_reason, 0);
|
1320
|
+
rb_define_method(geos_geometry_methods,
|
1321
|
+
"invalid_reason_location",
|
1322
|
+
method_geometry_invalid_reason_location,
|
1323
|
+
0);
|
1324
|
+
rb_define_method(geos_geometry_methods,
|
1325
|
+
"point_on_surface",
|
1326
|
+
method_geometry_point_on_surface,
|
1327
|
+
0);
|
1328
|
+
rb_define_method(
|
1329
|
+
geos_geometry_methods, "make_valid", method_geometry_make_valid, 0);
|
1330
|
+
rb_define_method(
|
1331
|
+
geos_geometry_methods, "polygonize", method_geometry_polygonize, 0);
|
1332
|
+
#ifdef RGEO_GEOS_SUPPORTS_DENSIFY
|
1333
|
+
rb_define_method(
|
1334
|
+
geos_geometry_methods, "segmentize", method_geometry_segmentize, 1);
|
1335
|
+
#endif
|
1129
1336
|
}
|
1130
1337
|
|
1131
|
-
|
1132
1338
|
RGEO_END_C
|
1133
1339
|
|
1134
1340
|
#endif
|