Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/Interpolation2D.java @ 507:45be952a3215
Solved some issues. Removed encoding problems while formatting coordinates (issue137) and use this format as subtitle in charts (issue136).
gnv-artifacts/trunk@590 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 21 Jan 2010 14:42:51 +0000 |
parents | 70adafe2b9d5 |
children | d9d933e06875 |
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 |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import com.vividsolutions.jts.index.quadtree.Quadtree; |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 |
501
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
8 import gnu.trove.TDoubleArrayList; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
9 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
10 import java.util.ArrayList; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
11 import java.util.Collections; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
12 import java.util.HashMap; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
13 import java.util.List; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
14 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
15 import org.apache.commons.math.stat.descriptive.moment.Mean; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
16 import org.apache.commons.math.stat.descriptive.moment.StandardDeviation; |
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 /** |
501
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
21 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) |
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
|
22 */ |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 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
|
24 { |
365
f66088a43ecc
Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
361
diff
changeset
|
25 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
|
26 |
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
|
27 public interface Consumer { |
416
04a242c67fe6
Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
366
diff
changeset
|
28 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
|
29 } // 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
|
30 |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 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
|
32 } |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
501
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
34 private static final double dist(double a, double b) { |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
35 a -= b; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
36 return Math.sqrt(a*a); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
37 } |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
38 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
39 private static final double OUTLIER_EPS = 0.4d; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
40 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
41 public static final double [] calculateBufferRemoveOutlier( |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
42 List <? extends Point2d> points |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
43 ) { |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
44 HashMap<Integer, ArrayList<Point2d>> iMap = |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
45 new HashMap<Integer, ArrayList<Point2d>>(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
46 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
47 HashMap<Integer, ArrayList<Point2d>> jMap = |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
48 new HashMap<Integer, ArrayList<Point2d>>(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
49 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
50 for (int k = points.size()-1; k >= 0; --k) { |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
51 Point2d p = points.get(k); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
52 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
53 ArrayList<Point2d> jList = jMap.get(p.j); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
54 ArrayList<Point2d> iList = iMap.get(p.i); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
55 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
56 if (jList == null) { |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
57 jMap.put(p.j, jList = new ArrayList<Point2d>()); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
58 } |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
59 jList.add(p); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
60 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
61 if (iList == null) { |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
62 iMap.put(p.i, iList = new ArrayList<Point2d>()); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
63 } |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
64 iList.add(p); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
65 } |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
66 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
67 TDoubleArrayList deltas = new TDoubleArrayList(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
68 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
69 Mean mean = new Mean(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
70 StandardDeviation sd = new StandardDeviation(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
71 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
72 for (ArrayList<Point2d> v: jMap.values()) { |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
73 Collections.sort(v, Point2d.Y_COMPARATOR); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
74 for (int i = 1, L = v.size(); i < L; ++i) { |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
75 double dy = Math.abs(v.get(i).y - v.get(i-1).y); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
76 deltas.add(dy); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
77 mean.increment(dy); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
78 sd .increment(dy); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
79 } |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
80 } |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
81 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
82 deltas.sort(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
83 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
84 double m = mean.getResult(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
85 double s = sd .getResult(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
86 double eps = OUTLIER_EPS*s; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
87 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
88 int yi = deltas.size() - 1; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
89 while (yi > 0 && dist(deltas.get(yi), m) > eps) { |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
90 --yi; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
91 } |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
92 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
93 double dyMax = deltas.get(yi) + 1e-5d; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
94 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
95 if (log.isDebugEnabled()) { |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
96 log.debug("mean y: " + m); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
97 log.debug("sigma y: " + s); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
98 } |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
99 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
100 deltas.reset(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
101 mean.clear(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
102 sd .clear(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
103 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
104 for (ArrayList<Point2d> v: iMap.values()) { |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
105 Collections.sort(v, Point2d.X_COMPARATOR); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
106 for (int i = 1, L = v.size(); i < L; ++i) { |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
107 double dx = Math.abs(v.get(i).x - v.get(i-1).x); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
108 deltas.add(dx); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
109 mean.increment(dx); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
110 sd .increment(dx); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
111 } |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
112 } |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
113 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
114 deltas.sort(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
115 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
116 m = mean.getResult(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
117 s = sd .getResult(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
118 eps = OUTLIER_EPS*s; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
119 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
120 int xi = deltas.size() - 1; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
121 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
122 while (xi > 0 && dist(deltas.get(xi), m) > eps) { |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
123 --xi; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
124 } |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
125 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
126 double dxMax = deltas.get(xi) + 1e-5d; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
127 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
128 if (log.isDebugEnabled()) { |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
129 log.debug("mean y: " + m); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
130 log.debug("sigma y: " + s); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
131 } |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
132 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
133 return new double [] { dxMax, dyMax }; |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
134 } |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
135 |
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
|
136 public static final double [] calculateBuffer( |
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
|
137 List <? extends Point2d> points |
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
|
138 ) { |
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
|
139 HashMap<Integer, ArrayList<Point2d>> iMap = |
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
|
140 new HashMap<Integer, ArrayList<Point2d>>(); |
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
|
141 |
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
|
142 HashMap<Integer, ArrayList<Point2d>> jMap = |
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
|
143 new HashMap<Integer, ArrayList<Point2d>>(); |
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
|
144 |
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
|
145 for (int k = points.size()-1; k >= 0; --k) { |
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
|
146 Point2d p = points.get(k); |
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
|
147 |
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
|
148 ArrayList<Point2d> jList = jMap.get(p.j); |
445
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
434
diff
changeset
|
149 ArrayList<Point2d> iList = iMap.get(p.i); |
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
|
150 |
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
|
151 if (jList == null) { |
445
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
434
diff
changeset
|
152 jMap.put(p.j, jList = new ArrayList<Point2d>()); |
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
|
153 } |
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
|
154 jList.add(p); |
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
|
155 |
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
|
156 if (iList == null) { |
445
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
434
diff
changeset
|
157 iMap.put(p.i, iList = new ArrayList<Point2d>()); |
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
|
158 } |
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
|
159 iList.add(p); |
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
|
160 } |
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
|
161 |
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
|
162 double dxMax = -Double.MAX_VALUE; |
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
|
163 double dyMax = -Double.MAX_VALUE; |
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
|
164 |
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
|
165 for (ArrayList<Point2d> v: jMap.values()) { |
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
|
166 Collections.sort(v, Point2d.Y_COMPARATOR); |
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
|
167 for (int i = 1, L = v.size(); i < L; ++i) { |
445
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
434
diff
changeset
|
168 double dy = Math.abs(v.get(i).y - v.get(i-1).y); |
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
|
169 if (dy > dyMax) { |
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
|
170 dyMax = dy; |
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
|
171 } |
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
|
172 } |
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
|
173 } |
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
|
174 |
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
|
175 dyMax += 1e-5d; |
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
|
176 |
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
|
177 for (ArrayList<Point2d> v: iMap.values()) { |
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
|
178 Collections.sort(v, Point2d.X_COMPARATOR); |
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
|
179 for (int i = 1, L = v.size(); i < L; ++i) { |
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
|
180 double dx = Math.abs(v.get(i).x - v.get(i-1).x); |
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
|
181 if (dx > dxMax) { |
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
|
182 dxMax = dx; |
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
|
183 } |
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
|
184 } |
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
|
185 } |
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
|
186 |
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
|
187 dxMax += 1e-5d; |
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
|
188 |
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
|
189 return new double [] { dxMax, dyMax }; |
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
|
190 } |
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
|
191 |
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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 ) { |
434
0eed5749fd63
Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
201 boolean debug = log.isDebugEnabled(); |
0eed5749fd63
Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
202 |
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
|
203 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
|
204 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
|
205 |
434
0eed5749fd63
Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
206 if (debug) { |
416
04a242c67fe6
Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
366
diff
changeset
|
207 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
|
208 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
|
209 } |
365
f66088a43ecc
Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
361
diff
changeset
|
210 |
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
|
211 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
|
212 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
|
213 } |
365
f66088a43ecc
Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
361
diff
changeset
|
214 |
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
|
215 double [] buffer = calculateBuffer(points); |
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
|
216 double dxMax = buffer[0]; |
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
|
217 double dyMax = buffer[1]; |
365
f66088a43ecc
Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
361
diff
changeset
|
218 |
434
0eed5749fd63
Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
219 if (debug) { |
416
04a242c67fe6
Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
366
diff
changeset
|
220 log.debug("buffer size: " + dxMax + " / " + dyMax); |
04a242c67fe6
Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
366
diff
changeset
|
221 } |
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
|
222 |
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 // put into spatial index to speed up finding neighbors. |
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 Quadtree spatialIndex = new Quadtree(); |
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 |
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 for (int i = 0; i < M; ++i) { |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 Point2d p = points.get(i); |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 spatialIndex.insert(p.envelope(), p); |
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 } |
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 |
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 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
|
232 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
|
233 |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 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
|
235 |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 Coordinate center = new 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
|
237 |
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 Envelope queryBuffer = new 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
|
239 |
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 Point2d [] neighbors = new Point2d[4]; |
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 |
365
f66088a43ecc
Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
361
diff
changeset
|
242 int missedInterpolations = 0; |
f66088a43ecc
Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
361
diff
changeset
|
243 int interpolations = 0; |
f66088a43ecc
Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
361
diff
changeset
|
244 |
474
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
245 L1Comparator invL1 = new L1Comparator(center); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
246 |
365
f66088a43ecc
Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
361
diff
changeset
|
247 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
|
248 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
|
249 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
|
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 queryBuffer.init( |
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 center.x - dxMax, center.x + dxMax, |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 center.y - dyMax, center.y + dyMax); |
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 List potential = spatialIndex.query(queryBuffer); |
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 |
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 Collections.sort(potential, invL1); |
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 neighbors[0] = neighbors[1] = |
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 neighbors[2] = neighbors[3] = null; |
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 |
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 /* bit code of neighbors |
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 0---1 |
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 | 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
|
265 2---3 |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 */ |
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 |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 int mask = 0; |
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 // reversed order is essential here! |
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 for (int i = potential.size()-1; i >= 0; --i) { |
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 Point2d n = (Point2d)potential.get(i); |
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 int code = n.x > center.x ? 1 : 0; |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
273 if (n.y > center.y) code |= 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
|
274 neighbors[code] = n; |
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 mask |= 1 << code; |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
276 } |
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 int numNeighbors = Integer.bitCount(mask); |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
279 |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
280 // only interpolate if we have all four neighbors |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
281 // and we do not have any gaps. |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
282 if (numNeighbors == 4 |
366
086e3af38b96
Fixed index error in i-gap detection in 2D interpolation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
365
diff
changeset
|
283 && !neighbors[0].hasIGap(neighbors[1]) |
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
|
284 && !neighbors[1].hasJGap(neighbors[3]) |
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 && !neighbors[3].hasIGap(neighbors[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
|
286 && !neighbors[2].hasJGap(neighbors[0]) |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
287 ) { |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
288 double z1 = 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
|
289 neighbors[0].x, neighbors[0].z, |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
290 neighbors[1].x, neighbors[1].z, |
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 center.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
|
292 double z2 = 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
|
293 neighbors[2].x, neighbors[2].z, |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
294 neighbors[3].x, neighbors[3].z, |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
295 center.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
|
296 double y1 = 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
|
297 neighbors[0].x, neighbors[0].y, |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
298 neighbors[1].x, neighbors[1].y, |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
299 center.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
|
300 double y2 = 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
|
301 neighbors[2].x, neighbors[2].y, |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
302 neighbors[3].x, neighbors[3].y, |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
303 center.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
|
304 center.z = 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
|
305 y1, z1, |
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 y2, z2, |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
307 center.y); |
416
04a242c67fe6
Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
366
diff
changeset
|
308 consumer.interpolated(center, true); |
365
f66088a43ecc
Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
361
diff
changeset
|
309 ++interpolations; |
f66088a43ecc
Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
361
diff
changeset
|
310 } |
f66088a43ecc
Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
361
diff
changeset
|
311 else { |
416
04a242c67fe6
Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
366
diff
changeset
|
312 consumer.interpolated(center, false); |
365
f66088a43ecc
Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
361
diff
changeset
|
313 ++missedInterpolations; |
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 } |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
315 } |
365
f66088a43ecc
Added horizontal crossprofile charts to chart pallet. Fixed some bugs before interpolation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
361
diff
changeset
|
316 |
434
0eed5749fd63
Implemented the raster interpolation for the 'Profilschnitt'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
431
diff
changeset
|
317 if (debug) { |
416
04a242c67fe6
Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
366
diff
changeset
|
318 log.debug("interpolations: " + |
04a242c67fe6
Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
366
diff
changeset
|
319 interpolations + " / " + missedInterpolations); |
04a242c67fe6
Added support of gap detection in horizontalcrossprofile charts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
366
diff
changeset
|
320 } |
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
|
321 } |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
322 |
aec85d00d82c
Added code to do 2D interpolations along a digitied track on the map.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
323 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
|
324 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
|
325 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
|
326 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
|
327 ) { |
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 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
|
329 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
|
330 } |
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 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
|
332 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
|
333 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
|
334 } |
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |