Class: Geos::Geometry

Inherits:
Object
  • Object
show all
Includes:
Tools
Defined in:
lib/ffi-geos/geometry.rb

Direct Known Subclasses

GeometryCollection, LineString, Point, Polygon

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

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

#ptrObject (readonly)

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

:nodoc:



35
36
37
# File 'lib/ffi-geos/geometry.rb', line 35

def self.release(ptr) #:nodoc:
  FFIGeos.GEOSGeom_destroy_r(Geos.current_handle, ptr)
end

Instance Method Details

#areaObject



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

#boundaryObject



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

#centroidObject 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

Returns:

  • (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_hullObject



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

#coord_seqObject



78
79
80
# File 'lib/ffi-geos/geometry.rb', line 78

def coord_seq
  CoordinateSequence.new(FFIGeos.GEOSGeom_getCoordSeq_r(Geos.current_handle, self.ptr), false, self)
end

#covered_by?(geom) ⇒ Boolean

:nodoc:

Returns:

  • (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

:nodoc:

Returns:

  • (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

Returns:

  • (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

#dimensionsObject



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

Returns:

  • (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

Returns:

  • (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_pointObject



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

#envelopeObject



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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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

#extract_unique_pointsObject Also known as: unique_points



247
248
249
# File 'lib/ffi-geos/geometry.rb', line 247

def extract_unique_points
  cast_geometry_ptr(FFIGeos.GEOSGeom_extractUniquePoints_r(Geos.current_handle, self.ptr), :srid_copy => self.srid)
end

#geom_typeObject

Returns the name of the Geometry type, i.e. “Point”, “Polygon”, etc.



40
41
42
# File 'lib/ffi-geos/geometry.rb', line 40

def geom_type
  FFIGeos.GEOSGeomType_r(Geos.current_handle, self.ptr)
end

#has_z?Boolean

Returns:

  • (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)
  )

  # Copy over SRID since GEOS does not
  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

Returns:

  • (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

#lengthObject



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_mergeObject



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

Available in GEOS 3.4+.



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

#nodeObject

Available in GEOS 3.3.4+



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_coordinatesObject



74
75
76
# File 'lib/ffi-geos/geometry.rb', line 74

def num_coordinates
  FFIGeos.GEOSGetNumCoordinates_r(Geos.current_handle, self.ptr)
end

#num_geometriesObject



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

Returns:

  • (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_surfaceObject 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

#polygonizeObject



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_edgesObject



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_fullObject

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

Raises:

  • (TypeError)


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

Available in GEOS 3.3+.



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

Returns:

  • (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

Returns:

  • (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

#sridObject



58
59
60
# File 'lib/ffi-geos/geometry.rb', line 58

def srid
  FFIGeos.GEOSGetSRID_r(Geos.current_handle, self.ptr)
end

#srid=(s) ⇒ Object



62
63
64
# File 'lib/ffi-geos/geometry.rb', line 62

def srid=(s)
  FFIGeos.GEOSSetSRID_r(Geos.current_handle, self.ptr, s)
end

#start_pointObject



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_preparedObject



561
562
563
# File 'lib/ffi-geos/geometry.rb', line 561

def to_prepared
  Geos::PreparedGeometry.new(self)
end

#to_sObject



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

Returns:

  • (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_idObject

Returns one of the values from Geos::GeomTypes.



45
46
47
# File 'lib/ffi-geos/geometry.rb', line 45

def type_id
  FFIGeos.GEOSGeomTypeId_r(Geos.current_handle, self.ptr)
end

#unary_unionObject

Available in GEOS 3.3+



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_cascadedObject



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

Returns:

  • (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 # centered on the problem
}

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_reasonObject

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

Returns:

  • (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