annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/Interpolation2D.java @ 1139:3a28fef65500

dummy merge for repo head
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:15:16 +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
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
9 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
10
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 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
12 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
13
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
14 import com.vividsolutions.jts.index.strtree.STRtree;
501
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
15
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
16 import java.util.List;
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
17
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
18 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
19
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
20 /**
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
21 * 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
22 * "horizontale Schnittprofile".
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
23 *
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
24 * @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
25 */
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 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
27 {
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
28 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
29
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
30 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
31 * 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
32 * 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
33 */
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
34 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
35 "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
36
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
37 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
38 * Numerical stability epsilon.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
39 */
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
40 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
41
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
42 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
43 * 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
44 * caller without building large temporary strcutures.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
45 */
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
46 public interface Consumer {
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
47 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
48 * 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
49 * 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
50 * @param point The interpolated point.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
51 * @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
52 * succeed, else false.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
53 */
416
04a242c67fe6 Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 366
diff changeset
54 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
55 } // 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
56
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 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
58 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
60 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
61 * 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
62 * @param path The line string.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
63 * @param points The sample points.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
64 * @return The relevant area.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
65 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
66 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
67 List<? extends Coordinate> path,
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
68 List<? extends Coordinate> points
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
69 ) {
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
70 return relevantArea(path, points, CULL_POINT_THRESHOLD);
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
71 }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
72
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
73 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
74 * 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
75 * @param pathBBox The bounding box.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
76 * @param points The sample points.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
77 * @return The relevant area.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
78 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
79 public static final Envelope relevantArea(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
80 Envelope pathBBox,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
81 List<? extends Coordinate> points
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
82 ) {
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
83 return relevantArea(pathBBox, points, CULL_POINT_THRESHOLD);
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
84 }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
85
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
86 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
87 * 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
88 * @param pathBBox The bounding box.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
89 * @param points The sample points.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
90 * @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
91 * 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
92 * @return The relevant area.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
93 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
94 public static final Envelope relevantArea(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
95 Envelope pathBBox,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
96 List<? extends Coordinate> points,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
97 int threshold
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
98 ) {
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
99 return points.size() < threshold
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
100 ? null
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
101 : relevantArea(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
102 pathBBox,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
103 pointsBoundingBox(points));
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
104 }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
105
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
106 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
107 * 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
108 * @param path The line string.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
109 * @param points The sample points.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
110 * @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
111 * 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
112 * @return The relevant area.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
113 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
114 public static final Envelope relevantArea(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
115 List<? extends Coordinate> path,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
116 List<? extends Coordinate> points,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
117 int threshold
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
118 ) {
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
119 return points.size() < threshold || path.isEmpty()
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
120 ? null
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
121 : relevantArea(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
122 pointsBoundingBox(path),
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
123 pointsBoundingBox(points));
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
124 }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
125
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
126 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
127 * 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
128 * @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
129 * @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
130 * @return The relevant area.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
131 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
132 public static final Envelope relevantArea(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
133 Envelope pathBBox,
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
134 Envelope pointsBBox
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
135 ) {
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
136 double pathArea = pathBBox.getWidth()*pathBBox.getHeight();
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
137 double pointsArea = pointsBBox.getWidth()*pointsBBox.getHeight();
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 (pathArea > 0.8d*pointsArea) { 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 nArea = 1.44d * pathArea;
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
142 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
143 double w = pathBBox.getWidth();
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
144 double h = pathBBox.getHeight();
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
145 double [] d = solveQuadratic(1d, w+h, pathArea - nArea);
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 if (d == null) { return null; }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
148
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
149 double extra = pos(d);
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
150
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
151 pathBBox.expandBy(extra);
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
152
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
153 return pathBBox;
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
154 }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
155
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
156 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
157 * 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
158 * @param a a-coefficent.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
159 * @param b b-coefficent
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
160 * @param c c-coefficent.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
161 * @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
162 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
163 public static final double [] solveQuadratic(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
164 double a, double b, double c
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
165 ) {
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
166 double d = b*b - 4d*a*c;
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
167 if (d < 0d) { return null; }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
168
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
169 d = Math.sqrt(d);
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
170 a = 1d/(2d*a);
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
171 b = -b;
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
172
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
173 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
174 }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
175
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
176 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
177 * 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
178 * is greater or equal zero.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
179 * @param x The two values.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
180 * @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
181 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
182 public static final double pos(double [] x) {
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
183 return x[0] >= 0 ? x[0] : x[1];
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
184 }
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
185
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
186
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
187 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
188 * 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
189 * @param path The line string.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
190 * @return The bounding box.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
191 */
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
192 public static Envelope pointsBoundingBox(
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
193 List<? extends Coordinate> path
501
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
194 ) {
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
195 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
196 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
197
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
198 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
199 area.expandToInclude(path.get(i));
501
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
200 }
70adafe2b9d5 Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
201
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
202 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
203 }
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
204
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
205 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
206 * 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
207 * 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
208 * @param path The line string path.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
209 * @param points The sample points.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
210 * @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
211 * referenced on the line string.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
212 * @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
213 * referenced on the line string.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
214 * @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
215 * @param metrics The used metric.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
216 * @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
217 */
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
218 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
219 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
220 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
221 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
222 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
223 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
224 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
225 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
226 ) {
434
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
227 boolean debug = log.isDebugEnabled();
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
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 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
230 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
231
434
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
232 if (debug) {
416
04a242c67fe6 Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 366
diff changeset
233 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
234 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
235 }
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
236
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
237 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
238 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
239 }
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
240
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
241 List<GridCell> cells = GridCell.pointsToGridCells(
528
44415ae01ddb Fixed issue gnv/issue159
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 519
diff changeset
242 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
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 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
245 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
246 return;
416
04a242c67fe6 Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 366
diff changeset
247 }
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
248
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 // 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
250 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
251
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
252 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
253 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
254 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
255
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 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
257 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
258
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
259 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
260
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
261 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
262 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
263 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
264
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
265 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
266 int interpolations = 0;
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 445
diff changeset
267
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
268 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
269 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
270 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
271 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
272 queryBuffer.init(
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 528
diff changeset
273 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
274 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
275
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
276 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
277 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
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 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
280
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 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
282 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
283 ++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
284 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
285 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
286
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
287 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
288 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
289 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
290 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
291
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
292 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
293 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
294 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
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 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
297 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
298 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
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 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
301 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
302 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
303 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
304 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
305 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
306 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
307 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
308 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
309 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
310 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
311 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
312 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
313 ++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
314 }
365
f66088a43ecc Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 361
diff changeset
315
434
0eed5749fd63 Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 431
diff changeset
316 if (debug) {
778
9a828e5a2390 Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 528
diff changeset
317 log.debug("interpolations: " +
416
04a242c67fe6 Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 366
diff changeset
318 interpolations + " / " + missedInterpolations);
04a242c67fe6 Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 366
diff changeset
319 }
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
320 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
321
807
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
322 /**
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
323 * 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
324 * a given x-value.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
325 * @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
326 * @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
327 * @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
328 * @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
329 * @param x The x value.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
330 * @return The intepolated result.
a645bd23c1c8 Added more javadoc. Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 798
diff changeset
331 */
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
332 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
333 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
334 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
335 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
336 ) {
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
337 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
338 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
339 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
340 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
341 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
342 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
343 }
aec85d00d82c Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
344 }
836
05bf8534a35a Using unix line endings only.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 807
diff changeset
345 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org