Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java @ 505:7ff916744f40
Solved issue152. Time intervals of timeseries axis are defined by JFreeChart automatically.
gnv-artifacts/trunk@588 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 20 Jan 2010 17:54:48 +0000 |
parents | 70adafe2b9d5 |
children | d9d933e06875 |
rev | line source |
---|---|
474
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.math; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import com.vividsolutions.jts.geom.Coordinate; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import com.vividsolutions.jts.geom.Envelope; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import com.vividsolutions.jts.index.quadtree.Quadtree; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 |
479
d47b478e662b
Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
8 import java.awt.Dimension; |
d47b478e662b
Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
9 |
d47b478e662b
Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
10 import java.io.Serializable; |
d47b478e662b
Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
11 |
495
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
12 import java.util.ArrayList; |
479
d47b478e662b
Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
13 import java.util.Arrays; |
d47b478e662b
Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
14 import java.util.Collections; |
d47b478e662b
Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
15 import java.util.List; |
d47b478e662b
Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
474
diff
changeset
|
16 |
474
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import org.apache.log4j.Logger; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 /** |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 */ |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 public class AreaInterpolation |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 implements Serializable |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 { |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 private static Logger log = Logger.getLogger(AreaInterpolation.class); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 protected double [] raster; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 protected int width; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 protected int height; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 public AreaInterpolation() { |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 } |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 public int getWidth() { |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 return width; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 } |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 public int getHeight() { |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 return height; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 } |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 public double [] getRaster() { |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 return raster; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 } |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 public boolean interpolate( |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 List<? extends Point2d> points, |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 Envelope boundingBox, |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 Dimension samples, |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 XYDepth depth |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 ) { |
482
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
53 boolean debug = log.isDebugEnabled(); |
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
54 |
474
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 if (points == null || points.isEmpty()) { |
482
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
56 if (debug) { |
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
57 log.debug("no points to interpolate"); |
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
58 } |
474
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 return false; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 } |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 |
495
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
62 int W = samples.width; |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
63 int H = samples.height; |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
64 |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
65 double cellWidth = boundingBox.getWidth() / W; |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
66 double cellHeight = boundingBox.getHeight() / H; |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
67 Envelope gridEnvelope = new Envelope(boundingBox); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
68 |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
69 gridEnvelope.expandBy(2d*cellWidth, 2d*cellWidth); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
70 |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
71 ArrayList<Point2d>relevantPoints = |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
72 new ArrayList<Point2d>(); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
73 |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
74 for (int i = points.size()-1; i >= 0; --i) { |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
75 if (gridEnvelope.contains(points.get(i))) { |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
76 relevantPoints.add(points.get(i)); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
77 } |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
78 } |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
79 |
501
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
498
diff
changeset
|
80 double [] buffer = Interpolation2D |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
498
diff
changeset
|
81 .calculateBufferRemoveOutlier(relevantPoints); |
474
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 double dxMax = buffer[0]; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 double dyMax = buffer[1]; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 Quadtree spatialIndex = new Quadtree(); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 |
495
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
87 for (int i = relevantPoints.size()-1; i >= 0; --i) { |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
88 Point2d p = relevantPoints.get(i); |
474
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 spatialIndex.insert(p.envelope(), p); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 } |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 |
482
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
92 if (debug) { |
495
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
93 log.debug("points: " + relevantPoints.size()); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
94 log.debug("width: " + boundingBox.getWidth()); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
95 log.debug("height: " + boundingBox.getHeight()); |
482
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
96 log.debug("sample width: " + W); |
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
97 log.debug("sample height: " + H); |
495
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
98 log.debug("cell width: " + cellWidth); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
99 log.debug("cell height: " + cellHeight); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
100 log.debug("buffer x: " + dxMax); |
6e8364e766fa
Generate JTS geometries of "Horizontalschnitte" correctly.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
482
diff
changeset
|
101 log.debug("buffer y: " + dyMax); |
482
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
102 } |
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
103 |
474
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 Envelope queryBuffer = new Envelope(); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 Point2d [] neighbors = new Point2d[4]; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 Coordinate center = new Coordinate(); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 L1Comparator invL1 = new L1Comparator(center); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 double [] raster = new double[W*H]; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 Arrays.fill(raster, Double.NaN); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 |
482
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
112 double minX = boundingBox.getMinX(); |
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
113 double minY = boundingBox.getMinY(); |
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
114 |
501
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
498
diff
changeset
|
115 long startTime = System.currentTimeMillis(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
498
diff
changeset
|
116 |
498
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
117 int row = 0; |
4080b57dcb52
Upgraded to Geotools 2.5.8. Write polygons and line strings to
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
118 for (int j = 0; j < H; ++j, row += W) { |
482
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
119 double y = j*cellHeight + 0.5d*cellHeight + minY; |
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
120 double x = 0.5d*cellWidth + minX; |
474
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 for (int i = 0; i < W; ++i, x += cellWidth) { |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 queryBuffer.init( |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 x - dxMax, x + dxMax, |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 y - dyMax, y + dyMax); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 List potential = spatialIndex.query(queryBuffer); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 |
482
64e65daa65e9
Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
479
diff
changeset
|
128 if (potential.size() < 4) { |
474
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 continue; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 } |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 center.x = x; center.y = y; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 Collections.sort(potential, invL1); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 neighbors[0] = neighbors[1] = |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 neighbors[2] = neighbors[3] = null; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 int mask = 0; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 // reversed order is essential here! |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 for (int k = potential.size()-1; k >= 0; --k) { |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 Point2d n = (Point2d)potential.get(k); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 int code = n.x > center.x ? 1 : 0; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 if (n.y > center.y) code |= 2; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 neighbors[code] = n; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 mask |= 1 << code; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 } |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 int numNeighbors = Integer.bitCount(mask); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 // only interpolate if we have all four neighbors |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 // we do not have any gaps and we are below surface. |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 if (numNeighbors == 4 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 && !neighbors[0].hasIGap(neighbors[1]) |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 && !neighbors[1].hasJGap(neighbors[3]) |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 && !neighbors[3].hasIGap(neighbors[2]) |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 && !neighbors[2].hasJGap(neighbors[0]) |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 && depth.depth(center) <= 0d |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 ) { |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 double z1 = Interpolation2D.interpolate( |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 neighbors[0].x, neighbors[0].z, |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 neighbors[1].x, neighbors[1].z, |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 center.x); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 double z2 = Interpolation2D.interpolate( |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 neighbors[2].x, neighbors[2].z, |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 neighbors[3].x, neighbors[3].z, |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 center.x); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 double y1 = Interpolation2D.interpolate( |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 neighbors[0].x, neighbors[0].y, |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 neighbors[1].x, neighbors[1].y, |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 center.x); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 double y2 = Interpolation2D.interpolate( |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 neighbors[2].x, neighbors[2].y, |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 neighbors[3].x, neighbors[3].y, |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 center.x); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 raster[row+i] = Interpolation2D.interpolate( |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 y1, z1, |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 y2, z2, |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 center.y); |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 } |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 } |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 } |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 |
501
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
498
diff
changeset
|
183 long stopTime = System.currentTimeMillis(); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
498
diff
changeset
|
184 |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
498
diff
changeset
|
185 if (debug) { |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
498
diff
changeset
|
186 log.debug("interpolation took: " + (stopTime - startTime)/1000f + " secs"); |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
498
diff
changeset
|
187 } |
70adafe2b9d5
Speed up the "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
498
diff
changeset
|
188 |
474
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 this.raster = raster; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 this.width = W; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 this.height = H; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 return true; |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 } |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 } |
ab29e4ff2fda
Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |