comparison gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java @ 495:6e8364e766fa

Generate JTS geometries of "Horizontalschnitte" correctly. gnv-artifacts/trunk@572 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 19 Jan 2010 14:06:10 +0000
parents 64e65daa65e9
children 75306d856004
comparison
equal deleted inserted replaced
494:292f0c8d356c 495:6e8364e766fa
7 7
8 import java.awt.Dimension; 8 import java.awt.Dimension;
9 9
10 import java.io.Serializable; 10 import java.io.Serializable;
11 11
12 import java.util.ArrayList;
12 import java.util.Arrays; 13 import java.util.Arrays;
13 import java.util.Collections; 14 import java.util.Collections;
14 import java.util.List; 15 import java.util.List;
15 16
16 import org.apache.log4j.Logger; 17 import org.apache.log4j.Logger;
18
19 import de.intevation.gnv.utils.GridIndex;
17 20
18 /** 21 /**
19 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) 22 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
20 */ 23 */
21 public class AreaInterpolation 24 public class AreaInterpolation
56 log.debug("no points to interpolate"); 59 log.debug("no points to interpolate");
57 } 60 }
58 return false; 61 return false;
59 } 62 }
60 63
61 double [] buffer = Interpolation2D.calculateBuffer(points); 64 int W = samples.width;
65 int H = samples.height;
66
67 double cellWidth = boundingBox.getWidth() / W;
68 double cellHeight = boundingBox.getHeight() / H;
69 Envelope gridEnvelope = new Envelope(boundingBox);
70
71 gridEnvelope.expandBy(2d*cellWidth, 2d*cellWidth);
72
73 ArrayList<Point2d>relevantPoints =
74 new ArrayList<Point2d>();
75
76 for (int i = points.size()-1; i >= 0; --i) {
77 if (gridEnvelope.contains(points.get(i))) {
78 relevantPoints.add(points.get(i));
79 }
80 }
81
82 double [] buffer = Interpolation2D.calculateBuffer(relevantPoints);
62 double dxMax = buffer[0]; 83 double dxMax = buffer[0];
63 double dyMax = buffer[1]; 84 double dyMax = buffer[1];
64 85
65 Quadtree spatialIndex = new Quadtree(); 86 Quadtree spatialIndex = new Quadtree();
66 87
67 for (int i = points.size()-1; i >= 0; --i) { 88 for (int i = relevantPoints.size()-1; i >= 0; --i) {
68 Point2d p = points.get(i); 89 Point2d p = relevantPoints.get(i);
69 spatialIndex.insert(p.envelope(), p); 90 spatialIndex.insert(p.envelope(), p);
70 } 91 }
71 92
72 int W = samples.width;
73 int H = samples.height;
74
75 double cellWidth = boundingBox.getWidth() / W;
76 double cellHeight = boundingBox.getHeight() / H;
77
78 if (debug) { 93 if (debug) {
79 log.debug("width: " + boundingBox.getWidth()); 94 log.debug("points: " + relevantPoints.size());
80 log.debug("height: " + boundingBox.getHeight()); 95 log.debug("width: " + boundingBox.getWidth());
96 log.debug("height: " + boundingBox.getHeight());
81 log.debug("sample width: " + W); 97 log.debug("sample width: " + W);
82 log.debug("sample height: " + H); 98 log.debug("sample height: " + H);
83 log.debug("cell width: " + cellWidth); 99 log.debug("cell width: " + cellWidth);
84 log.debug("cell height: " + cellHeight); 100 log.debug("cell height: " + cellHeight);
85 log.debug("buffer x: " + dxMax); 101 log.debug("buffer x: " + dxMax);
86 log.debug("buffer y: " + dyMax); 102 log.debug("buffer y: " + dyMax);
87 } 103 }
88 104
89 Envelope queryBuffer = new Envelope(); 105 Envelope queryBuffer = new Envelope();
90 Point2d [] neighbors = new Point2d[4]; 106 Point2d [] neighbors = new Point2d[4];
91 Coordinate center = new Coordinate(); 107 Coordinate center = new Coordinate();
95 Arrays.fill(raster, Double.NaN); 111 Arrays.fill(raster, Double.NaN);
96 112
97 double minX = boundingBox.getMinX(); 113 double minX = boundingBox.getMinX();
98 double minY = boundingBox.getMinY(); 114 double minY = boundingBox.getMinY();
99 115
100 int row = 0; 116 int row = (H-1)*W;
101 for (int j = 0; j < H; ++j, row += W) { 117 for (int j = 0; j < H; ++j, row -= W) {
102 double y = j*cellHeight + 0.5d*cellHeight + minY; 118 double y = j*cellHeight + 0.5d*cellHeight + minY;
103 double x = 0.5d*cellWidth + minX; 119 double x = 0.5d*cellWidth + minX;
104 for (int i = 0; i < W; ++i, x += cellWidth) { 120 for (int i = 0; i < W; ++i, x += cellWidth) {
105 queryBuffer.init( 121 queryBuffer.init(
106 x - dxMax, x + dxMax, 122 x - dxMax, x + dxMax,

http://dive4elements.wald.intevation.org