annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/XYColumn.java @ 1119:7c4f81f74c47

merged gnv-artifacts
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:00 +0200
parents f953c9a559d8
children
rev   line source
1115
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
1 /*
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
2 * Copyright (c) 2010 by Intevation GmbH
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
3 *
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
4 * This program is free software under the LGPL (>=v2.1)
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
5 * Read the file LGPL.txt coming with the software for details
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
6 * or visit http://www.gnu.org/licenses/ if it does not exist.
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
7 */
f953c9a559d8 Added license file and license headers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 836
diff changeset
8
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 package de.intevation.gnv.math;
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 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
12 import java.util.Collections;
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 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
14
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 451
diff changeset
15 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
16 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
17
b1f5f2a8840f Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 451
diff changeset
18 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
19
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
20 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
21 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
22
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
23 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
24
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 /**
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
26 * 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
27 * 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
28 *
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
29 * @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
30 * @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
31 */
429
bed9735adf84 Finished preprocessing data for interpolation in verticalcrosssection charts.ß
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 427
diff changeset
32 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
33 extends Point2d
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
34 implements UnivariateRealFunction
429
bed9735adf84 Finished preprocessing data for interpolation in verticalcrosssection charts.ß
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 427
diff changeset
35 {
434
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
36 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
37
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
38 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
39 * The list of discrete height values.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
40 */
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
41 protected List<HeightValue> values;
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
43 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
44 * 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
45 * discrete height values.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
46 */
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
47 protected transient UnivariateRealFunction curve;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
48
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
49 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
50 * Default constructor.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
51 */
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
52 public XYColumn() {
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
53 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
54 }
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
56 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
57 * 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
58 * and an (i, j) index tuple.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
59 * @param x The x coordinate.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
60 * @param y The y coordinate.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
61 * @param i The i component.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
62 * @param j The j component.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
63 */
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 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
65 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
66 values = new ArrayList<HeightValue>();
427
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 * 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
71 * @param value The height value.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
72 */
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 public void add(HeightValue value) {
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 values.add(value);
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 }
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
77 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
78 * Returns the list of height values.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
79 * @return The list of height values.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
80 */
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
81 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
82 return values;
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 }
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
84
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
85 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
86 try {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
87 if (curve != null) {
434
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
88 HeightValue h = values.get(0);
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
89 // extrapolate beyond boundaries by repeating
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
90 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
91 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
92 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
93 return curve.value(depth);
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
94 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
95 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
96 catch (FunctionEvaluationException fee) {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
97 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
98 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
99
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
100 return Double.NaN;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
101 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
102
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
103 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
104 * 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
105 * 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
106 * @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
107 * @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
108 */
434
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
109 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
110 if (curve == null) {
451
bc5901bb4525 Use JFreeCharts ValueAxis.valueToJava2D() to transform data values
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 448
diff changeset
111 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
112 if (N == 0) {
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 440
diff changeset
113 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
114 return false;
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 440
diff changeset
115 }
f42ed4f10b79 Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 440
diff changeset
116
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
117 if (N == 1) {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
118 // 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
119 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
120 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
121 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
122 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
123 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
124
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
125 // 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
126 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
127 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
128 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
129 ++N;
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
130 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
131
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
132 // 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
133 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
134 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
135 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
136 ++N;
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
137 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
138 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
139 first = values.get(0);
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
140 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
141 curve = new LinearFunction.Univariate(
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
142 first.z, first.v,
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
143 last.z, last.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 else { // higher degree interpolation
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
146 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
147 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
148 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
149 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
150 z[i] = h.z;
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
151 v[i] = h.v;
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 try {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
154 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
155 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
156 catch (MathException me) {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
157 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
158 return false;
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
159 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
160 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
161 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
162 }
434
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 433
diff changeset
163 return true;
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
164 }
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
165
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
166 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
167 * 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
168 * 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
169 * {@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
170 * 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
171 * @return The interpolator to be used.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
172 */
433
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
173 protected UnivariateRealInterpolator getInterpolator() {
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
174 return new SplineInterpolator();
828df3ddb758 Added interpolation capabilities along z axis to XYColumns.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 432
diff changeset
175 }
427
a95aaeb206f7 Added data model classes to store information for interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 }
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 807
diff changeset
177 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org