ffi-geos 0.0.1.beta1 → 0.0.1.beta2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -43,7 +43,13 @@ Ruby bindings along with the following enhancements and additions:
43
43
  have been enhanced to take options Hashes allowing you to set per-write
44
44
  settings.
45
45
 
46
- == New Methods and Additions
46
+ * Geos::BufferParams class that allows for more extensive Geos::Geometry#buffer
47
+ options.
48
+
49
+ * Geos::PreparedGeometry class and Geos::Geometry#to_prepared method to
50
+ allow for prepared geometries and more efficient relationship testing.
51
+
52
+ == New Methods and Additions (not exhaustive)
47
53
 
48
54
  === Geos
49
55
 
@@ -73,8 +79,6 @@ Ruby bindings along with the following enhancements and additions:
73
79
 
74
80
  === Geos::Geometry
75
81
 
76
- * Geos::Geometry#buffer_with_style
77
-
78
82
  * Geos::Geometry#num_coordinates
79
83
 
80
84
  * Geos::Geometry#union_cascaded. Geos::Geometry#union can also be called
@@ -118,8 +122,6 @@ Ruby bindings along with the following enhancements and additions:
118
122
 
119
123
  * Geos::LineString#point_n
120
124
 
121
- * Geos::LineString#buffer_single_sided
122
-
123
125
  * Geos::LineString#closed?
124
126
 
125
127
  === Geos::WktWriter
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1.beta1
1
+ 0.0.1.beta2
data/ffi-geos.gemspec ADDED
@@ -0,0 +1,85 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ffi-geos}
8
+ s.version = "0.0.1.beta2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["J Smith"]
12
+ s.date = %q{2011-05-11}
13
+ s.description = %q{An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).}
14
+ s.email = %q{dark.panda@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ "MIT-LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "ffi-geos.gemspec",
24
+ "lib/buffer_params.rb",
25
+ "lib/coordinate_sequence.rb",
26
+ "lib/ffi-geos.rb",
27
+ "lib/geometry.rb",
28
+ "lib/geometry_collection.rb",
29
+ "lib/line_string.rb",
30
+ "lib/linear_ring.rb",
31
+ "lib/multi_line_string.rb",
32
+ "lib/multi_point.rb",
33
+ "lib/multi_polygon.rb",
34
+ "lib/point.rb",
35
+ "lib/polygon.rb",
36
+ "lib/prepared_geometry.rb",
37
+ "lib/strtree.rb",
38
+ "lib/tools.rb",
39
+ "lib/utils.rb",
40
+ "lib/wkb_reader.rb",
41
+ "lib/wkb_writer.rb",
42
+ "lib/wkt_reader.rb",
43
+ "lib/wkt_writer.rb",
44
+ "test/coordinate_sequence_tests.rb",
45
+ "test/geometry_tests.rb",
46
+ "test/misc_tests.rb",
47
+ "test/point_tests.rb",
48
+ "test/prepared_geometry_tests.rb",
49
+ "test/strtree_tests.rb",
50
+ "test/test_helper.rb",
51
+ "test/utils_tests.rb",
52
+ "test/wkb_reader_tests.rb",
53
+ "test/wkb_writer_tests.rb",
54
+ "test/wkt_reader_tests.rb",
55
+ "test/wkt_writer_tests.rb"
56
+ ]
57
+ s.homepage = %q{http://github.com/dark-panda/ffi-geos}
58
+ s.require_paths = ["lib"]
59
+ s.rubygems_version = %q{1.7.2}
60
+ s.summary = %q{An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).}
61
+ s.test_files = [
62
+ "test/coordinate_sequence_tests.rb",
63
+ "test/geometry_tests.rb",
64
+ "test/misc_tests.rb",
65
+ "test/point_tests.rb",
66
+ "test/prepared_geometry_tests.rb",
67
+ "test/strtree_tests.rb",
68
+ "test/test_helper.rb",
69
+ "test/utils_tests.rb",
70
+ "test/wkb_reader_tests.rb",
71
+ "test/wkb_writer_tests.rb",
72
+ "test/wkt_reader_tests.rb",
73
+ "test/wkt_writer_tests.rb"
74
+ ]
75
+
76
+ if s.respond_to? :specification_version then
77
+ s.specification_version = 3
78
+
79
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
80
+ else
81
+ end
82
+ else
83
+ end
84
+ end
85
+
@@ -0,0 +1,81 @@
1
+
2
+ module Geos
3
+ class BufferParams
4
+ include Geos::Tools
5
+
6
+ attr_reader :ptr, :params
7
+
8
+ VALID_PARAMETERS = [
9
+ :quad_segs, :endcap, :join, :mitre_limit, :single_sided
10
+ ].freeze
11
+
12
+ # The defaults for the params according to GEOS are as found in
13
+ # Geos::Constants::BUFFER_PARAMS_DEFAULTS. Note that when setting the
14
+ # :quad_segs value that you should set it before setting other values like
15
+ # :join and :mitre_limit, as GEOS contains logic concerning how the
16
+ # :quad_segs value affects these parameters and vice versa. For details,
17
+ # refer to src/operation/buffer/BufferParameters.cpp and the
18
+ # BufferParameters::setQuadrantSegments(int) method in the GEOS source
19
+ # code for details.
20
+ def initialize(params = {})
21
+ params = Geos::Constants::BUFFER_PARAM_DEFAULTS.merge(params)
22
+
23
+ ptr = FFIGeos.GEOSBufferParams_create_r(Geos.current_handle)
24
+ @ptr = FFI::AutoPointer.new(
25
+ ptr,
26
+ self.class.method(:release)
27
+ )
28
+
29
+ @params = {}
30
+ VALID_PARAMETERS.each do |param|
31
+ self.send("#{param}=", params[param])
32
+ end
33
+ end
34
+
35
+ def self.release(ptr) #:nodoc:
36
+ FFIGeos.GEOSBufferParams_destroy_r(Geos.current_handle, ptr)
37
+ end
38
+
39
+ def endcap=(value)
40
+ check_enum_value(Geos::BufferCapStyles, value)
41
+
42
+ if bool_result(FFIGeos.GEOSBufferParams_setEndCapStyle_r(Geos.current_handle, ptr, value))
43
+ @params[:endcap] = symbol_for_enum(Geos::BufferCapStyles, value)
44
+ end
45
+ end
46
+
47
+ def join=(value)
48
+ check_enum_value(Geos::BufferJoinStyles, value)
49
+
50
+ if bool_result(FFIGeos.GEOSBufferParams_setJoinStyle_r(Geos.current_handle, ptr, value))
51
+ @params[:join] = symbol_for_enum(Geos::BufferJoinStyles, value)
52
+ end
53
+ end
54
+
55
+ def mitre_limit=(value)
56
+ if bool_result(FFIGeos.GEOSBufferParams_setMitreLimit_r(Geos.current_handle, ptr, value))
57
+ @params[:mitre_limit] = value
58
+ end
59
+ end
60
+
61
+ def quad_segs=(value)
62
+ if bool_result(FFIGeos.GEOSBufferParams_setQuadrantSegments_r(Geos.current_handle, ptr, value))
63
+ @params[:quad_segs] = value
64
+ end
65
+ end
66
+
67
+ def single_sided=(value)
68
+ if bool_result(FFIGeos.GEOSBufferParams_setSingleSided_r(Geos.current_handle, ptr, value ? 1 : 0))
69
+ @params[:single_sided] = value
70
+ end
71
+ end
72
+
73
+ VALID_PARAMETERS.each do |param|
74
+ self.class_eval(<<-EOF, __FILE__, __LINE__ + 1)
75
+ def #{param}
76
+ @params[:#{param}]
77
+ end
78
+ EOF
79
+ end
80
+ end
81
+ end
data/lib/ffi-geos.rb CHANGED
@@ -37,6 +37,8 @@ module Geos
37
37
  File.join(GEOS_BASE, 'point')
38
38
  autoload :STRtree,
39
39
  File.join(GEOS_BASE, 'strtree')
40
+ autoload :BufferParams,
41
+ File.join(GEOS_BASE, 'buffer_params')
40
42
  autoload :Tools,
41
43
  File.join(GEOS_BASE, 'tools')
42
44
  autoload :Utils,
@@ -110,15 +112,31 @@ module Geos
110
112
  :monovalent_endpoint, 4
111
113
  ])
