annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/Interpolation2D.java @ 850:39d06d01825a

Finalized the odv export of a 'Profilschnitt' (issue217). gnv-artifacts/trunk@966 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 21 Apr 2010 12:34:44 +0000
parents 05bf8534a35a
children f953c9a559d8
rev   line source
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.math;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import com.vividsolutions.jts.geom.Coordinate;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import com.vividsolutions.jts.geom.Envelope;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
6 import com.vividsolutions.jts.index.strtree.STRtree;
501
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
7
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
8 import java.util.List;
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
9
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
10 import org.apache.log4j.Logger;
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
11
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 /**
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
13 * Interpolates along a given line string. This used to generate
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
14 * "horizontale Schnittprofile".
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
15 *
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
16 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 */
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 public final class Interpolation2D
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 {
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
20 private static Logger log = Logger.getLogger(Interpolation2D.class);
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
21
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
22 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
23 * If the number of input points are over this threshold
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
24 * some culling strategies are applied to reduce the amount of points.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
25 */
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
26 public static final int CULL_POINT_THRESHOLD = Integer.getInteger(
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
27 "gnv.interpolation2d.cull.point.threshold", 1000);
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
28
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
29 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
30 * Numerical stability epsilon.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
31 */
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
32 public static final double EPS = 1e-6d;
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
33
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
34 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
35 * Callback to send the interpolated values back to the
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
36 * caller without building large temporary strcutures.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
37 */
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 public interface Consumer {
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
39 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
40 * Sends an interpolated point back to the called.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
41 * The interpolated parameter is stored in the z component.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
42 * @param point The interpolated point.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
43 * @param success true if interpolation at the point
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
44 * succeed, else false.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
45 */
416
04a242c67fe6 Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 366
diff changeset
46 void interpolated(Coordinate point, boolean success);
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 } // interface Consumer
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 private Interpolation2D() {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
52 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
53 * Calculates the relevant area for a given line string.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
54 * @param path The line string.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
55 * @param points The sample points.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
56 * @return The relevant area.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
57 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
58 public static final Envelope relevantArea(
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
59 List<? extends Coordinate> path,
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
60 List<? extends Coordinate> points
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
61 ) {
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
62 return relevantArea(path, points, CULL_POINT_THRESHOLD);
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
63 }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
64
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
65 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
66 * Calculates the relevant area for a given bounding box.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
67 * @param pathBBox The bounding box.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
68 * @param points The sample points.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
69 * @return The relevant area.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
70 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
71 public static final Envelope relevantArea(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
72 Envelope pathBBox,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
73 List<? extends Coordinate> points
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
74 ) {
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
75 return relevantArea(pathBBox, points, CULL_POINT_THRESHOLD);
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
76 }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
77
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
78 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
79 * Calculates the relevant area for a given bounding box.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
80 * @param pathBBox The bounding box.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
81 * @param points The sample points.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
82 * @param threshold If the number of sample points
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
83 * are below this threshold no relevant area is calculated.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
84 * @return The relevant area.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
85 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
86 public static final Envelope relevantArea(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
87 Envelope pathBBox,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
88 List<? extends Coordinate> points,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
89 int threshold
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
90 ) {
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
91 return points.size() < threshold
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
92 ? null
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
93 : relevantArea(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
94 pathBBox,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
95 pointsBoundingBox(points));
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
96 }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
97
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
98 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
99 * Calculates the relevant area for a given line string.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
100 * @param path The line string.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
101 * @param points The sample points.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
102 * @param threshold If the number of sample points
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
103 * are below this threshold no relevant area is calculated.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
104 * @return The relevant area.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
105 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
106 public static final Envelope relevantArea(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
107 List<? extends Coordinate> path,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
108 List<? extends Coordinate> points,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
109 int threshold
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
110 ) {
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
111 return points.size() < threshold || path.isEmpty()
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
112 ? null
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
113 : relevantArea(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
114 pointsBoundingBox(path),
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
115 pointsBoundingBox(points));
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
116 }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
117
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
118 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
119 * Heuristic function to define a 'relevant area'.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
120 * @param pathBBox The bounding box of the line line string.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
121 * @param pointsBBox The bounding box of the sample points.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
122 * @return The relevant area.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
123 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
124 public static final Envelope relevantArea(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
125 Envelope pathBBox,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
126 Envelope pointsBBox
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
127 ) {
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
128 double pathArea = pathBBox.getWidth()*pathBBox.getHeight();
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
129 double pointsArea = pointsBBox.getWidth()*pointsBBox.getHeight();
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
130
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
131 if (pathArea > 0.8d*pointsArea) { return null; }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
132
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
133 double nArea = 1.44d * pathArea;
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
134 if (nArea < 0.1d*pointsArea) nArea = 0.1d*pointsArea;
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
135 double w = pathBBox.getWidth();
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
136 double h = pathBBox.getHeight();
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
137 double [] d = solveQuadratic(1d, w+h, pathArea - nArea);
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
138
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
139 if (d == null) { return null; }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
140
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
141 double extra = pos(d);
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
142
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
143 pathBBox.expandBy(extra);
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
144
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
145 return pathBBox;
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
146 }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
147
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
148 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
149 * Solves quadratic equation a*x*x + b*x + c = 0.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
150 * @param a a-coefficent.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
151 * @param b b-coefficent
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
152 * @param c c-coefficent.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
153 * @return the solution of the equation, or null if not solvable.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
154 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
155 public static final double [] solveQuadratic(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
156 double a, double b, double c
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
157 ) {
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
158 double d = b*b - 4d*a*c;
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
159 if (d < 0d) { return null; }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
160
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
161 d = Math.sqrt(d);
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
162 a = 1d/(2d*a);
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
163 b = -b;
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
164
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
165 return new double [] { a*(b + d), a*(b - d) };
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
166 }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
167
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
168 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
169 * Return the element of a two element array which
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
170 * is greater or equal zero.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
171 * @param x The two values.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
172 * @return The value which is greater or equal zero.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
173 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
174 public static final double pos(double [] x) {
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
175 return x[0] >= 0 ? x[0] : x[1];
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
176 }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
177
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
178
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
179 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
180 * Calculates the bounding box of a given line string.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
181 * @param path The line string.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
182 * @return The bounding box.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
183 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
184 public static Envelope pointsBoundingBox(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
185 List<? extends Coordinate> path
501
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
186 ) {
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
187 int N = path.size();
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
188 Envelope area = new Envelope(path.get(N-1));
501
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
189
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
190 for (int i = N-2; i >= 0; --i) {
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
191 area.expandToInclude(path.get(i));
501
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
192 }
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
193
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
194 return area;
431
422275fc9927 Refactored the XYColumn and Point2d code a bit to be more reusable in 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 416
diff changeset
195 }
422275fc9927 Refactored the XYColumn and Point2d code a bit to be more reusable in 3D.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 416
diff changeset
196
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
197 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
198 * Interpolates linearly a number of coordinates and parameter values along
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
199 * a given line string path. The results are issued to a consumer.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
200 * @param path The line string path.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
201 * @param points The sample points.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
202 * @param from Start point as a scalar value linear
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
203 * referenced on the line string.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
204 * @param to End point of as a scalar value linear
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
205 * referenced on the line string.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
206 * @param steps Number of points to be interpolated.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
207 * @param metrics The used metric.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
208 * @param consumer The callback to retrieve the result points.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
209 */
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
210 public static void interpolate(
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
211 List<? extends Coordinate> path,
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
212 List<? extends Point2d> points,
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
213 double from,
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
214 double to,
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
215 int steps,
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
216 Metrics metrics,
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
217 Consumer consumer
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
218 ) {
434
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
219 boolean debug = log.isDebugEnabled();
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
220
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
221 int N = path.size();
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
222 int M = points.size();
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
223
434
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
224 if (debug) {
416
04a242c67fe6 Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 366
diff changeset
225 log.debug("Size of path: " + N);
04a242c67fe6 Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 366
diff changeset
226 log.debug("Size of points: " + M);
04a242c67fe6 Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 366
diff changeset
227 }
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
228
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
229 if (M < 1 || N < 2) { // nothing to do
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
230 return;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
231 }
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
232
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
233 List<GridCell> cells = GridCell.pointsToGridCells(
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
234 points, relevantArea(path, points));
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
235
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
236 if (cells.isEmpty()) {
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
237 log.warn("no cells found");
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
238 return;
416
04a242c67fe6 Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 366
diff changeset
239 }
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
240
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
241 // put into spatial index to speed up finding neighbors.
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
242 STRtree spatialIndex = new STRtree();
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
243
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
244 for (GridCell cell: cells) {
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
245 spatialIndex.insert(cell.getEnvelope(), cell);
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
246 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
247
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
248 LinearToMap linearToMap = new LinearToMap(
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
249 path, from, to, metrics);
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
250
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
251 double dP = (to - from)/steps;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
252
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
253 Coordinate center = new Coordinate();
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
254 Envelope queryBuffer = new Envelope();
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
255 GridCell.CellFinder finder = new GridCell.CellFinder();
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
256
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
257 int missedInterpolations = 0;
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
258 int interpolations = 0;
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 445
diff changeset
259
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
260 for (double p = from; p <= to; p += dP) {
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
261 if (!linearToMap.locate(p, center)) {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
262 continue;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
263 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
264 queryBuffer.init(
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 528
diff changeset
265 center.x - EPS, center.x + EPS,
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
266 center.y - EPS, center.y + EPS);
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
267
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
268 finder.prepare(center);
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
269 spatialIndex.query(queryBuffer, finder);
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
270
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
271 GridCell found = finder.found;
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
272
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
273 if (found == null) {
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
274 consumer.interpolated(center, false);
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
275 ++missedInterpolations;
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
276 continue;
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
277 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
278
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
279 Point2d n0 = found.p1;
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
280 Point2d n1 = found.p2;
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
281 Point2d n2 = found.p3;
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
282 Point2d n3 = found.p4;
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
283
519
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
284 double z1 = interpolate(
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
285 n0.x, n0.z,
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
286 n1.x, n1.z,
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
287 center.x);
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
288 double z2 = interpolate(
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
289 n2.x, n2.z,
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
290 n3.x, n3.z,
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
291 center.x);
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
292 double y1 = interpolate(
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
293 n0.x, n0.y,
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
294 n1.x, n1.y,
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
295 center.x);
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
296 double y2 = interpolate(
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
297 n2.x, n2.y,
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
298 n3.x, n3.y,
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
299 center.x);
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
300 center.z = interpolate(
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
301 y1, z1,
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
302 y2, z2,
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
303 center.y);
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
304 consumer.interpolated(center, true);
4e347624ee7c Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 514
diff changeset
305 ++interpolations;
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
306 }
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
307
434
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
308 if (debug) {
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 528
diff changeset
309 log.debug("interpolations: " +
416
04a242c67fe6 Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 366
diff changeset
310 interpolations + " / " + missedInterpolations);
04a242c67fe6 Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 366
diff changeset
311 }
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
312 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
313
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
314 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
315 * Linear interpolate a value between (x1, y1) and (x2, y2) at
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
316 * a given x-value.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
317 * @param x1 x component of first point.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
318 * @param y1 y component of first point.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
319 * @param x2 x component of second point.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
320 * @param y2 y component of second point.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
321 * @param x The x value.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
322 * @return The intepolated result.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
323 */
361
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
324 public static final double interpolate(
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
325 double x1, double y1,
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
326 double x2, double y2,
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
327 double x
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
328 ) {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
329 if (x2 == x1) {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
330 return (y1 + y2)*0.5d;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
331 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
332 double m = (y2-y1)/(x2-x1);
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
333 double b = y1 - m*x1;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
334 return m*x + b;
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
335 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
336 }
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 807
diff changeset
337 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org