Module: RGeo::Geos::FFIGeometryMethods

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_klassesObject (readonly)

:nodoc:


62
63
64
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 62

def _klasses
  @_klasses
end

#factoryObject (readonly)

Returns the value of attribute factory.


59
60
61
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 59

def factory
  @factory
end

#fg_geomObject (readonly)

Returns the value of attribute fg_geom.


60
61
62
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 60

def fg_geom
  @fg_geom
end

Instance Method Details

#as_binaryObject


120
121
122
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 120

def as_binary
  @factory.generate_wkb(self)
end

#as_textObject Also known as: to_s


113
114
115
116
117
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 113

def as_text
  str = @factory.generate_wkt(self)
  str.force_encoding("US-ASCII") if str.respond_to?(:force_encoding)
  str
end

#boundaryObject


107
108
109
110
111
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 107

def boundary
  @factory.wrap_fg_geom(@fg_geom.boundary, nil)
rescue ::Geos::GEOSException
  raise Error::InvalidGeometry, "Operation not supported by GeometryCollection"
end

#buffer(distance) ⇒ Object


264
265
266
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 264

def buffer(distance)
  @factory.wrap_fg_geom(@fg_geom.buffer(distance, @factory.buffer_resolution), nil)
end

#contains?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

233
234
235
236
237
238
239
240
241
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 233

def contains?(rhs)
  fg = factory.convert_to_fg_geometry(rhs)
  if fg
    prep = request_prepared if Utils.ffi_supports_prepared_level_1
    prep ? prep.contains?(fg) : @fg_geom.contains?(fg)
  else
    false
  end
end

#convex_hullObject


268
269
270
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 268

def convex_hull
  @factory.wrap_fg_geom(@fg_geom.convex_hull, nil)
end

#coordinate_dimensionObject


80
81
82
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 80

def coordinate_dimension
  factory.coordinate_dimension
end

#crosses?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

213
214
215
216
217
218
219
220
221
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 213

def crosses?(rhs)
  fg = factory.convert_to_fg_geometry(rhs)
  if fg
    prep = request_prepared if Utils.ffi_supports_prepared_level_2
    prep ? prep.crosses?(fg) : @fg_geom.crosses?(fg)
  else
    false
  end
end

#detach_fg_geomObject


307
308
309
310
311
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 307

def detach_fg_geom
  fg = @fg_geom
  @fg_geom = nil
  fg
end

#difference(rhs) ⇒ Object Also known as: -


291
292
293
294
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 291

def difference(rhs)
  fg = factory.convert_to_fg_geometry(rhs)
  fg ? @factory.wrap_fg_geom(@fg_geom.difference(fg), nil) : nil
end

#dimensionObject


76
77
78
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 76

def dimension
  Utils.ffi_compute_dimension(@fg_geom)
end

#disjoint?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

183
184
185
186
187
188
189
190
191
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 183

def disjoint?(rhs)
  fg = factory.convert_to_fg_geometry(rhs)
  if fg
    prep = request_prepared if Utils.ffi_supports_prepared_level_2
    prep ? prep.disjoint?(fg) : @fg_geom.disjoint?(fg)
  else
    false
  end
end

#distance(rhs) ⇒ Object


259
260
261
262
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 259

def distance(rhs)
  fg = factory.convert_to_fg_geometry(rhs)
  fg ? @fg_geom.distance(fg) : nil
end

#empty?Boolean

Returns:

  • (Boolean)

124
125
126
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 124

def empty?
  @fg_geom.empty?
end

#encode_with(coder) ⇒ Object

Psych support


44
45
46
47
48
49
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 44

def encode_with(coder) # :nodoc:
  coder["factory"] = @factory
  str = @factory.write_for_psych(self)
  str = str.encode("US-ASCII") if str.respond_to?(:encode)
  coder["wkt"] = str
end

#envelopeObject


103
104
105
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 103

def envelope
  @factory.wrap_fg_geom(@fg_geom.envelope, nil)
end

#eql?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

303
304
305
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 303

def eql?(rhs)
  rep_equals?(rhs)
end

#equals?(rhs) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)

168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 168

def equals?(rhs)
  return false unless rhs.is_a?(RGeo::Feature::Instance)
  fg = factory.convert_to_fg_geometry(rhs)
  if !fg
    false
  # GEOS has a bug where empty geometries are not spatially equal
  # to each other. Work around this case first.
  elsif fg.empty? && @fg_geom.empty?
    true
  else
    @fg_geom.eql?(fg)
  end
end

#geometry_typeObject


88
89
90
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 88

def geometry_type
  Feature::Geometry
end

#init_with(coder) ⇒ Object

:nodoc:


51
52
53
54
55
56
57
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 51

def init_with(coder) # :nodoc:
  @factory = coder["factory"]
  @fg_geom = @factory.read_for_psych(coder["wkt"])
  @fg_geom.srid = @factory.srid
  @_fg_prep = @factory._auto_prepare ? 1 : 0
  @_klasses = nil
end

#initialize(factory, fg_geom, klasses) ⇒ Object


16
17
18
19
20
21
22
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 16

def initialize(factory, fg_geom, klasses)
  @factory = factory
  @fg_geom = fg_geom
  @_fg_prep = factory._auto_prepare ? 1 : 0
  @_klasses = klasses
  fg_geom.srid = factory.srid
end

#initialize_copy(orig) ⇒ Object


64
65
66
67
68
69
70
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 64

def initialize_copy(orig)
  @factory = orig.factory
  @fg_geom = orig.fg_geom.clone
  @fg_geom.srid = orig.fg_geom.srid
  @_fg_prep = @factory._auto_prepare ? 1 : 0
  @_klasses = orig._klasses
end

#inspectObject


24
25
26
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 24