112
114
 
115
+ Geos::GeometryTypes = enum(:geometry_type, [
116
+ :point, 0,
117
+ :line_string, 1,
118
+ :linear_ring, 2,
119
+ :polygon, 3,
120
+ :multi_point, 4,
121
+ :multi_line_string, 5,
122
+ :multi_polygon, 6,
123
+ :geometry_collection, 7
124
+ ])
125
+
113
126
  FFI_LAYOUT = {
114
127
  #### Utility functions ####
115
128
  :initGEOS_r => [
116
129
  :pointer,
130
+
131
+ # notice callback
117
132
  callback([ :string, :string ], :void),
133
+
134
+ # error callback
118
135
  callback([ :string, :string ], :void)
119
136
  ],
120
137
 
121
138
  :finishGEOS_r => [
139
+ # void, *handle
122
140
  :void, :pointer
123
141
  ],
124
142
 
@@ -131,538 +149,715 @@ module Geos
131
149
  ],
132
150
 
133
151
  :GEOSPolygonize_r => [
152
+ # *geom, *handle, **geoms, ngeoms
134
153
  :pointer, :pointer, :pointer, :uint
135
154
  ],
136
155
 
137
156
  :GEOSPolygonizer_getCutEdges_r => [
157
+ # *geom, *handle, **geoms, ngeoms
138
158
  :pointer, :pointer, :pointer, :uint
139
159
  ],
140
160
 
141
161
  :GEOSPolygonize_full_r => [
162
+ # *geom, *handle, *geom, **cuts, **dangles, **invalid
142
163
  :pointer, :pointer, :pointer, :pointer, :pointer, :pointer
143
164
  ],
144
165
 
145
166
  :GEOSGeom_createPoint_r => [
167
+ # *geom, *handle, *coord_seq
146
168
  :pointer, :pointer, :pointer
147
169
  ],
148
170
 
149
171
  :GEOSGeom_createEmptyPoint_r => [
172
+ # *geom, *handle
150
173
  :pointer, :pointer
151
174
  ],
152
175
 
153
176
  :GEOSGeom_createEmptyLineString_r => [
177
+ # *geom, *handle
154
178
  :pointer, :pointer
155
179
  ],
156
180
 
157
181
  :GEOSGeom_createLinearRing_r => [
182
+ # *geom, *handle, *coord_seq
158
183
  :pointer, :pointer, :pointer
159
184
  ],
160
185
 
161
186
  :GEOSGeom_createLineString_r => [
187
+ # *geom, *handle, *coord_seq
162
188
  :pointer, :pointer, :pointer
163
189
  ],
164
190
 
165
191
  :GEOSGeom_createPolygon_r => [
192
+ # *geom, *handle, *geom, **holes, nholes
166
193
  :pointer, :pointer, :pointer, :pointer, :uint
167
194
  ],
168
195
 
169
196
  :GEOSGeom_createEmptyPolygon_r => [
197
+ # *geom, *handle
170
198
  :pointer, :pointer
171
199
  ],
172
200
 
173
201
  :GEOSGeom_createCollection_r => [
174
- :pointer, :pointer, :int, :pointer, :uint
202
+ # *geom, *handle, type, **geoms, ngeoms
203
+ :pointer, :pointer, :geometry_type, :pointer, :uint
175
204
  ],
