changeset 5655:53a2ceeae9a3

Create floodmap colorrange dynamically from artifact parameters. Theme setting for colorrange classes is currently not functioning (wasn't before either).
author Christian Lins <christian.lins@intevation.de>
date Thu, 11 Apr 2013 11:25:41 +0200 (2013-04-11)
parents c5854dc8d6a1
children e8babbae5ee0
files flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java
diffstat 2 files changed, 36 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java	Thu Apr 11 10:55:41 2013 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/MapGenerator.java	Thu Apr 11 11:25:41 2013 +0200
@@ -2,6 +2,7 @@
 
 import com.vividsolutions.jts.geom.Envelope;
 
+import de.intevation.artifactdatabase.data.StateData;
 import de.intevation.artifactdatabase.state.ArtifactAndFacet;
 import de.intevation.artifactdatabase.state.Facet;
 import de.intevation.artifactdatabase.state.Settings;
@@ -15,6 +16,7 @@
 import de.intevation.flys.artifacts.model.map.WMSDBLayerFacet;
 import de.intevation.flys.artifacts.model.map.WMSLayerFacet;
 import de.intevation.flys.artifacts.model.map.WSPLGENLayerFacet;
+import de.intevation.flys.artifacts.states.WaterlevelGroundDifferences;
 import de.intevation.flys.collections.FLYSArtifactCollection;
 import de.intevation.flys.utils.ArtifactMapfileGenerator;
 import de.intevation.flys.utils.GeometryUtils;
@@ -134,11 +136,24 @@
     ) {
         try {
             if(wms instanceof WSPLGENLayerFacet) {
+                // Retrieve waterlevel ground differences from artifact
+                StateData dFrom = flys.getData(WaterlevelGroundDifferences.LOWER_FIELD);
+                StateData dTo   = flys.getData(WaterlevelGroundDifferences.UPPER_FIELD);
+                StateData dStep = flys.getData(WaterlevelGroundDifferences.DIFF_FIELD);
+
+                String fromStr = dFrom != null ? (String) dFrom.getValue() : null;
+                String toStr   = dTo   != null ? (String) dTo.getValue()   : null;
+                String stepStr = dStep != null ? (String) dStep.getValue() : null;
+
+                float from = Float.parseFloat(fromStr);
+                float to   = Float.parseFloat(toStr);
+                float step = Float.parseFloat(stepStr);
+
                 ArtifactMapfileGenerator mfg = new ArtifactMapfileGenerator();
                 mfg.createUeskLayer(
                     flys,
                     (WSPLGENLayerFacet) wms,
-                    ThemeUtil.createDynamicMapserverStyle(attr),
+                    ThemeUtil.createDynamicMapserverStyle(attr, from, to, step),
                     context);
             }
             else {
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Thu Apr 11 10:55:41 2013 +0200
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Thu Apr 11 11:25:41 2013 +0200
@@ -660,22 +660,35 @@
      * @param theme
      * @return String representation of the MapserverStyle
      */
-    public static String createDynamicMapserverStyle(Document theme) {
+    public static String createDynamicMapserverStyle(Document theme,
+            float from, float to, float step)
+    {
         MapserverStyle ms = new MapserverStyle();
 
         String strStartColor = XMLUtils.xpathString(theme, XPATH_WSPLGEN_STARTCOLOR, null);
         Color startColor = strStartColor != null ? parseColor(strStartColor) : new Color(178, 201, 215);
         String strEndColor = XMLUtils.xpathString(theme, XPATH_WSPLGEN_ENDCOLOR, null);
         Color endColor = strEndColor != null? parseColor(strEndColor) : new Color(2, 27, 42);
+/*
         String strNumClasses = XMLUtils.xpathString(theme, XPATH_WSPLGEN_NUMCLASSES, null);
-        int numClasses = strNumClasses != null ? Integer.parseInt(strNumClasses) : 5;
+        int numClasses;
+        if (strNumClasses != null) {
+            numClasses = Integer.parseInt(strNumClasses);
+        }
+        else {
+            numClasses = 5;
+            logger.warn("createDynamicMapserverStyle(): strNumClasses is null");
+        }
 
         if (numClasses < 5) {
             numClasses = 5;
         }
         else if (numClasses > 20) {
             numClasses = 20;
-        }
+        }*/
+
+
+        int numClasses = (int)((to - from) / step);
 
         float rd = (endColor.getRed()   - startColor.getRed())   / (float)numClasses;
         float gd = (endColor.getGreen() - startColor.getGreen()) / (float)numClasses;
@@ -689,7 +702,7 @@
             newColor.append(' ');
             newColor.append(startColor.getBlue()  + Math.round(n * bd));
 
-            String expr = createWSPLGENExpression(n + 1, numClasses);
+            String expr = createWSPLGENExpression(from + n * step, step, n + 1, numClasses);
 
             Clazz c = new Clazz(expr);
             Style s = new Style();
@@ -706,13 +719,12 @@
     }
 
 
-    protected static String createWSPLGENExpression(int idx, int maxIdx) {
+    protected static String createWSPLGENExpression(float val, float step, int idx, int maxIdx) {
         if (idx < maxIdx) {
-            int lower = idx - 1;
-            return "[DIFF] >= " + lower + " AND  [DIFF] < " + idx;
+            return "[DIFF] >= " + val + " AND  [DIFF] < " + (val + step);
         }
         else {
-            return "[DIFF] >= " + (maxIdx - 1);
+            return "[DIFF] >= " + val;
         }
     }
 

http://dive4elements.wald.intevation.org