Module: RGeo::ImplHelper::BasicGeometryCollectionMethods

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#[](n_) ⇒ Object


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

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

#_copy_state_from(obj_) ⇒ Object

:nodoc:


117
118
119
120
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 117

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

#_elementsObject

:nodoc:


123
124
125
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 123

def _elements  # :nodoc:
  @elements
end

#dimensionObject


78
79
80
81
82
83
84
85
86
87
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 78

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


73
74
75
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 73

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

#geometry_n(n_) ⇒ Object


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

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

#geometry_typeObject


90
91
92
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 90

def geometry_type
  Feature::GeometryCollection
end

#hashObject


109
110
111
112
113
114
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 109

def hash
  @hash ||= begin
    hash_ = [factory, geometry_type].hash
    @elements.inject(hash_){ |h_, g_| (1664525 * h_ + g_.hash).hash }
  end
end

#initialize(factory_, elements_) ⇒ Object


45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 45

def initialize(factory_, elements_)
  _set_factory(factory_)
  @elements = elements_.map do |elem_|
    elem_ = Feature.cast(elem_, factory_)
    unless elem_
      raise Error::InvalidGeometry, "Could not cast #{elem_}"
    end
    elem_
  end
  _validate_geometry
end

#is_empty?Boolean

Returns:

  • (Boolean)

95
96
97
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 95

def is_empty?
  @elements.size == 0
end

#num_geometriesObject


58
59
60
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 58

def num_geometries
  @elements.size
end

#rep_equals?(rhs_) ⇒ Boolean

Returns:

  • (Boolean)

100
101
102
103
104
105
106
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 100

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