changeset 517:96a1e92e7ed2

If the number of data points to generate a "Horizontalschnitt" is above a given threshold, they are culled against an 5% extented bounding box of the interpolation area. gnv-artifacts/trunk@611 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 23 Jan 2010 17:42:04 +0000 (2010-01-23)
parents 4f2a18abc780
children 464e03bf786b
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java gnv-artifacts/src/main/java/de/intevation/gnv/math/GridCell.java
diffstat 3 files changed, 63 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Sat Jan 23 14:03:26 2010 +0000
+++ b/gnv-artifacts/ChangeLog	Sat Jan 23 17:42:04 2010 +0000
@@ -1,4 +1,23 @@
-2010-01-22	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+2010-01-23	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/gnv/math/AreaInterpolation.java:
+	  - The lastest refactoring removed the evaluation of the
+	    depth. Now its back in again. 
+
+	  - If the number of incoming points is greater than
+	    a given threshold (default: 1000) than the bounding box
+		of the interpolation is extend about 5% for a test
+		if the points are in this area. Points outside this
+	    area are culled because its unlikely that they have
+		any influence on the result. Use the system property
+		"gnv.areainterpolation.cull.point.threshold" to modify
+		the threshold value.
+
+	* src/main/java/de/intevation/gnv/math/GridCell.java: When
+	  build the interpolation areas the points are culled against
+	  extented bounding box.
+
+2010-01-23	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* contrib/palette2qgis.xsl: New. XST tranformation to turn a
 	  palette XML file into a style definition suitable to be used
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java	Sat Jan 23 14:03:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java	Sat Jan 23 17:42:04 2010 +0000
@@ -22,6 +22,9 @@
 {
     private static Logger log = Logger.getLogger(AreaInterpolation.class);
 
+    public static final int CULL_POINT_THRESHOLD = Integer.getInteger(
+        "gnv.areainterpolation.cull.point.threshold", 1000);
+
     protected double [] raster;
 
     protected int width;
@@ -58,7 +61,17 @@
             return false;
         }
 
-        List<GridCell> cells = GridCell.pointsToGridCells(points);
+        Envelope relevantArea = null;
+        
+        if (points.size() > CULL_POINT_THRESHOLD) {
+            relevantArea = new Envelope(boundingBox);
+            relevantArea.expandBy(
+                0.05d*boundingBox.getWidth(),
+                0.05d*boundingBox.getHeight());
+        }
+
+        List<GridCell> cells = GridCell.pointsToGridCells(
+            points, relevantArea);
 
         if (cells.isEmpty()) {
             log.warn("no cells to interpolate");
@@ -98,11 +111,13 @@
 
         long startTime = System.currentTimeMillis();
 
-        int row = 0;
-        for (int j = 0; j < H; ++j, row += W) {
+        int pos = 0;
+        for (int j = 0; j < H; ++j) {
+
             double y = j*cellHeight + 0.5d*cellHeight + minY;
             double x = 0.5d*cellWidth + minX;
-            for (int i = 0; i < W; ++i, x += cellWidth) {
+
+            for (int end = pos + W; pos < end; ++pos, x += cellWidth) {
 
                 queryBuffer.init(x - EPS, x + EPS, y - EPS, y + EPS);
                 center.x = x; center.y = y;
@@ -111,7 +126,7 @@
 
                 GridCell found = finder.found;
 
-                if (found == null) {
+                if (found == null || depth.depth(center) > 0d) {
                     continue;
                 }
 
@@ -131,7 +146,7 @@
                     found.p3.x, found.p3.y,
                     found.p4.x, found.p4.y,
                     center.x);
-                raster[row+i] = Interpolation2D.interpolate(
+                raster[pos] = Interpolation2D.interpolate(
                     y1, z1,
                     y2, z2,
                     center.y);
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/GridCell.java	Sat Jan 23 14:03:26 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/GridCell.java	Sat Jan 23 17:42:04 2010 +0000
@@ -16,12 +16,16 @@
 import java.util.HashMap;
 import java.util.List;
 
+import org.apache.log4j.Logger;
+
 /**
  *  @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
  */
 public class GridCell
 implements   Serializable
 {
+    private static Logger log = Logger.getLogger(GridCell.class);
+
     public static final class CellFinder
     implements                ItemVisitor
     {
@@ -85,6 +89,13 @@
     public static List<GridCell> pointsToGridCells(
         List<? extends Point2d> points
     ) {
+        return pointsToGridCells(points, null);
+    }
+
+    public static List<GridCell> pointsToGridCells(
+        List<? extends Point2d> points,
+        Envelope                relevantArea
+    ) {
         int minI = Integer.MAX_VALUE;
         int maxI = Integer.MIN_VALUE;
         int minJ = Integer.MAX_VALUE;
@@ -93,8 +104,15 @@
         HashMap<Integer, HashMap<Integer, Point2d>> rows =
             new HashMap<Integer, HashMap<Integer, Point2d>>();
 
+        int culled = 0;
+
         for (Point2d p: points) {
 
+            if (relevantArea != null && !relevantArea.contains(p.x, p.y)) {
+                ++culled;
+                continue;
+            }
+
             if (p.i < minI) minI = p.i;
             if (p.i > maxI) maxI = p.i;
             if (p.j < minJ) minJ = p.j;
@@ -109,6 +127,10 @@
             row.put(p.j, p);
         }
 
+        if (log.isDebugEnabled()) {
+            log.debug("culled points: " + culled);
+        }
+
         ArrayList<GridCell> cells = new ArrayList<GridCell>(points.size());
 
         for (int i = minI + 1; i <= maxI; ++i) {

http://dive4elements.wald.intevation.org