176
205
 
177
206
  :GEOSGeom_createEmptyCollection_r => [
178
- :pointer, :pointer, :int
207
+ # *geom, *handle, type
208
+ :pointer, :pointer, :geometry_type
179
209
  ],
180
210
  #### /Utility functions ####
181
211
 
182
212
  #### CoordinateSequence functions ####
183
213
  :GEOSCoordSeq_create_r => [
214
+ # *coord_seq, *handle, size, dims
184
215
  :pointer, :pointer, :uint, :uint
185
216
  ],
186
217
 
187
218
  :GEOSCoordSeq_destroy_r => [
219
+ # void, *handle, *coord_seq
188
220
  :void, :pointer, :pointer
189
221
  ],
190
222
 
191
223
  :GEOSCoordSeq_clone_r => [
224
+ # *coord_seq, *handle, *coord_seq
192
225
  :pointer, :pointer, :pointer
193
226
  ],
194
227
 
195
228
  :GEOSCoordSeq_setX_r => [
229
+ # 0 on exception, *handle, *coord_seq, idx, val
196
230
  :int, :pointer, :pointer, :uint, :double
197
231
  ],
198
232
 
199
233
  :GEOSCoordSeq_setY_r => [
234
+ # 0 on exception, *handle, *coord_seq, idx, val
200
235
  :int, :pointer, :pointer, :uint, :double
201
236
  ],
202
237
 
203
238
  :GEOSCoordSeq_setZ_r => [
239
+ # 0 on exception, *handle, *coord_seq, idx, val
204
240
  :int, :pointer, :pointer, :uint, :double
205
241
  ],
206
242
 
207
243
  :GEOSCoordSeq_setOrdinate_r => [
244
+ # 0 on exception, *handle, *coord_seq, idx, dim, val
208
245
  :int, :pointer, :pointer, :uint, :uint, :double
209
246
  ],
210
247
 
211
248
  :GEOSCoordSeq_getX_r => [
249
+ # 0 on exception, *handle, *coord_seq, idx, (double *) val
212
250
  :int, :pointer, :pointer, :uint, :pointer
213
251
  ],
214
252
 
215
253
  :GEOSCoordSeq_getY_r => [
254
+ # 0 on exception, *handle, *coord_seq, idx, (double *) val
216
255
  :int, :pointer, :pointer, :uint, :pointer
217
256
  ],
218
257
 
219
258
  :GEOSCoordSeq_getZ_r => [
259
+ # 0 on exception, *handle, *coord_seq, idx, (double *) val
220
260
  :int, :pointer, :pointer, :uint, :pointer
221
261
  ],
222
262
 
223
263
  :GEOSCoordSeq_getOrdinate_r => [
264
+ # 0 on exception, *handle, *coord_seq, idx, dim, (double *) val
224
265
  :int, :pointer, :pointer, :uint, :uint, :pointer
225
266
  ],
226
267
 
227
268
  :GEOSCoordSeq_getSize_r => [
269
+ # 0 on exception, *handle, *coord_seq, (uint *) size
228
270
  :int, :pointer, :pointer, :pointer
229
271
  ],
230
272
 
231
- :GEOSNormalize_r => [
232
- :int, :pointer, :pointer
233
- ],
234
-
235
273
  :GEOSCoordSeq_getDimensions_r => [
274
+ # 0 on exception, *handle, *coord_seq, (uint *) size
236
275
  :int, :pointer, :pointer, :pointer
237
276
  ],
238
277
  #### /CoordinateSequence functions ####
239
278
 
240
279
  #### Geometry functions ####
241
280
  :GEOSGeom_destroy_r => [
281
+ # void, *handle, *geom
242
282
  :void, :pointer, :pointer
243
283
  ],
244
284
 
245
285
  :GEOSGeom_clone_r => [
286
+ # *geom, *handle, *geom
246
287
  :pointer, :pointer, :pointer
247
288
  ],
248
289
 
249
290
  :GEOSGeomTypeId_r => [
291
+ # type, *handle, *geom
250
292
  :int, :pointer, :pointer
251
293
  ],
252
294
 
253
295
  :GEOSGeomType_r => [
296
+ # type, *handle, *geom
254
297
  :string, :pointer, :pointer
255
298
  ],
256
299
 
257
300
  :GEOSGetSRID_r => [
301
+ # srid, *handle, *geom
258
302
  :int, :pointer, :pointer
259
303
  ],
260
304
 
261
305
  :GEOSSetSRID_r => [
306
+ # void, *handle, *geom, srid
262
307
  :void, :pointer, :pointer, :int
263
308
  ],
264
309
 
265
310
  :GEOSGeom_getDimensions_r => [
311
+ # dims, *handle, *geom
266
312
  :int, :pointer, :pointer
267
313
  ],
268
314
 
269
315
  :GEOSGetNumGeometries_r => [
316
+ # ngeoms, *handle, *geom
270
317
  :int, :pointer, :pointer
271
318
  ],
272
319
 
273
320
  :GEOSGetNumCoordinates_r => [
321
+ # numcoords, *handle, *geom
274
322
  :int, :pointer, :pointer
275
323
  ],
276
324
 
277
325
  :GEOSGeom_getCoordSeq_r => [
326
+ # *coord_seq, *handle, *geom
278
327
  :pointer, :pointer, :pointer
279
328
  ],
280
329
 
281
330
  :GEOSIntersection_r => [
331
+ # *geom, *handle, *geom_a, *geom_b
282
332
  :pointer, :pointer, :pointer, :pointer
283
333
  ],
284
334
 
335
+ :GEOSBufferWithParams_r => [
336
+ # *geom, *handle, *geom, *oarams, width
337
+ :pointer, :pointer, :pointer, :pointer, :double
338
+ ],
339
+
285
340
  :GEOSBuffer_r => [
341
+ # *geom, *handle, *geom, width, quad_segs
286
342
  :pointer, :pointer, :pointer, :double, :int
287
343
  ],
