[Dive4elements-commits] [PATCH 1 of 2] flys/issue863: Create gaps for middlebedheight data if distance > 110 m

Wald Commits scm-commit at wald.intevation.org
Thu Jun 6 11:12:11 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1370510401 -7200
# Node ID 128686fa5adda52da58ff1eb0258dbe7eefe83eb
# Parent  c40acb6bfe381f9e2b4d0082dca13c31b3dcea98
flys/issue863: Create gaps for middlebedheight data if distance > 110 m.

diff -r c40acb6bfe38 -r 128686fa5add artifacts/src/main/java/org/dive4elements/river/exports/MiddleBedHeightGenerator.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/MiddleBedHeightGenerator.java	Thu Jun 06 10:56:05 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/MiddleBedHeightGenerator.java	Thu Jun 06 11:20:01 2013 +0200
@@ -249,7 +249,7 @@
 
         XYSeries series = new StyledXYSeries(aandf.getFacetDescription(), theme);
 
-        StyledSeriesBuilder.addPoints(series, data.getMiddleHeightsPoints(), false);
+        StyledSeriesBuilder.addPoints(series, data.getMiddleHeightsPoints(), false, 0.110d);
 
         addAxisSeries(series, YAXIS.H.idx, visible);
     }
diff -r c40acb6bfe38 -r 128686fa5add artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java	Thu Jun 06 10:56:05 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/StyledSeriesBuilder.java	Thu Jun 06 11:20:01 2013 +0200
@@ -40,6 +40,39 @@
 
 
     /**
+     * Add points to series, create gaps if certain distance between points is met.
+     *
+     * @param series Series to add points to.
+     * @param points Points to add to series, points[0] to 1st dim, points[1]
+     *               to 2nd dim.
+     * @param skipNANs if true, skip NAN values in points parameter.
+     * @param distance if two consecutive entries in points[0] are more
+     *                 than distance apart, create a NaN value to skip in display.
+     */
+    public static void addPoints(XYSeries series, double[][] points, boolean skipNANs, double distance) {
+        if (points == null || points.length <= 1) {
+            return;
+        }
+        double [] xPoints = points[0];
+        double [] yPoints = points[1];
+        for (int i = 0; i < xPoints.length; i++) {
+            if (skipNANs &&
+                (Double.isNaN(xPoints[i]) || Double.isNaN(yPoints[i]))) {
+                logger.warn ("Skipping NaN in StyledSeriesBuilder.");
+                continue;
+            }
+            // Create gap if distance >= distance.
+            if (i != 0 && Math.abs(xPoints[i-1] - xPoints[i]) >= distance) {
+                if (!Double.isNaN(yPoints[i-1]) && !Double.isNaN(yPoints[i])) {
+                    series.add((xPoints[i-1]+xPoints[i])/2.d, Double.NaN, false);
+                }
+                logger.warn ("Gap " + xPoints[i-1] + " " + xPoints[i] + "!");
+            }
+            series.add(xPoints[i], yPoints[i], false);
+        }
+    }
+
+    /**
      * Add points to series.
      *
      * @param series Series to add points to.


More information about the Dive4elements-commits mailing list