comparison flys-backend/contrib/shpimporter/hws.py @ 4935:c0a58558b817 dami

Importer: - Handle regular expressions for attribute names - Convert Strings to UTF-8 - Add regular expressions for hws_points values
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 31 Jan 2013 12:23:41 +0100
parents 11b459a3eb5c
children 7323847fa7df
comparison
equal deleted inserted replaced
4934:11b459a3eb5c 4935:c0a58558b817
89 89
90 return newFeat 90 return newFeat
91 91
92 class HWSPoints(Importer): 92 class HWSPoints(Importer):
93 fieldmap = { 93 fieldmap = {
94 "Name" : "name", 94 "name$" : "name",
95 "Quelle" : "source", 95 "quelle$" : "source",
96 "Anmerkung" : "description", 96 "anmerkung$" : "description",
97 "Stand" : "status_date", 97 "stand$" : "status_date",
98 "Verband" : "agency", 98 "verband$" : "agency",
99 "Deich_KM" : "dike_km", 99 "Deich_{0,1}KM$" : "dike_km",
100 "Bereich" : "range", 100 "Bereich$" : "range",
101 "Höhe_SOLL" : "z_target", 101 "H[oeö]{0,2}he_{0,1}SOLL$" : "z_target",
102 "WSP_BfG100" : "rated_level", 102 "(WSP_){0,1}BfG_{0,1}100$" : "rated_level",
103 "Hoehe_IST" : "z", 103 "H[oeö]{0,2}he_{0,1}IST$" : "z",
104 } 104 }
105 105
106 def getPath(self, base): 106 def getPath(self, base):
107 return "%s/%s" % (base, PATH) 107 return "%s/%s" % (base, PATH)
108 108
130 130
131 self.copyFields(feat, newFeat, self.fieldmap) 131 self.copyFields(feat, newFeat, self.fieldmap)
132 132
133 newFeat.SetGeometry(geometry) 133 newFeat.SetGeometry(geometry)
134 134
135 newFeat.SetFID(feat.GetFID())
136
137 newFeat.SetField("ogr_fid", feat.GetFID()) 135 newFeat.SetField("ogr_fid", feat.GetFID())
138 136 artname = self.searchField("art$")
139 if self.IsFieldSet(feat, "Art"): 137 if self.IsFieldSet(feat, artname):
140 self.handled("Art") 138 self.handled(artname)
141 kind_id = HWS_KIND.get(feat.GetField("Art")) 139 kind_id = HWS_KIND.get(feat.GetField(artname))
142 if not kind_id: 140 if not kind_id:
143 print ("Unbekannte Art: %s" % \ 141 print ("Unknown Art: %s" % \
144 feat.GetField("Art")) 142 feat.GetField(artname))
145 else: 143 else:
146 newFeat.SetField("kind_id", kind_id) 144 newFeat.SetField("kind_id", kind_id)
147 145
148 if self.IsFieldSet(feat, "Bundesland"): 146 fname = self.searchField("Bundesland$")
149 self.handled("Bundesland") 147 if self.IsFieldSet(feat, fname):
150 fed_id = FED_STATES.get(feat.GetField("Bundesland")) 148 self.handled(fname)
149 fed_id = FED_STATES.get(feat.GetField(fname))
151 150
152 if not fed_id: 151 if not fed_id:
153 print ("Unbekanntes Bundesland: %s" % \ 152 print ("Unknown Bundesland: %s" % \
154 feat.GetField("Bundesland")) 153 feat.GetField("Bundesland"))
155 else: 154 else:
156 newFeat.SetField("fed_state_id", fed_id) 155 newFeat.SetField("fed_state_id", fed_id)
157 156
158 if self.IsFieldSet(feat, "river_id"): 157 fname = self.searchField("(ufer$)|(flussseite$)")
159 self.handled("river_id") 158 if self.IsFieldSet(feat, fname):
160 if feat.GetField("river_id") != self.river_id: 159 self.handled(fname)
161 print ("River_id mismatch between shapefile and" 160 shoreString = feat.GetField(fname)
162 " importer parameter.")
163 newFeat.SetField("river_id", feat.GetField("river_id"))
164 else:
165 newFeat.SetField("river_id", self.river_id)
166
167 if self.IsFieldSet(feat, "Ufer"):
168 self.handled("Ufer")
169 shoreString = feat.GetField("Ufer")
170 if "links" in shoreString.lower(): 161 if "links" in shoreString.lower():
171 newFeat.SetField("shore_side", True) 162 newFeat.SetField("shore_side", True)
172 elif "rechts" in shoreString.lower(): 163 elif "rechts" in shoreString.lower():
173 newFeat.SetField("shore_side", False) 164 newFeat.SetField("shore_side", False)
174 165
175 if not self.IsFieldSet(feat, "Name"): 166
176 self.handled("Name") 167 fname = self.searchField("river_{0,1}id$")
168 if self.IsFieldSet(feat, fname):
169 self.handled(fname)
170 if feat.GetField(fname) != self.river_id:
171 print ("River_id mismatch between shapefile and"
172 " importer parameter.")
173 newFeat.SetField("river_id", feat.GetField(fname))
174 else:
175 newFeat.SetField("river_id", self.river_id)
176
177 fname = self.searchField("name$")
178 if not self.IsFieldSet(feat, fname):
177 newFeat.SetField("name", args['name']) 179 newFeat.SetField("name", args['name'])
178 180
179 if self.IsFieldSet(feat, "offiziell"): 181 fname = self.searchField("offiziell$")
180 self.handled("offiziell") 182 if self.IsFieldSet(feat, fname):
181 offiziell = feat.GetField("offiziell") 183 self.handled(fname)
184 offiziell = feat.GetField(fname)
182 if offiziell == "1" or offiziell == 1: 185 if offiziell == "1" or offiziell == 1:
183 newFeat.SetField("offiziell", True) 186 newFeat.SetField("offiziell", True)
184 else: 187 else:
185 newFeat.SetField("offiziell", False) 188 newFeat.SetField("offiziell", False)
186 189
187 if self.IsFieldSet(newFeat, "z") and \ 190 if self.IsFieldSet(newFeat, "z") and \
188 self.IsFieldSet(newFeat, "rated_level"): 191 self.IsFieldSet(newFeat, "rated_level"):
189 self.handled("Freibord_m") 192 fname = self.searchField("freibord(_m){0,1}$")
193 self.handled(fname)
190 z = newFeat.GetFieldAsDouble("z") 194 z = newFeat.GetFieldAsDouble("z")
191 rl = newFeat.GetFieldAsDouble("rated_level") 195 rl = newFeat.GetFieldAsDouble("rated_level")
192 newFeat.SetField("freeboard", z - rl) 196 newFeat.SetField("freeboard", z - rl)
193 197
194 return newFeat 198 return newFeat

http://dive4elements.wald.intevation.org