Module: RGeo::Geos::FFIGeometryMethods

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_klassesObject (readonly)

:nodoc:


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

def _klasses
  @_klasses
end

#factoryObject (readonly)

Returns the value of attribute factory


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

def factory
  @factory
end

#fg_geomObject (readonly)

Returns the value of attribute fg_geom


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

def fg_geom
  @fg_geom
end

Instance Method Details

#as_binaryObject


112
113
114
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 112

def as_binary
  @factory.generate_wkb(self)
end

#as_textObject Also known as: to_s


105
106
107
108
109
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 105

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

#boundaryObject


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

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

#buffer(distance) ⇒ Object


220
221
222
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 220

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

#contains?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

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

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


224
225
226
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 224

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

#crosses?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

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

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


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

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

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


247
248
249
250
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 247

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

#dimensionObject


74
75
76
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 74

def dimension
  Utils.ffi_compute_dimension(@fg_geom)
end

#disjoint?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

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

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


215
216
217
218
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 215

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

#encode_with(coder) ⇒ Object

Psych support


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

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


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

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

#eql?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

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

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

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

Returns:

  • (Boolean)

124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 124

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


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

def geometry_type
  Feature::Geometry
end

#init_with(coder) ⇒ Object

:nodoc:


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

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


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

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


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

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


22
23
24
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 22

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

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


228
229
230
231
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 228

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)

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

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)

116
117
118
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 116

def is_empty?
  @fg_geom.empty?
end

#is_simple?Boolean

Returns:

  • (Boolean)

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

def is_simple?
  @fg_geom.simple?
end

#marshal_dumpObject

Marshal support


28
29
30
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 28

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

#marshal_load(data) ⇒ Object

:nodoc:


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

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)

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

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


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

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

#prepare!Object


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

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

#prepared?Boolean

Returns:

  • (Boolean)

82
83
84
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 82

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

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

Returns:

  • (Boolean)

209
210
211
212
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 209

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

#sridObject


70
71
72
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 70

def srid
  @fg_geom.srid
end

#sym_difference(rhs) ⇒ Object


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

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)

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

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


242
243
244
245
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 242

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: +


235
236
237
238
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 235

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)

179
180
181
182
183
184
185
186
187
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 179

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