changeset 4974:a92241d40228 dami

Handle transformation errors
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 13 Feb 2013 17:45:35 +0100
parents fc7ebf104779
children 9eea3cd22ee7
files flys-backend/contrib/shpimporter/importer.py
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/contrib/shpimporter/importer.py	Wed Feb 13 12:07:10 2013 +0100
+++ b/flys-backend/contrib/shpimporter/importer.py	Wed Feb 13 17:45:35 2013 +0100
@@ -104,7 +104,8 @@
             return feat
 
         transformer = osr.CoordinateTransformation(src_srs, self.dest_srs)
-        geometry.Transform(transformer)
+        if geometry.Transform(transformer):
+            return None
 
         return feat
 
@@ -193,11 +194,15 @@
                 if newFeat is not None:
                     newFeat.SetField("path", utils.getUTF8Path(path))
                     newFeat = self.transform(newFeat)
-                    res = destLayer.CreateFeature(newFeat)
-                    if res is None or res > 0:
-                        shpimporter.ERROR("Unable to insert feature. Error: %r" % res)
+                    if newFeat:
+                        res = destLayer.CreateFeature(newFeat)
+                        if res is None or res > 0:
+                            shpimporter.ERROR("Unable to insert feature. Error: %r" % res)
+                        else:
+                            success = success + 1
                     else:
-                        success = success + 1
+                        shpimporter.ERROR("Could not transform feature: %s " % feat.GetFID())
+                        creationFailed += 1
                 else:
                     creationFailed = creationFailed + 1
             else:

http://dive4elements.wald.intevation.org