[Dive4elements-commits] [PATCH 5 of 5] Import buildings according to specification

Wald Commits scm-commit at wald.intevation.org
Fri Mar 22 17:32:18 CET 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1363969929 -3600
# Node ID 974f0e3dcc281e92e524e5f3186a56c1872c5fd3
# Parent  6c2751c17869b7a127a59484ac94116f213e0bc8
Import buildings according to specification

diff -r 6c2751c17869 -r 974f0e3dcc28 flys-backend/contrib/shpimporter/buildings.py
--- 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
 


More information about the Dive4elements-commits mailing list