changeset 5545:ed149d5d7fb7

Add floodmarks importer
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 03 Apr 2013 16:33:28 +0200
parents 12f4d088f088
children 5b50247d4d99
files flys-backend/contrib/run_geo.sh flys-backend/contrib/shpimporter/floodmarks.py flys-backend/contrib/shpimporter/shpimporter.py flys-backend/doc/documentation/de/importer-geodaesie.tex
diffstat 4 files changed, 86 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/contrib/run_geo.sh	Wed Apr 03 23:16:11 2013 +0200
+++ b/flys-backend/contrib/run_geo.sh	Wed Apr 03 16:33:28 2013 +0200
@@ -27,6 +27,7 @@
 SKIP_UESG=0
 SKIP_DGM=0
 SKIP_JETTIES=0
+SKIP_FLOODMARKS=0
 
 # There should be no need to change anything below this line
 
@@ -63,4 +64,5 @@
     --skip_hws_lines $SKIP_HWS_LINES \
     --skip_hws_points $SKIP_HWS_POINTS \
     --skip_dgm $SKIP_DGM \
-    --skip_jetties $SKIP_JETTIES
+    --skip_jetties $SKIP_JETTIES \
+    --skip_floodmarks $SKIP_FLOODMARKS
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/contrib/shpimporter/floodmarks.py	Wed Apr 03 16:33:28 2013 +0200
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+try:
+    from osgeo import ogr
+except ImportError:
+    import ogr
+
+from importer import Importer
+import logging
+import os
+import re
+
+TABLE_NAME="flood_marks"
+PATH="Hydrologie/HW-Marken"
+NAME="Floodmarks"
+
+logger = logging.getLogger(NAME)
+
+BUILDING_KINDS= {
+        "sonstige" : 0,
+        "brücken"  : 1,
+        "wehre"    : 2,
+        "pegel"    : 3,
+        }
+
+class Floodmark(Importer):
+    fieldmap = {
+            "^station$"       : "km",
+            "^km$"            : "km",
+            "^wsv-km$"        : "km",
+            "^FlussKm$"       : "km",
+            "^z$"             : "z",
+            "^z\d*"           : "z", # z02, z1890, usw.
+            "^m+NHN$"         : "z",
+            "^Ort$"           : "location",
+            "^Pegel$"         : "location",
+        }
+
+    def getPath(self, base):
+        return "%s/%s" % (base, PATH)
+
+    def getTablename(self):
+        return TABLE_NAME
+
+    def getName(self):
+        return NAME
+
+    def isGeometryValid(self, geomType):
+        return geomType == ogr.wkbPoint
+
+    def isShapeRelevant(self, name, path):
+        return "hw-marken" in name.lower()
+
+    def createNewFeature(self, featureDef, feat, **args):
+        newFeat  = ogr.Feature(featureDef)
+        geometry = feat.GetGeometryRef()
+        geometry.SetCoordinateDimension(2)
+        newFeat.SetGeometry(geometry)
+
+        self.copyFields(feat, newFeat, self.fieldmap)
+
+        newFeat.SetField("river_id", self.river_id)
+
+        filename = os.path.basename(args['path'])
+
+        # Try to extract the year from the filename
+        match = re.search(r"([_\-])(\d\d\d\d)([_\-])", filename)
+        if match:
+            year = match.groups()[1]
+            year = int(year)
+            newFeat.SetField("year", year)
+        else:
+            logger.warn(u"Could not extract year from filename: %s " % filename)
+
+        return newFeat
+
--- a/flys-backend/contrib/shpimporter/shpimporter.py	Wed Apr 03 23:16:11 2013 +0200
+++ b/flys-backend/contrib/shpimporter/shpimporter.py	Wed Apr 03 16:33:28 2013 +0200
@@ -20,6 +20,7 @@
 from gauges import GaugeLocation
 from jetties import Jetties
 from dgm import insertRiverDgm
+from floodmarks import Floodmark
 
 logger = logging.getLogger("shpimporter")
 
@@ -48,6 +49,7 @@
         HWSPoints(river_id, dbconn, dry_run),
         GaugeLocation(river_id, dbconn, dry_run),
         Jetties(river_id, dbconn, dry_run),
+        Floodmark(river_id, dbconn, dry_run),
         UESG(river_id, dbconn, dry_run)
         ]
 
@@ -76,6 +78,7 @@
     parser.add_option("--skip_uesgs", type="int")
     parser.add_option("--skip_dgm", type="int")
     parser.add_option("--skip_jetties", type="int")
+    parser.add_option("--skip_floodmarks", type="int")
     (config, args) = parser.parse_args()
 
     if config.verbose > 1:
@@ -130,6 +133,8 @@
         return True
     elif config.skip_uesgs == 1 and isinstance(importer, UESG):
         return True
+    elif config.skip_floodmarks == 1 and isinstance(importer, Floodmark):
+        return True
 
     return False
 
--- a/flys-backend/doc/documentation/de/importer-geodaesie.tex	Wed Apr 03 23:16:11 2013 +0200
+++ b/flys-backend/doc/documentation/de/importer-geodaesie.tex	Wed Apr 03 16:33:28 2013 +0200
@@ -269,6 +269,9 @@
 \textbf{SKIP\_JETTIES}
 \\Bei gesetztem Wert `1` werden keine Informationen über Buhnen importiert.
 
+\textbf{SKIP\_FLOODMARKS}
+\\Bei gesetztem Wert `1` werden keine Informationen über HW-Marken importiert.
+
 \subsection{Starten des Geodaten Importers}
 \label{Starten des Geodaten Importers}
 Der Geodaten Importer wird mittels eines Shellskripts von einer Konsole

http://dive4elements.wald.intevation.org