Module: RGeo::ImplHelper::BasicGeometryCollectionMethods

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements


14
15
16
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 14

def elements
  @elements
end

Instance Method Details

#[](n) ⇒ Object


34
35
36
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 34

def [](n)
  @elements[n]
end

#dimensionObject


46
47
48
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 46

def dimension
  @dimension ||= @elements.map(&:dimension).max || -1
end

#each(&block) ⇒ Object


38
39
40
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 38

def each(&block)
  @elements.each(&block)
end

#geometriesObject


42
43
44
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 42

def geometries
  @elements
end

#geometry_n(n) ⇒ Object


30
31
32
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 30

def geometry_n(n)
  n < 0 ? nil : @elements[n]
end

#geometry_typeObject


50
51
52
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 50

def geometry_type
  Feature::GeometryCollection
end

#hashObject


66
67
68
69
70
71
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 66

def hash
  @hash ||= begin
    hash = [factory, geometry_type].hash
    @elements.inject(hash) { |h, g| (1_664_525 * h + g.hash).hash }
  end
end

#initialize(factory, elements) ⇒ Object


16
17
18
19
20
21
22
23
24
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 16

def initialize(factory, elements)
  self.factory = factory
  @elements = elements.map do |elem|
    elem = Feature.cast(elem, factory)
    raise Error::InvalidGeometry, "Could not cast #{elem}" unless elem
    elem
  end
  validate_geometry
end

#is_empty?Boolean

Returns:

  • (Boolean)

54
55
56
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 54

def is_empty?
  @elements.size == 0
end

#num_geometriesObject


26
27
28
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 26

def num_geometries
  @elements.size
end

#rep_equals?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

58
59
60
61
62
63
64
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 58

def rep_equals?(rhs)
  if rhs.is_a?(self.class) && rhs.factory.eql?(@factory) && @elements.size == rhs.num_geometries
    rhs.each_with_index { |p, i| return false unless @elements[i].rep_equals?(p) }
  else
    false
  end
end