-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKMLConverter.rb
41 lines (36 loc) · 1.29 KB
/
KMLConverter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'nokogiri'
arduino_array = []
# Opens POIs.kml file in this directory, removes namespaces, extracts placemarks which is the area
# that holds the POI info, iterates through to create proper arduino data structure
# of nested arrays
doc = File.open("POIs.kml") { |f| Nokogiri::XML(f)}
doc.remove_namespaces!
placemarks = doc.xpath("//Folder/Placemark")
placemarks.each do | placemark |
name = placemark.search("name").text
# This sets fixed length to 13 so LCD on arduino fills up the right space
size = name.length
if name.length < 13
diff = 13 - size
name += " " * diff
elsif size > 13
name = name[0..12]
end
lat = placemark.search('coordinates').text.split("\n")[1].split(',')[1]
lon = placemark.search('coordinates').text.split("\n")[1].split(',').first.lstrip!
arr = [name, lat, lon]
arduino_array.push(arr)
end
number_of_points = arduino_array.length
output = File.open("points.txt", "w") do | line |
line.puts "Poi poi_list[" + arduino_array.length.to_s + "] = {"
arduino_array.each do | point |
line.puts "{" + "\"" + point[0] + "\"" + "," + point[1].strip + "," + point[2].strip + "}"
if arduino_array[-1] != point
line.puts ","
end
end
line.puts "};"
number_of_points = arduino_array.length
line.puts "int number_of_points = " + number_of_points.to_s + ";"
end