Module: RGeo::ImplHelper::BasicGeometryCollectionMethods

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#[](n_) ⇒ Object



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

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

#_copy_state_from(obj_) ⇒ Object

:nodoc:



70
71
72
73
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 70

def _copy_state_from(obj_) # :nodoc:
  super
  @elements = obj_._elements
end

#_elementsObject

:nodoc:



75
76
77
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 75

def _elements # :nodoc:
  @elements
end

#dimensionObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 36

def dimension
  unless defined?(@dimension)
    @dimension = -1
    @elements.each do |elem_|
      dim_ = elem_.dimension
      @dimension = dim_ if @dimension < dim_
    end
  end
  @dimension
end

#each(&block_) ⇒ Object



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

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

#geometry_n(n_) ⇒ Object



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

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

#geometry_typeObject



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

def geometry_type
  Feature::GeometryCollection
end

#hashObject



63
64
65
66
67
68
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 63

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



10
11
12
13
14
15
16
17
18
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 10

def initialize(factory_, elements_)
  _set_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)


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

def is_empty?
  @elements.size == 0
end

#num_geometriesObject



20
21
22
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 20

def num_geometries
  @elements.size
end

#rep_equals?(rhs_) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
58
59
60
61
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 55

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