comparison flys-backend/contrib/shpimporter/hws.py @ 4884:b457532dae63

Importer: Move copy fields into importer class and track imported/unimported fields
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 28 Jan 2013 12:25:24 +0100
parents 9b03cf6b85c9
children 60b026b4340e
comparison
equal deleted inserted replaced
4883:186dd186d5bd 4884:b457532dae63
117 def createNewFeature(self, featureDef, feat, **args): 117 def createNewFeature(self, featureDef, feat, **args):
118 newFeat = ogr.Feature(featureDef) 118 newFeat = ogr.Feature(featureDef)
119 geometry = feat.GetGeometryRef() 119 geometry = feat.GetGeometryRef()
120 geometry.SetCoordinateDimension(2) 120 geometry.SetCoordinateDimension(2)
121 121
122 utils.copyFields(feat, newFeat, self.fieldmap) 122 self.copyFields(feat, newFeat, self.fieldmap)
123 123
124 newFeat.SetGeometry(geometry) 124 newFeat.SetGeometry(geometry)
125 125
126 newFeat.SetFID(feat.GetFID()) 126 newFeat.SetFID(feat.GetFID())
127 127
128 newFeat.SetField("ogr_fid", feat.GetFID()) 128 newFeat.SetField("ogr_fid", feat.GetFID())
129 129
130 if self.IsFieldSet(feat, "Art"): 130 if self.IsFieldSet(feat, "Art"):
131 self.handled("Art")
131 kind_id = HWS_KIND.get(feat.GetField("Art")) 132 kind_id = HWS_KIND.get(feat.GetField("Art"))
132 if not kind_id: 133 if not kind_id:
133 print ("Unbekannte Art: %s" % \ 134 print ("Unbekannte Art: %s" % \
134 feat.GetField("Art")) 135 feat.GetField("Art"))
135 else: 136 else:
136 newFeat.SetField("kind_id", kind_id) 137 newFeat.SetField("kind_id", kind_id)
137 138
138 if self.IsFieldSet(feat, "Bundesland"): 139 if self.IsFieldSet(feat, "Bundesland"):
140 self.handled("Bundesland")
139 fed_id = FED_STATES.get(feat.GetField("Bundesland")) 141 fed_id = FED_STATES.get(feat.GetField("Bundesland"))
140 142
141 if not fed_id: 143 if not fed_id:
142 print ("Unbekanntes Bundesland: %s" % \ 144 print ("Unbekanntes Bundesland: %s" % \
143 feat.GetField("Bundesland")) 145 feat.GetField("Bundesland"))
144 else: 146 else:
145 newFeat.SetField("fed_state_id", fed_id) 147 newFeat.SetField("fed_state_id", fed_id)
146 148
147 if self.IsFieldSet(feat, "river_id"): 149 if self.IsFieldSet(feat, "river_id"):
150 self.handled("river_id")
148 if feat.GetField("river_id") != self.river_id: 151 if feat.GetField("river_id") != self.river_id:
149 print ("River_id mismatch between shapefile and" 152 print ("River_id mismatch between shapefile and"
150 " importer parameter.") 153 " importer parameter.")
151 newFeat.SetField("river_id", feat.GetField("river_id")) 154 newFeat.SetField("river_id", feat.GetField("river_id"))
152 else: 155 else:
153 newFeat.SetField("river_id", self.river_id) 156 newFeat.SetField("river_id", self.river_id)
154 157
155 if self.IsFieldSet(feat, "Ufer"): 158 if self.IsFieldSet(feat, "Ufer"):
159 self.handled("Ufer")
156 shoreString = feat.GetField("Ufer") 160 shoreString = feat.GetField("Ufer")
157 if "links" in shoreString.lower(): 161 if "links" in shoreString.lower():
158 newFeat.SetField("shore_side", True) 162 newFeat.SetField("shore_side", True)
159 elif "rechts" in shoreString.lower(): 163 elif "rechts" in shoreString.lower():
160 newFeat.SetField("shore_side", False) 164 newFeat.SetField("shore_side", False)
161 165
162 if not self.IsFieldSet(feat, "Name"): 166 if not self.IsFieldSet(feat, "Name"):
167 self.handled("Name")
163 newFeat.SetField("name", args['name']) 168 newFeat.SetField("name", args['name'])
164 169
165 if self.IsFieldSet(feat, "offiziell"): 170 if self.IsFieldSet(feat, "offiziell"):
171 self.handled("offiziell")
166 offiziell = feat.GetField("offiziell") 172 offiziell = feat.GetField("offiziell")
167 if offiziell == "1" or offiziell == 1: 173 if offiziell == "1" or offiziell == 1:
168 newFeat.SetField("offiziell", True) 174 newFeat.SetField("offiziell", True)
169 else: 175 else:
170 newFeat.SetField("offiziell", False) 176 newFeat.SetField("offiziell", False)
171 177
172 if self.IsFieldSet(newFeat, "z") and \ 178 if self.IsFieldSet(newFeat, "z") and \
173 self.IsFieldSet(newFeat, "rated_level"): 179 self.IsFieldSet(newFeat, "rated_level"):
180 self.handled("Freibord_m")
174 z = newFeat.GetFieldAsDouble("z") 181 z = newFeat.GetFieldAsDouble("z")
175 rl = newFeat.GetFieldAsDouble("rated_level") 182 rl = newFeat.GetFieldAsDouble("rated_level")
176 newFeat.SetField("freeboard", z - rl) 183 newFeat.SetField("freeboard", z - rl)
177 184
178 return newFeat 185 return newFeat

http://dive4elements.wald.intevation.org