changeset 635:acf3b49ec31f

Take the flow direction into account. flys-artifacts/trunk@2010 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 26 May 2011 14:27:06 +0000 (2011-05-26)
parents d8c47520c726
children 58276db49b16
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java
diffstat 5 files changed, 35 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu May 26 09:41:57 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu May 26 14:27:06 2011 +0000
@@ -1,3 +1,17 @@
+2011-05-26	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  Take the flow direction into account.
+
+	* src/main/java/de/intevation/flys/artifacts/states/DefaultState.java:
+	  Prevent NPE.
+
+	* src/main/java/de/intevation/flys/artifacts/states/RangeState.java:
+	  Allow to be 'from' greater than 'to' in ranges.
+
+	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Negate
+	  step if 'from' is greater than 'to'.
+
 2011-05-26	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Thu May 26 09:41:57 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Thu May 26 14:27:06 2011 +0000
@@ -930,6 +930,10 @@
 
         double [] values = new double[num];
 
+        if (from > to) {
+            step = -step;
+        }
+
         for (int idx = 0; idx < num; idx++) {
             values[idx] = Math.round(lower * precision)/precision;
             lower      += step;
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu May 26 09:41:57 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu May 26 14:27:06 2011 +0000
@@ -277,7 +277,7 @@
             throw new NullPointerException("No Wst found for selected river.");
         }
 
-        WQKms[] results = computeWaterlevelData(kms, qs, wst);
+        WQKms[] results = computeWaterlevelData(kms, qs, wst, river.getKmUp());
 
         // TODO Introduce a caching mechanism here!
 
@@ -315,8 +315,9 @@
     public static WQKms[] computeWaterlevelData(
         double[]      kms,
         double[]      qs,
-        WstValueTable wst)
-    {
+        WstValueTable wst,
+        boolean       up
+    ) {
         logger.info("WINFOArtifact.computeWaterlevelData");
 
         WQKms[] wqkms = new WQKms[qs.length];
@@ -326,7 +327,7 @@
         for (int i = 0; i < qs.length; i++) {
             double [] oqs = new double[kms.length];
             double [] ows = new double[kms.length];
-            int referenceIndex = 0; // TODO: Make depend on the flow direction
+            int referenceIndex = up ? 0 : kms.length-1; 
             WstValueTable.QPosition qPosition =
                 wst.interpolate(qs[i], referenceIndex, kms, ows, oqs);
             if (qPosition != null) {
@@ -511,6 +512,8 @@
             return new WQKms[0];
         }
 
+        boolean kmUp = river.getKmUp();
+
         WstValueTable wst = WstValueTableFactory.getTable(river);
         if (wst == null) {
             logger.error("No wst found for selected river.");
@@ -533,7 +536,7 @@
             }
             if (qs.length == 1) {
                 double [] kms = getKms(segments[0]);
-                return computeWaterlevelData(kms, qs, wst);
+                return computeWaterlevelData(kms, qs, wst, kmUp);
             }
         }
 
@@ -617,7 +620,9 @@
             double [] iqsi = iqs[i];
 
             QPosition qPosition = wst.interpolate(
-                iqsi[0], 0, boundKms, boundWs, boundQs);
+                iqsi[0],
+                kmUp ? 0 : boundKms.length-1,
+                boundKms, boundWs, boundQs);
 
             if (qPosition == null) {
                 logger.warn("interpolation failed for " + iqsi[i]);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java	Thu May 26 09:41:57 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java	Thu May 26 14:27:06 2011 +0000
@@ -160,8 +160,10 @@
             ui.appendChild(select);
 
             Element[] items = createItems(creator, artifact, name, context);
-            for (Element item: items) {
-                choices.appendChild(item);
+            if (items != null) {
+                for (Element item: items) {
+                    choices.appendChild(item);
+                }
             }
         }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java	Thu May 26 09:41:57 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java	Thu May 26 14:27:06 2011 +0000
@@ -44,9 +44,11 @@
                 "Invalid 'to'. " + to + " is bigger than " + toValid);
             throw new IllegalArgumentException("error_feed_to_out_of_range");
         }
+        /*
         else if (from > to) {
             throw new IllegalArgumentException("error_feed_from_bigger_to");
         }
+        */
 
         return true;
     }

http://dive4elements.wald.intevation.org