Module: RGeo::ImplHelper::BasicGeometryCollectionMethods
- Included in:
- Cartesian::GeometryCollectionImpl, Cartesian::MultiLineStringImpl, Cartesian::MultiPointImpl, Cartesian::MultiPolygonImpl, Geographic::ProjectedGeometryCollectionImpl, Geographic::ProjectedMultiLineStringImpl, Geographic::ProjectedMultiPointImpl, Geographic::ProjectedMultiPolygonImpl, Geographic::SphericalGeometryCollectionImpl, Geographic::SphericalMultiLineStringImpl, Geographic::SphericalMultiPointImpl, Geographic::SphericalMultiPolygonImpl
- Defined in:
- lib/rgeo/impl_helper/basic_geometry_collection_methods.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
Instance Method Summary collapse
- #[](n) ⇒ Object
- #dimension ⇒ Object
- #each(&block) ⇒ Object
- #geometry_n(n) ⇒ Object
- #geometry_type ⇒ Object
- #hash ⇒ Object
- #initialize(factory, elements) ⇒ Object
- #is_empty? ⇒ Boolean
- #num_geometries ⇒ Object
- #rep_equals?(rhs) ⇒ Boolean
Instance Attribute Details
#elements ⇒ Object (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 |
#dimension ⇒ Object
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_type ⇒ Object
44 45 46 |
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 44 def geometry_type Feature::GeometryCollection end |
#hash ⇒ Object
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
48 49 50 |
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 48 def is_empty? @elements.size == 0 end |
#num_geometries ⇒ Object
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
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 |