-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparseGeoData.rb
More file actions
53 lines (46 loc) · 950 Bytes
/
parseGeoData.rb
File metadata and controls
53 lines (46 loc) · 950 Bytes
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
50
51
52
53
# -*- coding: UTF-8 -*-
require 'hpricot'
data = File.open(ARGV[0]) do
|f| Hpricot.XML(f)
end
res = []
(data/"Document/Folder/Placemark").each do |elm|
town = {}
town["name"] = "#{(elm/"name").text} " # add a tail space to force to_yaml escape utf-8 string.
town["city"] = ""
town["region"] = ""
town["type"] = "town"
town["latitude"] = (elm/"LookAt/Latitude").text.to_f
town["longitude"] = (elm/"LookAt/Longitude").text.to_f
res.push town
end
File.open("geoData.yml", "w") do |f|
yaml = res.to_yaml
utf8 = ""
conv_states = [:z, :e, :x, :f]
cs = :z
byte = ""
yaml.each_byte do |c|
case cs
when :z
if c != ?\\
utf8 << c; next
end
cs = :e
when :e
if c != ?x
cs = :z; next
end
cs = :x
when :x
byte << c
cs = :f
when :f
byte << c
utf8 << byte.to_i(16)
cs = :z
byte = ""
end
end
f.puts utf8
end