288
344
 
289
345
  :GEOSBufferWithStyle_r => [
346
+ # *geom, *handle, *geom, width, quad_segs, buffer_cap_style, buffer_join_style, mitre_limit
290
347
  :pointer, :pointer, :pointer, :double, :int, :buffer_cap_style, :buffer_join_style, :double
291
348
  ],
292
349
 
350
+ # Deprecated in GEOS 3.3.0.
293
351
  :GEOSSingleSidedBuffer_r => [
352
+ # *geom, *handle, *geom, width, quad_segs, buffer_join_style, mitre_limit, is_left
294
353
  :pointer, :pointer, :pointer, :double, :int, :buffer_join_style, :double, :int
295
354
  ],
296
355
 
356
+ :GEOSOffsetCurve_r => [
357
+ # *geom, *handle, *geom, width, quad_segs, buffer_join_style, mitre_limit
358
+ :pointer, :pointer, :pointer, :double, :int, :buffer_join_style, :double
359
+ ],
360
+
297
361
  :GEOSConvexHull_r => [
362
+ # *geom, *handle, *geom
298
363
  :pointer, :pointer, :pointer
299
364
  ],
300
365
 
301
366
  :GEOSDifference_r => [
367
+ # *geom, *handle, *geom_a, *geom_b
302
368
  :pointer, :pointer, :pointer, :pointer
303
369
  ],
304
370
 
305
371
  :GEOSSymDifference_r => [
372
+ # *geom, *handle, *geom_a, *geom_b
306
373
  :pointer, :pointer, :pointer, :pointer
307
374
  ],
308
375
 
309
376
  :GEOSBoundary_r => [
377
+ # *geom, *handle, *geom
310
378
  :pointer, :pointer, :pointer
311
379
  ],
312
380
 
313
381
  :GEOSUnion_r => [
382
+ # *geom, *handle, *geom_a, *geom_b
314
383
  :pointer, :pointer, :pointer, :pointer
315
384
  ],
316
385
 
317
386
  :GEOSUnaryUnion_r => [
387
+ # *geom, *handle, *geom
318
388
  :pointer, :pointer, :pointer
319
389
  ],
320
390
 
391
+ # Deprecated in GEOS 3.3.0. Use GEOSUnaryUnion_r instead.
321
392
  :GEOSUnionCascaded_r => [
393
+ # *geom, *handle, *geom
322
394
  :pointer, :pointer, :pointer
323
395
  ],
324
396
 
325
397
  :GEOSPointOnSurface_r => [
398
+ # *geom, *handle, *geom
326
399
  :pointer, :pointer, :pointer
327
400
  ],
328
401
 
329
402
  :GEOSGetCentroid_r => [
403
+ # *geom, *handle, *geom
330
404
  :pointer, :pointer, :pointer
331
405
  ],
332
406
 
333
407
  :GEOSEnvelope_r => [
408
+ # *geom, *handle, *geom
334
409
  :pointer, :pointer, :pointer
335
410
  ],
336
411
 
337
412
  :GEOSLineMerge_r => [
413
+ # *geom, *handle, *geom
338
414
  :pointer, :pointer, :pointer
339
415
  ],
340
416
 
341
417
  :GEOSSimplify_r => [
418
+ # *geom, *handle, *geom, tolerance
342
419
  :pointer, :pointer, :pointer, :double
343
420
  ],
344
421
 
345
422
  :GEOSTopologyPreserveSimplify_r => [
423
+ # *geom, *handle, *geom, tolerance
346
424
  :pointer, :pointer, :pointer, :double
347
425
  ],
348
426
 
349
427
  :GEOSGeom_extractUniquePoints_r => [
428
+ # *geom, *handle, *geom
350
429
  :pointer, :pointer, :pointer
351
430
  ],
352
431
 
353
432
  :GEOSSharedPaths_r => [
433
+ # *geom, *handle, *geom_a, *geom_b
354
434
  :pointer, :pointer, :pointer, :pointer
355
435
  ],
356
436
 
357
437
  :GEOSSnap_r => [
438
+ # *geom, *handle, *geom_a, *geom_b, tolerance
358
439
  :pointer, :pointer, :pointer, :pointer, :double
359
440
  ],
360
441
 
361
442
  :GEOSRelate_r => [
443
+ # string, *handle, *geom_a, *geom_b
362
444
  :string, :pointer, :pointer, :pointer
363
445
  ],
364
446
 
365
447
  :GEOSRelatePatternMatch_r => [
448
+ # (2 on exception, 1 on true, 2 on false), *handle, pattern_a, pattern_b
366
449
  :char, :pointer, :string, :string
367
450
  ],
368
451
 
369
452
  :GEOSRelatePattern_r => [
453
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom_a, *geom_b, pattern
370
454
  :char, :pointer, :pointer, :pointer, :string
371
455
  ],
372
456
 
373
457
  :GEOSRelateBoundaryNodeRule_r => [
458
+ # string, *handle, *geom_a, *geom_b, bnr
374
459
  :string, :pointer, :pointer, :pointer, :relate_boundary_node_rule
375
460
  ],
376
461
 
377
462
  :GEOSDisjoint_r => [
463
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom_a, *geom_b
378
464
  :char, :pointer, :pointer, :pointer
379
465
  ],
380
466
 
381
467
  :GEOSTouches_r => [
468
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom_a, *geom_b
382
469
  :char, :pointer, :pointer, :pointer
383
470
  ],
384
471
 
385
472
  :GEOSIntersects_r => [
473
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom_a, *geom_b
386
474
  :char, :pointer, :pointer, :pointer
387
475
  ],
388
476
 
