Module: RGeo::Geos::FFIGeometryMethods

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_klassesObject (readonly)

Returns the value of attribute _klasses.



16
17
18
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 16

def _klasses
  @_klasses
end

#factoryObject (readonly)

Returns the value of attribute factory.



16
17
18
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 16

def factory
  @factory
end

#fg_geomObject (readonly)

Returns the value of attribute fg_geom.



16
17
18
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 16

def fg_geom
  @fg_geom
end

Instance Method Details

#as_binaryObject



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

def as_binary
  @factory.generate_wkb(self)
end

#as_textObject Also known as: to_s



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

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

#boundaryObject



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

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



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

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

#contains?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#convex_hullObject



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

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

#coordinate_dimensionObject



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

def coordinate_dimension
  factory.coordinate_dimension
end

#crosses?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#detach_fg_geomObject



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

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

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



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

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

#dimensionObject



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

def dimension
  Utils.ffi_compute_dimension(@fg_geom)
end

#disjoint?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#distance(rhs) ⇒ Object



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  @fg_geom.empty?
end

#encode_with(coder) ⇒ Object

Psych support



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

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



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

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

def eql?(other)
  rep_equals?(other)
end

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

Returns:

  • (Boolean)


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

def equals?(rhs)
  return false unless rhs.is_a?(RGeo::Feature::Instance)
  fg = factory.convert_to_fg_geometry(rhs)

  # GEOS has a bug where empty geometries are not spatially equal
  # to each other. Work around this case first.
  if fg.empty? && @fg_geom.empty?
    true
  else
    @fg_geom.eql?(fg)
  end
end

#geometry_typeObject



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

def geometry_type
  Feature::Geometry
end

#init_with(coder) ⇒ Object

:nodoc:



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

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



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

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



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

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



26
27
28
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 26

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

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



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

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

#intersects?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


175
176
177
178
179
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 175

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

#invalid_reasonObject



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

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)


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

def is_3d?
  factory.property(:has_z_coordinate)
end

#make_validObject



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

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

#marshal_dumpObject

Marshal support



32
33
34
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 32

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

#marshal_load(data) ⇒ Object

:nodoc:



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

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)


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

def measured?
  factory.property(:has_m_coordinate)
end

#overlaps?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#point_on_surfaceObject



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

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

#prepare!Object



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

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

#prepared?Boolean

Returns:

  • (Boolean)


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

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

#relate?(rhs, pattern) ⇒ Boolean

Returns:

  • (Boolean)


211
212
213
214
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 211

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

#simple?Boolean

Returns:

  • (Boolean)


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

def simple?
  @fg_geom.simple?
end

#spatial_dimensionObject



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

def spatial_dimension
  factory.spatial_dimension
end

#sridObject



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

def srid
  @fg_geom.srid
end

#sym_difference(rhs) ⇒ Object



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

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

#touches?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#unary_unionObject



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

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



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

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

#valid?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/rgeo/geos/ffi_feature_methods.rb', line 135

def valid?
  @fg_geom.valid?
end

#within?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


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

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