Class: KML

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

Instance Method Summary collapse

Constructor Details

#initialize(kml_file) ⇒ KML

Returns a new instance of KML.



4
5
6
7
8
9
10
11
# File 'lib/kmlbo/kml.rb', line 4

def initialize(kml_file)
  @file_data = ""
  @point_list = PointList.new([])
  File.open(kml_file, "r") do |file|
    @file_data = file.read
    parse_coordinates
  end
end

Instance Method Details

#simplify!(epsilon = nil, passes = nil) ⇒ Object



21
22
23
24
25
26
# File 'lib/kmlbo/kml.rb', line 21

def simplify!(epsilon=nil, passes=nil)
  original_number_of_coords = @point_list.size
  @point_list = PointList.new(@point_list.tuple_array, epsilon, passes).simplify
  puts "Simplified path from #{original_number_of_coords} to #{@point_list.size} points"
  self
end

#to_aObject



13
14
15
# File 'lib/kmlbo/kml.rb', line 13

def to_a
  @point_list.tuple_array
end

#to_encodedObject



17
18
19
# File 'lib/kmlbo/kml.rb', line 17

def to_encoded
  @point_list.to_s
end

#to_kmlObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/kmlbo/kml.rb', line 28

def to_kml
  kml = "No Result."
  template = File.expand_path(File.join(File.dirname(__FILE__), "output.kml.erb"))
  File.open(template, "r") do |file|
    mapname = "Kmlbo output"
    template = ERB.new file.read
    kml = template.result(binding)
  end
  kml
end