389
477
  :GEOSCrosses_r => [
478
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom_a, *geom_b
390
479
  :char, :pointer, :pointer, :pointer
391
480
  ],
392
481
 
393
482
  :GEOSWithin_r => [
483
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom_a, *geom_b
394
484
  :char, :pointer, :pointer, :pointer
395
485
  ],
396
486
 
397
487
  :GEOSContains_r => [
488
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom_a, *geom_b
398
489
  :char, :pointer, :pointer, :pointer
399
490
  ],
400
491
 
401
492
  :GEOSOverlaps_r => [
493
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom_a, *geom_b
402
494
  :char, :pointer, :pointer, :pointer
403
495
  ],
404
496
 
405
497
  :GEOSCovers_r => [
498
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom_a, *geom_b
406
499
  :char, :pointer, :pointer, :pointer
407
500
  ],
408
501
 
409
502
  :GEOSCoveredBy_r => [
503
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom_a, *geom_b
410
504
  :char, :pointer, :pointer, :pointer
411
505
  ],
412
506
 
413
507
  :GEOSEquals_r => [
508
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom_a, *geom_b
414
509
  :char, :pointer, :pointer, :pointer
415
510
  ],
416
511
 
417
512
  :GEOSEqualsExact_r => [
513
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom_a, *geom_b
418
514
  :char, :pointer, :pointer, :pointer, :double
419
515
  ],
420
516
 
421
517
  :GEOSisEmpty_r => [
518
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom
422
519
  :char, :pointer, :pointer
423
520
  ],
424
521
 
425
522
  :GEOSisValid_r => [
523
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom
426
524
  :char, :pointer, :pointer
427
525
  ],
428
526
 
429
527
  :GEOSisValidReason_r => [
528
+ # reason, *handle, *geom
430
529
  :string, :pointer, :pointer
431
530
  ],
432
531
 
433
532
  :GEOSisValidDetail_r => [
533
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom, flags, (string**) reasons, **geoms
434
534
  :char, :pointer, :pointer, :int, :pointer, :pointer
435
535
  ],
436
536
 
437
537
  :GEOSisSimple_r => [
538
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom
438
539
  :char, :pointer, :pointer
439
540
  ],
440
541
 
441
542
  :GEOSisRing_r => [
543
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom
442
544
  :char, :pointer, :pointer
443
545
  ],
444
546
 
445
547
  :GEOSHasZ_r => [
548
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom
446
549
  :char, :pointer, :pointer
447
550
  ],
448
551
 
449
552
  :GEOSisClosed_r => [
553
+ # (2 on exception, 1 on true, 2 on false), *handle, *geom
450
554
  :char, :pointer, :pointer
451
555
  ],
452
556
 
453
557
  :GEOSArea_r => [
558
+ # (0 on exception, 1 otherwise), *handle, *geom, (double *) area
454
559
  :int, :pointer, :pointer, :pointer
455
560
  ],
456
561
 
457
562
  :GEOSLength_r => [
563
+ # (0 on exception, 1 otherwise), *handle, *geom, (double *) length
458
564
  :int, :pointer, :pointer, :pointer
459
565
  ],
460
566
 
461
567
  :GEOSDistance_r => [
568
+ # (0 on exception, 1 otherwise), *handle, *geom_a, *geom_b, (double *) distance
462
569
  :int, :pointer, :pointer, :pointer, :pointer
463
570
  ],
464
571
 
465
572
  :GEOSHausdorffDistance_r => [
573
+ # (0 on exception, 1 otherwise), *handle, *geom_a, *geom_b, (double *) distance
466
574
  :int, :pointer, :pointer, :pointer, :pointer
467
575
  ],
468
576
 
577
+ :GEOSHausdorffDistanceDensify_r => [
578
+ # (0 on exception, 1 otherwise), *handle, *geom_a, *geom_b, densifyFrac, (double *) distance
579
+ :int, :pointer, :pointer, :pointer, :double, :pointer
580
+ ],
581
+
469
582
  :GEOSGetGeometryN_r => [
583
+ # *geom, *handle, *geom, n
470
584
  :pointer, :pointer, :pointer, :int
471
585
  ],
472
586
 
473
587
  :GEOSGetNumInteriorRings_r => [
588
+ # rings, *handle, *geom
589
+ :int, :pointer, :pointer
590
+ ],
591
+
592
+ :GEOSNormalize_r => [
593
+ # -1 on exception, *handle, *geom
474
594
  :int, :pointer, :pointer
475
595
  ],
476
596
 
477
597
  :GEOSGetInteriorRingN_r => [
598
+ # *geom, *handle, *geom, n
478
599
  :pointer, :pointer, :pointer, :int
479
600
  ],
480
601
 
481
602
  :GEOSGetExteriorRing_r => [
603
+ # *geom, *handle, *geom
482
604
  :pointer, :pointer, :pointer
483
605
  ],
484
606
 
485
607
  :GEOSGeomGetNumPoints_r => [
608
+ # numpoints, *handle, *geom
486
609
  :int, :pointer, :pointer
487
610
  ],
488
611
 
489
612
  :GEOSGeomGetX_r => [
613
+ # -1 on exception, *handle, *geom, *point
490
614
  :int, :pointer, :pointer, :pointer
491
615
  ],
492
616
 
493
617
  :GEOSGeomGetY_r => [
618
+ # -1 on exception, *handle, *geom, *point
494
619
  :int, :pointer, :pointer, :pointer
495
620
  ],
496
621
 
497
622
  :GEOSGeomGetPointN_r => [
623
+ # *point, *handle, *geom, n
498
624
  :pointer, :pointer, :pointer, :int
499
625
  ],
500
626
 
501
627
  :GEOSGeomGetStartPoint_r => [
628
+ # *point, *handle, *geom
502
629
  :pointer, :pointer, :pointer
503
630
  ],
504
631
 
