-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkml.rb
50 lines (35 loc) · 958 Bytes
/
kml.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
42
43
44
45
46
47
48
49
require 'rubygems'
require 'nokogiri'
require 'csv'
require 'awesome_print'
require 'json'
@doc = Nokogiri::XML File.open('map.kml')
puts '===================================='
puts '--- START ---'
puts '------------------------------------'
places = []
@doc.css('Placemark').each do |place|
name = place.css('name').text.strip
size = place.css('description').text.strip
coords = place.css('coordinates').text.strip
coords = coords.split ',0 '
status = rand(1..2)
points = []
coords.each do |coord|
coord = coord.split ','
points << {
lng: coord[0].to_f,
lat: coord[1].to_f
}
end
places << { name: name, size: size, price: '1000 uf', status: status, coords: points }
end
places = places.to_json
ap places
File.open('map_output.json', 'w') do |f|
f.write places
puts '>> File created!'
end
puts '------------------------------------'
puts '--- END ---'
puts '===================================='