Class: CloudMade::Polygon

Inherits:
Geometry show all
Defined in:
lib/cloudmade/geometry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Geometry

parse

Constructor Details

#initialize(coords) ⇒ Polygon

Returns a new instance of Polygon.



122
123
124
125
# File 'lib/cloudmade/geometry.rb', line 122

def initialize(coords)
  @border_line = Line.new(coords[0])
  @holes = coords.slice(1, coords.length).map { |line_coords| Line.new(line_coords) }
end

Instance Attribute Details

#border_lineObject

Returns the value of attribute border_line.



119
120
121
# File 'lib/cloudmade/geometry.rb', line 119

def border_line
  @border_line
end

#holesObject

Returns the value of attribute holes.



120
121
122
# File 'lib/cloudmade/geometry.rb', line 120

def holes
  @holes
end

Instance Method Details

#to_sObject



127
128
129
# File 'lib/cloudmade/geometry.rb', line 127

def to_s
  "Polygon(#{@border_line} - (#{@holes.join(',')}))"
end

#to_wktObject



131
132
133
# File 'lib/cloudmade/geometry.rb', line 131

def to_wkt
  "POLYGON (#{wkt_helper})"
end

#wkt_helperObject



135
136
137
138
# File 'lib/cloudmade/geometry.rb', line 135

def wkt_helper
  holes = @holes.map(&:wkt_helper).join(', ') if @holes.any?
  [@border_line.wkt_helper, holes].compact.join(', ')
end