changeset 6382:43ef4943e0c2

SedimentLoadFacet: Now that we have total load values with correct ranges in place, use them accordingly instead of guessing ranges based on point data.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 21 Jun 2013 11:42:11 +0200
parents df1a3826c691
children e26655a8f98d
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFacet.java
diffstat 1 files changed, 32 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFacet.java	Fri Jun 21 11:41:10 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFacet.java	Fri Jun 21 11:42:11 2013 +0200
@@ -8,6 +8,8 @@
 
 package org.dive4elements.river.artifacts.model.minfo;
 
+import gnu.trove.TDoubleArrayList;
+
 import org.dive4elements.artifactdatabase.state.Facet;
 
 import org.dive4elements.artifacts.Artifact;
@@ -70,6 +72,11 @@
             return null;
         }
 
+        // These complicated calculations were necessary because
+        // SedimentLoad/Fraction did not contain the ranges of the given
+        // values. Since this changed, the code is somewhat obsolete, but stable.
+        // For an example of easier calculation, see the "total" part below.
+
         List<Double> sortedStarts = new ArrayList<Double>();
         // Filter stations according to type.
         List<MeasurementStation> stations = new ArrayList<MeasurementStation>();
@@ -90,7 +97,31 @@
         }
         Collections.sort(sortedStarts);
 
-        // Access data according to type.
+        // Handle sediment load differently, as it respects already
+        // the ranges that were added to SedimentLoad/Fraction.
+        if (getName().equals(FacetTypes.SEDIMENT_LOAD_TOTAL)) {
+            SedimentLoad load = result.getLoad();
+            TDoubleArrayList xPos = new TDoubleArrayList();
+            TDoubleArrayList yPos = new TDoubleArrayList();
+            double lastX = -1d;
+            for (double km: load.getKms()) {
+                SedimentLoadFraction fraction = load.getFraction(km);
+                if (fraction.getTotal() != 0) {
+                    if (Math.abs(lastX-km) >= EPSILON) {
+                       xPos.add(Double.NaN);
+                       yPos.add(Double.NaN);
+                    }
+                    xPos.add(km);
+                    yPos.add(fraction.getTotal());
+                    xPos.add(fraction.getTotalRange().getEnd());
+                    yPos.add(fraction.getTotal());
+                    lastX = fraction.getTotalRange().getEnd();
+                }
+            }
+            return new double[][] {xPos.toNativeArray(), yPos.toNativeArray()};
+        }
+
+        // Access data according to type (except total - see above).
         double[][] sd = getLoadData(result);
 
         // Sort by km.

http://dive4elements.wald.intevation.org