def inspect
  "#<#{self.class}:0x#{object_id.to_s(16)} #{as_text.inspect}>"
end

#intersection(rhs) ⇒ Object Also known as: *


272
273
274
275
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 272

def intersection(rhs)
  fg = factory.convert_to_fg_geometry(rhs)
  fg ? @factory.wrap_fg_geom(@fg_geom.intersection(fg), nil) : nil
end

#intersects?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

193
194
195
196
197
198
199
200
201
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 193

def intersects?(rhs)
  fg = factory.convert_to_fg_geometry(rhs)
  if fg
    prep = request_prepared if Utils.ffi_supports_prepared_level_1
    prep ? prep.intersects?(fg) : @fg_geom.intersects?(fg)
  else
    false
  end
end

#invalid_reasonObject


154
155
156
157
158
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 154

def invalid_reason
  # valid_detail gives solely the reason, or nil if valid, which is
  # what we want.
  fg_geom.valid_detail&.dig(:detail)&.force_encoding(Encoding::UTF_8)
end

#is_3d?Boolean

Returns:

  • (Boolean)

142
143
144
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 142

def is_3d?
  factory.property(:has_z_coordinate)
end

#is_empty?Boolean

Returns:

  • (Boolean)

128
129
130
131
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 128

def is_empty?
  warn "The is_empty? method is deprecated, please use the empty? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
  empty?
end

#is_simple?Boolean

Returns:

  • (Boolean)

137
138
139
140
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 137

def is_simple?
  warn "The is_simple? method is deprecated, please use the simple? counterpart, will be removed in v3" unless ENV["RGEO_SILENCE_DEPRECATION"]
  simple?
end

#make_validObject

Try and make the geometry valid, this may change its shape. Returns a valid copy of the geometry. Only available since GEOS 3.8+


162
163
164
165
166
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 162

def make_valid
  @factory.wrap_fg_geom(@fg_geom.make_valid, nil)
rescue ::Geos::GEOSException
  raise Error::UnsupportedOperation
end

#marshal_dumpObject

Marshal support


30
31
32
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 30

def marshal_dump # :nodoc:
  [@factory, @factory.write_for_marshal(self)]
end

#marshal_load(data) ⇒ Object

:nodoc:


34
35
36
37
38
39
40
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 34

def marshal_load(data) # :nodoc:
  @factory = data[0]
  @fg_geom = @factory.read_for_marshal(data[1])
  @fg_geom.srid = @factory.srid
  @_fg_prep = @factory._auto_prepare ? 1 : 0
  @_klasses = nil
end

#measured?Boolean

Returns:

  • (Boolean)

146
147
148
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 146

def measured?
  factory.property(:has_m_coordinate)
end

#overlaps?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

243
244
245
246
247
248
249
250
251
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 243

def overlaps?(rhs)
  fg = factory.convert_to_fg_geometry(rhs)
  if fg
    prep = request_prepared if Utils.ffi_supports_prepared_level_2
    prep ? prep.overlaps?(fg) : @fg_geom.overlaps?(fg)
  else
    false
  end
end

#point_on_surfaceObject


313
314
315
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 313

def point_on_surface
  @factory.wrap_fg_geom(@fg_geom.point_on_surface, FFIPointImpl)
end

#prepare!Object


96
97
98
99
100
101
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 96

def prepare!
  if @_fg_prep.is_a?(Integer)
    @_fg_prep = ::Geos::PreparedGeometry.new(@fg_geom)
  end
  self
end

#prepared?Boolean

Returns:

  • (Boolean)

92
93
94
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 92

def prepared?
  !@_fg_prep.is_a?(Integer)
end

#relate?(rhs, pattern) ⇒ Boolean Also known as: relate

Returns:

  • (Boolean)

253
254
255
256
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 253

def relate?(rhs, pattern)
  fg = factory.convert_to_fg_geometry(rhs)
  fg ? @fg_geom.relate_pattern(fg, pattern) : nil
end

#simple?Boolean

Returns:

  • (Boolean)

133
134
135
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 133

def simple?
  @fg_geom.simple?
end

#spatial_dimensionObject


84
85
86
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 84

def spatial_dimension
  factory.spatial_dimension
end

#sridObject


72
73
74
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 72

def srid
  @fg_geom.srid
end

#sym_difference(rhs) ⇒ Object


298
299
300
301
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 298

def sym_difference(rhs)
  fg = factory.convert_to_fg_geometry(rhs)
  fg ? @factory.wrap_fg_geom(@fg_geom.sym_difference(fg), nil) : nil
end

#touches?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

203
204
205
206
207
208
209
210
211
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 203

def touches?(rhs)
  fg = factory.convert_to_fg_geometry(rhs)
  if fg
    prep = request_prepared if Utils.ffi_supports_prepared_level_2
    prep ? prep.touches?(fg) : @fg_geom.touches?(fg)
  else
    false
  end
end

#unary_unionObject


286
287
288
289
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 286

def unary_union
  return unless @fg_geom.respond_to?(:unary_union)
  @factory.wrap_fg_geom(@fg_geom.unary_union)
end

#union(rhs) ⇒ Object Also known as: +


279
280
281
282
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 279

def union(rhs)
  fg = factory.convert_to_fg_geometry(rhs)
  fg ? @factory.wrap_fg_geom(@fg_geom.union(fg), nil) : nil
end

#valid?Boolean

Returns:

  • (Boolean)

150
151
152
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 150

def valid?
  @fg_geom.valid?
end

#within?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

223
224
225
226
227
228
229
230
231
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 223

def within?(rhs)
  fg = factory.convert_to_fg_geometry(rhs)
  if fg
    prep = request_prepared if Utils.ffi_supports_prepared_level_2
    prep ? prep.within?(fg) : @fg_geom.within?(fg)
  else
    false
  end
end