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


12
13
14
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 12

def elements
  @elements
end

Instance Method Details

#[](n) ⇒ Object


32
33
34
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 32

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

#dimensionObject


40
41
42
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 40

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

#each(&block) ⇒ Object


36
37
38
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 36

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

#geometry_n(n) ⇒ Object


28
29
30
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 28

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

#geometry_typeObject


44
45
46
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 44

def geometry_type
  Feature::GeometryCollection
end

#hashObject


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

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


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

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)

48
49
50
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 48

def is_empty?
  @elements.size == 0
end

#num_geometriesObject


24
25
26
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 24

def num_geometries
  @elements.size
end

#rep_equals?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

52
53
54
55
56
57
58
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 52

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