changeset 5387:974f0e3dcc28

Import buildings according to specification
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 22 Mar 2013 17:32:09 +0100 (2013-03-22)
parents 6c2751c17869
children 5ace307430bf
files flys-backend/contrib/shpimporter/buildings.py
diffstat 1 files changed, 48 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/contrib/shpimporter/buildings.py	Fri Mar 22 17:31:48 2013 +0100
+++ b/flys-backend/contrib/shpimporter/buildings.py	Fri Mar 22 17:32:09 2013 +0100
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 try:
     from osgeo import ogr
 except ImportError:
@@ -9,8 +10,24 @@
 PATH="Geodaesie/Bauwerke"
 NAME="Buildings"
 
+BUILDING_KINDS= {
+        "sonstige" : 0,
+        "brücken"  : 1,
+        "wehre"    : 2,
+        "pegel"    : 3,
+        }
 
 class Building(Importer):
+    fieldmap = {
+            "^station$"       : "km",
+            "^km$"            : "km",
+            "^wsv-km$"        : "km",
+            "^z$"             : "z",
+            "^H[oeö]{0,2}he$" : "z",
+            "^m+NHN$"         : "z",
+            "^KWNAAM$"        : "description",
+            "^Name$"          : "description"
+        }
 
     def getPath(self, base):
         return "%s/%s" % (base, PATH)
@@ -29,22 +46,42 @@
 
 
     def isShapeRelevant(self, name, path):
-        return True
+        return "buhnen.shp" not in name.lower()
+
+    def getKind(self, feat, path):
+        # First try to resolve it with the filename
+        for fname in ["brücke.shp", "bruecke.shp",
+                     "brücken.shp", "bruecken.shp"]:
+            if path.lower().endswith(fname):
+                return BUILDING_KINDS["brücken"]
+        for fname in ["wehr.shp", "wehre.shp"]:
+            if path.lower().endswith(fname):
+                return BUILDING_KINDS["wehre"]
+        for fname in ["pegel.shp"]:
+            if path.lower().endswith(fname):
+                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}$"):
+            return BUILDING_KINDS["brücken"]
+        if self.searchValue(feat, "^wehr[e]{0,1}$"):
+            return BUILDING_KINDS["wehre"]
+
+        return BUILDING_KINDS["sonstige"]
 
 
     def createNewFeature(self, featureDef, feat, **args):
-        newFeat = ogr.Feature(featureDef)
-        newFeat.SetGeometry(feat.GetGeometryRef())
+        newFeat  = ogr.Feature(featureDef)
+        geometry = feat.GetGeometryRef()
+        geometry.SetCoordinateDimension(2)
+        newFeat.SetGeometry(geometry)
 
-        if self.IsFieldSet(feat, "river_id"):
-            newFeat.SetField("river_id", feat.GetField("river_id"))
-        else:
-            newFeat.SetField("river_id", self.river_id)
+        self.copyFields(feat, newFeat, self.fieldmap)
 
-        if self.IsFieldSet(feat, "Name"):
-            newFeat.SetField("name", feat.GetField("Name"))
-        elif self.IsFieldSet(feat, "KWNAAM"):
-            newFeat.SetField("name", feat.GetField("KWNAAM"))
+        newFeat.SetField("kind_id", self.getKind(feat, args['path']))
+        newFeat.SetField("name", args["name"])
+
+        newFeat.SetField("river_id", self.river_id)
 
         return newFeat
 

http://dive4elements.wald.intevation.org