class RGeo::Kml::CoordinatesBuilder

Attributes

geo_factory[R]
parent[R]
points[R]
text[RW]

Public Class Methods

new( geo_factory, parent) click to toggle source
# File lib/rgeo/kml/coordinates_builder.rb, line 8
def initialize( geo_factory, parent)
  @geo_factory = geo_factory
  @parent = parent
  @points = []
end

Public Instance Methods

build() click to toggle source
# File lib/rgeo/kml/coordinates_builder.rb, line 14
def build
  @text.gsub(/\n/, ' ').strip.split(/\s+/).each do |coord|
    x, y, z = coord.split(',')
    if x.nil? || y.nil?
      fail StandardError, 'Coordinates must have at least x and y elements'
    end
    if z.nil?
      @points << @geo_factory.point(x, y)
    else
      @points << @geo_factory.point(x, y, z)
    end

    @points
  end
  
rescue Exception => e
  puts "Exception #{e.message} \n #{e.backtrace}"
  raise StandardError, 'Error parsing coordinates: check your kml for errors'
end