diff gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java @ 482:64e65daa65e9

Fixed some bugs with calculating "Horizontalschnitte". gnv-artifacts/trunk@557 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 17 Jan 2010 21:26:21 +0000
parents d47b478e662b
children 6e8364e766fa
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java	Sun Jan 17 16:34:11 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java	Sun Jan 17 21:26:21 2010 +0000
@@ -49,7 +49,12 @@
         Dimension               samples,
         XYDepth                 depth
     ) {
+        boolean debug = log.isDebugEnabled();
+
         if (points == null || points.isEmpty()) {
+            if (debug) {
+                log.debug("no points to interpolate");
+            }
             return false;
         }
 
@@ -70,6 +75,17 @@
         double cellWidth  = boundingBox.getWidth()  / W;
         double cellHeight = boundingBox.getHeight() / H;
 
+        if (debug) {
+            log.debug("width:  " + boundingBox.getWidth());
+            log.debug("height:  " + boundingBox.getHeight());
+            log.debug("sample width:  " + W);
+            log.debug("sample height: " + H);
+            log.debug("cell width:  " + cellWidth);
+            log.debug("cell height: " + cellHeight);
+            log.debug("buffer x: " + dxMax);
+            log.debug("buffer y: " + dyMax);
+        }
+
         Envelope     queryBuffer = new Envelope();
         Point2d []   neighbors   = new Point2d[4];
         Coordinate   center      = new Coordinate();
@@ -78,10 +94,13 @@
         double [] raster = new double[W*H];
         Arrays.fill(raster, Double.NaN);
 
+        double minX = boundingBox.getMinX();
+        double minY = boundingBox.getMinY();
+
         int row = 0;
         for (int j = 0; j < H; ++j, row += W) {
-            double y = j*cellHeight + 0.5d*cellHeight;
-            double x = 0.5d*cellWidth;
+            double y = j*cellHeight + 0.5d*cellHeight + minY;
+            double x = 0.5d*cellWidth + minX;
             for (int i = 0; i < W; ++i, x += cellWidth) {
                 queryBuffer.init(
                     x - dxMax, x + dxMax, 
@@ -89,7 +108,7 @@
 
                 List potential = spatialIndex.query(queryBuffer);
 
-                if (potential.isEmpty()) {
+                if (potential.size() < 4) {
                     continue;
                 }
 

http://dive4elements.wald.intevation.org