changeset 5353:d086ce6c13d3

Add jetties importer
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 20 Mar 2013 17:55:53 +0100
parents f1009aa7dcd1
children 555a99dff849
files flys-backend/contrib/run_geo.sh flys-backend/contrib/shpimporter/jetties.py flys-backend/contrib/shpimporter/shpimporter.py flys-backend/doc/documentation/de/importer-geodaesie.tex
diffstat 4 files changed, 79 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/contrib/run_geo.sh	Wed Mar 20 17:20:19 2013 +0100
+++ b/flys-backend/contrib/run_geo.sh	Wed Mar 20 17:55:53 2013 +0100
@@ -26,6 +26,7 @@
 SKIP_CATCHMENTS=0
 SKIP_UESG=0
 SKIP_DGM=0
+SKIP_JETTIES=0
 
 # There should be no need to change anything below this line
 
@@ -61,4 +62,5 @@
     --skip_uesgs $SKIP_UESG \
     --skip_hws_lines $SKIP_HWS_LINES \
     --skip_hws_points $SKIP_HWS_POINTS \
-    --skip_dgm $SKIP_DGM
+    --skip_dgm $SKIP_DGM \
+    --skip_jetties $SKIP_JETTIES
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/contrib/shpimporter/jetties.py	Wed Mar 20 17:55:53 2013 +0100
@@ -0,0 +1,69 @@
+# -*- coding: utf-8 -*-
+import os
+
+try:
+    from osgeo import ogr
+except ImportError:
+    import ogr
+
+from importer import Importer
+import utils
+
+import logging
+logger = logging.getLogger("Jetties")
+
+PATH="Geodaesie/Bauwerke"
+NAME="Jetties"
+
+# strings need to be lowercase
+JETTY_KIND = {
+        "buhnenkopf" : 0,
+        "buhnenfuß" : 1,
+        "buhnenwurzel" : 2,
+    }
+
+class Jetties(Importer):
+    fieldmap = {
+            "^station$" : "km",
+            "^z$" : "z",
+        }
+
+    def getPath(self, base):
+        return "%s/%s" % (base, PATH)
+
+    def getTablename(self):
+        return "jetties"
+
+    def getName(self):
+        return "JETTIES"
+
+    def isGeometryValid(self, geomType):
+        return geomType == ogr.wkbPoint or geomType == ogr.wkbPoint25D
+
+    def isShapeRelevant(self, name, path):
+        if not path.endswith("Buhnen.shp"):
+            return False
+        shp = ogr.Open(path)
+        return self.isGeometryValid(shp.GetLayerByName(name).GetGeomType())
+
+    def createNewFeature(self, featureDef, feat, **args):
+        newFeat  = ogr.Feature(featureDef)
+        geometry = feat.GetGeometryRef()
+        geometry.SetCoordinateDimension(2)
+
+        self.copyFields(feat, newFeat, self.fieldmap)
+
+        newFeat.SetGeometry(geometry)
+
+        artname = self.searchField("^type$")
+        if self.IsFieldSet(feat, artname):
+            self.handled(artname)
+            kind_id = JETTY_KIND.get(feat.GetField(artname).lower())
+            if not kind_id:
+                logger.warn("Unknown Type: %s" % \
+                        feat.GetField(artname))
+            else:
+                newFeat.SetField("kind_id", kind_id)
+
+        return newFeat
+
--- a/flys-backend/contrib/shpimporter/shpimporter.py	Wed Mar 20 17:20:19 2013 +0100
+++ b/flys-backend/contrib/shpimporter/shpimporter.py	Wed Mar 20 17:55:53 2013 +0100
@@ -18,6 +18,7 @@
 from boundaries import HydrBoundary, HydrBoundaryPoly
 from hws import HWSLines, HWSPoints
 from gauges import GaugeLocation
+from jetties import Jetties
 from dgm import insertRiverDgm
 
 logger = logging.getLogger("shpimporter")
@@ -46,6 +47,7 @@
         HWSLines(river_id, dbconn, dry_run),
         HWSPoints(river_id, dbconn, dry_run),
         GaugeLocation(river_id, dbconn, dry_run),
+        Jetties(river_id, dbconn, dry_run),
         UESG(river_id, dbconn, dry_run)
         ]
 
@@ -73,6 +75,7 @@
     parser.add_option("--skip_kms", type="int")
     parser.add_option("--skip_uesgs", type="int")
     parser.add_option("--skip_dgm", type="int")
+    parser.add_option("--skip_jetties", type="int")
     (config, args) = parser.parse_args()
 
     if config.verbose > 1:
@@ -121,6 +124,8 @@
         return True
     elif config.skip_gauge_locations == 1 and isinstance(importer, GaugeLocation):
         return True
+    elif config.skip_jetties == 1 and isinstance(importer, Jetties):
+        return True
     elif config.skip_kms == 1 and isinstance(importer, KM):
         return True
     elif config.skip_uesgs == 1 and isinstance(importer, UESG):
--- a/flys-backend/doc/documentation/de/importer-geodaesie.tex	Wed Mar 20 17:20:19 2013 +0100
+++ b/flys-backend/doc/documentation/de/importer-geodaesie.tex	Wed Mar 20 17:55:53 2013 +0100
@@ -257,9 +257,6 @@
 \textbf{SKIP\_HWS\_POINTS}
 \\Bei gesetztem Wert `1` werden kein Hochwasserschutz Punktdaten importiert.
 
-\textbf{SKIP\_GAUGE\_LOCATION}
-\\Bei gesetztem Wert `1` werden keine Pegelorte importiert.
-
 \textbf{SKIP\_CATCHMENTS}
 \\Bei gesetztem Wert `1` werden keine Einzugsgebiete importiert.
 
@@ -269,6 +266,8 @@
 \textbf{SKIP\_DGM}
 \\Bei gesetztem Wert `1` werden keine Informationen über Digitale Geländemodelle importiert.
 
+\textbf{SKIP\_JETTIES}
+\\Bei gesetztem Wert `1` werden keine Informationen über Buhnen importiert.
 
 \subsection{Starten des Geodaten Importers}
 \label{Starten des Geodaten Importers}

http://dive4elements.wald.intevation.org