Class: Geospatial::KML::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/geospatial/kml/reader.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ Reader

Returns a new instance of Reader.



33
34
35
# File 'lib/geospatial/kml/reader.rb', line 33

def initialize(doc)
	@doc = doc
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



37
38
39
# File 'lib/geospatial/kml/reader.rb', line 37

def doc
  @doc
end

Class Method Details

.load_file(path) ⇒ Object



27
28
29
30
31
# File 'lib/geospatial/kml/reader.rb', line 27

def self.load_file(path)
	doc = File.open(path) {|file| Nokogiri::XML(file)}
	
	return self.new(doc)
end

Instance Method Details

#polygonsObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/geospatial/kml/reader.rb', line 39

def polygons
	@doc.css("Polygon").collect do |polygon_node|
		coordinates_node = polygon_node.css("coordinates").first
		
		text = coordinates_node.text.strip
		coordinates = text.split(/\s+/).collect do |coordinate| 
			Vector.elements(coordinate.split(',').collect(&:to_f).first(2))
		end
		
		Polygon.new(coordinates)
	end
end