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 Container

#features, #plain_children

Attributes inherited from Feature

#address, #address_details, #description, #look_at, #metadata, #name, #phone_number, #region, #snippet, #style_selector, #style_url, #time_primitive

Attributes inherited from Object

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Geometry

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

Methods inherited from Feature

#open, #open=, #open?, #visibility, #visibility=, #visibility?

Methods inherited from Object

#initialize

Constructor Details

This class inherits a constructor from KML::Object

Class Method Details

.parse(node) ⇒ Object



49
50
51
# File 'lib/kml/linear_ring.rb', line 49

def self.parse(node)
  self.new.parse(node)
end

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.strip.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

#parse(node) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/kml/linear_ring.rb', line 53

def parse(node)
  super(node) do |cld|
    case cld.name
    when 'coordinates'
      self.coordinates = cld.content
    else
      puts "LinearRing"
      p cld
      puts
    end
  end
  self
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