Debian Codegraph @

scripts/new_style.py

raw symbols SCIP
1 #
2 # File: p.py
3 #
4 # Copyright (C) 2006 Steve Ratcliffe
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2 as
8 # published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 #
16 # Author: Steve Ratcliffe
17 # Create date: 31 Dec 2006
18 #
19
20 #
21 # Create the new style files points, lines and polygons from a map-features file.
22 #
23
24 import sys
25 import csv
26
27 MAP_FEATURES = 'map-features.csv'
28
29 if len(sys.argv) > 1:
30 MAP_FEATURES = sys.argv[1]
31
32 points = []
33 lines = []
34 polygons = []
35
36 features = {
37 'polyline': lines,
38 'polygon': polygons,
39 'point': points,
40 }
41 file_names = {
42 'polyline': 'lines',
43 'polygon': 'polygons',
44 'point': 'points',
45 }
46
47 def main():
48
49 # Read the garmin feature name to internal number file
50 f = open(MAP_FEATURES)
51 r = csv.reader(f, delimiter='|')
52 for line in r:
53 kind = line[0]
54 if kind[0] == '#': continue
55 key = line[1] + '=' + line[2]
56 value = makeval(line[3], line[4])
57 res = int(line[5])
58
59 line = "%s [%s resolution %d]" % (key, value, res)
60 ft = features[kind]
61 ft.append(line)
62
63
64 # Write out the files
65 for name in features.keys():
66 f = open(file_names[name], 'w')
67 ft = features[name]
68 for line in ft:
69 f.write(line)
70 f.write("\n")
71
72 def makeval(a, b):
73 if not b: return a
74 return a + b[2:]
75
76 if __name__ == '__main__':
77 main()