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