changeset 1122:111794adf285

Get real (but yet not parameterized) data to display in CrossSection. flys-artifacts/trunk@2631 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 01 Sep 2011 12:15:46 +0000 (2011-09-01)
parents 66783d957201
children be9bb260b835
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/winfo.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java
diffstat 9 files changed, 210 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Sep 01 07:27:44 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu Sep 01 12:15:46 2011 +0000
@@ -1,3 +1,33 @@
+2011-08-31  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	Get real data to display in CrossSection (although ignorant of
+	parameterization), making use of the showcase code of the CrossSectionApp-
+	Standalone application.
+
+	* doc/conf/artifacts/winfo.xml: Add new facet (~waterline) to state/out.
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  New methods to get relevant data. So far just takes the first value of
+	  everything and assuming a waterlevel at 130m.
+
+	* src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java:
+	  New Facet responsible of water level in cross section.
+
+	* src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java:
+	  Made some functionality publicly and statically available.
+
+	* src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java:
+	  Update call.
+
+	* src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java: Added new
+	  Facet type.
+
+	* src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java:
+	  Added new Facet to out.
+
+	* src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java:
+	  Respect new facet and facets data.
+
 2011-09-01  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/utils/GeometryUtils.java: Close an open
--- a/flys-artifacts/doc/conf/artifacts/winfo.xml	Thu Sep 01 07:27:44 2011 +0000
+++ b/flys-artifacts/doc/conf/artifacts/winfo.xml	Thu Sep 01 12:15:46 2011 +0000
@@ -200,6 +200,7 @@
                 </outputmode>
                 <outputmode name="cross_section" description="output.cross_section" mime-type="image/png" type="chart">
                     <facets>
+                        <facet name="cross_section_water_line" description="facet.cross_section_water_line"/>
                         <facet name="cross_section" description="facet.cross_section"/>
                     </facets>
                 </outputmode>
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu Sep 01 07:27:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu Sep 01 12:15:46 2011 +0000
@@ -1,5 +1,7 @@
 package de.intevation.flys.artifacts;
 
+import java.awt.geom.Point2D;
+
 import de.intevation.artifactdatabase.ProtocolUtils;
 
 import de.intevation.artifactdatabase.data.StateData;
@@ -39,6 +41,8 @@
 import de.intevation.flys.model.Gauge;
 import de.intevation.flys.model.River;
 import de.intevation.flys.model.CrossSection;
+import de.intevation.flys.model.CrossSectionLine;
+import de.intevation.flys.model.CrossSectionPoint;
 
 import de.intevation.flys.utils.DoubleUtil;
 import de.intevation.flys.utils.FLYSUtils;
