comparison flys-backend/contrib/shpimporter/dgm.py @ 5085:4f46679e13d0 dami

Put km_from and km_to into name of dgm
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 25 Feb 2013 11:46:36 +0100
parents d6860fca89e4
children f459911fdbfb
comparison
equal deleted inserted replaced
5082:fb4d87274f28 5085:4f46679e13d0
6 def latin(string): 6 def latin(string):
7 return unicode(string, "latin1") 7 return unicode(string, "latin1")
8 8
9 # <dbfield> : (<csvfield>, conversion function) 9 # <dbfield> : (<csvfield>, conversion function)
10 DGM_MAP = { 10 DGM_MAP = {
11 "name" : latin("Gewässer"),
12 "lower" : ("km_von", lambda x: int(x)), 11 "lower" : ("km_von", lambda x: int(x)),
13 "upper" : ("km_bis", lambda x: int(x)), 12 "upper" : ("km_bis", lambda x: int(x)),
14 "year_from" : "Jahr_von", 13 "year_from" : "Jahr_von",
15 "year_to" : "Jahr_bis", 14 "year_to" : "Jahr_bis",
16 "projection" : "Projektion", 15 "projection" : "Projektion",
22 # "description" : 21 # "description" :
23 "srid" : "SRID", 22 "srid" : "SRID",
24 "path" : ("Pfad_Bestand", lambda x: x), 23 "path" : ("Pfad_Bestand", lambda x: x),
25 } 24 }
26 25
27 SQL_INSERT_DGT = "INSERT INTO dem (river_id, " + ", ".join(DGM_MAP.keys()) + \ 26 SQL_INSERT_DGT = "INSERT INTO dem (river_id, name, " + ", ".join(DGM_MAP.keys()) + \
28 ") VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)" 27 ") VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
29 SQL_INSERT_DGT_ORA = "INSERT INTO dem (river_id, " + ", ".join(DGM_MAP.keys()) + \ 28 SQL_INSERT_DGT_ORA = "INSERT INTO dem (river_id, name, " + ", ".join(DGM_MAP.keys()) + \
30 ") VALUES (:s, :s, :s, :s, :s, :s, :s, :s, :s, :s, :s, :s, :s)" 29 ") VALUES (:s, :s, :s, :s, :s, :s, :s, :s, :s, :s, :s, :s, :s)"
31 30
32 def insertRiverDgm(dbconn, dgmfile, river_name, dry_run, oracle): 31 def insertRiverDgm(dbconn, dgmfile, river_name, dry_run, oracle):
33 with codecs.open(dgmfile, "r", "latin1") as csvfile: 32 with codecs.open(dgmfile, "r", "latin1") as csvfile:
34 firstline = csvfile.readline() 33 firstline = csvfile.readline()
51 if isinstance(val, tuple): 50 if isinstance(val, tuple):
52 values.append(val[1](fields[namedict[val[0]]])) 51 values.append(val[1](fields[namedict[val[0]]]))
53 else: 52 else:
54 values.append(unicode.encode( 53 values.append(unicode.encode(
55 fields[namedict[val]], "UTF-8")) 54 fields[namedict[val]], "UTF-8"))
55 name = "%s KM %s - %s" % (river_name, fields[namedict["km_von"]],
56 fields[namedict["km_bis"]])
56 cur = dbconn.cursor() 57 cur = dbconn.cursor()
57 if oracle: 58 if oracle:
58 stmt = SQL_INSERT_DGT_ORA 59 stmt = SQL_INSERT_DGT_ORA
59 else: 60 else:
60 stmt = SQL_INSERT_DGT 61 stmt = SQL_INSERT_DGT
61 62
62 cur.execute(stmt, [river_id] + values) 63 cur.execute(stmt, [river_id, name] + values)
63 64
64 if not dry_run: 65 if not dry_run:
65 dbconn.commit() 66 dbconn.commit()
66 67

http://dive4elements.wald.intevation.org