changeset 3124:555ed85af32e

fix issue680; hack. flys-artifacts/trunk@4725 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 20 Jun 2012 12:46:31 +0000
parents edf629d43f05
children 070b76fbae46
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java
diffstat 3 files changed, 58 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Jun 20 12:27:10 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jun 20 12:46:31 2012 +0000
@@ -1,3 +1,14 @@
+2012-06-20	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	Avoid problems with corrected Ws in cross-sections; hacky solution,
+	issue680.
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java
+	  (waterLineC): New, get corrected W.
+
+	* src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java:
+	  Create C-facet with other index.
+
 2012-06-20	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Jun 20 12:27:10 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Wed Jun 20 12:46:31 2012 +0000
@@ -34,6 +34,7 @@
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.MainValuesFactory;
 import de.intevation.flys.artifacts.model.Segment;
+import de.intevation.flys.artifacts.model.WQCKms;
 import de.intevation.flys.artifacts.model.WQKms;
 import de.intevation.flys.artifacts.model.WW;
 import de.intevation.flys.artifacts.model.WstValueTable;
@@ -720,6 +721,45 @@
 
 
     /**
+     * Get corrected waterline against surface/profile.
+     */
+    public Lines.LineData waterLineC(int idx, FastCrossSectionLine csl) {
+        List<Point2D> points = csl.getPoints();
+
+        WQKms[] wqckms = (WQKms[])
+            getDischargeLongitudinalSectionData().getData();
+
+        // Find index of km.
+        double wishKM = csl.getKm();
+
+        // Find W/C at km, linear naive approach.
+        WQCKms triple = (WQCKms) wqckms[idx-1];
+
+        int old_idx = 0;
+
+        if (triple.size() == 0) {
+            logger.warn("Calculation of c/waterline is empty.");
+            return Lines.createWaterLines(points, 0.0f);
+        }
+
+        // Linear seach in WQKms for closest km.
+        double old_dist_wish = Math.abs(wishKM - triple.getKm(0));
+        double last_c = triple.getC(0);
+
+        for (int i = 0, T = triple.size(); i < T; i++) {
+            double diff = Math.abs(wishKM - triple.getKm(i));
+            if (diff > old_dist_wish) {
+                break;
+            }
+            last_c = triple.getC(i);
+            old_dist_wish = diff;
+        }
+
+        return Lines.createWaterLines(points, last_c);
+    }
+
+
+    /**
      * Get points of line describing the surface of water at cross section.
      *
      * @param idx Index for getWaterlevelData.
@@ -744,13 +784,15 @@
         if (wqkms.length <= idx) {
             logger.error("getWaterLines() requested index ("
                          + idx + " not found.");
+            return waterLineC(idx, csl);
         }
 
+        // Find index of km.
+        double wishKM = csl.getKm();
+
         // Find W at km, linear naive approach.
         WQKms triple = wqkms[idx];
 
-        // Find index of km.
-        double wishKM = csl.getKm();
         int old_idx = 0;
 
         if (triple.size() == 0) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java	Wed Jun 20 12:27:10 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java	Wed Jun 20 12:46:31 2012 +0000
@@ -93,7 +93,9 @@
                 Facet c = new WaterlevelFacet(
                     i, DISCHARGE_LONGITUDINAL_C, nameC);
 
-                Facet r = new CrossSectionWaterLineFacet(i, nameC);
+                // Here, avoid index clash with Facet "s" above and
+                // signal the WINFO later that we want to access Cs.
+                Facet r = new CrossSectionWaterLineFacet(i + 1, nameC);
 
                 facets.add(c);
                 facets.add(r);

http://dive4elements.wald.intevation.org