@@ -57,6 +61,8 @@
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
+import de.intevation.flys.artifacts.charts.CrossSectionApp;
+
 /**
  * The default WINFO artifact.
  *
@@ -599,7 +605,13 @@
         return Segment.parseSegments(input);
     }
 
-    public List<CrossSection> getCrossSections() {
+
+    /**
+     * Get List of all cross-sections for current river.
+     *
+     * @return List of CrossSections for current river, null in case of error.
+     */
+    protected List<CrossSection> getCrossSections() {
         River river = FLYSUtils.getRiver(this);
         if (river == null) {
             logger.warn("No river in WINFO found");
@@ -610,6 +622,84 @@
 
 
     /**
+     * Get sorted, valid Points of a CrossSectionLine.
+     *
+     * @param line line of interest.
+     *
+     * @return list of points of CrossSectionLine, sorted.
+     */
+    protected List<Point2D> getCrossSectionLinesPoints(CrossSectionLine line) {
+        List<Point2D> points = new ArrayList<Point2D>(); 
+        List<CrossSectionPoint> linePoints = line.getPoints();
+        if (linePoints.isEmpty()) {
+            logger.info("No points in selected CrossSectionLine.");
+            return points;
+        }
+        Collections.sort(linePoints, CrossSectionApp.COL_POS_CMP);
+        for (CrossSectionPoint p: linePoints) {
+            double x = p.getX().doubleValue();
+            double y = p.getY().doubleValue();
+            if (CrossSectionApp.isValid(x) && CrossSectionApp.isValid(y)) {
+                points.add(new Point2D.Double(x,y));
+            }
+        }
+        return points;
+    }
+
+
+    /**
+     * Get points of Profile of cross section.
+     *
+     * @return an array holding coordinates of points of profile (
+     *         in the form {{x1, x2} {y1, y2}} ).
+     */
+    public double [][] getCrossSectionData() {
+        return getCrossSectionProfile(getCrossSections().get(0).getLines().get(0));
+    }
+
+
+    /**
+     * Get points of line describing the surface of water at cross section.
+     *
+     * @return an array holding coordinates of points of surface of water (
+     *         in the form {{x1, x2} {y1, y2}} ).
+     */
+
+    public double [][] getWaterLines() {
+        CrossSectionLine csl = getCrossSections().get(0).getLines().get(0);
+        List<Point2D> points = getCrossSectionLinesPoints(csl);
+        return CrossSectionApp.createWaterLines(points, 130);
+    }
+
+
+    /**
+     * Get points of CrossSection Line.
+     */
+    protected double [][] getCrossSectionProfile(CrossSectionLine csl) {
+        List<Point2D> points = getCrossSectionLinesPoints(csl);
+        double [] xs = new double[points.size()];
+        double [] ys = new double[points.size()];
+
+        if (points.isEmpty()) {
+            return new double [][] {xs, ys};
+        }
+
+        xs[0] = points.get(0).getX();
+        ys[0] = points.get(0).getY();
+
+        for (int i = 1; i < points.size(); i++) {
+            Point2D p = points.get(i);
+            xs[i] = p.getX();
+            if (xs[i] < xs[i-1]) {
+                xs[i] = xs[i-1] + CrossSectionApp.EPSILON;
+            }
+            ys[i] = p.getY(); 
+        }
+        return new double [][] { xs, ys };
+    }
+
+
+    /**
      * Returns the Qs for a number of Ws. This method makes use of
      * DischargeTables.getQForW().
      *
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java	Thu Sep 01 07:27:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java	Thu Sep 01 12:15:46 2011 +0000
@@ -64,7 +64,7 @@
 public class CrossSectionApp
 extends      ApplicationFrame
 {
-    public static final String RIVER = System.getProperty("river", "Mosel");
+    public static final String RIVER = System.getProperty("river", "Saar");
 
     public static final double EPSILON   = 1e-4;
 
@@ -75,6 +75,8 @@
         new Comparator<CrossSectionPoint>() {
             @Override
             public int compare(CrossSectionPoint a, CrossSectionPoint b) {
+                // TODO evaluate: isnt it enough to
+                // return (|d| > |EPS|) ? d : diff
                 double xa = a.getX().doubleValue();
                 double xb = b.getX().doubleValue();
                 double d = xa - xb;
@@ -312,7 +314,7 @@
         }
     }
 
-    protected XYDataset generateDataset(
+    public static XYDataset generateDataset(
         CrossSectionLine line,
         Double           waterlevel
     ) {
@@ -373,7 +375,7 @@
         return dataset;
     }
 
-    protected static double [][] createWaterLines(
+    public static double [][] createWaterLines(
         List<Point2D> points,
         double        waterlevel
     ) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java	Thu Sep 01 07:27:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionFacet.java	Thu Sep 01 12:15:46 2011 +0000
@@ -37,7 +37,7 @@
 
         WINFOArtifact winfo = (WINFOArtifact)artifact;
 
-        return winfo.getCrossSections();
+        return winfo.getCrossSectionData();
     }
 
     @Override 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java	Thu Sep 01 12:15:46 2011 +0000
@@ -0,0 +1,51 @@
+package de.intevation.flys.artifacts.model;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifactdatabase.state.DefaultFacet;
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.flys.artifacts.WINFOArtifact;
+
+import de.intevation.flys.artifacts.states.DefaultState.ComputeType;
+
+
+/**
+ * Facet for Waterlines in Cross Sections.
+ */
+public class CrossSectionWaterLineFacet
+extends      DefaultFacet
+implements   FacetTypes {
+
+    private static Logger logger = Logger.getLogger(CrossSectionWaterLineFacet.class);
+
+
+    /** Trivial constructor, set (maybe localized) description. */
+    public CrossSectionWaterLineFacet(String description) {
+        super(0, CROSS_SECTION_WATER_LINE, description);
+    }
+
+
+    /**
+     * Gets dummy data.
+     */
+    public Object getData(Artifact artifact, CallContext context) {
+        logger.debug("Get data for cross section water line");
+
+        WINFOArtifact winfo = (WINFOArtifact)artifact;
+
+        return winfo.getWaterLines();
+    }
+
+    @Override 
+    public Facet deepCopy() {
+        CrossSectionWaterLineFacet copy = new CrossSectionWaterLineFacet(this.description);
+        copy.set(this);
+        return copy;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
+
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Thu Sep 01 07:27:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Thu Sep 01 12:15:46 2011 +0000
@@ -19,6 +19,7 @@
     String COMPUTED_DISCHARGE_MAINVALUES_W = "computed_discharge_curve.mainvalues.w";
 
     String CROSS_SECTION = "cross_section";
+    String CROSS_SECTION_WATER_LINE = "cross_section_water_line";
 
     String DISCHARGE_CURVE = "discharge_curve.curve";
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java	Thu Sep 01 07:27:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java	Thu Sep 01 12:15:46 2011 +0000
@@ -17,6 +17,7 @@
 
 import de.intevation.flys.artifacts.model.DataFacet;
 import de.intevation.flys.artifacts.model.CrossSectionFacet;
+import de.intevation.flys.artifacts.model.CrossSectionWaterLineFacet;
 import de.intevation.flys.artifacts.model.CalculationResult;
 import de.intevation.artifactdatabase.state.DefaultFacet;
 
@@ -98,6 +99,7 @@
 
         // Also register the CrossSectionFacet (added to respective out).
         facets.add(new CrossSectionFacet("facet.cross_section"));
+        facets.add(new CrossSectionWaterLineFacet("facet.cross_section_water_line"));
         return res;
     }
 }
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Thu Sep 01 07:27:44 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java	Thu Sep 01 12:15:46 2011 +0000
@@ -171,6 +171,9 @@
         if (name.equals(CROSS_SECTION)) {
             doCrossSectionOut(f.getData(artifact, context), attr);
         }
+        else if (name.equals(CROSS_SECTION_WATER_LINE)) {
+            doCrossSectionWaterLineOut(f.getData(artifact, context), attr);
+        }
         else {
             logger.warn("CrossSection.doOut: Unknown facet name: " + name);
             return;
@@ -179,6 +182,24 @@
 
 
     /**
+     * Do cross sections waterline out.
+     *
+     * @param theme Theme for the data series.
+     */
+    protected void doCrossSectionWaterLineOut(Object o, Document theme) {
+        logger.debug("CrossSectionGenerator.doCrossSectionWaterLineOut");
+        XYSeries series = new StyledXYSeries("water", theme);
+
+        double[][] a = (double [][]) o;
+        double [] pxs = a[0];
+        for (int i = 0; i < pxs.length; i++) {
+            series.add (a[0][i], a[1][i]);
+        }
+        addFirstAxisSeries(series);
+    }
+
+
+    /**
      * Do cross sections out.
      *
      * @param theme Theme for the data series.
@@ -186,10 +207,13 @@
     protected void doCrossSectionOut(Object o, Document theme) {
         logger.debug("CrossSectionGenerator.doCrossSectionOut");
 
-        XYSeries series = new StyledXYSeries("bogus", theme);
-        // Add increadibly sophisticated values.
-        series.add(4, 4);
-        series.add(5, 14);
+        XYSeries series = new StyledXYSeries("aliquide", theme);
+
+        double[][] a = (double [][]) o;
+        double [] pxs = a[0];
+        for (int i = 0; i < pxs.length; i++) {
+            series.add (a[0][i], a[1][i]);
+        }
         addFirstAxisSeries(series);
     }
 

http://dive4elements.wald.intevation.org