changeset 1118:7398280b11a0

Write WSP file for WSPLGEN and add its filepath to the WSPLGEN job. flys-artifacts/trunk@2625 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 31 Aug 2011 13:19:29 +0000
parents ea80e652f033
children faca1825818e
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java
diffstat 3 files changed, 115 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Aug 31 12:44:07 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Aug 31 13:19:29 2011 +0000
@@ -1,3 +1,14 @@
+2011-08-31  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/utils/FLYSUtils.java: Added a method
+	  stub that should return a FLYSArtifact based on a given UUID.
+
+	* src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java:
+	  Write the selected WST file for WSPLGEN. Note, that this is the WST file
+	  of the current WINFO artifact. Furthermore, there is currently no way
+	  for the user to select a column from WST file, so we currently use the
+	  column that is written to WST file at first.
+
 2011-08-31  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Changed
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Wed Aug 31 12:44:07 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FloodMapState.java	Wed Aug 31 13:19:29 2011 +0000
@@ -1,6 +1,8 @@
 package de.intevation.flys.artifacts.states;
 
 import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.util.List;
@@ -35,9 +37,13 @@
 import de.intevation.flys.model.RiverAxis;
 
 import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.model.CalculationResult;
 import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.WQKms;
 import de.intevation.flys.artifacts.model.WSPLGENFacet;
 import de.intevation.flys.artifacts.model.WSPLGENJob;
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+import de.intevation.flys.exports.WstWriter;
 import de.intevation.flys.utils.FLYSUtils;
 import de.intevation.flys.utils.GeometryUtils;
 
@@ -57,12 +63,18 @@
     public static final String XPATH_SHAPEFILE_DIR =
         "/artifact-database/floodmap/shapefile-path/@value";
 
+    public static final String WSP_ARTIFACT_UUID = "uesk.wsp.artifact";
+
+    public static final String WINFO_WSP_STATE_ID = "state.winfo.waterlevel";
+
     public static final String WSPLGEN_PARAMETER_FILE = "wsplgen.par";
     public static final String WSPLGEN_BARRIERS_LINES = "barrier_lines.shp";
     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 String WSPLGEN_WSP_FILE       = "waterlevel.txt";
+    public static final String WSPLGEN_OUTPUT_FILE    = "wsplgen.shp";
 
     public static final int WSPLGEN_DEFAULT_OUTPUT = 0;
 
@@ -85,7 +97,7 @@
             return null;
         }
 
-        WSPLGENJob job = prepareWSPLGENJob(artifact, artifactDir);
+        WSPLGENJob job = prepareWSPLGENJob(artifact, artifactDir, context);
 
         if (job == null) {
             if (KEEP_ARTIFACT_DIR.equals("false")) {
@@ -166,7 +178,8 @@
 
     protected WSPLGENJob prepareWSPLGENJob(
         FLYSArtifact artifact,
-        File         artifactDir
+        File         artifactDir,
+        CallContext  context
     ) {
         logger.debug("FloodMapState.prepareWSPLGENJob");
 
@@ -183,11 +196,11 @@
         setPro(artifact, artifactDir, job);
         setDgm(artifact, job);
         setArea(artifact, artifactDir, job);
+        setOutFile(artifact, job);
+        setWsp(artifact, context, artifactDir, job);    // WSP
 
         // TODO
-        // setWsp(artifact, job);    // WSP
         // setWspTag(artifact, job);
-        // setOutFile(artifact, job);
 
         try {
             job.toFile(paraFile);
@@ -475,5 +488,82 @@
             logger.error("Error while writing shapefile: " + ioe.getMessage());
         }
     }
+
+
+    protected void setOutFile(FLYSArtifact artifact, WSPLGENJob job) {
+        job.setOutFile(WSPLGEN_OUTPUT_FILE);
+    }
+
+
+    protected void setWsp(
+        FLYSArtifact artifact,
+        CallContext  context,
+        File         dir,
+        WSPLGENJob   job)
+    {
+        logger.debug("FloodMapState.setWsp");
+
+        String otherArtifact = artifact.getDataAsString(WSP_ARTIFACT_UUID);
+        FLYSArtifact     src = otherArtifact != null
+            ? FLYSUtils.getArtifact(otherArtifact, context)
+            : artifact;
+
+        CalculationResult rawData = (CalculationResult) src.compute(
+            context,
+            null,
+            WINFO_WSP_STATE_ID,
+            ComputeType.ADVANCE,
+            false);
+
+        if (rawData == null) {
+            logger.warn("No WST data found!");
+            return;
+        }
+
+        WQKms[]    data = (WQKms[]) rawData.getData();
+        WstWriter writer = new WstWriter(data.length);
+
+        // TODO REMOVE job.setWspTag(...) This is only used until the user is
+        // able to select the WSP column himself!
+        boolean writeWspTag = true;
+
+        double[] buf = new double[4];
+        for (WQKms wqkms: data) {
+            logger.debug("Add WST column: " + wqkms.getName());
+            writer.addColumn(wqkms.getName());
+
+            if (writeWspTag) {
+                job.setWspTag(wqkms.getName());
+                writeWspTag = false;
+            }
+
+            for (int i = 0, num = wqkms.size(); i < num; i++) {
+                wqkms.get(i, buf);
+                writer.add(buf);
+            }
+        }
+
+        FileOutputStream fout = null;
+
+        try {
+            File wspFile = new File(dir, WSPLGEN_WSP_FILE);
+            fout         = new FileOutputStream(wspFile);
+
+            writer.write(fout);
+
+            job.setWsp(wspFile.getAbsolutePath());
+        }
+        catch (FileNotFoundException fnfe) {
+            logger.warn("Error while writing wsp file: " + fnfe.getMessage());
+        }
+        finally {
+            if (fout != null) {
+                try {
+                    fout.close();
+                }
+                catch (IOException ioe) { /* do nothing */ }
+            }
+        }
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Wed Aug 31 12:44:07 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Wed Aug 31 13:19:29 2011 +0000
@@ -9,6 +9,8 @@
 
 import gnu.trove.TDoubleArrayList;
 
+import de.intevation.artifacts.CallContext;
+
 import de.intevation.artifacts.common.utils.Config;
 import de.intevation.artifacts.common.utils.XMLUtils;
 
@@ -28,6 +30,14 @@
     }
 
 
+    public static FLYSArtifact getArtifact(String uuid, CallContext context) {
+        // TODO IMPLEMENT ME
+        // Fetch artifact based on its UUID from ArtifactDatabase
+
+        return null;
+    }
+
+
     public static KM_MODE getKmRangeMode(FLYSArtifact flys) {
         String mode = flys.getDataAsString("ld_mode");
 

http://dive4elements.wald.intevation.org