505
632
  :GEOSGeomGetEndPoint_r => [
633
+ # *point, *handle, *geom
506
634
  :pointer, :pointer, :pointer
507
635
  ],
508
636
  #### /Geometry functions ####
509
637
 
510
638
  #### STRtree functions ####
511
639
  :GEOSSTRtree_create_r => [
640
+ # *tree, *handle, node_capacity
512
641
  :pointer, :pointer, :size_t
513
642
  ],
514
643
 
515
644
  :GEOSSTRtree_insert_r => [
645
+ # void, *handle, *tree, *geom, *void
516
646
  :void, :pointer, :pointer, :pointer, :pointer
517
647
  ],
518
648
 
519
649
  :GEOSSTRtree_query_r => [
650
+ # void, *handle, *tree, *geom, void query_callback((void *) item, (void *) user_data), (void *) user_data
520
651
  :void, :pointer, :pointer, :pointer, callback([ :pointer, :pointer ], :void), :pointer
521
652
  ],
522
653
 
523
654
  :GEOSSTRtree_iterate_r => [
655
+ # void, *handle, *tree, void query_callback((void *) item, (void *) user_data), (void *) user_data
524
656
  :void, :pointer, :pointer, callback([ :pointer, :pointer ], :void), :pointer
525
657
  ],
526
658
 
527
659
  :GEOSSTRtree_remove_r => [
660
+ # bool, *handle, *tree, *geom, (void *) item
528
661
  :char, :pointer, :pointer, :pointer, :pointer
529
662
  ],
530
663
 
531
664
  :GEOSSTRtree_destroy_r => [
665
+ # void, *handle, *tree
532
666
  :void, :pointer, :pointer
533
667
  ],
534
668
  #### /STRtree functions ####
535
669
 
536
670
  #### PreparedGeometry functions ####
537
671
  :GEOSPrepare_r => [
672
+ # *prepared, *handle, *geom
538
673
  :pointer, :pointer, :pointer
539
674
  ],
540
675
 
541
676
  :GEOSPreparedGeom_destroy_r => [
677
+ # void, *handle, *geom
542
678
  :void, :pointer, :pointer
543
679
  ],
544
680
 
545
681
  :GEOSPreparedContains_r => [
682
+ # (2 on exception, 1 on true, 0 on false), *handle, *prepared, *geom
546
683
  :char, :pointer, :pointer, :pointer
547
684
  ],
548
685
 
549
686
  :GEOSPreparedContainsProperly_r => [
687
+ # (2 on exception, 1 on true, 0 on false), *handle, *prepared, *geom
688
+ :char, :pointer, :pointer, :pointer
689
+ ],
690
+
691
+ :GEOSPreparedCoveredBy_r => [
692
+ # (2 on exception, 1 on true, 0 on false), *handle, *prepared, *geom
550
693
  :char, :pointer, :pointer, :pointer
551
694
  ],
552
695
 
553
696
  :GEOSPreparedCovers_r => [
697
+ # (2 on exception, 1 on true, 0 on false), *handle, *prepared, *geom
698
+ :char, :pointer, :pointer, :pointer
699
+ ],
700
+
701
+ :GEOSPreparedCrosses_r => [
702
+ # (2 on exception, 1 on true, 0 on false), *handle, *prepared, *geom
703
+ :char, :pointer, :pointer, :pointer
704
+ ],
705
+
706
+ :GEOSPreparedDisjoint_r => [
707
+ # (2 on exception, 1 on true, 0 on false), *handle, *prepared, *geom
554
708
  :char, :pointer, :pointer, :pointer
555
709
  ],
556
710
 
557
711
  :GEOSPreparedIntersects_r => [
712
+ # (2 on exception, 1 on true, 0 on false), *handle, *prepared, *geom
713
+ :char, :pointer, :pointer, :pointer
714
+ ],
715
+
716
+ :GEOSPreparedOverlaps_r => [
717
+ # (2 on exception, 1 on true, 0 on false), *handle, *prepared, *geom
718
+ :char, :pointer, :pointer, :pointer
719
+ ],
720
+
721
+ :GEOSPreparedTouches_r => [
722
+ # (2 on exception, 1 on true, 0 on false), *handle, *prepared, *geom
723
+ :char, :pointer, :pointer, :pointer
724
+ ],
725
+
726
+ :GEOSPreparedWithin_r => [
727
+ # (2 on exception, 1 on true, 0 on false), *handle, *prepared, *geom
558
728
  :char, :pointer, :pointer, :pointer
559
729
  ],
560
730
  #### /PreparedGeometry functions ####
561
731
 
562
732
  #### WktReader functions ####
563
733
  :GEOSWKTReader_create_r => [
734
+ # *wktr, *handle
564
735
  :pointer, :pointer
565
736
  ],
566
737
 
567
738
  :GEOSWKTReader_read_r => [
739
+ # *geom, *handle, *wktr, string
568
740
  :pointer, :pointer, :pointer, :string
569
741
  ],
570
742
 
571
743
  :GEOSWKTReader_destroy_r => [
744
+ # void, *handle, *wktr
572
745
  :void, :pointer, :pointer
573
746
  ],
574
747
  #### /WktReader functions ###
575
748
 
576
749
  #### WktWriter functions ####
577
750
  :GEOSWKTWriter_create_r => [
751
+ # *wktw, *handle
578
752
  :pointer, :pointer
579
753
  ],
580
754
 
581
755
  :GEOSWKTWriter_write_r => [
756
+ # string, *handle, *wktw, *geom
582
757
  :string, :pointer, :pointer, :pointer
583
758
  ],
584
759
 
585
760
  :GEOSWKTWriter_destroy_r => [
761
+ # void, *handle, *wktw
586
762
  :void, :pointer, :pointer
587
763
  ],
588
764
 
589
765
  :GEOSWKTWriter_setTrim_r => [
766
+ # void, *handle, *wktw, bool
590
767
  :void, :pointer, :pointer, :char
591
768
  ],
