annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/XYColumn.java @ 1030:c07d9f9a738c

Removed bugs that existed in the caching mechanism (issue264, issue268). gnv-artifacts/trunk@1067 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 06 May 2010 08:32:56 +0000
parents 05bf8534a35a
children f953c9a559d8
rev   line source
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.math;
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import java.util.ArrayList;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 451
diff changeset
4 import java.util.Collections;
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import java.util.List;
779
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 451
diff changeset
6
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 451
diff changeset
7 import org.apache.commons.math.FunctionEvaluationException;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 451
diff changeset
8 import org.apache.commons.math.MathException;
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 451
diff changeset
9
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 451
diff changeset
10 import org.apache.commons.math.analysis.UnivariateRealFunction;
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
11
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
12 import org.apache.commons.math.analysis.interpolation.SplineInterpolator;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
13 import org.apache.commons.math.analysis.interpolation.UnivariateRealInterpolator;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
14
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
15 import org.apache.log4j.Logger;
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 /**
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
18 * A column of discrete attributed height values located at a point.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
19 * Values between the discrete height values are interpolated.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
20 *
780
c4156275c1e1 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 779
diff changeset
21 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
c4156275c1e1 Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 779
diff changeset
22 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 */
429
bed9735adf84 Finished preprocessing data for interpolation in verticalcrosssection charts.ß
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 427
diff changeset
24 public class XYColumn
431
422275fc9927 Refactored the XYColumn and Point2d code a bit to be more reusable in 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 429
diff changeset
25 extends Point2d
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
26 implements UnivariateRealFunction
429
bed9735adf84 Finished preprocessing data for interpolation in verticalcrosssection charts.ß
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 427
diff changeset
27 {
434
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
28 private static Logger log = Logger.getLogger(XYColumn.class);
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
29
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
30 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
31 * The list of discrete height values.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
32 */
432
6a70e8883307 Added some type safety. Fixed z value bug in reading database preprocessing. Only dissemble WKT points if really needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
33 protected List<HeightValue> values;
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
35 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
36 * The curve used to interpolate the points between the
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
37 * discrete height values.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
38 */
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
39 protected transient UnivariateRealFunction curve;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
40
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
41 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
42 * Default constructor.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
43 */
431
422275fc9927 Refactored the XYColumn and Point2d code a bit to be more reusable in 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 429
diff changeset
44 public XYColumn() {
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
45 values = new ArrayList<HeightValue>();
431
422275fc9927 Refactored the XYColumn and Point2d code a bit to be more reusable in 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 429
diff changeset
46 }
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
48 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
49 * Constructor to create an XYColumn with a given (x, y) coordinate
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
50 * and an (i, j) index tuple.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
51 * @param x The x coordinate.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
52 * @param y The y coordinate.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
53 * @param i The i component.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
54 * @param j The j component.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
55 */
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 public XYColumn(double x, double y, int i, int j) {
431
422275fc9927 Refactored the XYColumn and Point2d code a bit to be more reusable in 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 429
diff changeset
57 super(x, y, i, j);
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
58 values = new ArrayList<HeightValue>();
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 }
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
61 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
62 * Adds a given height value to the list of height values.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
63 * @param value The height value.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
64 */
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 public void add(HeightValue value) {
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 values.add(value);
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 }
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
69 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
70 * Returns the list of height values.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
71 * @return The list of height values.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
72 */
432
6a70e8883307 Added some type safety. Fixed z value bug in reading database preprocessing. Only dissemble WKT points if really needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
73 public List<HeightValue> getValues() {
6a70e8883307 Added some type safety. Fixed z value bug in reading database preprocessing. Only dissemble WKT points if really needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
74 return values;
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 }
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
76
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
77 public double value(double depth) {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
78 try {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
79 if (curve != null) {
434
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
80 HeightValue h = values.get(0);
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
81 // extrapolate beyond boundaries by repeating
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
82 if (depth > h.z) return h.v;
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
83 h = values.get(values.size()-1);
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
84 if (depth < h.z) return h.v;
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
85 return curve.value(depth);
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
86 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
87 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
88 catch (FunctionEvaluationException fee) {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
89 log.error("evaluation failed", fee);
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
90 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
91
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
92 return Double.NaN;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
93 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
94
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
95 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
96 * Prepares this XYColumn to be queried. A given XYDepth
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
97 * object is used to fill the values to a certain depth.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
98 * @param xyDepth To figure out the depth a the cordinate.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
99 * @return true if preparation succeeds else false.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
100 */
434
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
101 public boolean prepare(XYDepth xyDepth) {
445
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 440
diff changeset
102 if (curve == null) {
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 448
diff changeset
103 int N = values.size();
445
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 440
diff changeset
104 if (N == 0) {
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 440
diff changeset
105 log.error("no points for interpolation");
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 440
diff changeset
106 return false;
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 440
diff changeset
107 }
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 440
diff changeset
108
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
109 if (N == 1) {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
110 // only one value -> constant function
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
111 curve = new ConstantFunction(values.get(0).v);
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
112 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
113 else { // more than on value
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
114 double depth = xyDepth.depth(this);
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
115 Collections.sort(values, HeightValue.INV_Z_COMPARATOR);
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
116
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
117 // if there is no value at 0 repeat first value
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
118 HeightValue first = values.get(0);
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
119 if (first.z < 0d) {
448
3cb2bea50456 Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 445
diff changeset
120 values.add(0, new HeightValue(0d, first.v, first.k-1));
445
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 440
diff changeset
121 ++N;
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
122 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
123
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
124 // if there is no value at depth repeat last value
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
125 HeightValue last = values.get(N-1);
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
126 if (last.z > depth) {
448
3cb2bea50456 Generate iso line classes according gnv-issues/issue108
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 445
diff changeset
127 values.add(new HeightValue(depth, last.v, last.k+1));
445
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 440
diff changeset
128 ++N;
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
129 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
130 if (N < 3) { // interpolate linear
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
131 first = values.get(0);
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
132 last = values.get(N-1);
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
133 curve = new LinearFunction.Univariate(
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
134 first.z, first.v,
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
135 last.z, last.v);
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
136 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
137 else { // higher degree interpolation
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
138 double [] z = new double[N];
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
139 double [] v = new double[N];
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
140 for (int i = 0; i < N; ++i) {
445
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 440
diff changeset
141 HeightValue h = values.get(N-1-i);
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
142 z[i] = h.z;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
143 v[i] = h.v;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
144 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
145 try {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
146 curve = getInterpolator().interpolate(z, v);
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
147 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
148 catch (MathException me) {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
149 log.error("interpolation failed", me);
434
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
150 return false;
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
151 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
152 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
153 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
154 }
434
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
155 return true;
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
156 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
157
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
158 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
159 * Returns the interpolator used to interpolate the values between
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
160 * the discrete height values. This class returns an instance of
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
161 * {@link org.apache.commons.math.analysis.interpolation.SplineInterpolator}.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
162 * Override this if you want to use another kind of interpolation.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
163 * @return The interpolator to be used.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
164 */
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
165 protected UnivariateRealInterpolator getInterpolator() {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
166 return new SplineInterpolator();
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
167 }
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
168 }
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 807
diff changeset
169 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org