Debian Codegraph @

scripts/mk_map_table.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 # The OSMGarminMap project contains two files that map
22 # OSM map-features to the codes used in Garmin maps. This
23 # script does a join between them to produce one file.
24 #
25
26 import sys
27 import libxml2
28 import csv
29
30 # The list of garmin features.
31 FEATURE_LIST_FILE = 'garmin_feature_list.csv'
32
33 # The mapping between OSM and garmin features
34 FEATURE_MAP_FILE = 'osm_garmin_map.csv'
35
36 if len(sys.argv) > 2:
37 FEATURE_LIST_FILE = sys.argv[1]
38 FEATURE_MAP_FILE = sys.argv[2]
39
40 features = {}
41
42 def main():
43
44 # Read the garmin feature name to internal number file
45 f = open(FEATURE_LIST_FILE)
46 r = csv.reader(f, delimiter='|')
47 for line in r:
48 kind = line[0]
49 if kind[0] == '#': continue
50 key = (line[4], line[5])
51 val = (line[2], line[3])
52 try:
53 ft = features[kind]
54 except KeyError:
55 ft = {}
56 features[kind] = ft
57 ft[key] = val
58
59 # Get the osm to garmin map rules
60 f = open(FEATURE_MAP_FILE)
61 r = csv.reader(f, delimiter='|')
62 w = csv.writer(sys.stdout, delimiter='|', lineterminator='\n')
63
64 for line in r:
65 kind = line[0]
66 if kind[0] == '#': continue
67 key = (line[3], line[4])
68 res = line[5]
69 try:
70 val = features[kind][key]
71 l = []
72 l.append(kind)
73 l.append(line[1])
74 l.append(line[2])
75 l.append(val[0])
76 if val[1]:
77 l.append(val[1])
78 else:
79 l.append('')
80 l.append(res)
81 w.writerow(l)
82 except KeyError:
83 print >>sys.stderr, "No garmin entry at", kind, key
84
85
86 if __name__ == '__main__':
87 main()