changeset 1139:6d9b08b958e2

Fix waterline in crosssection diagram. flys-artifacts/trunk@2660 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 07 Sep 2011 09:24:32 +0000 (2011-09-07)
parents d90f5bfa3ddf
children 96d7842e80ee
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java
diffstat 2 files changed, 69 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Sep 07 07:48:03 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Sep 07 09:24:32 2011 +0000
@@ -1,3 +1,13 @@
+2011-09-07  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	Fix waterline "calculation" at given km. Chosen approach is
+	"head-through-wall".
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  Some refactoring to do the same calculation twice easier and be able
+	  to "cross" waterline against correct profile data.
+
+
 2011-09-07  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	Fix setting of kilometer for profile (not yet waterlevel) of cross section
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Sep 07 07:48:03 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Sep 07 09:24:32 2011 +0000
@@ -649,13 +649,12 @@
 
 
     /**
-     * Get points of Profile of cross section.
+     * Get CrossSectionLine spatially closest to what is specified in the data
+     * "cross_section.km".
      *
-     * @return an array holding coordinates of points of profile (
-     *         in the form {{x1, x2} {y1, y2}} ).
+     * @return CrossSectionLine closest to "cross_section.km".
      */
-    public double [][] getCrossSectionData() {
-        logger.info("getCrossSectionData(), also cross_section.km " + getDataAsString("cross_section.km"));
+    protected CrossSectionLine searchCrossSectionKmLine() {
         double wishKM = 0.0f;
         try {
             wishKM = Double.parseDouble(getDataAsString("cross_section.km"));
@@ -665,7 +664,6 @@
         }
 
         // Get the cross section closest to requested km.
-        //
         // Naive, linear approach.
         List<CrossSectionLine> crossSectionLines =
             getCrossSections().get(0).getLines();
@@ -679,7 +677,21 @@
             oldDiff = diff;
             oldLine = line;
         }
-        return getCrossSectionProfile(oldLine);
+        return oldLine;
+    }
+
+
+    /**
+     * 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() {
+        logger.info("getCrossSectionData() for cross_section.km "
+            + getDataAsString("cross_section.km"));
+        CrossSectionLine line = searchCrossSectionKmLine();
+        return getCrossSectionProfile(line);
     }
 
 
@@ -689,11 +701,47 @@
      * @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);
+        logger.debug("getWaterLines()");
+        CrossSectionLine csl = searchCrossSectionKmLine();
         List<Point2D> points = getCrossSectionLinesPoints(csl);
-        return CrossSectionApp.createWaterLines(points, 130);
+        // Need W at km
+        WQKms [] wqkms = (WQKms[]) getWaterlevelData().getData();
+        if (wqkms.length == 0) {
+            logger.error("No WQKms found.");
+            return CrossSectionApp.createWaterLines(points, 0.0f);
+        }
+        else
+        {
+            if (wqkms.length > 1) {
+                logger.warn("More than one wqkms found, taking first one.");
+            }
+            // Find W at km, linear naive approach.
+            WQKms triple = wqkms[0];
+            // Find index of km.
+            double wishKM = 0.0f;
+            int old_idx = 0;
+            try {
+                wishKM = Double.parseDouble(getDataAsString("cross_section.km"));
+            }
+            catch (Exception e) {
+                ;
+            }
+
+            // Linear seach in WQKms for closest km.
+            double old_dist_wish = Math.abs(wishKM - triple.getKm(0));
+
+            for (int i = 0; i < triple.size(); i++) {
+                double diff = Math.abs(wishKM - triple.getKm(i));
+                if (diff > old_dist_wish) {
+                    return CrossSectionApp.createWaterLines(points,
+                        triple.getW(i));
+                }
+                old_dist_wish = diff;
+            }
+            return CrossSectionApp.createWaterLines(points,
+                triple.getW(triple.size()-1));
+        }
     }
 
 
@@ -1066,7 +1114,7 @@
         StateData dMode   = getData("wq_mode");
         StateData dSingle = getData("wq_single");
 
-        String mode = dMode != null ? (String) dMode.getValue() : "";
+        String mode = (dMode != null) ? (String) dMode.getValue() : "";
 
         if (mode.equals("W")) {
             if (dSingle != null) {

http://dive4elements.wald.intevation.org