changeset 7200:483cae8915f6

issue1435: Add methods to get data in StyledSeriesBuilder-friendly format, doc.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 30 Sep 2013 17:28:58 +0200
parents baf04164fcc6
children 3aaacdedf360
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensity.java
diffstat 1 files changed, 44 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensity.java	Mon Sep 30 09:38:09 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensity.java	Mon Sep 30 17:28:58 2013 +0200
@@ -14,10 +14,12 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeMap;
 
 import org.apache.log4j.Logger;
 
 
+/** Sediment Densities for multiple years. */
 public class SedimentDensity
 {
     private static final Logger logger = Logger
@@ -67,8 +69,8 @@
 
     /**
      * Get the density at year.
-     * measured densities are valid until the next measurement.
-     * if no measurement was found 1.8 is returned.
+     * Measured densities are valid until the next measurement.
+     * If no measurement was found 1.8 is returned.
      */
     public double getDensity(double km, int year) {
         Collections.sort(this.years);
@@ -91,6 +93,45 @@
         return 1.8d;
     }
 
+    /** Get (sorted) map of km to density of all years. */
+    protected double[][] getAllDensities()
+    {
+        TreeMap<Double, Double> map = new TreeMap<Double,Double>();
+        for (int year: years) {
+            for (SedimentDensityValue sdv: densities.get(year)) {
+                map.put(sdv.getKm(), sdv.getDensity());
+            }
+        }
+        double[][] points = new double[2][map.keySet().size()];
+        int i = 0;
+        for (Map.Entry<Double, Double> kmDens: map.entrySet()) {
+            points[0][i] = kmDens.getKey();
+            points[2][i] = kmDens.getValue();
+            i++;
+        }
+
+        return points;
+    }
+
+    /** Get points  km,density (sorted by km), for a given year. */
+    public double[][] getDensities(int year)
+    {
+        TreeMap<Double, Double> map = new TreeMap<Double,Double>();
+        for (SedimentDensityValue sdv: densities.get(year)) {
+            map.put(sdv.getKm(), sdv.getDensity());
+        }
+        double[][] points = new double[2][map.keySet().size()];
+        int i = 0;
+        for (Map.Entry<Double, Double> kmDens: map.entrySet()) {
+            points[0][i] = kmDens.getKey();
+            points[1][i] = kmDens.getValue();
+            i++;
+        }
+
+        return points;
+    }
+
+    /** Get value at km, interpolated. */
     private double getDensityAtKm(
         List<SedimentDensityValue> values,
         double km
@@ -111,6 +152,7 @@
         return spline(prev, next, km);
     }
 
+    /** Linearly interpolate between density values. */
     private static double spline(
         SedimentDensityValue prev,
         SedimentDensityValue next,

http://dive4elements.wald.intevation.org