592
769
 
593
770
  :GEOSWKTWriter_setRoundingPrecision_r => [
771
+ # void, *handle, *wktw, precision
594
772
  :void, :pointer, :pointer, :int
595
773
  ],
596
774
 
597
775
  :GEOSWKTWriter_setOutputDimension_r => [
776
+ # void, *handle, *wktw, dimensions
598
777
  :void, :pointer, :pointer, :int
599
778
  ],
600
779
 
601
780
  :GEOSWKTWriter_getOutputDimension_r => [
781
+ # dimensions, *handle, *wktw
602
782
  :int, :pointer, :pointer
603
783
  ],
604
784
 
605
785
  :GEOSWKTWriter_setOld3D_r => [
786
+ # void, *handle, *wktw, bool
606
787
  :void, :pointer, :pointer, :int
607
788
  ],
608
789
  #### /WktWriter functions ####
609
790
 
610
791
  #### WkbReader functions ####
611
792
  :GEOSWKBReader_create_r => [
793
+ # *wkbr, *handle
612
794
  :pointer, :pointer
613
795
  ],
614
796
 
615
797
  :GEOSWKBReader_destroy_r => [
798
+ # void, *handle, *wkbr
616
799
  :void, :pointer, :pointer
617
800
  ],
618
801
 
619
802
  :GEOSWKBReader_read_r => [
803
+ # *geom, *handle, *wkbr, (unsigned char *) string, size_t
620
804
  :pointer, :pointer, :pointer, :pointer, :size_t
621
805
  ],
622
806
 
623
807
  :GEOSWKBReader_readHEX_r => [
808
+ # *geom, *handle, *wkbr, string, size_t
624
809
  :pointer, :pointer, :pointer, :string, :size_t
625
810
  ],
626
811
  #### /WkbReader functions ####
627
812
 
628
813
  #### WkbWriter functions ####
629
814
  :GEOSWKBWriter_create_r => [
815
+ # *wkbw, *handle
630
816
  :pointer, :pointer
631
817
  ],
632
818
 
633
819
  :GEOSWKBWriter_destroy_r => [
820
+ # void, *handle, *wkbw
634
821
  :void, :pointer, :pointer
635
822
  ],
636
823
 
637
824
  :GEOSWKBWriter_write_r => [
825
+ # (unsigned char *) string, *handle, *wkbw, *geom, *size_t
638
826
  :pointer, :pointer, :pointer, :pointer, :pointer
639
827
  ],
640
828
 
641
829
  :GEOSWKBWriter_writeHEX_r => [
830
+ # (unsigned char *) string, *handle, *wkbw, *geom, *size_t
642
831
  :pointer, :pointer, :pointer, :pointer, :pointer
643
832
  ],
644
833
 
645
834
  :GEOSWKBWriter_setOutputDimension_r => [
835
+ # void, *handle, *wkbw, dimensions
646
836
  :void, :pointer, :pointer, :int
647
837
  ],
648
838
 
649
839
  :GEOSWKBWriter_getOutputDimension_r => [
840
+ # dimensions, *handle, *wkbw
650
841
  :int, :pointer, :pointer
651
842
  ],
652
843
 
653
844
  :GEOSWKBWriter_getByteOrder_r => [
845
+ # byte_order, *handle, *wkbw
654
846
  :byte_order, :pointer, :pointer
655
847
  ],
656
848
 
657
849
  :GEOSWKBWriter_setByteOrder_r => [
850
+ # void, *handle, *wkbw, byte_order
658
851
  :void, :pointer, :pointer, :byte_order
659
852
  ],
660
853
 
661
854
  :GEOSWKBWriter_getIncludeSRID_r => [
855
+ # bool, *handle, *geom
662
856
  :char, :pointer, :pointer
663
857
  ],
664
858
 
665
859
  :GEOSWKBWriter_setIncludeSRID_r => [
860
+ # void, *handle, *geom, bool
666
861
  :void, :pointer, :pointer, :char
667
862
  ],
668
863
  #### /WkbWriter functions ####
@@ -670,24 +865,69 @@ module Geos
670
865
 
671
866
  #### Linearref functions ####
672
867
  :GEOSProject_r => [
868
+ # distance, *handle, *geom_a, *geom_b
673
869
  :double, :pointer, :pointer, :pointer
674
870
  ],
675
871
 
676
872
  :GEOSProjectNormalized_r => [
873
+ # distance, *handle, *geom_a, *geom_b
677
874
  :double, :pointer, :pointer, :pointer
678
875
  ],
679
876
 
680
877
  :GEOSInterpolate_r => [
878
+ # *geom, *handle, *geom, distance
681
879
  :pointer, :pointer, :pointer, :double
682
880
  ],
683
881
 
684
882
  :GEOSInterpolateNormalized_r => [
883
+ # *geom, *handle, *geom, distance
685
884
  :pointer, :pointer, :pointer, :double
686
885
  ],
687
886
  #### /Linearref functions ####
688
887
 
888
+ #### BufferParams functions ####
889
+ :GEOSBufferParams_create_r => [
890
+ # GEOSBufferParams*, *handle
891
+ :pointer, :pointer
892
+ ],
893
+
894
+ :GEOSBufferParams_destroy_r => [
895
+ # void, *handle, *params
896
+ :void, :pointer, :pointer
897
+ ],
898
+
899
+ :GEOSBufferParams_setEndCapStyle_r => [
900
+ # 0 on exception, *handle, *params, style
901
+ :int, :pointer, :pointer, :buffer_cap_style
902
+ ],
903
+
904
+ :GEOSBufferParams_setJoinStyle_r => [
905
+ # 0 on exception, *handle, *params, style
906
+ :int, :pointer, :pointer, :buffer_join_style
907
+ ],
908
+
909
+ :GEOSBufferParams_setMitreLimit_r => [
910
+ # 0 on exception, *handle, *params, mitre_limit
911
+ :int, :pointer, :pointer, :double
912
+ ],
913
+
914
+ :GEOSBufferParams_setQuadrantSegments_r => [
915
+ # 0 on exception, *handle, *params, quad_segs
916
+ :int, :pointer, :pointer, :int
917
+ ],
918
+
919
+ :GEOSBufferParams_setSingleSided_r => [
920
+ # 0 on exception, *handle, *params, bool
921
+ :int, :pointer, :pointer, :int
922
+ ],
923
+ #### /BufferParams functions ####
924
+
689
925
  #### Algorithms ####
