changeset 1110:563e015f0f22

Export floodplain to shapefile and add its file path to WSPLGEN job. flys-artifacts/trunk@2616 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 31 Aug 2011 08:53:30 +0000
parents ba9fa72dd6f5
children b96ce07ba56c
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENJob.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java
diffstat 3 files changed, 51 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Aug 31 07:50:01 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Aug 31 08:53:30 2011 +0000
@@ -1,3 +1,12 @@
+2011-08-31  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/model/WSPLGENJob.java: Marked
+	  required parameters with a comment.
+
+	* src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java:
+	  Export floodplains (german 'Talaue') to shapefile and write its file
+	  path into the WSPLGEN job.
+
 2011-08-31  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENJob.java	Wed Aug 31 07:50:01 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WSPLGENJob.java	Wed Aug 31 08:53:30 2011 +0000
@@ -240,8 +240,8 @@
     protected void write(PrintWriter writer)
     throws IOException, IllegalArgumentException
     {
-        writeWsp(writer);
-        writeWspTag(writer);
+        writeWsp(writer);    // required
+        writeWspTag(writer); // required
         writeLin(writer);
         writeAxis(writer);
         writeArea(writer);
@@ -252,7 +252,7 @@
         writeGel(writer);
         writeDist(writer);
         writePro(writer);
-        writeDgm(writer);
+        writeDgm(writer);    // required
     }
 
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Wed Aug 31 07:50:01 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Wed Aug 31 08:53:30 2011 +0000
@@ -9,6 +9,7 @@
 
 import com.vividsolutions.jts.geom.Geometry;
 import com.vividsolutions.jts.geom.LineString;
+import com.vividsolutions.jts.geom.MultiPolygon;
 import com.vividsolutions.jts.geom.Polygon;
 
 import org.apache.log4j.Logger;
@@ -30,6 +31,7 @@
 
 import de.intevation.flys.model.CrossSectionTrack;
 import de.intevation.flys.model.DGM;
+import de.intevation.flys.model.Floodplain;
 import de.intevation.flys.model.RiverAxis;
 
 import de.intevation.flys.artifacts.FLYSArtifact;
@@ -60,6 +62,7 @@
     public static final String WSPLGEN_BARRIERS_POLY  = "barrier_polygons.shp";
     public static final String WSPLGEN_AXIS           = "axis.shp";
     public static final String WSPLGEN_QPS            = "qps.shp";
+    public static final String WSPLGEN_FLOODPLAIN     = "talaue.shp";
 
     public static final int WSPLGEN_DEFAULT_OUTPUT = 0;
 
@@ -179,11 +182,11 @@
         setAxis(artifact, artifactDir, job);
         setPro(artifact, artifactDir, job);
         setDgm(artifact, job);
+        setArea(artifact, artifactDir, job);
 
         // TODO
         // setWsp(artifact, job);    // WSP
         // setWspTag(artifact, job);
-        // setArea(artifact, job);   // SHP
         // setOutFile(artifact, job);
 
         try {
@@ -437,5 +440,40 @@
 
         job.setDgm(dgm.getPath());
     }
+
+
+    protected void setArea(FLYSArtifact artifact, File dir, WSPLGENJob job) {
+        String river = artifact.getDataAsString("river");
+        String srid  = FLYSUtils.getRiverSrid(artifact);
+        String srs   = "EPSG:" + srid;
+
+        Floodplain plain = Floodplain.getFloodplain(river);
+
+        SimpleFeatureType ft = GeometryUtils.buildFeatureType(
+            "talaue", srs, MultiPolygon.class);
+
+        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(ft);
+        builder.add(plain.getGeom());
+
+        FeatureCollection collection = FeatureCollections.newCollection();
+        collection.add(builder.buildFeature("0"));
+
+        File talaueShape = new File(dir, WSPLGEN_FLOODPLAIN);
+
+        try {
+            GeometryUtils.writeShapefile(
+                talaueShape,
+                GeometryUtils.buildFeatureType(
+                    "talaue", srs, MultiPolygon.class),
+                collection);
+            job.setArea(talaueShape.getAbsolutePath());
+        }
+        catch (MalformedURLException mue) {
+            logger.error("Error while writing shapefile: " + mue.getMessage());
+        }
+        catch (IOException ioe) {
+            logger.error("Error while writing shapefile: " + ioe.getMessage());
+        }
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org