Module: RGeo::ImplHelper::BasicPolygonMethods

Included in:
Cartesian::PolygonImpl, Geographic::ProjectedPolygonImpl, Geographic::SphericalPolygonImpl
Defined in:
lib/rgeo/impl_helper/basic_polygon_methods.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#boundaryObject



52
53
54
55
56
57
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 52

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

#contains?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
85
86
87
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 78

def contains?(rhs)
  if Feature::Point === rhs
    contains_point?(rhs)
  else
    raise(
      Error::UnsupportedOperation,
      "Method Polygon#contains? is only defined for Point"
    )
  end
end

#coordinatesObject



74
75
76
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 74

def coordinates
  ([@exterior_ring] + @interior_rings).map(&:coordinates)
end

#dimensionObject



40
41
42
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 40

def dimension
  2
end

#empty?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 48

def empty?
  @exterior_ring.empty?
end

#exterior_ringObject



24
25
26
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 24

def exterior_ring
  @exterior_ring
end

#geometry_typeObject



44
45
46
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 44

def geometry_type
  Feature::Polygon
end

#hashObject



70
71
72
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 70

def hash
  @hash ||= [geometry_type, @exterior_ring, *@interior_rings].hash
end

#initialize(factory, exterior_ring, interior_rings) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 12

def initialize(factory, exterior_ring, interior_rings)
  self.factory = factory
  @exterior_ring = Feature.cast(exterior_ring, factory, Feature::LinearRing)
  raise Error::InvalidGeometry, "Failed to cast exterior ring #{exterior_ring}" unless @exterior_ring
  @interior_rings = (interior_rings || []).map do |elem|
    elem = Feature.cast(elem, factory, Feature::LinearRing)
    raise Error::InvalidGeometry, "Could not cast interior ring #{elem}" unless elem
    elem
  end
  init_geometry
end

#interior_ring_n(idx) ⇒ Object



32
33
34
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 32

def interior_ring_n(idx)
  idx < 0 ? nil : @interior_rings[idx]
end

#interior_ringsObject



36
37
38
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 36

def interior_rings
  @interior_rings.dup
end

#num_interior_ringsObject



28
29
30
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 28

def num_interior_rings
  @interior_rings.size
end

#rep_equals?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
68
# File 'lib/rgeo/impl_helper/basic_polygon_methods.rb', line 59

def rep_equals?(rhs)
  proper_match = rhs.is_a?(self.class) &&
    rhs.factory.eql?(@factory) &&
    @exterior_ring.rep_equals?(rhs.exterior_ring) &&
    @interior_rings.size == rhs.num_interior_rings

  return false unless proper_match

  rhs.interior_rings.each_with_index { |r, i| return false unless @interior_rings[i].rep_equals?(r) }
end