diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 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
parents 05e4ef0f9489
children 65d8b3340397
line wrap: on
line diff
--- 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().
      *

http://dive4elements.wald.intevation.org