changeset 5294:3f35d9db48c1

Force UESG to multipolygon and import source field for messungen
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 14 Mar 2013 12:45:51 +0100
parents 8aae8c26844f
children 55122db34cd0
files flys-backend/contrib/shpimporter/uesg.py flys-backend/contrib/shpimporter/utils.py
diffstat 2 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/contrib/shpimporter/uesg.py	Thu Mar 14 12:44:04 2013 +0100
+++ b/flys-backend/contrib/shpimporter/uesg.py	Thu Mar 14 12:45:51 2013 +0100
@@ -4,7 +4,8 @@
     import ogr
 
 from importer import Importer
-
+import os.path
+import utils
 
 TABLE_NAME="floodmaps"
 PATH="Hydrologie/UeSG"
@@ -26,11 +27,8 @@
 
 
     def isGeometryValid(self, geomType):
-        if geomType == 3 or geomType == 6:
-            return True
-        else:
-            return False
-
+        return geomType in [ogr.wkbMultiPolygon,
+                            ogr.wkbPolygon]
 
     def getKind(self, path):
         kind = 0
@@ -54,7 +52,6 @@
 
     def createNewFeature(self, featureDef, feat, **args):
         kind  = self.getKind(args['path'])
-
         newFeat = ogr.Feature(featureDef)
         newFeat.SetGeometry(feat.GetGeometryRef())
 
@@ -83,6 +80,11 @@
         else:
             perimeter = 0
 
+        if kind >= 200:
+            newFeat.SetField("source",
+                    os.path.basename(os.path.dirname(args['path'])))
+
+
         groupId = 2
 
         newFeat.SetField("river_id", riverId)
@@ -93,5 +95,5 @@
         newFeat.SetField("kind", kind)
         newFeat.SetField("name", args['name'])
 
-        return newFeat
+        return utils.convertToMultiPolygon(newFeat)
 
--- a/flys-backend/contrib/shpimporter/utils.py	Thu Mar 14 12:44:04 2013 +0100
+++ b/flys-backend/contrib/shpimporter/utils.py	Thu Mar 14 12:45:51 2013 +0100
@@ -108,3 +108,15 @@
     geometry.AssignSpatialReference(srs)
     feature.SetGeometry(geometry)
     return feature
+
+def convertToMultiPolygon(feature):
+    """
+    Converts a feature to a multiline feature.
+    """
+    geometry = feature.GetGeometryRef()
+    # SRS information is lost while forcing to multiline
+    srs = geometry.GetSpatialReference()
+    geometry = ogr.ForceToMultiPolygon(geometry)
+    geometry.AssignSpatialReference(srs)
+    feature.SetGeometry(geometry)
+    return feature

http://dive4elements.wald.intevation.org