Module: RGeo::Geos::FFIGeometryMethods

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_klassesObject (readonly)

:nodoc:


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

def _klasses
  @_klasses
end

#factoryObject (readonly)

Returns the value of attribute factory


94
95
96
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 94

def factory
  @factory
end

#fg_geomObject (readonly)

Returns the value of attribute fg_geom


95
96
97
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 95

def fg_geom
  @fg_geom
end

Instance Method Details

#_detach_fg_geomObject

:nodoc:


325
326
327
328
329
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 325

def _detach_fg_geom  # :nodoc:
  fg_ = @fg_geom
  @fg_geom = nil
  fg_
end

#_request_preparedObject

:nodoc:


332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 332

def _request_prepared  # :nodoc:
  case @_fg_prep
  when 0
    nil
  when 1
    @_fg_prep = 2
    nil
  when 2
    @_fg_prep = ::Geos::PreparedGeometry.new(@fg_geom)
  else
    @_fg_prep
  end
end

#as_binaryObject


159
160
161
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 159

def as_binary
  @factory._generate_wkb(self)
end

#as_textObject Also known as: to_s


151
152
153
154
155
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 151

def as_text
  str_ = @factory._generate_wkt(self)
  str_.force_encoding('US-ASCII') if str_.respond_to?(:force_encoding)
  str_
end

#boundaryObject


142
143
144
145
146
147
148
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 142

def boundary
  if self.class == FFIGeometryCollectionImpl
    nil
  else
    @factory._wrap_fg_geom(@fg_geom.boundary, nil)
  end
end

#buffer(distance_) ⇒ Object


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

def buffer(distance_)
  @factory._wrap_fg_geom(@fg_geom.buffer(distance_, @factory.buffer_resolution), nil)
end

#contains?(rhs_) ⇒ Boolean

Returns:

  • (Boolean)

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

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


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

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

#crosses?(rhs_) ⇒ Boolean

Returns:

  • (Boolean)

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

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

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


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

def difference(rhs_)
  fg_ = factory._convert_to_fg_geometry(rhs_)
  fg_ ? @factory._wrap_fg_geom(@fg_geom.difference(fg_), nil) : nil
end

#dimensionObject


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

def dimension
  Utils.ffi_compute_dimension(@fg_geom)
end

#disjoint?(rhs_) ⇒ Boolean

Returns:

  • (Boolean)

190
191
192
193
194
195
196
197
198
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 190

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


274
275
276
277
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 274

def distance(rhs_)
  fg_ = factory._convert_to_fg_geometry(rhs_)
  fg_ ? @fg_geom.distance(fg_) : nil
end

#encode_with(coder_) ⇒ Object

Psych support


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

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


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

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

#eql?(rhs_) ⇒ Boolean

Returns:

  • (Boolean)

320
321
322
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 320

def eql?(rhs_)
  rep_equals?(rhs_)
end

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

Returns:

  • (Boolean)

174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 174

def equals?(rhs_)
  return false unless rhs_.kind_of?(::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


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

def geometry_type
  Feature::Geometry
end

#init_with(coder_) ⇒ Object

:nodoc:


85
86
87
88
89
90
91
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 85

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


47
48
49
50
51
52
53
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 47

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


100
101
102
103
104
105
106
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 100

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


56
57
58
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 56

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

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


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

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)

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

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

#is_empty?Boolean

Returns:

  • (Boolean)

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

def is_empty?
  @fg_geom.empty?
end

#is_simple?Boolean

Returns:

  • (Boolean)

169
170
171
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 169

def is_simple?
  @fg_geom.simple?
end

#marshal_dumpObject

Marshal support


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

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

#marshal_load(data_) ⇒ Object

:nodoc:


67
68
69
70
71
72
73
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 67

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

#overlaps?(rhs_) ⇒ Boolean

Returns:

  • (Boolean)

256
257
258
259
260
261
262
263
264
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 256

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

#prepare!Object


129
130
131
132
133
134
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 129

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

#prepared?Boolean

Returns:

  • (Boolean)

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

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

#relate?(rhs_, pattern_) ⇒ Boolean Also known as: relate

Returns:

  • (Boolean)

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

def relate?(rhs_, pattern_)
  fg_ = factory._convert_to_fg_geometry(rhs_)
  fg_ ? @fg_geom.relate_pattern(fg_, pattern_) : nil
end

#sridObject


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

def srid
  @fg_geom.srid
end

#sym_difference(rhs_) ⇒ Object


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

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)

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

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

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


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

def union(rhs_)
  fg_ = factory._convert_to_fg_geometry(rhs_)
  fg_ ? @factory._wrap_fg_geom(@fg_geom.union(fg_), nil) : nil
end

#within?(rhs_) ⇒ Boolean

Returns:

  • (Boolean)

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

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