Class: Geos::Geometry
- Inherits:
-
Object
show all
- Includes:
- Tools
- Defined in:
- lib/ffi-geos/geometry.rb
Constant Summary
Constants included
from GeomTypes
Geos::GeomTypes::GEOS_GEOMETRYCOLLECTION, Geos::GeomTypes::GEOS_LINEARRING, Geos::GeomTypes::GEOS_LINESTRING, Geos::GeomTypes::GEOS_MULTILINESTRING, Geos::GeomTypes::GEOS_MULTIPOINT, Geos::GeomTypes::GEOS_MULTIPOLYGON, Geos::GeomTypes::GEOS_POINT, Geos::GeomTypes::GEOS_POLYGON
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#area ⇒ Object
-
#boundary ⇒ Object
-
#buffer(width, options = nil) ⇒ Object
:call-seq: buffer(width) buffer(width, options) buffer(width, buffer_params) buffer(width, quad_segs).
-
#centroid ⇒ Object
(also: #center)
-
#contains?(geom) ⇒ Boolean
-
#convex_hull ⇒ Object
-
#coord_seq ⇒ Object
-
#covered_by?(geom) ⇒ Boolean
-
#covers?(geom) ⇒ Boolean
-
#crosses?(geom) ⇒ Boolean
-
#delaunay_triangulation(tolerance, options = {}) ⇒ Object
-
#difference(geom) ⇒ Object
-
#dimensions ⇒ Object
-
#disjoint?(geom) ⇒ Boolean
-
#distance(geom) ⇒ Object
-
#empty? ⇒ Boolean
-
#end_point ⇒ Object
-
#envelope ⇒ Object
-
#eql?(geom) ⇒ Boolean
(also: #==, #equals?)
-
#eql_almost?(geom, decimal = 6) ⇒ Boolean
(also: #equals_almost?, #almost_equals?)
-
#eql_exact?(geom, tolerance) ⇒ Boolean
(also: #equals_exact?, #exactly_equals?)
-
#extract_unique_points ⇒ Object
(also: #unique_points)
-
#geom_type ⇒ Object
Returns the name of the Geometry type, i.e.
-
#has_z? ⇒ Boolean
-
#hausdorff_distance(geom, densify_frac = nil) ⇒ Object
-
#initialize(ptr, options = {}) ⇒ Geometry
constructor
-
#initialize_copy(source) ⇒ Object
-
#interpolate(d, normalized = false) ⇒ Object
-
#interpolate_normalized(d) ⇒ Object
-
#intersection(geom) ⇒ Object
-
#intersects?(geom) ⇒ Boolean
-
#length ⇒ Object
-
#line_merge ⇒ Object
-
#nearest_points(geom) ⇒ Object
-
#node ⇒ Object
Available in GEOS 3.3.4+.
-
#normalize! ⇒ Object
(also: #normalize)
-
#num_coordinates ⇒ Object
-
#num_geometries ⇒ Object
-
#overlaps?(geom) ⇒ Boolean
-
#point_on_surface ⇒ Object
(also: #representative_point)
-
#polygonize ⇒ Object
-
#polygonize_cut_edges ⇒ Object
-
#polygonize_full ⇒ Object
Returns a Hash with the following structure:.
-
#project(geom, normalized = false) ⇒ Object
-
#project_normalized(geom) ⇒ Object
-
#relate(geom) ⇒ Object
Returns the Dimensionally Extended Nine-Intersection Model (DE-9IM) matrix of the geometries as a String.
-
#relate_boundary_node_rule(geom, bnr = :mod2) ⇒ Object
-
#relate_pattern(geom, pattern) ⇒ Object
Checks the DE-9IM pattern against the geoms.
-
#ring? ⇒ Boolean
-
#shared_paths(geom) ⇒ Object
-
#simple? ⇒ Boolean
-
#simplify(tolerance) ⇒ Object
-
#snap(geom, tolerance) ⇒ Object
(also: #snap_to)
-
#srid ⇒ Object
-
#srid=(s) ⇒ Object
-
#start_point ⇒ Object
-
#sym_difference(geom) ⇒ Object
(also: #symmetric_difference)
-
#to_prepared ⇒ Object
-
#to_s ⇒ Object
-
#topology_preserve_simplify(tolerance) ⇒ Object
-
#touches?(geom) ⇒ Boolean
-
#type_id ⇒ Object
Returns one of the values from Geos::GeomTypes.
-
#unary_union ⇒ Object
-
#union(geom = nil) ⇒ Object
Calling without a geom argument is equivalent to calling unary_union when using GEOS 3.3+ and is equivalent to calling union_cascaded in older versions.
-
#union_cascaded ⇒ Object
-
#valid? ⇒ Boolean
-
#valid_detail(flags = 0) ⇒ Object
Returns a Hash containing the following structure on invalid geometries:.
-
#valid_reason ⇒ Object
Returns a String describing whether or not the Geometry is valid.
-
#within?(geom) ⇒ Boolean
Methods included from Tools
#bool_result, #cast_geometry_ptr, #check_enum_value, #check_geometry, #pick_srid_according_to_policy, #pick_srid_from_geoms, #symbol_for_enum
Constructor Details
#initialize(ptr, options = {}) ⇒ Geometry
For internal use. Geometry objects should be created via WkbReader, WktReader and the various Geos.create_* methods.
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/ffi-geos/geometry.rb', line 11
def initialize(ptr, options = {})
options = {
:auto_free => true
}.merge(options)
@ptr = FFI::AutoPointer.new(
ptr,
self.class.method(:release)
)
@ptr.autorelease = !!options[:auto_free]
@parent = options[:parent] if options[:parent]
end
|
Instance Attribute Details
#ptr ⇒ Object
Returns the value of attribute ptr.
7
8
9
|
# File 'lib/ffi-geos/geometry.rb', line 7
def ptr
@ptr
end
|
Class Method Details
.release(ptr) ⇒ Object
35
36
37
|
# File 'lib/ffi-geos/geometry.rb', line 35
def self.release(ptr) FFIGeos.GEOSGeom_destroy_r(Geos.current_handle, ptr)
end
|
Instance Method Details
#area ⇒ Object
442
443
444
445
446
447
448
449
450
|
# File 'lib/ffi-geos/geometry.rb', line 442
def area
if self.empty?
0
else
double_ptr = FFI::MemoryPointer.new(:double)
FFIGeos.GEOSArea_r(Geos.current_handle, self.ptr, double_ptr)
double_ptr.read_double
end
end
|
#boundary ⇒ Object
155
156
157
|
# File 'lib/ffi-geos/geometry.rb', line 155
def boundary
cast_geometry_ptr(FFIGeos.GEOSBoundary_r(Geos.current_handle, self.ptr), :srid_copy => self.srid)
end
|
#buffer(width, options = nil) ⇒ Object
:call-seq:
buffer(width)
buffer(width, options)
buffer(width, buffer_params)
buffer(width, quad_segs)
Calls buffer on the Geometry. Options can be passed as either a BufferParams object, as an equivalent Hash or as a quad_segs value. Default values can be found in Geos::Constants::BUFFER_PARAM_DEFAULTS.
Note that when using versions of GEOS prior to 3.3.0, only the quad_segs option is recognized when using Geometry#buffer and other options are ignored.
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/ffi-geos/geometry.rb', line 103
def buffer(width, options = nil)
options ||= {}
params = case options
when Hash
Geos::BufferParams.new(options)
when Geos::BufferParams
options
when Numeric
Geos::BufferParams.new(:quad_segs => options)
else
raise ArgumentError.new("Expected Geos::BufferParams, a Hash or a Numeric")
end
cast_geometry_ptr(FFIGeos.GEOSBufferWithParams_r(Geos.current_handle, self.ptr, params.ptr, width), :srid_copy => self.srid)
end
|
#centroid ⇒ Object
Also known as:
center
204
205
206
|
# File 'lib/ffi-geos/geometry.rb', line 204
def centroid
cast_geometry_ptr(FFIGeos.GEOSGetCentroid_r(Geos.current_handle, self.ptr), :srid_copy => self.srid)
end
|
#contains?(geom) ⇒ Boolean
277
278
279
280
|
# File 'lib/ffi-geos/geometry.rb', line 277
def contains?(geom)
check_geometry(geom)
bool_result(FFIGeos.GEOSContains_r(Geos.current_handle, self.ptr, geom.ptr))
end
|
#convex_hull ⇒ Object
136
137
138
|
# File 'lib/ffi-geos/geometry.rb', line 136
def convex_hull
cast_geometry_ptr(FFIGeos.GEOSConvexHull_r(Geos.current_handle, self.ptr), :srid_copy => self.srid)
end
|
#covered_by?(geom) ⇒ Boolean
313
314
315
316
|
# File 'lib/ffi-geos/geometry.rb', line 313
def covered_by?(geom)
check_geometry(geom)
bool_result(FFIGeos.GEOSCoveredBy_r(Geos.current_handle, self.ptr, geom.ptr))
end
|
#covers?(geom) ⇒ Boolean
291
292
293
294
|
# File 'lib/ffi-geos/geometry.rb', line 291
def covers?(geom)
check_geometry(geom)
bool_result(FFIGeos.GEOSCovers_r(Geos.current_handle, self.ptr, geom.ptr))
end
|
#crosses?(geom) ⇒ Boolean
267
268
269
270
|
# File 'lib/ffi-geos/geometry.rb', line 267
def crosses?(geom)
check_geometry(geom)
bool_result(FFIGeos.GEOSCrosses_r(Geos.current_handle, self.ptr, geom.ptr))
end
|
#delaunay_triangulation(tolerance, options = {}) ⇒ Object
556
557
558
|
# File 'lib/ffi-geos/geometry.rb', line 556
def delaunay_triangulation(tolerance, options = {})
cast_geometry_ptr(FFIGeos.GEOSDelaunayTriangulation_r(Geos.current_handle, self.ptr, tolerance, options[:only_edges] ? 1 : 0))
end
|
#difference(geom) ⇒ Object
140
141
142
143
144
145
|
# File 'lib/ffi-geos/geometry.rb', line 140
def difference(geom)
check_geometry(geom)
cast_geometry_ptr(FFIGeos.GEOSDifference_r(Geos.current_handle, self.ptr, geom.ptr), {
:srid_copy => pick_srid_from_geoms(self.srid, geom.srid)
})
end
|
#dimensions ⇒ Object
66
67
68
|
# File 'lib/ffi-geos/geometry.rb', line 66
def dimensions
FFIGeos.GEOSGeom_getDimensions_r(Geos.current_handle, self.ptr)
end
|
#disjoint?(geom) ⇒ Boolean
252
253
254
255
|
# File 'lib/ffi-geos/geometry.rb', line 252
def disjoint?(geom)
check_geometry(geom)
bool_result(FFIGeos.GEOSDisjoint_r(Geos.current_handle, self.ptr, geom.ptr))
end
|
#distance(geom) ⇒ Object
462
463
464
465
466
467
|
# File 'lib/ffi-geos/geometry.rb', line 462
def distance(geom)
check_geometry(geom)
double_ptr = FFI::MemoryPointer.new(:double)
FFIGeos.GEOSDistance_r(Geos.current_handle, self.ptr, geom.ptr, double_ptr)
double_ptr.read_double
end
|
#empty? ⇒ Boolean
352
353
354
|
# File 'lib/ffi-geos/geometry.rb', line 352
def empty?
bool_result(FFIGeos.GEOSisEmpty_r(Geos.current_handle, self.ptr))
end
|
#end_point ⇒ Object
438
439
440
|
# File 'lib/ffi-geos/geometry.rb', line 438
def end_point
cast_geometry_ptr(FFIGeos.GEOSGeomGetEndPoint_r(Geos.current_handle, self.ptr), :srid_copy => self.srid)
end
|
#envelope ⇒ Object
209
210
211
|
# File 'lib/ffi-geos/geometry.rb', line 209
def envelope
cast_geometry_ptr(FFIGeos.GEOSEnvelope_r(Geos.current_handle, self.ptr), :srid_copy => self.srid)
end
|
#eql?(geom) ⇒ Boolean
Also known as:
==, equals?
331
332
333
334
|
# File 'lib/ffi-geos/geometry.rb', line 331
def eql?(geom)
check_geometry(geom)
bool_result(FFIGeos.GEOSEquals_r(Geos.current_handle, self.ptr, geom.ptr))
end
|
#eql_almost?(geom, decimal = 6) ⇒ Boolean
Also known as:
equals_almost?, almost_equals?
345
346
347
348
|
# File 'lib/ffi-geos/geometry.rb', line 345
def eql_almost?(geom, decimal = 6)
check_geometry(geom)
bool_result(FFIGeos.GEOSEqualsExact_r(Geos.current_handle, self.ptr, geom.ptr, 0.5 * 10 ** (-decimal)))
end
|
#eql_exact?(geom, tolerance) ⇒ Boolean
Also known as:
equals_exact?, exactly_equals?
338
339
340
341
|
# File 'lib/ffi-geos/geometry.rb', line 338
def eql_exact?(geom, tolerance)
check_geometry(geom)
bool_result(FFIGeos.GEOSEqualsExact_r(Geos.current_handle, self.ptr, geom.ptr, tolerance))
end
|
247
248
249
|
# File 'lib/ffi-geos/geometry.rb', line 247
def
cast_geometry_ptr(FFIGeos.GEOSGeom_extractUniquePoints_r(Geos.current_handle, self.ptr), :srid_copy => self.srid)
end
|
#geom_type ⇒ Object
Returns the name of the Geometry type, i.e. “Point”, “Polygon”, etc.
#has_z? ⇒ Boolean
398
399
400
|
# File 'lib/ffi-geos/geometry.rb', line 398
def has_z?
bool_result(FFIGeos.GEOSHasZ_r(Geos.current_handle, self.ptr))
end
|
#hausdorff_distance(geom, densify_frac = nil) ⇒ Object
469
470
471
472
473
474
475
476
477
478
479
480
481
|
# File 'lib/ffi-geos/geometry.rb', line 469
def hausdorff_distance(geom, densify_frac = nil)
check_geometry(geom)
double_ptr = FFI::MemoryPointer.new(:double)
if densify_frac
FFIGeos.GEOSHausdorffDistanceDensify_r(Geos.current_handle, self.ptr, geom.ptr, densify_frac, double_ptr)
else
FFIGeos.GEOSHausdorffDistance_r(Geos.current_handle, self.ptr, geom.ptr, double_ptr)
end
double_ptr.read_double
end
|
#initialize_copy(source) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/ffi-geos/geometry.rb', line 25
def initialize_copy(source)
@ptr = FFI::AutoPointer.new(
FFIGeos.GEOSGeom_clone_r(Geos.current_handle, source.ptr),
self.class.method(:release)
)
self.srid = source.srid
end
|
#interpolate(d, normalized = false) ⇒ Object
420
421
422
423
424
425
426
427
428
|
# File 'lib/ffi-geos/geometry.rb', line 420
def interpolate(d, normalized = false)
ret = if normalized
FFIGeos.GEOSInterpolateNormalized_r(Geos.current_handle, self.ptr, d)
else
FFIGeos.GEOSInterpolate_r(Geos.current_handle, self.ptr, d)
end
cast_geometry_ptr(ret, :srid_copy => self.srid)
end
|
#interpolate_normalized(d) ⇒ Object
430
431
432
|
# File 'lib/ffi-geos/geometry.rb', line 430
def interpolate_normalized(d)
self.interpolate(d, true)
end
|
#intersection(geom) ⇒ Object
82
83
84
85
86
87
|
# File 'lib/ffi-geos/geometry.rb', line 82
def intersection(geom)
check_geometry(geom)
cast_geometry_ptr(FFIGeos.GEOSIntersection_r(Geos.current_handle, self.ptr, geom.ptr), {
:srid_copy => pick_srid_from_geoms(self.srid, geom.srid)
})
end
|
#intersects?(geom) ⇒ Boolean
262
263
264
265
|
# File 'lib/ffi-geos/geometry.rb', line 262
def intersects?(geom)
check_geometry(geom)
bool_result(FFIGeos.GEOSIntersects_r(Geos.current_handle, self.ptr, geom.ptr))
end
|
#length ⇒ Object
452
453
454
455
456
457
458
459
460
|
# File 'lib/ffi-geos/geometry.rb', line 452
def length
if self.empty?
0
else
double_ptr = FFI::MemoryPointer.new(:double)
FFIGeos.GEOSLength_r(Geos.current_handle, self.ptr, double_ptr)
double_ptr.read_double
end
end
|
#line_merge ⇒ Object
235
236
237
|
# File 'lib/ffi-geos/geometry.rb', line 235
def line_merge
cast_geometry_ptr(FFIGeos.GEOSLineMerge_r(Geos.current_handle, self.ptr), :srid_copy => self.srid)
end
|
#nearest_points(geom) ⇒ Object
485
486
487
488
489
490
491
492
|
# File 'lib/ffi-geos/geometry.rb', line 485
def nearest_points(geom)
check_geometry(geom)
ptr = FFIGeos.GEOSNearestPoints_r(Geos.current_handle, self.ptr, geom.ptr)
if !ptr.null?
CoordinateSequence.new(ptr)
end
end
|
#node ⇒ Object
194
195
196
|
# File 'lib/ffi-geos/geometry.rb', line 194
def node
cast_geometry_ptr(FFIGeos.GEOSNode_r(Geos.current_handle, self.ptr))
end
|
#normalize! ⇒ Object
Also known as:
normalize
49
50
51
52
53
54
55
|
# File 'lib/ffi-geos/geometry.rb', line 49
def normalize!
if FFIGeos.GEOSNormalize_r(Geos.current_handle, self.ptr) == -1
raise RuntimeError.new("Couldn't normalize #{self.class}")
end
self
end
|
#num_coordinates ⇒ Object
74
75
76
|
# File 'lib/ffi-geos/geometry.rb', line 74
def num_coordinates
FFIGeos.GEOSGetNumCoordinates_r(Geos.current_handle, self.ptr)
end
|
#num_geometries ⇒ Object
70
71
72
|
# File 'lib/ffi-geos/geometry.rb', line 70
def num_geometries
FFIGeos.GEOSGetNumGeometries_r(Geos.current_handle, self.ptr)
end
|
#overlaps?(geom) ⇒ Boolean
282
283
284
285
|
# File 'lib/ffi-geos/geometry.rb', line 282
def overlaps?(geom)
check_geometry(geom)
bool_result(FFIGeos.GEOSOverlaps_r(Geos.current_handle, self.ptr, geom.ptr))
end
|
#point_on_surface ⇒ Object
Also known as:
representative_point
199
200
201
|
# File 'lib/ffi-geos/geometry.rb', line 199
def point_on_surface
cast_geometry_ptr(FFIGeos.GEOSPointOnSurface_r(Geos.current_handle, self.ptr), :srid_copy => self.srid)
end
|
#polygonize ⇒ Object
541
542
543
544
545
546
|
# File 'lib/ffi-geos/geometry.rb', line 541
def polygonize
ary = FFI::MemoryPointer.new(:pointer)
ary.write_array_of_pointer([ self.ptr ])
cast_geometry_ptr(FFIGeos.GEOSPolygonize_r(Geos.current_handle, ary, 1), :srid_copy => self.srid).to_a
end
|
#polygonize_cut_edges ⇒ Object
548
549
550
551
552
553
|
# File 'lib/ffi-geos/geometry.rb', line 548
def polygonize_cut_edges
ary = FFI::MemoryPointer.new(:pointer)
ary.write_array_of_pointer([ self.ptr ])
cast_geometry_ptr(FFIGeos.GEOSPolygonizer_getCutEdges_r(Geos.current_handle, ary, 1), :srid_copy => self.srid).to_a
end
|
#polygonize_full ⇒ Object
Returns a Hash with the following structure:
{
:rings => [ ... ],
:cuts => [ ... ],
:dangles => [ ... ],
:invalid_rings => [ ... ]
}
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
|
# File 'lib/ffi-geos/geometry.rb', line 518
def polygonize_full
cuts = FFI::MemoryPointer.new(:pointer)
dangles = FFI::MemoryPointer.new(:pointer)
invalid_rings = FFI::MemoryPointer.new(:pointer)
rings = cast_geometry_ptr(
FFIGeos.GEOSPolygonize_full_r(Geos.current_handle, self.ptr, cuts, dangles, invalid_rings), {
:srid_copy => self.srid
}
)
cuts = cast_geometry_ptr(cuts.read_pointer, :srid_copy => self.srid)
dangles = cast_geometry_ptr(dangles.read_pointer, :srid_copy => self.srid)
invalid_rings = cast_geometry_ptr(invalid_rings.read_pointer, :srid_copy => self.srid)
{
:rings => rings.to_a,
:cuts => cuts.to_a,
:dangles => dangles.to_a,
:invalid_rings => invalid_rings.to_a
}
end
|
#project(geom, normalized = false) ⇒ Object
405
406
407
408
409
410
411
412
413
|
# File 'lib/ffi-geos/geometry.rb', line 405
def project(geom, normalized = false)
raise TypeError.new("Expected Geos::Point type") if !geom.is_a?(Geos::Point)
if normalized
FFIGeos.GEOSProjectNormalized_r(Geos.current_handle, self.ptr, geom.ptr)
else
FFIGeos.GEOSProject_r(Geos.current_handle, self.ptr, geom.ptr)
end
end
|
#project_normalized(geom) ⇒ Object
415
416
417
|
# File 'lib/ffi-geos/geometry.rb', line 415
def project_normalized(geom)
self.project(geom, true)
end
|
#relate(geom) ⇒ Object
Returns the Dimensionally Extended Nine-Intersection Model (DE-9IM) matrix of the geometries as a String.
215
216
217
218
|
# File 'lib/ffi-geos/geometry.rb', line 215
def relate(geom)
check_geometry(geom)
FFIGeos.GEOSRelate_r(Geos.current_handle, self.ptr, geom.ptr)
end
|
#relate_boundary_node_rule(geom, bnr = :mod2) ⇒ Object
228
229
230
231
232
|
# File 'lib/ffi-geos/geometry.rb', line 228
def relate_boundary_node_rule(geom, bnr = :mod2)
check_geometry(geom)
check_enum_value(Geos::RelateBoundaryNodeRules, bnr)
FFIGeos.GEOSRelateBoundaryNodeRule_r(Geos.current_handle, self.ptr, geom.ptr, bnr)
end
|
#relate_pattern(geom, pattern) ⇒ Object
Checks the DE-9IM pattern against the geoms.
221
222
223
224
|
# File 'lib/ffi-geos/geometry.rb', line 221
def relate_pattern(geom, pattern)
check_geometry(geom)
bool_result(FFIGeos.GEOSRelatePattern_r(Geos.current_handle, self.ptr, geom.ptr, pattern))
end
|
#ring? ⇒ Boolean
394
395
396
|
# File 'lib/ffi-geos/geometry.rb', line 394
def ring?
bool_result(FFIGeos.GEOSisRing_r(Geos.current_handle, self.ptr))
end
|
#shared_paths(geom) ⇒ Object
503
504
505
506
507
508
|
# File 'lib/ffi-geos/geometry.rb', line 503
def shared_paths(geom)
check_geometry(geom)
cast_geometry_ptr(FFIGeos.GEOSSharedPaths_r(Geos.current_handle, self.ptr, geom.ptr), {
:srid_copy => pick_srid_from_geoms(self.srid, geom.srid)
}).to_a
end
|
#simple? ⇒ Boolean
390
391
392
|
# File 'lib/ffi-geos/geometry.rb', line 390
def simple?
bool_result(FFIGeos.GEOSisSimple_r(Geos.current_handle, self.ptr))
end
|
#simplify(tolerance) ⇒ Object
239
240
241
|
# File 'lib/ffi-geos/geometry.rb', line 239
def simplify(tolerance)
cast_geometry_ptr(FFIGeos.GEOSSimplify_r(Geos.current_handle, self.ptr, tolerance), :srid_copy => self.srid)
end
|
#snap(geom, tolerance) ⇒ Object
Also known as:
snap_to
495
496
497
498
499
500
|
# File 'lib/ffi-geos/geometry.rb', line 495
def snap(geom, tolerance)
check_geometry(geom)
cast_geometry_ptr(FFIGeos.GEOSSnap_r(Geos.current_handle, self.ptr, geom.ptr, tolerance), {
:srid_copy => pick_srid_from_geoms(self.srid, geom.srid)
})
end
|
#start_point ⇒ Object
434
435
436
|
# File 'lib/ffi-geos/geometry.rb', line 434
def start_point
cast_geometry_ptr(FFIGeos.GEOSGeomGetStartPoint_r(Geos.current_handle, self.ptr), :srid_copy => self.srid)
end
|
#sym_difference(geom) ⇒ Object
Also known as:
symmetric_difference
147
148
149
150
151
152
|
# File 'lib/ffi-geos/geometry.rb', line 147
def sym_difference(geom)
check_geometry(geom)
cast_geometry_ptr(FFIGeos.GEOSSymDifference_r(Geos.current_handle, self.ptr, geom.ptr), {
:srid_copy => pick_srid_from_geoms(self.srid, geom.srid)
})
end
|
#to_s ⇒ Object
565
566
567
568
569
570
571
572
573
|
# File 'lib/ffi-geos/geometry.rb', line 565
def to_s
writer = WktWriter.new
wkt = writer.write(self)
if wkt.length > 120
wkt = "#{wkt[0...120]} ... "
end
"#<Geos::#{self.geom_type}: #{wkt}>"
end
|
#topology_preserve_simplify(tolerance) ⇒ Object
243
244
245
|
# File 'lib/ffi-geos/geometry.rb', line 243
def topology_preserve_simplify(tolerance)
cast_geometry_ptr(FFIGeos.GEOSTopologyPreserveSimplify_r(Geos.current_handle, self.ptr, tolerance), :srid_copy => self.srid)
end
|
#touches?(geom) ⇒ Boolean
257
258
259
260
|
# File 'lib/ffi-geos/geometry.rb', line 257
def touches?(geom)
check_geometry(geom)
bool_result(FFIGeos.GEOSTouches_r(Geos.current_handle, self.ptr, geom.ptr))
end
|
#type_id ⇒ Object
Returns one of the values from Geos::GeomTypes.
#unary_union ⇒ Object
185
186
187
188
189
|
# File 'lib/ffi-geos/geometry.rb', line 185
def unary_union
cast_geometry_ptr(FFIGeos.GEOSUnaryUnion_r(Geos.current_handle, self.ptr), {
:srid_copy => self.srid
})
end
|
#union(geom = nil) ⇒ Object
Calling without a geom argument is equivalent to calling unary_union when using GEOS 3.3+ and is equivalent to calling union_cascaded in older versions.
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/ffi-geos/geometry.rb', line 162
def union(geom = nil)
if geom
check_geometry(geom)
cast_geometry_ptr(FFIGeos.GEOSUnion_r(Geos.current_handle, self.ptr, geom.ptr), {
:srid_copy => pick_srid_from_geoms(self.srid, geom.srid)
})
else
if self.respond_to?(:unary_union)
self.unary_union
else
self.union_cascaded
end
end
end
|
#union_cascaded ⇒ Object
177
178
179
180
181
|
# File 'lib/ffi-geos/geometry.rb', line 177
def union_cascaded
cast_geometry_ptr(FFIGeos.GEOSUnionCascaded_r(Geos.current_handle, self.ptr), {
:srid_copy => self.srid
})
end
|
#valid? ⇒ Boolean
356
357
358
|
# File 'lib/ffi-geos/geometry.rb', line 356
def valid?
bool_result(FFIGeos.GEOSisValid_r(Geos.current_handle, self.ptr))
end
|
#valid_detail(flags = 0) ⇒ Object
Returns a Hash containing the following structure on invalid geometries:
{
:detail => "String explaining the problem",
:location => Geos::Point }
If the Geometry is valid, returns nil.
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
|
# File 'lib/ffi-geos/geometry.rb', line 373
def valid_detail(flags = 0)
detail = FFI::MemoryPointer.new(:pointer)
location = FFI::MemoryPointer.new(:pointer)
valid = bool_result(
FFIGeos.GEOSisValidDetail_r(Geos.current_handle, self.ptr, flags, detail, location)
)
if !valid
{
:detail => detail.read_pointer.read_string,
:location => cast_geometry_ptr(location.read_pointer, {
:srid_copy => self.srid
})
}
end
end
|
#valid_reason ⇒ Object
Returns a String describing whether or not the Geometry is valid.
361
362
363
|
# File 'lib/ffi-geos/geometry.rb', line 361
def valid_reason
FFIGeos.GEOSisValidReason_r(Geos.current_handle, self.ptr)
end
|
#within?(geom) ⇒ Boolean
272
273
274
275
|
# File 'lib/ffi-geos/geometry.rb', line 272
def within?(geom)
check_geometry(geom)
bool_result(FFIGeos.GEOSWithin_r(Geos.current_handle, self.ptr, geom.ptr))
end
|