test the not implemented yet _applyChanges2Map
[osm-ro-tools.git] / sirutacsv.py
blobb388e9bc8d010ba1dca9ee033f3ed50ef7d2083c
1 #!/uss/bin/python
3 import csv
5 class SirutaDictReader(csv.DictReader):
6 """
7 A CSV dict reader which maps the CSV field names to proper OSM tag names
8 """
10 def _mapCSVNamesToOSMNames(self, csvnames):
12 namemap = { 'X':u'lon', \
13 'Y':u'lat', \
14 'NAME':u'name', \
15 'SIRUTA':u'siruta:code', \
16 'OLD_POSTAL':u'old_postal_code', \
17 'RANG':u'siruta:rank', \
18 'TIP':u'siruta:type', \
19 'SIRUTA_SUP':u'siruta:code_sup', \
20 'NAME_SUP':u'siruta:name_sup', \
21 'COUNTY':u'siruta:county', \
22 'COUNTY_ID':u'siruta:county_id', \
23 'COUNTY_MN':u'siruta:county_code', \
24 'POP2002':u'population2002', \
25 'REGION':u'region', \
26 'REGION_ID':u'siruta:region_id', \
27 'ENVIRO_TYP':u'siruta:enviro_type', \
28 'SORT_CODE':u'siruta:sortcode' }
30 osmnames = []
31 for name in csvnames:
32 # although this will fail if unknown rows appear, that
33 # is the intended behaviour since we don't want to silently
34 # add or ignore fields unintentionaly
35 osmnames.append(namemap[name])
37 return osmnames
39 def next(self):
40 if self.fieldnames is None:
41 row = self.reader.next()
42 row = self._mapCSVNamesToOSMNames(row)
43 self.fieldnames = row
45 d = csv.DictReader.next(self)
47 for cell in d:
48 try:
49 d[cell] = unicode(d[cell], 'utf-8')
50 except TypeError:
51 pass
52 return d