Class: RubyVolt::Meta::Geography::Polygon
- Inherits:
-
Object
- Object
- RubyVolt::Meta::Geography::Polygon
- Defined in:
- lib/ruby_volt/meta/geography.rb
Instance Attribute Summary collapse
-
#rings ⇒ Object
readonly
Returns the value of attribute rings.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_ring(ring) ⇒ Object
- #fork_transform_rings! ⇒ Object
- #has_holes? ⇒ Boolean
- #holes ⇒ Object
-
#initialize(rings = []) ⇒ Polygon
constructor
In the wire protocol the first ring is still the exterior boundary and subsequent rings are holes.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #to_wkt ⇒ Object
- #transform_rings ⇒ Object
- #transform_rings! ⇒ Object
Constructor Details
#initialize(rings = []) ⇒ Polygon
In the wire protocol the first ring is still the exterior boundary and subsequent rings are holes. However, in the wire protocol all rings, exterior and hole alike, must be counter clockwise, and the last point should not be equal to the first point.
109 110 111 112 |
# File 'lib/ruby_volt/meta/geography.rb', line 109 def initialize(rings = []) @rings = [] rings.each {|ring| add_ring(ring)} end |
Instance Attribute Details
#rings ⇒ Object (readonly)
Returns the value of attribute rings.
105 106 107 |
# File 'lib/ruby_volt/meta/geography.rb', line 105 def rings @rings end |
Instance Method Details
#==(other) ⇒ Object
158 159 160 |
# File 'lib/ruby_volt/meta/geography.rb', line 158 def ==(other) other.is_a?(Polygon) && (rings.size == other.rings.size) && eval(rings.map.with_index {|ring, index| ring == other.rings[index]}.join("&&"))||true end |
#add_ring(ring) ⇒ Object
114 115 116 117 |
# File 'lib/ruby_volt/meta/geography.rb', line 114 def add_ring(ring) raise(::ArgumentError, "LineString has to be represented by a pseudo container RubyVolt::Meta::Geography::Ring") unless ring.is_a?(Ring) @rings << ring end |
#fork_transform_rings! ⇒ Object
127 128 129 |
# File 'lib/ruby_volt/meta/geography.rb', line 127 def fork_transform_rings! Polygon.new(transform_rings) end |
#has_holes? ⇒ Boolean
123 124 125 |
# File 'lib/ruby_volt/meta/geography.rb', line 123 def has_holes? rings.size > 1 end |
#holes ⇒ Object
119 120 121 |
# File 'lib/ruby_volt/meta/geography.rb', line 119 def holes has_holes? ? rings[1..-1] : [] end |
#inspect ⇒ Object
146 147 148 |
# File 'lib/ruby_volt/meta/geography.rb', line 146 def inspect to_wkt end |
#to_s ⇒ Object
150 151 152 |
# File 'lib/ruby_volt/meta/geography.rb', line 150 def to_s rings.join(", ") end |
#to_wkt ⇒ Object
154 155 156 |
# File 'lib/ruby_volt/meta/geography.rb', line 154 def to_wkt "POLYGON(#{to_s})" end |
#transform_rings ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/ruby_volt/meta/geography.rb', line 136 def transform_rings # To transform a ring [from Java] representation to wire protocol representation one must: # • Remove the last vertex, which is the same as the first vertex, # • Transform the coordinates to XYZPoint values, and # • Reverse the order of the rings from the second to the end. rings.map.with_index do |ring, index| index > 0 ? ring.fork_reverse_points : ring end.compact end |
#transform_rings! ⇒ Object
131 132 133 134 |
# File 'lib/ruby_volt/meta/geography.rb', line 131 def transform_rings! @rings = transform_rings self end |