diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java @ 3892:1dc658c3306b

Fix issue886 (no extrapolation of waterlines). flys-artifacts/trunk@5547 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 21 Sep 2012 09:22:51 +0000
parents c0a15547ad76
children e1f81795401f
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Fri Sep 21 07:50:26 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Fri Sep 21 09:22:51 2012 +0000
@@ -647,18 +647,28 @@
         // Find W at km, linear naive approach.
         WQKms triple = wqkms[idx];
 
-        int old_idx = 0;
-
         if (triple.size() == 0) {
             logger.warn("Calculation of waterline is empty.");
             return Lines.createWaterLines(points, 0.0f);
         }
 
+        // Early abort if we would need to extrapolate.
+        int T = triple.size();
+        double max_km = triple.getKm(T-1), min_km = triple.getKm(0);
+        if (wishKM < min_km || wishKM > max_km) {
+            // TODO Does this have to be done in the other WaterlineArtifact
+            //      implementations, too?
+            logger.warn("Will not extrapolate waterlevels.");
+            return Lines.createWaterLines(points, 0.0f);
+        }
+
+        int old_idx = 0;
+
         // Linear seach in WQKms for closest km.
         double old_dist_wish = Math.abs(wishKM - triple.getKm(0));
         double last_w = triple.getW(0);
 
-        for (int i = 0, T = triple.size(); i < T; i++) {
+        for (int i = 0; i < T; i++) {
             double diff = Math.abs(wishKM - triple.getKm(i));
             if (diff > old_dist_wish) {
                 break;

http://dive4elements.wald.intevation.org