annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java @ 1141:f030acb8d999

dummy merge for repo head
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:15:18 +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
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 package de.intevation.gnv.math;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import com.vividsolutions.jts.geom.Coordinate;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import com.vividsolutions.jts.geom.Envelope;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
14 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
15
479
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
16 import java.awt.Dimension;
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
17
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
18 import java.io.Serializable;
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
19
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
20 import java.util.Arrays;
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
21 import java.util.List;
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
22
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 import org.apache.log4j.Logger;
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 /**
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
26 * 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
27 *
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
28 * @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
29 */
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 public class AreaInterpolation
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 implements Serializable
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 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
34
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
35 /**
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
36 * The generated raster.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
37 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 protected double [] raster;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
40 /**
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
41 * The width of the raster.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
42 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 protected int width;
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
44 /**
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
45 * The height of the raster.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
46 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 protected int height;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
49 /**
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
50 * Default constructor.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
51 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 public AreaInterpolation() {
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 width of the generated raster.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
57 * @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
58 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 public int getWidth() {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60 return width;
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 * 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
65 * @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
66 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 public int getHeight() {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 return height;
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 * The generated raster.
815
22c18083225e Removed compiler warnings while JavaDoc generation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 808
diff changeset
73 * @return the raster.
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
74 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 public double [] getRaster() {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 return raster;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
79 /**
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
80 * Epsilon for numerical stability.
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
81 */
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
82 public static final double EPS = 1e-6d;
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
83
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
84
808
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
85 /**
2e951160c43d Finished the javadoc of the math package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 801
diff changeset
86 * 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
87 * @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
88 * @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
89 * @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
90 * @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
91 * @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
92 * 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
93 * @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
94 */
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 public boolean interpolate(
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 List<? extends Point2d> points,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 Envelope boundingBox,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 Dimension samples,
593
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 528
diff changeset
99 XYDepth depth,
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 528
diff changeset
100 int extrapolationRounds
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 ) {
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
102 boolean debug = log.isDebugEnabled();
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
103
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 if (points == null || points.isEmpty()) {
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
105 log.warn("no points to interpolate");
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
106 return false;
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
517
96a1e92e7ed2 If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
109 List<GridCell> cells = GridCell.pointsToGridCells(
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 517
diff changeset
110 points,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 517
diff changeset
111 Interpolation2D.relevantArea(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 517
diff changeset
112 boundingBox,
593
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 528
diff changeset
113 points),
b248531fa20b Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 528
diff changeset
114 extrapolationRounds);
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
115
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
116 if (cells.isEmpty()) {
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
117 log.warn("no cells to interpolate");
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118 return false;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120
495
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
121 int W = samples.width;
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
122 int H = samples.height;
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
123
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
124 double cellWidth = boundingBox.getWidth() / W;
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
125 double cellHeight = boundingBox.getHeight() / H;
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
126
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
127 STRtree spatialIndex = new STRtree();
495
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
128
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
129 for (GridCell cell: cells) {
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
130 spatialIndex.insert(cell.getEnvelope(), cell);
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
132
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
133 if (debug) {
495
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
134 log.debug("width: " + boundingBox.getWidth());
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
135 log.debug("height: " + boundingBox.getHeight());
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
136 log.debug("sample width: " + W);
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
137 log.debug("sample height: " + H);
495
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
138 log.debug("cell width: " + cellWidth);
6e8364e766fa Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 482
diff changeset
139 log.debug("cell height: " + cellHeight);
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
140 }
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
141
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
142 Envelope queryBuffer = new Envelope();
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
143 Coordinate center = new Coordinate();
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
144 GridCell.CellFinder finder = new GridCell.CellFinder();
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
146 double [] raster = new double[W*H];
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147 Arrays.fill(raster, Double.NaN);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
149 double minX = boundingBox.getMinX();
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
150 double minY = boundingBox.getMinY();
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
151
501
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
152 long startTime = System.currentTimeMillis();
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
153
517
96a1e92e7ed2 If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
154 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
155 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
156
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
157 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
158 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
159
96a1e92e7ed2 If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
160 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
161
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
162 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
163 center.x = x; center.y = y;
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
164 finder.prepare(center);
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
165 spatialIndex.query(queryBuffer, finder);
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
167 GridCell found = finder.found;
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
168
517
96a1e92e7ed2 If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
169 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
170 continue;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
173 double z1 = Interpolation2D.interpolate(
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
174 found.p1.x, found.p1.z,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
175 found.p2.x, found.p2.z,
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 z2 = Interpolation2D.interpolate(
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
178 found.p3.x, found.p3.z,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
179 found.p4.x, found.p4.z,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
180 center.x);
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
181 double y1 = Interpolation2D.interpolate(
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
182 found.p1.x, found.p1.y,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
183 found.p2.x, found.p2.y,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
184 center.x);
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
185 double y2 = Interpolation2D.interpolate(
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
186 found.p3.x, found.p3.y,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
187 found.p4.x, found.p4.y,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
188 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
189 raster[pos] = Interpolation2D.interpolate(
514
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
190 y1, z1,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
191 y2, z2,
d9d933e06875 Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 501
diff changeset
192 center.y);
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
193 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
194 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
195
501
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
196 long stopTime = System.currentTimeMillis();
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
197
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
198 if (debug) {
801
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
199 log.debug("interpolation took: " +
d766fe2d917a More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 780
diff changeset
200 (stopTime - startTime)/1000f + " secs");
501
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
201 }
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 498
diff changeset
202
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
203 this.raster = raster;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
204 this.width = W;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
205 this.height = H;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
206
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
207 return true;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
208 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
209 }
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 815
diff changeset
210 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org