comparison 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
comparison
equal deleted inserted replaced
433:828df3ddb758 434:0eed5749fd63
22 */ 22 */
23 public class XYColumn 23 public class XYColumn
24 extends Point2d 24 extends Point2d
25 implements UnivariateRealFunction 25 implements UnivariateRealFunction
26 { 26 {
27 private static Logger log = Logger.getLogger(Interpolation2D.class); 27 private static Logger log = Logger.getLogger(XYColumn.class);
28 28
29 protected List<HeightValue> values; 29 protected List<HeightValue> values;
30 30
31 protected transient UnivariateRealFunction curve; 31 protected transient UnivariateRealFunction curve;
32 32
48 } 48 }
49 49
50 public double value(double depth) { 50 public double value(double depth) {
51 try { 51 try {
52 if (curve != null) { 52 if (curve != null) {
53 HeightValue h = values.get(0);
54 // extrapolate beyond boundaries by repeating
55 if (depth > h.z) return h.v;
56 h = values.get(values.size()-1);
57 if (depth < h.z) return h.v;
53 return curve.value(depth); 58 return curve.value(depth);
54 } 59 }
55 } 60 }
56 catch (FunctionEvaluationException fee) { 61 catch (FunctionEvaluationException fee) {
57 log.error("evaluation failed", fee); 62 log.error("evaluation failed", fee);
58 } 63 }
59 64
60 return Double.NaN; 65 return Double.NaN;
61 } 66 }
62 67
63 public void prepare(XYDepth xyDepth) { 68 public boolean prepare(XYDepth xyDepth) {
64 int N = values.size(); 69 int N = values.size();
65 if (curve == null && N > 0) { 70 if (curve == null && N > 0) {
66 if (N == 1) { 71 if (N == 1) {
67 // only one value -> constant function 72 // only one value -> constant function
68 curve = new ConstantFunction(values.get(0).v); 73 curve = new ConstantFunction(values.get(0).v);
101 try { 106 try {
102 curve = getInterpolator().interpolate(z, v); 107 curve = getInterpolator().interpolate(z, v);
103 } 108 }
104 catch (MathException me) { 109 catch (MathException me) {
105 log.error("interpolation failed", me); 110 log.error("interpolation failed", me);
111 return false;
106 } 112 }
107 } 113 }
108 } 114 }
109 } 115 }
110 else { 116 else {
111 log.error("no points for interpolation"); 117 log.error("no points for interpolation");
118 return false;
112 } 119 }
120 return true;
113 } 121 }
114 122
115 protected UnivariateRealInterpolator getInterpolator() { 123 protected UnivariateRealInterpolator getInterpolator() {
116 return new SplineInterpolator(); 124 return new SplineInterpolator();
117 } 125 }

http://dive4elements.wald.intevation.org