comparison flys-backend/contrib/shpimporter/importer.py @ 4995:998b29c8d2fd dami

Improve debug output for unsupported features and skipped shapefiles
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 15 Feb 2013 11:51:58 +0100
parents a92241d40228
children fed74592a2ba
comparison
equal deleted inserted replaced
4993:71e1b96f4794 4995:998b29c8d2fd
75 def isShapeRelevant(self, name, path): 75 def isShapeRelevant(self, name, path):
76 return True 76 return True
77 77
78 def walkOverShapes(self, shape): 78 def walkOverShapes(self, shape):
79 (name, path) = shape 79 (name, path) = shape
80 if not self.isShapeRelevant(name, path):
81 shpimporter.INFO("Skip shapefile '%s'" % path)
82 return
83 80
84 shp = ogr.Open(shape[1]) 81 shp = ogr.Open(shape[1])
85 if shp is None: 82 if shp is None:
86 shpimporter.ERROR("Shapefile '%s' could not be opened!" % path) 83 shpimporter.ERROR("Shapefile '%s' could not be opened!" % path)
87 return 84 return
85
86 if not self.isShapeRelevant(name, path):
87 shpimporter.INFO("Skip shapefile: '%s' of Type: %s" % (path,
88 utils.getWkbString(shp.GetLayerByName(name).GetGeomType())))
89 return
90
88 91
89 shpimporter.INFO("Processing shapefile '%s'" % path) 92 shpimporter.INFO("Processing shapefile '%s'" % path)
90 srcLayer = shp.GetLayerByName(name) 93 srcLayer = shp.GetLayerByName(name)
91 94
92 if srcLayer is None: 95 if srcLayer is None:
170 srcLayer.ResetReading() 173 srcLayer.ResetReading()
171 self.srcLayer = srcLayer 174 self.srcLayer = srcLayer
172 175
173 geomType = -1 176 geomType = -1
174 success = 0 177 success = 0
175 unsupported = 0 178 unsupported = {}
176 creationFailed = 0 179 creationFailed = 0
177 featureDef = destLayer.GetLayerDefn() 180 featureDef = destLayer.GetLayerDefn()
178 181
179 for feat in srcLayer: 182 for feat in srcLayer:
180 geom = feat.GetGeometryRef() 183 geom = feat.GetGeometryRef()
204 shpimporter.ERROR("Could not transform feature: %s " % feat.GetFID()) 207 shpimporter.ERROR("Could not transform feature: %s " % feat.GetFID())
205 creationFailed += 1 208 creationFailed += 1
206 else: 209 else:
207 creationFailed = creationFailed + 1 210 creationFailed = creationFailed + 1
208 else: 211 else:
209 unsupported = unsupported + 1 212 unsupported[utils.getWkbString(geomType)] = \
213 unsupported.get(utils.getWkbString(geomType), 0) + 1
210 214
211 shpimporter.INFO("Inserted %i features" % success) 215 shpimporter.INFO("Inserted %i features" % success)
212 shpimporter.INFO("Failed to create %i features" % creationFailed) 216 shpimporter.INFO("Failed to create %i features" % creationFailed)
213 shpimporter.INFO("Found %i unsupported features" % unsupported) 217 for key, value in unsupported:
218 shpimporter.INFO("Found %i unsupported features of type: %s" % (value, key))
214 219
215 if self.tracking_import: 220 if self.tracking_import:
216 unhandled = [] 221 unhandled = []
217 for i in range(0, srcLayer.GetLayerDefn().GetFieldCount()): 222 for i in range(0, srcLayer.GetLayerDefn().GetFieldCount()):
218 act_field = srcLayer.GetLayerDefn().GetFieldDefn(i).GetNameRef() 223 act_field = srcLayer.GetLayerDefn().GetFieldDefn(i).GetNameRef()

http://dive4elements.wald.intevation.org