diff gnv-artifacts/src/main/java/de/intevation/gnv/math/XYColumn.java @ 434:0eed5749fd63

Implemented the raster interpolation for the 'Profilschnitt'. gnv-artifacts/trunk@482 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 23 Dec 2009 15:28:40 +0000
parents 828df3ddb758
children eb2ac62e853a
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/XYColumn.java	Wed Dec 23 12:20:25 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/XYColumn.java	Wed Dec 23 15:28:40 2009 +0000
@@ -24,7 +24,7 @@
 extends      Point2d
 implements   UnivariateRealFunction
 {
-    private static Logger log = Logger.getLogger(Interpolation2D.class);
+    private static Logger log = Logger.getLogger(XYColumn.class);
 
     protected List<HeightValue> values;
 
@@ -50,6 +50,11 @@
     public double value(double depth) {
         try {
             if (curve != null) {
+                HeightValue h = values.get(0);
+                // extrapolate beyond boundaries by repeating
+                if (depth > h.z) return h.v;
+                h = values.get(values.size()-1);
+                if (depth < h.z) return h.v;
                 return curve.value(depth);
             }
         }
@@ -60,7 +65,7 @@
         return Double.NaN;
     }
 
-    public void prepare(XYDepth xyDepth) {
+    public boolean prepare(XYDepth xyDepth) {
         int N = values.size();
         if (curve == null && N > 0) {
             if (N == 1) {
@@ -103,13 +108,16 @@
                     }
                     catch (MathException me) {
                         log.error("interpolation failed", me);
+                        return false;
                     }
                 }
             }
         }
         else {
             log.error("no points for interpolation");
+            return false;
         }
+        return true;
     }
 
     protected UnivariateRealInterpolator getInterpolator() {

http://dive4elements.wald.intevation.org