math works with numbers, so we convert to float lat and lon
[osm-ro-tools.git] / sirutacsv.py
blob3460aea8a41001ea804d4e448a5193f353512211
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':'lon', \
13 'Y':'lat', \
14 'NAME':'name', \
15 'SIRUTA':'siruta:code', \
16 'OLD_POSTAL':'old_postal_code', \
17 'RANG':'siruta:rank', \
18 'TIP':'siruta:type', \
19 'SIRUTA_SUP':'siruta:code_sup', \
20 'NAME_SUP':'siruta:name_sup', \
21 'COUNTY':'siruta:county', \
22 'COUNTY_ID':'siruta:county_id', \
23 'COUNTY_MN':'siruta:county_code', \
24 'POP2002':'population2002', \
25 'REGION':'region', \
26 'REGION_ID':'siruta:region_id', \
27 'ENVIRO_TYP':'siruta:enviro_type', \
28 'SORT_CODE':'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)
46 return d