Class: Geospatial::KML::Reader
- Inherits:
-
Object
- Object
- Geospatial::KML::Reader
- Defined in:
- lib/geospatial/kml/reader.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(doc) ⇒ Reader
constructor
A new instance of Reader.
- #placemarks ⇒ Object
- #polygons ⇒ Object
Constructor Details
#initialize(doc) ⇒ Reader
Returns a new instance of Reader.
35 36 37 |
# File 'lib/geospatial/kml/reader.rb', line 35 def initialize(doc) @doc = doc end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
39 40 41 |
# File 'lib/geospatial/kml/reader.rb', line 39 def doc @doc end |
Class Method Details
.load_file(path) ⇒ Object
29 30 31 32 33 |
# File 'lib/geospatial/kml/reader.rb', line 29 def self.load_file(path) doc = File.open(path) {|file| Nokogiri::XML(file)} return self.new(doc) end |
Instance Method Details
#placemarks ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/geospatial/kml/reader.rb', line 41 def placemarks return to_enum(:placemarks) unless block_given? @doc.css("Placemark").collect do |node| yield Placemark.new(node) end end |
#polygons ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/geospatial/kml/reader.rb', line 49 def polygons return to_enum(:polygons) unless block_given? @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 yield Polygon.new(coordinates) end end |