Class: KML::LinearRing

Inherits:
Geometry show all
Defined in:
lib/kml/linear_ring.rb

Overview

Defines a closed line string, typically the outer boundary of a Polygon. Optionally, a LinearRing can also be used as the inner boundary of a Polygon to create holes in the Polygon. A Polygon can contain multiple LinearRing instances used as inner boundaries.

Instance Attribute Summary

Attributes inherited from Object

#id

Instance Method Summary collapse

Methods inherited from Geometry

#altitude_mode, #altitude_mode=, #altitude_mode_set?, #extrude, #extrude=, #extrude?, #tessellate, #tessellate=, #tessellate?

Methods inherited from Object

#initialize

Constructor Details

This class inherits a constructor from KML::Object

Instance Method Details

#coordinatesObject

Four or more tuples, each consisting of floating point values for longitude, latitude, and altitude. The altitude component is optional. Do not include spaces within a tuple. The last coordinate must be the same as the first coordinate. Coordinates are expressed in decimal degrees only.



20
21
22
# File 'lib/kml/linear_ring.rb', line 20

def coordinates
  @coordinates
end

#coordinates=(c) ⇒ Object

Set the coordinates



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/kml/linear_ring.rb', line 25

def coordinates=(c)
  case c
  when String
    @coordinates = c.split(/\s+/).collect { |coord| coord.split(',') }
  when Array
    c.each do |coord_array|
      unless coord_array.is_a?(Array)
        raise ArgumentError, "If set with an array, coordinates must be specified as an array of arrays"
      end
    end
    @coordinates = c
  else
    raise ArgumentError, "Coordinates must either be a String or an Array of Arrays"
  end
end

#render(xm = Builder::XmlMarkup.new(:indent => 2)) ⇒ Object

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
# File 'lib/kml/linear_ring.rb', line 41

def render(xm=Builder::XmlMarkup.new(:indent => 2))
  raise ArgumentError, "Coordinates required" if coordinates.nil?
  xm.LinearRing {
    super
    xm.coordinates(coordinates.collect { |c| c.join(',') }.join(" "))
  }
end