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


170
171
172
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 170

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

#boundaryObject


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

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

#contains?(rhs) ⇒ Boolean

Returns:

  • (Boolean)

187
188
189
190
191
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 187

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

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

#coordinatesObject


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

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

#geometry_typeObject


166
167
168
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 166

def geometry_type
  Feature::MultiPolygon
end

#initialize(factory, elements) ⇒ Object


156
157
158
159
160
161
162
163
164
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 156

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