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


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

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

#boundaryObject


180
181
182
183
184
185
186
187
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 180

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)

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

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

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

#coordinatesObject


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

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

#geometry_typeObject


172
173
174
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 172

def geometry_type
  Feature::MultiPolygon
end

#initialize(factory, elements) ⇒ Object


162
163
164
165
166
167
168
169
170
# File 'lib/rgeo/impl_helper/basic_geometry_collection_methods.rb', line 162

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