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


186
187
188
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 186

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

#boundaryObject


190
191
192
193
194
195
196
197
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 190

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

#contains?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

203
204
205
206
207
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 203

def contains?(rhs)
  return super unless Feature::Point === rhs

  @elements.any? { |poly| poly.contains?(rhs) }
end

#coordinatesObject


199
200
201
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 199

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

#geometry_typeObject


182
183
184
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 182

def geometry_type
  Feature::MultiPolygon
end

#initialize(factory, elements) ⇒ Object


172
173
174
175
176
177
178
179
180
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 172

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