rgeo 0.1.10
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.
- data/History.rdoc +22 -0
- data/README.rdoc +124 -0
- data/Version +1 -0
- data/ext/geos_c_impl/extconf.rb +72 -0
- data/ext/geos_c_impl/factory.c +468 -0
- data/ext/geos_c_impl/factory.h +217 -0
- data/ext/geos_c_impl/geometry.c +644 -0
- data/ext/geos_c_impl/geometry.h +65 -0
- data/ext/geos_c_impl/geometry_collection.c +580 -0
- data/ext/geos_c_impl/geometry_collection.h +79 -0
- data/ext/geos_c_impl/globals.h +58 -0
- data/ext/geos_c_impl/line_string.c +468 -0
- data/ext/geos_c_impl/line_string.h +74 -0
- data/ext/geos_c_impl/main.c +65 -0
- data/ext/geos_c_impl/point.c +201 -0
- data/ext/geos_c_impl/point.h +77 -0
- data/ext/geos_c_impl/polygon.c +259 -0
- data/ext/geos_c_impl/polygon.h +76 -0
- data/ext/geos_c_impl/preface.h +42 -0
- data/lib/rgeo.rb +68 -0
- data/lib/rgeo/errors.rb +59 -0
- data/lib/rgeo/features.rb +89 -0
- data/lib/rgeo/features/curve.rb +155 -0
- data/lib/rgeo/features/factory.rb +191 -0
- data/lib/rgeo/features/geometry.rb +560 -0
- data/lib/rgeo/features/geometry_collection.rb +118 -0
- data/lib/rgeo/features/line.rb +65 -0
- data/lib/rgeo/features/line_string.rb +101 -0
- data/lib/rgeo/features/linear_ring.rb +65 -0
- data/lib/rgeo/features/multi_curve.rb +112 -0
- data/lib/rgeo/features/multi_line_string.rb +65 -0
- data/lib/rgeo/features/multi_point.rb +72 -0
- data/lib/rgeo/features/multi_polygon.rb +96 -0
- data/lib/rgeo/features/multi_surface.rb +115 -0
- data/lib/rgeo/features/point.rb +97 -0
- data/lib/rgeo/features/polygon.rb +141 -0
- data/lib/rgeo/features/surface.rb +121 -0
- data/lib/rgeo/geo_json.rb +58 -0
- data/lib/rgeo/geo_json/coder.rb +305 -0
- data/lib/rgeo/geo_json/entities.rb +284 -0
- data/lib/rgeo/geo_json/interface.rb +95 -0
- data/lib/rgeo/geography.rb +75 -0
- data/lib/rgeo/geography/common/geometry_collection_methods.rb +206 -0
- data/lib/rgeo/geography/common/geometry_methods.rb +92 -0
- data/lib/rgeo/geography/common/helper.rb +102 -0
- data/lib/rgeo/geography/common/line_string_methods.rb +187 -0
- data/lib/rgeo/geography/common/point_methods.rb +149 -0
- data/lib/rgeo/geography/common/polygon_methods.rb +122 -0
- data/lib/rgeo/geography/factories.rb +136 -0
- data/lib/rgeo/geography/factory.rb +246 -0
- data/lib/rgeo/geography/projected_window.rb +467 -0
- data/lib/rgeo/geography/simple_mercator/feature_classes.rb +320 -0
- data/lib/rgeo/geography/simple_mercator/feature_methods.rb +291 -0
- data/lib/rgeo/geography/simple_mercator/projector.rb +116 -0
- data/lib/rgeo/geography/simple_spherical/calculations.rb +70 -0
- data/lib/rgeo/geography/simple_spherical/geometry_collection_impl.rb +66 -0
- data/lib/rgeo/geography/simple_spherical/geometry_methods.rb +59 -0
- data/lib/rgeo/geography/simple_spherical/line_string_impl.rb +104 -0
- data/lib/rgeo/geography/simple_spherical/multi_line_string_impl.rb +67 -0
- data/lib/rgeo/geography/simple_spherical/multi_point_impl.rb +67 -0
- data/lib/rgeo/geography/simple_spherical/multi_polygon_impl.rb +67 -0
- data/lib/rgeo/geography/simple_spherical/point_impl.rb +85 -0
- data/lib/rgeo/geography/simple_spherical/polygon_impl.rb +66 -0
- data/lib/rgeo/geos.rb +72 -0
- data/lib/rgeo/geos/factory.rb +260 -0
- data/lib/rgeo/geos/impl_additions.rb +57 -0
- data/lib/rgeo/geos/interface.rb +74 -0
- data/lib/rgeo/version.rb +52 -0
- data/tests/geos/tc_factory.rb +91 -0
- data/tests/geos/tc_geometry_collection.rb +226 -0
- data/tests/geos/tc_line_string.rb +310 -0
- data/tests/geos/tc_misc.rb +72 -0
- data/tests/geos/tc_multi_line_string.rb +211 -0
- data/tests/geos/tc_multi_point.rb +202 -0
- data/tests/geos/tc_multi_polygon.rb +210 -0
- data/tests/geos/tc_point.rb +305 -0
- data/tests/geos/tc_polygon.rb +240 -0
- data/tests/simple_mercator/tc_point.rb +303 -0
- data/tests/simple_mercator/tc_window.rb +219 -0
- data/tests/tc_geojson.rb +230 -0
- data/tests/tc_oneoff.rb +61 -0
- metadata +162 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
/*
|
2
|
+
-----------------------------------------------------------------------------
|
3
|
+
|
4
|
+
Geometry base class methods for GEOS wrapper
|
5
|
+
|
6
|
+
-----------------------------------------------------------------------------
|
7
|
+
Copyright 2010 Daniel Azuma
|
8
|
+
|
9
|
+
All rights reserved.
|
10
|
+
|
11
|
+
Redistribution and use in source and binary forms, with or without
|
12
|
+
modification, are permitted provided that the following conditions are met:
|
13
|
+
|
14
|
+
* Redistributions of source code must retain the above copyright notice,
|
15
|
+
this list of conditions and the following disclaimer.
|
16
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
17
|
+
this list of conditions and the following disclaimer in the documentation
|
18
|
+
and/or other materials provided with the distribution.
|
19
|
+
* Neither the name of the copyright holder, nor the names of any other
|
20
|
+
contributors to this software, may be used to endorse or promote products
|
21
|
+
derived from this software without specific prior written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
24
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
25
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
27
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
28
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
29
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
31
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
32
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
-----------------------------------------------------------------------------
|
35
|
+
*/
|
36
|
+
|
37
|
+
|
38
|
+
#ifndef RGEO_GEOS_GEOMETRY_INCLUDED
|
39
|
+
#define RGEO_GEOS_GEOMETRY_INCLUDED
|
40
|
+
|
41
|
+
#include "factory.h"
|
42
|
+
|
43
|
+
#ifdef __cplusplus
|
44
|
+
extern "C" {
|
45
|
+
#if 0
|
46
|
+
}
|
47
|
+
#endif
|
48
|
+
#endif
|
49
|
+
|
50
|
+
|
51
|
+
/*
|
52
|
+
Initializes the geometry module. This should be called after the factory
|
53
|
+
module is initialized, but before any of the other modules.
|
54
|
+
*/
|
55
|
+
void rgeo_init_geos_geometry(RGeo_Globals* globals);
|
56
|
+
|
57
|
+
|
58
|
+
#ifdef __cplusplus
|
59
|
+
#if 0
|
60
|
+
{
|
61
|
+
#endif
|
62
|
+
}
|
63
|
+
#endif
|
64
|
+
|
65
|
+
#endif
|
@@ -0,0 +1,580 @@
|
|
1
|
+
/*
|
2
|
+
-----------------------------------------------------------------------------
|
3
|
+
|
4
|
+
Geometry collection methods for GEOS wrapper
|
5
|
+
|
6
|
+
-----------------------------------------------------------------------------
|
7
|
+
Copyright 2010 Daniel Azuma
|
8
|
+
|
9
|
+
All rights reserved.
|
10
|
+
|
11
|
+
Redistribution and use in source and binary forms, with or without
|
12
|
+
modification, are permitted provided that the following conditions are met:
|
13
|
+
|
14
|
+
* Redistributions of source code must retain the above copyright notice,
|
15
|
+
this list of conditions and the following disclaimer.
|
16
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
17
|
+
this list of conditions and the following disclaimer in the documentation
|
18
|
+
and/or other materials provided with the distribution.
|
19
|
+
* Neither the name of the copyright holder, nor the names of any other
|
20
|
+
contributors to this software, may be used to endorse or promote products
|
21
|
+
derived from this software without specific prior written permission.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
24
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
25
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
26
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
27
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
28
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
29
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
30
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
31
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
32
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
-----------------------------------------------------------------------------
|
35
|
+
*/
|
36
|
+
|
37
|
+
|
38
|
+
#include "preface.h"
|
39
|
+
|
40
|
+
#ifdef RGEO_GEOS_SUPPORTED
|
41
|
+
|
42
|
+
#include <ruby.h>
|
43
|
+
#include <geos_c.h>
|
44
|
+
|
45
|
+
#include "factory.h"
|
46
|
+
#include "geometry.h"
|
47
|
+
#include "line_string.h"
|
48
|
+
#include "polygon.h"
|
49
|
+
#include "geometry_collection.h"
|
50
|
+
|
51
|
+
#ifdef __cplusplus
|
52
|
+
extern "C" {
|
53
|
+
#if 0
|
54
|
+
}
|
55
|
+
#endif
|
56
|
+
#endif
|
57
|
+
|
58
|
+
|
59
|
+
/**** INTERNAL IMPLEMENTATION OF CREATE ****/
|
60
|
+
|
61
|
+
|
62
|
+
static char compute_collection_klasses_internal(int type, VALUE factory, const GEOSGeometry* geom, VALUE in_klass, VALUE out_klasses)
|
63
|
+
{
|
64
|
+
char good = 1;
|
65
|
+
int geom_type = GEOSGeomTypeId_r(RGEO_CONTEXT_FROM_FACTORY(factory), geom);
|
66
|
+
if (type == GEOS_MULTIPOINT && geom_type == GEOS_POINT ||
|
67
|
+
type == GEOS_MULTILINESTRING && (geom_type == GEOS_LINESTRING || geom_type == GEOS_LINEARRING) ||
|
68
|
+
type == GEOS_MULTIPOLYGON && geom_type == GEOS_POLYGON) {
|
69
|
+
rb_ary_push(out_klasses, in_klass);
|
70
|
+
}
|
71
|
+
else if (geom_type == GEOS_GEOMETRYCOLLECTION || type == geom_type) {
|
72
|
+
int len = GEOSGetNumGeometries_r(RGEO_CONTEXT_FROM_FACTORY(factory), geom);
|
73
|
+
int i;
|
74
|
+
for (i=0; i<len; ++i) {
|
75
|
+
const GEOSGeometry* sub_geom = GEOSGetGeometryN_r(RGEO_CONTEXT_FROM_FACTORY(factory), geom, i);
|
76
|
+
if (sub_geom) {
|
77
|
+
VALUE sub_klass = (TYPE(in_klass) == T_ARRAY) ? rb_ary_entry(in_klass, i) : Qnil;
|
78
|
+
good = compute_collection_klasses_internal(type, factory, sub_geom, sub_klass, out_klasses);
|
79
|
+
if (!good) {
|
80
|
+
break;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
else {
|
84
|
+
good = 0;
|
85
|
+
break;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
else {
|
90
|
+
good = 0;
|
91
|
+
}
|
92
|
+
return good;
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
// This walks through an array of geometry objects, and determines the
|
97
|
+
// size of the collection that should be built. For straight
|
98
|
+
// GeometryCollection objects, the size is the same as the length of
|
99
|
+
// the array. For MultiPoint, MultiLineString, and MultiPolygon, we do
|
100
|
+
// recursive gathering of any sub-geometries, so the resulting collection
|
101
|
+
// may have a different length.
|
102
|
+
// We also build an array of the klasses for the geometries gathered.
|
103
|
+
// The array is returned. If a problem occurs-- usually a type mismatch
|
104
|
+
// such as trying to add a LineString to a MultiPoint-- we return Qnil.
|
105
|
+
|
106
|
+
static VALUE compute_collection_klasses(int type, VALUE factory, VALUE array)
|
107
|
+
{
|
108
|
+
unsigned int len = (unsigned int)RARRAY_LEN(array);
|
109
|
+
VALUE result = rb_ary_new();
|
110
|
+
unsigned int i;
|
111
|
+
for (i=0; i<len; ++i) {
|
112
|
+
VALUE entry = rb_ary_entry(array, i);
|
113
|
+
const GEOSGeometry* geom = rgeo_get_geos_geometry_safe(entry);
|
114
|
+
if (!geom) {
|
115
|
+
result = Qnil;
|
116
|
+
break;
|
117
|
+
}
|
118
|
+
VALUE klass = RGEO_KLASSES_FROM_GEOMETRY(entry);
|
119
|
+
if (NIL_P(klass)) {
|
120
|
+
klass = CLASS_OF(entry);
|
121
|
+
}
|
122
|
+
if (type == GEOS_GEOMETRYCOLLECTION) {
|
123
|
+
rb_ary_push(result, klass);
|
124
|
+
}
|
125
|
+
else {
|
126
|
+
char good = compute_collection_klasses_internal(type, factory, geom, klass, result);
|
127
|
+
if (!good) {
|
128
|
+
result = Qnil;
|
129
|
+
break;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
}
|
133
|
+
return result;
|
134
|
+
}
|
135
|
+
|
136
|
+
|
137
|
+
static char gather_geometry_collection_internal(int type, VALUE factory, GEOSGeometry** geoms, unsigned int* ci, const GEOSGeometry* geom, char geom_mine)
|
138
|
+
{
|
139
|
+
char good = 1;
|
140
|
+
int geom_type = GEOSGeomTypeId_r(RGEO_CONTEXT_FROM_FACTORY(factory), geom);
|
141
|
+
if (type != GEOS_GEOMETRYCOLLECTION && (geom_type == GEOS_GEOMETRYCOLLECTION || geom_type == type)) {
|
142
|
+
int len = GEOSGetNumGeometries_r(RGEO_CONTEXT_FROM_FACTORY(factory), geom);
|
143
|
+
int i;
|
144
|
+
for (i=0; i<len; ++i) {
|
145
|
+
const GEOSGeometry* sub_geom = GEOSGetGeometryN_r(RGEO_CONTEXT_FROM_FACTORY(factory), geom, i);
|
146
|
+
if (sub_geom) {
|
147
|
+
good = gather_geometry_collection_internal(type, factory, geoms, ci, sub_geom, 0);
|
148
|
+
if (!good) {
|
149
|
+
break;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
else {
|
153
|
+
good = 0;
|
154
|
+
break;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
}
|
158
|
+
else {
|
159
|
+
geoms[(*ci)++] = geom_mine ? (GEOSGeometry*)geom : GEOSGeom_clone_r(RGEO_CONTEXT_FROM_FACTORY(factory), geom);
|
160
|
+
}
|
161
|
+
return good;
|
162
|
+
}
|
163
|
+
|
164
|
+
|
165
|
+
// This walks through the array of geometries and builds a C array of the
|
166
|
+
// geometries to add to the collection we're building. If we're building
|
167
|
+
// a simple GeometryCollection, we just gather the geometries as they are.
|
168
|
+
// If we're building a MultiPoint, MultiLineString, or MultiPolygon, we
|
169
|
+
// recursively gather the contents of any collections we encounter.
|
170
|
+
|
171
|
+
static GEOSGeometry** gather_geometry_collection(int type, VALUE factory, VALUE array, unsigned int len)
|
172
|
+
{
|
173
|
+
GEOSGeometry** geoms = ALLOC_N(GEOSGeometry*, len == 0 ? 1 : len);
|
174
|
+
unsigned int ci = 0;
|
175
|
+
if (geoms) {
|
176
|
+
unsigned int array_len = (unsigned int)RARRAY_LEN(array);
|
177
|
+
unsigned int ai;
|
178
|
+
for (ai=0; ai<array_len; ++ai) {
|
179
|
+
GEOSGeometry* geom = rgeo_convert_to_detached_geos_geometry(RGEO_GLOBALS_FROM_FACTORY(factory), rb_ary_entry(array, ai), NULL);
|
180
|
+
if (geom) {
|
181
|
+
if (!gather_geometry_collection_internal(type, factory, geoms, &ci, geom, 1)) {
|
182
|
+
break;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
else {
|
186
|
+
break;
|
187
|
+
}
|
188
|
+
}
|
189
|
+
}
|
190
|
+
if (ci != len) {
|
191
|
+
unsigned int i;
|
192
|
+
for (i=0; i<ci; ++i) {
|
193
|
+
GEOSGeom_destroy_r(RGEO_CONTEXT_FROM_FACTORY(factory), geoms[i]);
|
194
|
+
}
|
195
|
+
free(geoms);
|
196
|
+
geoms = NULL;
|
197
|
+
}
|
198
|
+
return geoms;
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
// Main implementation of the "create" class method for geometry collections.
|
203
|
+
// You must pass in the correct GEOS geometry type ID.
|
204
|
+
|
205
|
+
static VALUE create_geometry_collection(VALUE module, int type, VALUE factory, VALUE array)
|
206
|
+
{
|
207
|
+
VALUE result = Qnil;
|
208
|
+
Check_Type(array, T_ARRAY);
|
209
|
+
// First pass: we determine the size of the collection to create, and
|
210
|
+
// build the klasses array.
|
211
|
+
VALUE klasses = compute_collection_klasses(type, factory, array);
|
212
|
+
if (!NIL_P(klasses)) {
|
213
|
+
unsigned int len = (unsigned int)RARRAY_LEN(klasses);
|
214
|
+
// Second pass: we gather the actual geometries into a C array
|
215
|
+
GEOSGeometry** geoms = gather_geometry_collection(type, factory, array, len);
|
216
|
+
if (geoms) {
|
217
|
+
// Create the collection itself.
|
218
|
+
GEOSGeometry* collection = GEOSGeom_createCollection_r(RGEO_CONTEXT_FROM_FACTORY(factory), type, geoms, len);
|
219
|
+
// Due to a limitation of GEOS, the MultiPolygon assertions are not checked.
|
220
|
+
// We do that manually here.
|
221
|
+
if (collection && type == GEOS_MULTIPOLYGON && (RGEO_FACTORY_DATA_PTR(factory)->flags & 1) == 0) {
|
222
|
+
char problem = 0;
|
223
|
+
unsigned int i, j;
|
224
|
+
for (i=1; i<len; ++i) {
|
225
|
+
for (j=0; j<i; ++j) {
|
226
|
+
GEOSGeometry* igeom = geoms[i];
|
227
|
+
GEOSGeometry* jgeom = geoms[j];
|
228
|
+
problem = GEOSRelatePattern_r(RGEO_CONTEXT_FROM_FACTORY(factory), igeom, jgeom, "2********");
|
229
|
+
if (problem) {
|
230
|
+
break;
|
231
|
+
}
|
232
|
+
problem = GEOSRelatePattern_r(RGEO_CONTEXT_FROM_FACTORY(factory), igeom, jgeom, "****1****");
|
233
|
+
if (problem) {
|
234
|
+
break;
|
235
|
+
}
|
236
|
+
}
|
237
|
+
if (problem) {
|
238
|
+
break;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
if (problem) {
|
242
|
+
GEOSGeom_destroy_r(RGEO_CONTEXT_FROM_FACTORY(factory), collection);
|
243
|
+
collection = NULL;
|
244
|
+
}
|
245
|
+
}
|
246
|
+
if (collection) {
|
247
|
+
result = rgeo_wrap_geos_geometry(factory, collection, module);
|
248
|
+
RGEO_GEOMETRY_DATA_PTR(result)->klasses = klasses;
|
249
|
+
}
|
250
|
+
// NOTE: We are assuming that GEOS will do its own cleanup of the
|
251
|
+
// element geometries if it fails to create the collection, so we
|
252
|
+
// are not doing that ourselves. If that turns out not to be the
|
253
|
+
// case, this will be a memory leak.
|
254
|
+
free(geoms);
|
255
|
+
}
|
256
|
+
}
|
257
|
+
return result;
|
258
|
+
}
|
259
|
+
|
260
|
+
|
261
|
+
/**** RUBY METHOD DEFINITIONS ****/
|
262
|
+
|
263
|
+
|
264
|
+
static VALUE method_geometry_collection_eql(VALUE self, VALUE rhs)
|
265
|
+
{
|
266
|
+
VALUE result = rgeo_geos_klasses_and_factories_eql(self, rhs);
|
267
|
+
if (RTEST(result)) {
|
268
|
+
result = rgeo_geos_geometry_collections_eql(RGEO_CONTEXT_FROM_GEOMETRY(self), RGEO_GET_GEOS_GEOMETRY(self), RGEO_GET_GEOS_GEOMETRY(rhs));
|
269
|
+
}
|
270
|
+
return result;
|
271
|
+
}
|
272
|
+
|
273
|
+
|
274
|
+
static VALUE method_geometry_collection_geometry_type(VALUE self)
|
275
|
+
{
|
276
|
+
VALUE result = Qnil;
|
277
|
+
const GEOSGeometry* self_geom = RGEO_GET_GEOS_GEOMETRY(self);
|
278
|
+
if (self_geom) {
|
279
|
+
result = rb_const_get_at(RGEO_GLOBALS_FROM_GEOMETRY(self)->features_module, rb_intern("GeometryCollection"));
|
280
|
+
}
|
281
|
+
return result;
|
282
|
+
}
|
283
|
+
|
284
|
+
|
285
|
+
static VALUE method_geometry_collection_num_geometries(VALUE self)
|
286
|
+
{
|
287
|
+
VALUE result = Qnil;
|
288
|
+
const GEOSGeometry* self_geom = RGEO_GET_GEOS_GEOMETRY(self);
|
289
|
+
if (self_geom) {
|
290
|
+
result = INT2NUM(GEOSGetNumGeometries_r(RGEO_CONTEXT_FROM_GEOMETRY(self), self_geom));
|
291
|
+
}
|
292
|
+
return result;
|
293
|
+
}
|
294
|
+
|
295
|
+
|
296
|
+
static VALUE method_geometry_collection_geometry_n(VALUE self, VALUE n)
|
297
|
+
{
|
298
|
+
VALUE result = Qnil;
|
299
|
+
const GEOSGeometry* self_geom = RGEO_GET_GEOS_GEOMETRY(self);
|
300
|
+
if (self_geom) {
|
301
|
+
VALUE klasses = RGEO_KLASSES_FROM_GEOMETRY(self);
|
302
|
+
int i = NUM2INT(n);
|
303
|
+
const GEOSGeometry* elem_geom = GEOSGetGeometryN_r(RGEO_CONTEXT_FROM_GEOMETRY(self), self_geom, i);
|
304
|
+
result = rgeo_wrap_geos_geometry_clone(RGEO_FACTORY_FROM_GEOMETRY(self), elem_geom, NIL_P(klasses) ? Qnil : rb_ary_entry(klasses, i));
|
305
|
+
}
|
306
|
+
return result;
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
static VALUE method_geometry_collection_each(VALUE self)
|
311
|
+
{
|
312
|
+
const GEOSGeometry* self_geom = RGEO_GET_GEOS_GEOMETRY(self);
|
313
|
+
if (self_geom) {
|
314
|
+
int len = GEOSGetNumGeometries_r(RGEO_CONTEXT_FROM_GEOMETRY(self), self_geom);
|
315
|
+
if (len > 0) {
|
316
|
+
VALUE klasses = RGEO_KLASSES_FROM_GEOMETRY(self);
|
317
|
+
int i;
|
318
|
+
for (i=0; i<len; ++i) {
|
319
|
+
VALUE elem;
|
320
|
+
const GEOSGeometry* elem_geom = GEOSGetGeometryN_r(RGEO_CONTEXT_FROM_GEOMETRY(self), self_geom, i);
|
321
|
+
elem = rgeo_wrap_geos_geometry_clone(RGEO_FACTORY_FROM_GEOMETRY(self), elem_geom, NIL_P(klasses) ? Qnil : rb_ary_entry(klasses, i));
|
322
|
+
if (!NIL_P(elem)) {
|
323
|
+
rb_yield(elem);
|
324
|
+
}
|
325
|
+
}
|
326
|
+
}
|
327
|
+
}
|
328
|
+
return self;
|
329
|
+
}
|
330
|
+
|
331
|
+
|
332
|
+
static VALUE method_multi_point_geometry_type(VALUE self)
|
333
|
+
{
|
334
|
+
VALUE result = Qnil;
|
335
|
+
const GEOSGeometry* self_geom = RGEO_GET_GEOS_GEOMETRY(self);
|
336
|
+
if (self_geom) {
|
337
|
+
result = rb_const_get_at(RGEO_GLOBALS_FROM_GEOMETRY(self)->features_module, rb_intern("MultiPoint"));
|
338
|
+
}
|
339
|
+
return result;
|
340
|
+
}
|
341
|
+
|
342
|
+
|
343
|
+
static VALUE method_multi_line_string_geometry_type(VALUE self)
|
344
|
+
{
|
345
|
+
VALUE result = Qnil;
|
346
|
+
const GEOSGeometry* self_geom = RGEO_GET_GEOS_GEOMETRY(self);
|
347
|
+
if (self_geom) {
|
348
|
+
result = rb_const_get_at(RGEO_GLOBALS_FROM_GEOMETRY(self)->features_module, rb_intern("MultiLineString"));
|
349
|
+
}
|
350
|
+
return result;
|
351
|
+
}
|
352
|
+
|
353
|
+
|
354
|
+
static VALUE method_multi_line_string_length(VALUE self)
|
355
|
+
{
|
356
|
+
const GEOSGeometry* self_geom = RGEO_GET_GEOS_GEOMETRY(self);
|
357
|
+
VALUE result = Qnil;
|
358
|
+
if (self_geom) {
|
359
|
+
double len;
|
360
|
+
if (GEOSLength_r(RGEO_CONTEXT_FROM_GEOMETRY(self), self_geom, &len)) {
|
361
|
+
result = rb_float_new(len);
|
362
|
+
}
|
363
|
+
}
|
364
|
+
return result;
|
365
|
+
}
|
366
|
+
|
367
|
+
|
368
|
+
static VALUE method_multi_line_string_is_closed(VALUE self)
|
369
|
+
{
|
370
|
+
const GEOSGeometry* self_geom = RGEO_GET_GEOS_GEOMETRY(self);
|
371
|
+
VALUE result = Qnil;
|
372
|
+
if (self_geom) {
|
373
|
+
result = Qtrue;
|
374
|
+
int len = GEOSGetNumGeometries_r(RGEO_CONTEXT_FROM_GEOMETRY(self), self_geom);
|
375
|
+
if (len > 0) {
|
376
|
+
int i;
|
377
|
+
for (i=0; i<len; ++i) {
|
378
|
+
const GEOSGeometry* geom = GEOSGetGeometryN_r(RGEO_CONTEXT_FROM_GEOMETRY(self), self_geom, i);
|
379
|
+
if (geom) {
|
380
|
+
result = rgeo_is_geos_line_string_closed(RGEO_CONTEXT_FROM_GEOMETRY(self), self_geom);
|
381
|
+
if (result != Qtrue) {
|
382
|
+
break;
|
383
|
+
}
|
384
|
+
}
|
385
|
+
}
|
386
|
+
}
|
387
|
+
}
|
388
|
+
return result;
|
389
|
+
}
|
390
|
+
|
391
|
+
|
392
|
+
static VALUE method_multi_polygon_geometry_type(VALUE self)
|
393
|
+
{
|
394
|
+
VALUE result = Qnil;
|
395
|
+
const GEOSGeometry* self_geom = RGEO_GET_GEOS_GEOMETRY(self);
|
396
|
+
if (self_geom) {
|
397
|
+
result = rb_const_get_at(RGEO_GLOBALS_FROM_GEOMETRY(self)->features_module, rb_intern("MultiPolygon"));
|
398
|
+
}
|
399
|
+
return result;
|
400
|
+
}
|
401
|
+
|
402
|
+
|
403
|
+
static VALUE method_multi_polygon_area(VALUE self)
|
404
|
+
{
|
405
|
+
VALUE result = Qnil;
|
406
|
+
const GEOSGeometry* self_geom = RGEO_GET_GEOS_GEOMETRY(self);
|
407
|
+
if (self_geom) {
|
408
|
+
double area;
|
409
|
+
if (GEOSArea_r(RGEO_CONTEXT_FROM_GEOMETRY(self), self_geom, &area)) {
|
410
|
+
result = rb_float_new(area);
|
411
|
+
}
|
412
|
+
}
|
413
|
+
return result;
|
414
|
+
}
|
415
|
+
|
416
|
+
|
417
|
+
static VALUE method_multi_polygon_centroid(VALUE self)
|
418
|
+
{
|
419
|
+
VALUE result = Qnil;
|
420
|
+
const GEOSGeometry* self_geom = RGEO_GET_GEOS_GEOMETRY(self);
|
421
|
+
if (self_geom) {
|
422
|
+
result = rgeo_wrap_geos_geometry(RGEO_FACTORY_FROM_GEOMETRY(self), GEOSGetCentroid_r(RGEO_CONTEXT_FROM_GEOMETRY(self), self_geom), Qnil);
|
423
|
+
}
|
424
|
+
return result;
|
425
|
+
}
|
426
|
+
|
427
|
+
|
428
|
+
static VALUE method_multi_polygon_point_on_surface(VALUE self)
|
429
|
+
{
|
430
|
+
VALUE result = Qnil;
|
431
|
+
const GEOSGeometry* self_geom = RGEO_GET_GEOS_GEOMETRY(self);
|
432
|
+
if (self_geom) {
|
433
|
+
result = rgeo_wrap_geos_geometry(RGEO_FACTORY_FROM_GEOMETRY(self), GEOSPointOnSurface_r(RGEO_CONTEXT_FROM_GEOMETRY(self), self_geom), Qnil);
|
434
|
+
}
|
435
|
+
return result;
|
436
|
+
}
|
437
|
+
|
438
|
+
|
439
|
+
static VALUE cmethod_geometry_collection_create(VALUE module, VALUE factory, VALUE array)
|
440
|
+
{
|
441
|
+
return create_geometry_collection(module, GEOS_GEOMETRYCOLLECTION, factory, array);
|
442
|
+
}
|
443
|
+
|
444
|
+
|
445
|
+
static VALUE cmethod_multi_point_create(VALUE module, VALUE factory, VALUE array)
|
446
|
+
{
|
447
|
+
return create_geometry_collection(module, GEOS_MULTIPOINT, factory, array);
|
448
|
+
}
|
449
|
+
|
450
|
+
|
451
|
+
static VALUE cmethod_multi_line_string_create(VALUE module, VALUE factory, VALUE array)
|
452
|
+
{
|
453
|
+
return create_geometry_collection(module, GEOS_MULTILINESTRING, factory, array);
|
454
|
+
}
|
455
|
+
|
456
|
+
|
457
|
+
static VALUE cmethod_multi_polygon_create(VALUE module, VALUE factory, VALUE array)
|
458
|
+
{
|
459
|
+
return create_geometry_collection(module, GEOS_MULTIPOLYGON, factory, array);
|
460
|
+
}
|
461
|
+
|
462
|
+
|
463
|
+
/**** INITIALIZATION FUNCTION ****/
|
464
|
+
|
465
|
+
|
466
|
+
void rgeo_init_geos_geometry_collection(RGeo_Globals* globals)
|
467
|
+
{
|
468
|
+
// Create implementation classes
|
469
|
+
VALUE geos_geometry_collection_class = rb_define_class_under(globals->geos_module, "GeometryCollectionImpl", rb_const_get_at(globals->geos_module, rb_intern("GeometryImpl")));
|
470
|
+
VALUE geos_multi_point_class = rb_define_class_under(globals->geos_module, "MultiPointImpl", geos_geometry_collection_class);
|
471
|
+
VALUE geos_multi_line_string_class = rb_define_class_under(globals->geos_module, "MultiLineStringImpl", geos_geometry_collection_class);
|
472
|
+
VALUE geos_multi_polygon_class = rb_define_class_under(globals->geos_module, "MultiPolygonImpl", geos_geometry_collection_class);
|
473
|
+
|
474
|
+
// Methods for GeometryCollectionImpl
|
475
|
+
rb_define_module_function(geos_geometry_collection_class, "create", cmethod_geometry_collection_create, 2);
|
476
|
+
rb_include_module(geos_geometry_collection_class, rb_define_module("Enumerable"));
|
477
|
+
rb_define_method(geos_geometry_collection_class, "eql?", method_geometry_collection_eql, 1);
|
478
|
+
rb_define_method(geos_geometry_collection_class, "geometry_type", method_geometry_collection_geometry_type, 0);
|
479
|
+
rb_define_method(geos_geometry_collection_class, "num_geometries", method_geometry_collection_num_geometries, 0);
|
480
|
+
rb_define_method(geos_geometry_collection_class, "size", method_geometry_collection_num_geometries, 0);
|
481
|
+
rb_define_method(geos_geometry_collection_class, "geometry_n", method_geometry_collection_geometry_n, 1);
|
482
|
+
rb_define_method(geos_geometry_collection_class, "[]", method_geometry_collection_geometry_n, 1);
|
483
|
+
rb_define_method(geos_geometry_collection_class, "each", method_geometry_collection_each, 0);
|
484
|
+
|
485
|
+
// Methods for MultiPointImpl
|
486
|
+
rb_define_module_function(geos_multi_point_class, "create", cmethod_multi_point_create, 2);
|
487
|
+
rb_define_method(geos_multi_point_class, "geometry_type", method_multi_point_geometry_type, 0);
|
488
|
+
|
489
|
+
// Methods for MultiLineStringImpl
|
490
|
+
rb_define_module_function(geos_multi_line_string_class, "create", cmethod_multi_line_string_create, 2);
|
491
|
+
rb_define_method(geos_multi_line_string_class, "geometry_type", method_multi_line_string_geometry_type, 0);
|
492
|
+
rb_define_method(geos_multi_line_string_class, "length", method_multi_line_string_length, 0);
|
493
|
+
rb_define_method(geos_multi_line_string_class, "is_closed?", method_multi_line_string_is_closed, 0);
|
494
|
+
|
495
|
+
// Methods for MultiPolygonImpl
|
496
|
+
rb_define_module_function(geos_multi_polygon_class, "create", cmethod_multi_polygon_create, 2);
|
497
|
+
rb_define_method(geos_multi_polygon_class, "geometry_type", method_multi_polygon_geometry_type, 0);
|
498
|
+
rb_define_method(geos_multi_polygon_class, "area", method_multi_polygon_area, 0);
|
499
|
+
rb_define_method(geos_multi_polygon_class, "centroid", method_multi_polygon_centroid, 0);
|
500
|
+
rb_define_method(geos_multi_polygon_class, "point_on_surface", method_multi_polygon_point_on_surface, 0);
|
501
|
+
}
|
502
|
+
|
503
|
+
|
504
|
+
/**** OTHER PUBLIC FUNCTIONS ****/
|
505
|
+
|
506
|
+
|
507
|
+
VALUE rgeo_geos_geometry_collections_eql(GEOSContextHandle_t context, const GEOSGeometry* geom1, const GEOSGeometry* geom2)
|
508
|
+
{
|
509
|
+
VALUE result = Qnil;
|
510
|
+
if (geom1 && geom2) {
|
511
|
+
int len1 = GEOSGetNumGeometries_r(context, geom1);
|
512
|
+
int len2 = GEOSGetNumGeometries_r(context, geom2);
|
513
|
+
if (len1 >= 0 && len2 >= 0) {
|
514
|
+
if (len1 == len2) {
|
515
|
+
result = Qtrue;
|
516
|
+
int i;
|
517
|
+
for (i=0; i<len1; ++i) {
|
518
|
+
const GEOSGeometry* sub_geom1 = GEOSGetGeometryN_r(context, geom1, i);
|
519
|
+
const GEOSGeometry* sub_geom2 = GEOSGetGeometryN_r(context, geom2, i);
|
520
|
+
if (sub_geom1 && sub_geom2) {
|
521
|
+
int type1 = GEOSGeomTypeId_r(context, sub_geom1);
|
522
|
+
int type2 = GEOSGeomTypeId_r(context, sub_geom2);
|
523
|
+
if (type1 >= 0 && type2 >= 0) {
|
524
|
+
if (type1 == type2) {
|
525
|
+
switch (type1) {
|
526
|
+
case GEOS_POINT:
|
527
|
+
case GEOS_LINESTRING:
|
528
|
+
case GEOS_LINEARRING:
|
529
|
+
result = rgeo_geos_coordseqs_eql(context, sub_geom1, sub_geom2);
|
530
|
+
break;
|
531
|
+
case GEOS_POLYGON:
|
532
|
+
result = rgeo_geos_polygons_eql(context, sub_geom1, sub_geom2);
|
533
|
+
break;
|
534
|
+
case GEOS_GEOMETRYCOLLECTION:
|
535
|
+
case GEOS_MULTIPOINT:
|
536
|
+
case GEOS_MULTILINESTRING:
|
537
|
+
case GEOS_MULTIPOLYGON:
|
538
|
+
result = rgeo_geos_geometry_collections_eql(context, sub_geom1, sub_geom2);
|
539
|
+
break;
|
540
|
+
default:
|
541
|
+
result = Qnil;
|
542
|
+
break;
|
543
|
+
}
|
544
|
+
if (!RTEST(result)) {
|
545
|
+
break;
|
546
|
+
}
|
547
|
+
}
|
548
|
+
else {
|
549
|
+
result = Qfalse;
|
550
|
+
break;
|
551
|
+
}
|
552
|
+
}
|
553
|
+
else {
|
554
|
+
result = Qnil;
|
555
|
+
break;
|
556
|
+
}
|
557
|
+
}
|
558
|
+
else {
|
559
|
+
result = Qnil;
|
560
|
+
break;
|
561
|
+
}
|
562
|
+
}
|
563
|
+
}
|
564
|
+
else {
|
565
|
+
result = Qfalse;
|
566
|
+
}
|
567
|
+
}
|
568
|
+
}
|
569
|
+
return result;
|
570
|
+
}
|
571
|
+
|
572
|
+
|
573
|
+
#ifdef __cplusplus
|
574
|
+
#if 0
|
575
|
+
{
|
576
|
+
#endif
|
577
|
+
}
|
578
|
+
#endif
|
579
|
+
|
580
|
+
#endif
|