Module: RGeo::ImplHelper::BasicMultiPolygonMethods

Included in:
Cartesian::MultiPolygonImpl, Geographic::ProjectedMultiPolygonImpl, Geographic::SphericalMultiPolygonImpl
Defined in:
lib/rgeo/impl_helper/basic_geometry_collection_methods.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#areaObject


164
165
166
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 164

def area
  @elements.inject(0.0) { |sum, obj| sum + obj.area }
end

#boundaryObject


168
169
170
171
172
173
174
175
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 168

def boundary
  array = []
  @elements.each do |poly|
    array << poly.exterior_ring unless poly.is_empty?
    array.concat(poly.interior_rings)
  end
  factory.multi_line_string(array)
end

#coordinatesObject


177
178
179
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 177

def coordinates
  @elements.map(&:coordinates)
end

#geometry_typeObject


160
161
162
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 160

def geometry_type
  Feature::MultiPolygon
end

#initialize(factory, elements) ⇒ Object


150
151
152
153
154
155
156
157
158
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 150

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