926
+ # -1 if reaching P takes a counter-clockwise (left) turn
927
+ # 1 if reaching P takes a clockwise (right) turn
928
+ # 0 if P is collinear with A-B
690
929
  :GEOSOrientationIndex_r => [
930
+ # int, *handle, Ax, Ay, Bx, By, Px, Py
691
931
  :int, :pointer, :double, :double, :double, :double, :double, :double
692
932
  ]
693
933
  #### /Algorithms ####
@@ -751,6 +991,7 @@ module Geos
751
991
  create_multi_line_string
752
992
  create_multi_polygon
753
993
  create_geometry_collection
994
+ create_collection
754
995
 
755
996
  create_empty_point
756
997
  create_empty_line_string
@@ -759,6 +1000,7 @@ module Geos
759
1000
  create_empty_multi_line_string
760
1001
  create_empty_multi_polygon
761
1002
  create_empty_geometry_collection
1003
+ create_empty_collection
762
1004
  }.each do |m|
763
1005
  self.class_eval <<-EOF
764
1006
  def #{m}(*args)
@@ -768,25 +1010,26 @@ module Geos
768
1010
  end
769
1011
  end
770
1012
 
1013
+ # For backwards compatibility with older native GEOS bindings.
771
1014
  module GeomTypes
772
- GEOS_POINT = 0
773
- GEOS_LINESTRING = 1
774
- GEOS_LINEARRING = 2
775
- GEOS_POLYGON = 3
776
- GEOS_MULTIPOINT = 4
777
- GEOS_MULTILINESTRING = 5
778
- GEOS_MULTIPOLYGON = 6
779
- GEOS_GEOMETRYCOLLECTION = 7
1015
+ GEOS_POINT = Geos::GeometryTypes[:point]
1016
+ GEOS_LINESTRING = Geos::GeometryTypes[:line_string]
1017
+ GEOS_LINEARRING = Geos::GeometryTypes[:linear_ring]
1018
+ GEOS_POLYGON = Geos::GeometryTypes[:polygon]
1019
+ GEOS_MULTIPOINT = Geos::GeometryTypes[:multi_point]
1020
+ GEOS_MULTILINESTRING = Geos::GeometryTypes[:multi_line_string]
1021
+ GEOS_MULTIPOLYGON = Geos::GeometryTypes[:multi_polygon]
1022
+ GEOS_GEOMETRYCOLLECTION = Geos::GeometryTypes[:geometry_collection]
780
1023
  end
781
1024
 
782
1025
  module VersionConstants
783
- VERSION = File.read(File.join(GEOS_BASE, %w{ .. VERSION })) rescue nil
1026
+ VERSION = File.read(File.join(GEOS_BASE, %w{ .. VERSION })).strip
784
1027
  GEOS_JTS_PORT = Geos.jts_port
785
1028
  GEOS_VERSION,
786
- GEOS_VERSION_MAJOR, GEOS_VERSION_MINOR, GEOS_VERISON_PATCH,
1029
+ GEOS_VERSION_MAJOR, GEOS_VERSION_MINOR, GEOS_VERISON_PATCH, GEOS_VERSION_PRERELEASE,
787
1030
  GEOS_CAPI_VERSION,
788
1031
  GEOS_CAPI_VERSION_MAJOR, GEOS_CAPI_VERSION_MINOR, GEOS_CAPI_VERSION_PATCH =
789
- if versions = Geos.version.scan(/^((\d+)\.(\d+)\.(\d+))-CAPI-((\d+)\.(\d+)\.(\d+))$/)
1032
+ if !(versions = Geos.version.scan(/^((\d+)\.(\d+)\.(\d+)((?:rc|beta|alpha)\d+)?)-CAPI-((\d+)\.(\d+)\.(\d+))$/)).empty?
790
1033
  versions = versions[0]
791
1034
  [
792
1035
  versions[0],
@@ -794,17 +1037,27 @@ module Geos
794
1037
  versions[2].to_i,
795
1038
  versions[3].to_i,
796
1039
  versions[4],
797
- versions[5].to_i,
1040
+ versions[5],
798
1041
  versions[6].to_i,
799
- versions[7].to_i
1042
+ versions[7].to_i,
1043
+ versions[8].to_i
800
1044
  ]
801
1045
  else
802
- []
1046
+ [ '0.0.0', 0, 0, 0, nil, '0.0.0', 0, 0, 0 ]
803
1047
  end
804
1048
  GEOS_CAPI_FIRST_INTERFACE = GEOS_CAPI_VERSION_MAJOR.to_i
805
1049
  GEOS_CAPI_LAST_INTERFACE = GEOS_CAPI_VERSION_MAJOR.to_i + GEOS_CAPI_VERSION_MINOR.to_i
806
1050
  end
807
1051
 
1052
+ module Constants
1053
+ BUFFER_PARAM_DEFAULTS = {
1054
+ :quad_segs => 8,
1055
+ :endcap => :round,
1056
+ :join => :round,
1057
+ :mitre_limit => 5.0
1058
+ }.freeze
1059
+ end
1060
+
808
1061
  include GeomTypes
809
1062
  include VersionConstants
810
1063
  end