changeset 7460:2733b4aae74b

flys/issue1625: Changed default sediment density factor from 1.8 to 1.9 . The value can be changed by adusting conf.xml (/artifact-databae/options/sediment-density-factor/text()).
author Sascha L. Teichmann <teichmann@intevation.de>
date Tue, 29 Oct 2013 19:46:41 +0100 (2013-10-29)
parents 9434437a1ef5
children 5b5a2cc8210f 906ed0b1f3f1
files artifacts/doc/conf/conf.xml artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensity.java
diffstat 2 files changed, 39 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/doc/conf/conf.xml	Tue Oct 29 19:17:28 2013 +0100
+++ b/artifacts/doc/conf/conf.xml	Tue Oct 29 19:46:41 2013 +0100
@@ -340,6 +340,8 @@
         </zoom-scales>
 
         <dgm-path>/path/to/rivers/</dgm-path>
+
+        <sediment-density-factor>1.9</sediment-density-factor>
     </options>
 
     <!-- base url for online help. -->
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensity.java	Tue Oct 29 19:17:28 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensity.java	Tue Oct 29 19:46:41 2013 +0100
@@ -8,6 +8,8 @@
 
 package org.dive4elements.river.artifacts.model.minfo;
 
+import java.io.Serializable;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -16,9 +18,9 @@
 import java.util.Set;
 import java.util.TreeMap;
 
-import java.io.Serializable;
+import org.apache.log4j.Logger;
 
-import org.apache.log4j.Logger;
+import org.dive4elements.artifacts.common.utils.Config;
 
 
 /** Sediment Densities for multiple years. */
@@ -27,9 +29,40 @@
     private static final Logger logger = Logger
         .getLogger(SedimentDensity.class);
 
+    public static final double DEFAULT_SEDIMNET_DENSITY_FACTOR = 1.9;
+
+    public static String SEDIMENT_DENSITY_FACTOR_XPATH =
+        "/artifact-database/options/sediment-density-factor/text()";
+
+    public static final double SEDIMNET_DENSITY_FACTOR =
+        getSedimentDensityFactor();
+
     private Map<Integer, List<SedimentDensityValue>> densities;
     private List<Integer> years;
 
+
+    /** Figures out the sediment density factor from global config. */
+    private static final double getSedimentDensityFactor() {
+
+        double factor = DEFAULT_SEDIMNET_DENSITY_FACTOR;
+
+        String factorString =
+            Config.getStringXPath(SEDIMENT_DENSITY_FACTOR_XPATH);
+
+        if (factorString != null) {
+            try {
+                factor = Double.parseDouble(factorString.trim());
+            }
+            catch (NumberFormatException nfe) {
+                logger.error(nfe);
+            }
+        }
+
+        logger.info("Sedmiment density factor: " + factor);
+
+        return factor;
+    }
+
     public SedimentDensity() {
         this.densities = new HashMap<Integer, List<SedimentDensityValue>>();
         this.years = new ArrayList<Integer>();
@@ -80,7 +113,7 @@
             logger.debug("get density from year " + year + " at km " + km);
             return getDensityAtKm(densities.get(years.get(0)), km);
         }
-        else if (this.years.size() > 1) {
+        if (this.years.size() > 1) {
             for (int i = 0, I = years.size()-1; i < I; i++) {
                 int y1 = years.get(i);
                 int y2 = years.get(i + 1);
@@ -92,7 +125,7 @@
                 }
             }
         }
-        return 1.8d;
+        return SEDIMNET_DENSITY_FACTOR;
     }
 
     /** Get (sorted) map of km to density of all years. */

http://dive4elements.wald.intevation.org