[Dive4elements-commits] [PATCH 1 of 3] Handle transformation errors

Wald Commits scm-commit at wald.intevation.org
Wed Feb 13 17:49:54 CET 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1360773935 -3600
# Branch dami
# Node ID a92241d402289bb97759e23e40c2a672b999803d
# Parent  fc7ebf104779034d0593df694fc0997c3ffcf865
Handle transformation errors

diff -r fc7ebf104779 -r a92241d40228 flys-backend/contrib/shpimporter/importer.py
--- 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:


More information about the Dive4elements-commits mailing list