[Dive4elements-commits] [PATCH] Importer: Add HWS lines stub. Needs some example data to finish

Wald Commits scm-commit at wald.intevation.org
Fri Feb 1 11:42:37 CET 2013


# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1359715354 -3600
# Branch dami
# Node ID 7323847fa7df74f1dd5999f67ce6d9935b5a0d49
# Parent  1a218a0bcfcf89d62f8d47d078443be9d36d5267
Importer: Add HWS lines stub. Needs some example data to finish
especially the setting of additional geometry values

diff -r 1a218a0bcfcf -r 7323847fa7df flys-backend/contrib/shpimporter/hws.py
--- a/flys-backend/contrib/shpimporter/hws.py	Fri Feb 01 10:43:19 2013 +0100
+++ b/flys-backend/contrib/shpimporter/hws.py	Fri Feb 01 11:42:34 2013 +0100
@@ -47,48 +47,6 @@
     "Hamburg" : 16,
 }
 
-class HWSLines(Importer):
-
-    def getPath(self, base):
-        return "%s/%s" % (base, PATH)
-
-    def getTablename(self):
-        return "hws_lines"
-
-    def getName(self):
-        return "HWS_LINES"
-
-    def isGeometryValid(self, geomType):
-        return geomType == 2
-
-    def isShapeRelevant(self, name, path):
-        return True
-
-    def createNewFeature(self, featureDef, feat, **args):
-        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)
-
-        if self.IsFieldSet(feat, "TYP"):
-            newFeat.SetField("type", feat.GetField("TYP"))
-
-        if self.IsFieldSet(feat, "Bauart"):
-            newFeat.SetField("hws_facility", feat.GetField("Bauart"))
-
-        if self.IsFieldSet(feat, "Name"):
-            newFeat.SetField("name", feat.GetField("name"))
-        else:
-            newFeat.SetField("name", args['name'])
-
-        return newFeat
-
 class HWSPoints(Importer):
     fieldmap = {
             "name$" : "name",
@@ -117,11 +75,7 @@
 
     def isShapeRelevant(self, name, path):
         shp = ogr.Open(path)
-        if shp.GetLayerByName(name).GetGeomType() == ogr.wkbPoint or \
-             shp.GetLayerByName(name).GetGeomType() == ogr.wkbPoint25D:
-            return True
-        else:
-            return False
+        return self.isGeometryValid(shp.GetLayerByName(name).GetGeomType())
 
     def createNewFeature(self, featureDef, feat, **args):
         newFeat  = ogr.Feature(featureDef)
@@ -197,4 +151,40 @@
 
         return newFeat
 
+class HWSLines(HWSPoints):
 
+    # TODO: GEOM_target, GEOM_rated_level, dike_km_from, dike_km_to
+    fieldmap = {
+            "name$" : "name",
+            "quelle$" : "source",
+            "anmerkung$" : "description",
+            "stand$" : "status_date",
+            "verband$" : "agency",
+            "Bereich$" : "range",
+        }
+
+    def getPath(self, base):
+        return "%s/%s" % (base, PATH)
+
+    def getTablename(self):
+        return "hws_lines"
+
+    def getName(self):
+        return "HWS_LINES"
+
+    def isGeometryValid(self, geomType):
+        return geomType == ogr.wkbLineString or geomType == ogr.wkbLineString25D
+
+    def isShapeRelevant(self, name, path):
+        shp = ogr.Open(path)
+        return self.isGeometryValid(shp.GetLayerByName(name).GetGeomType())
+
+    def createNewFeature(self, featureDef, feat, **args):
+        newFeat = HWSPoints.createNewFeature(self, featureDef, feat, **args)
+        geometry = feat.GetGeometryRef()
+        geometry.SetCoordinateDimension(3)
+        newFeat.SetGeometry(geometry)
+
+        return newFeat
+
+
diff -r 1a218a0bcfcf -r 7323847fa7df flys-backend/contrib/shpimporter/shpimporter.py
--- a/flys-backend/contrib/shpimporter/shpimporter.py	Fri Feb 01 10:43:19 2013 +0100
+++ b/flys-backend/contrib/shpimporter/shpimporter.py	Fri Feb 01 11:42:34 2013 +0100
@@ -121,7 +121,8 @@
     elif config.skip_floodplains == 1 and isinstance(importer, Floodplain):
         return True
     elif config.skip_hws_points == 1 and isinstance(importer, HWSPoints):
-        return True
+        if not isinstance(importer, HWSLines):
+            return True
     elif config.skip_hws_lines == 1 and isinstance(importer, HWSLines):
         return True
     elif config.skip_gauge_locations == 1 and isinstance(importer, GaugeLocation):


More information about the Dive4elements-commits mailing list