class RGeo::Kml::KmlStreamListener
Attributes
current_builder[R]
first_builder[R]
geo_factory[R]
result[R]
Public Class Methods
new( geo_factory, interesting_tags = %w{coordinates Point LineString LinearRing Polygon MultiGeometry}.freeze )
click to toggle source
# File lib/rgeo/kml/kml_stream_listener.rb, line 13 def initialize( geo_factory, interesting_tags = %w{coordinates Point LineString LinearRing Polygon MultiGeometry}.freeze ) @geo_factory = geo_factory @tags = interesting_tags end
Public Instance Methods
parse(text)
click to toggle source
# File lib/rgeo/kml/kml_stream_listener.rb, line 74 def parse(text) return nil if text.nil? REXML::Document.parse_stream(text, self) end
tag_end(name)
click to toggle source
# File lib/rgeo/kml/kml_stream_listener.rb, line 41 def tag_end(name) if @first_builder == @current_builder @result = @first_builder.build else @current_builder.build case name when "coordinates" @current_builder.parent.points = @current_builder.points @current_builder = @current_builder.parent when "Point" @current_builder.parent.add_point( @current_builder.point ) @current_builder = @current_builder.parent when "LineString" @current_builder.parent.add_line_string( @current_builder.line_string ) @current_builder = @current_builder.parent when "LinearRing" @current_builder.parent.add_linear_ring( @current_builder.linear_ring ) @current_builder = @current_builder.parent when "Polygon" @current_builder.parent.add_polygon( @current_builder.polygon ) @current_builder = @current_builder.parent else #puts "Unknown or unparsed tag #{name}" end end end
tag_start(name, attrs)
click to toggle source
# File lib/rgeo/kml/kml_stream_listener.rb, line 18 def tag_start(name, attrs) case name when "coordinates" @current_builder = CoordinatesBuilder.new(geo_factory, @current_builder) when "Point" @current_builder = PointBuilder.new(geo_factory, @current_builder) when "LineString" @current_builder = LineStringBuilder.new(geo_factory, @current_builder) when "LinearRing" @current_builder = LinearRingBuilder.new(geo_factory, @current_builder) when "Polygon" @current_builder = PolygonBuilder.new(geo_factory, @current_builder) when "MultiGeometry" @current_builder = MultiGeometryBuilder.new(geo_factory, @current_builder) else #puts "Unknown or unparsed tag #{name}" end if tags.include?(name) @first_builder = @current_builder if @first_builder == nil end end
text(text)
click to toggle source
# File lib/rgeo/kml/kml_stream_listener.rb, line 69 def text(text) @cur_text = text @current_builder.text = text end