[Dive4elements-commits] [PATCH 1 of 5] Fix searchValue and mark a field where a string is found as handled

Wald Commits scm-commit at wald.intevation.org
Mon Mar 25 15:39:16 CET 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1364210380 -3600
# Node ID ff11b178f152fe0fbad5a329cf70e8eb5964e854
# Parent  acc34bf0d5b264eb5f26ff2951e23c4e1988af51
Fix searchValue and mark a field where a string is found as handled

diff -r acc34bf0d5b2 -r ff11b178f152 flys-backend/contrib/shpimporter/buildings.py
--- a/flys-backend/contrib/shpimporter/buildings.py	Mon Mar 25 15:41:16 2013 +0100
+++ b/flys-backend/contrib/shpimporter/buildings.py	Mon Mar 25 12:19:40 2013 +0100
@@ -62,9 +62,13 @@
                 return BUILDING_KINDS["pegel"]
 
         # Now it gets ugly when we search all attributes
-        if self.searchValue(feat, "^br[ueü]{0,2}cke[n]{0,1}$"):
+        ret = self.searchValue(feat, "^br[ueü]{0,2}cke[n]{0,1}$")
+        if ret:
+            self.handled(ret)
             return BUILDING_KINDS["brücken"]
-        if self.searchValue(feat, "^wehr[e]{0,1}$"):
+        ret = self.searchValue(feat, "^wehr[e]{0,1}$")
+        if ret:
+            self.handled(ret)
             return BUILDING_KINDS["wehre"]
 
         return BUILDING_KINDS["sonstige"]
diff -r acc34bf0d5b2 -r ff11b178f152 flys-backend/contrib/shpimporter/importer.py
--- a/flys-backend/contrib/shpimporter/importer.py	Mon Mar 25 15:41:16 2013 +0100
+++ b/flys-backend/contrib/shpimporter/importer.py	Mon Mar 25 12:19:40 2013 +0100
@@ -47,12 +47,15 @@
 
     def searchValue(self, feat, regex):
         """
-        Searches for a value that matches regx in all attribute
+        Searches for a value that matches regex in all attribute
         fields of a feature.
+
+        @returns the name of the field where a match was found or None
         """
         for val in feat.items():
-            match = re.match(regex, val, re.IGNORECASE)
-            return match != None
+            match = re.match(regex, feat.items()[val], re.IGNORECASE)
+            if match:
+                return val
 
     def searchField(self, regex):
         """


More information about the Dive4elements-commits mailing list