annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java @ 809:d05b17a4f3d0

Added javadoc in describedata package. gnv-artifacts/trunk@891 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 09 Apr 2010 07:27:38 +0000
parents 2e951160c43d
children 22c18083225e
rev   line source
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.math;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import com.vividsolutions.jts.geom.Coordinate;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import com.vividsolutions.jts.geom.Envelope;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
6 import com.vividsolutions.jts.index.strtree.STRtree;
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
479
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
8 import java.awt.Dimension;
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
9
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
10 import java.io.Serializable;
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
11
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
12 import java.util.Arrays;
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
13 import java.util.List;
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
14
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import org.apache.log4j.Logger;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 /**
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
18 * Does an area interpolation for "Horizontalschnitte".
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
19 *
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
20 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 */
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 public class AreaInterpolation
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 implements Serializable
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 private static Logger log = Logger.getLogger(AreaInterpolation.class);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
27 /**
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
28 * The generated raster.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
29 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 protected double [] raster;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
32 /**
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
33 * The width of the raster.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
34 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 protected int width;
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
36 /**
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
37 * The height of the raster.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
38 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 protected int height;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
41 /**
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
42 * Default constructor.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
43 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 public AreaInterpolation() {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
47 /**
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
48 * Returns the width of the generated raster.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
49 * @return the width of the raster.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
50 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 public int getWidth() {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 return width;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
55 /**
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
56 * Returns the height of the raster.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
57 * @return The height of the raster.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
58 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 public int getHeight() {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 return height;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
63 /**
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
64 * The generated raster.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
65 * @return
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
66 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 public double [] getRaster() {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 return raster;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
71 /**
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
72 * Epsilon for numerical stability.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
73 */
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
74 public static final double EPS = 1e-6d;
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
75
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
76
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
77 /**
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
78 * Fills a raster by interpolating the input values.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
79 * @param points The attributed input values.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
80 * @param boundingBox The world area where to interpolate.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
81 * @param samples The width and height of the raster.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
82 * @param depth The callback to query the depth at a given point.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
83 * @param extrapolationRounds Number of extrapolation point layers
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
84 * to generate before doing the interpolation.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
85 * @return true if the interpolation succeeds else false.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
86 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 public boolean interpolate(
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 List<? extends Point2d> points,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 Envelope boundingBox,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 Dimension samples,
593
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 528
diff changeset
91 XYDepth depth,
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 528
diff changeset
92 int extrapolationRounds
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 ) {
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
94 boolean debug = log.isDebugEnabled();
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
95
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 if (points == null || points.isEmpty()) {
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
97 log.warn("no points to interpolate");
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
98 return false;
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
99 }
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
100
517
96a1e92e7ed2 If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
101 List<GridCell> cells = GridCell.pointsToGridCells(
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 517
diff changeset
102 points,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 517
diff changeset
103 Interpolation2D.relevantArea(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 517
diff changeset
104 boundingBox,
593
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 528
diff changeset
105 points),
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 528
diff changeset
106 extrapolationRounds);
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
107
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
108 if (cells.isEmpty()) {
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
109 log.warn("no cells to interpolate");
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 return false;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112
495
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
113 int W = samples.width;
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
114 int H = samples.height;
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
115
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
116 double cellWidth = boundingBox.getWidth() / W;
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
117 double cellHeight = boundingBox.getHeight() / H;
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
118
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
119 STRtree spatialIndex = new STRtree();
495
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
120
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
121 for (GridCell cell: cells) {
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
122 spatialIndex.insert(cell.getEnvelope(), cell);
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
125 if (debug) {
495
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
126 log.debug("width: " + boundingBox.getWidth());
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
127 log.debug("height: " + boundingBox.getHeight());
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
128 log.debug("sample width: " + W);
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
129 log.debug("sample height: " + H);
495
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
130 log.debug("cell width: " + cellWidth);
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
131 log.debug("cell height: " + cellHeight);
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
132 }
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
133
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
134 Envelope queryBuffer = new Envelope();
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
135 Coordinate center = new Coordinate();
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
136 GridCell.CellFinder finder = new GridCell.CellFinder();
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138 double [] raster = new double[W*H];
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139 Arrays.fill(raster, Double.NaN);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
141 double minX = boundingBox.getMinX();
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
142 double minY = boundingBox.getMinY();
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
143
501
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
144 long startTime = System.currentTimeMillis();
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
145
517
96a1e92e7ed2 If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
146 int pos = 0;
96a1e92e7ed2 If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
147 for (int j = 0; j < H; ++j) {
96a1e92e7ed2 If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
148
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
149 double y = j*cellHeight + 0.5d*cellHeight + minY;
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
150 double x = 0.5d*cellWidth + minX;
517
96a1e92e7ed2 If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
151
96a1e92e7ed2 If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
152 for (int end = pos + W; pos < end; ++pos, x += cellWidth) {
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
154 queryBuffer.init(x - EPS, x + EPS, y - EPS, y + EPS);
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
155 center.x = x; center.y = y;
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
156 finder.prepare(center);
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
157 spatialIndex.query(queryBuffer, finder);
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
159 GridCell found = finder.found;
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
160
517
96a1e92e7ed2 If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
161 if (found == null || depth.depth(center) > 0d) {
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 continue;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
165 double z1 = Interpolation2D.interpolate(
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
166 found.p1.x, found.p1.z,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
167 found.p2.x, found.p2.z,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
168 center.x);
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
169 double z2 = Interpolation2D.interpolate(
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
170 found.p3.x, found.p3.z,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
171 found.p4.x, found.p4.z,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
172 center.x);
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
173 double y1 = Interpolation2D.interpolate(
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
174 found.p1.x, found.p1.y,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
175 found.p2.x, found.p2.y,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
176 center.x);
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
177 double y2 = Interpolation2D.interpolate(
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
178 found.p3.x, found.p3.y,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
179 found.p4.x, found.p4.y,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
180 center.x);
517
96a1e92e7ed2 If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
181 raster[pos] = Interpolation2D.interpolate(
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
182 y1, z1,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
183 y2, z2,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
184 center.y);
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187
501
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
188 long stopTime = System.currentTimeMillis();
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
189
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
190 if (debug) {
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
191 log.debug("interpolation took: " +
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
192 (stopTime - startTime)/1000f + " secs");
501
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
193 }
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
194
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
195 this.raster = raster;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196 this.width = W;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197 this.height = H;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
198
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
199 return true;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
200 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
201 }
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
202 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org