[Dive4elements-commits] [PATCH] Floodmap can now be classified in the range 5 to 20 (incl.)

Wald Commits scm-commit at wald.intevation.org
Thu Nov 29 15:34:40 CET 2012


# HG changeset patch
# User Christian Lins <christian.lins at intevation.de>
# Date 1354199673 -3600
# Node ID 11545c3b9111288a768be46a769dea86bf42df7a
# Parent  bafb2e81a14a5010e451c3b23c0dbcde48c22f45
Floodmap can now be classified in the range 5 to 20 (incl.).

diff -r bafb2e81a14a -r 11545c3b9111 flys-artifacts/doc/conf/default-themes.xml
--- a/flys-artifacts/doc/conf/default-themes.xml	Thu Nov 29 10:29:34 2012 +0100
+++ b/flys-artifacts/doc/conf/default-themes.xml	Thu Nov 29 15:34:33 2012 +0100
@@ -1138,7 +1138,7 @@
             <field name="endcolor" type="Color"
                 display="Farbverlauf Endfarbe" default="2, 27, 42" />
             <field name="numclasses" type="int" display="Anzahl Klassen"
-                default="5" />
+                default="6" />
         </fields>
     </theme>
 
diff -r bafb2e81a14a -r 11545c3b9111 flys-artifacts/doc/conf/virtual-themes.xml
--- a/flys-artifacts/doc/conf/virtual-themes.xml	Thu Nov 29 10:29:34 2012 +0100
+++ b/flys-artifacts/doc/conf/virtual-themes.xml	Thu Nov 29 15:34:33 2012 +0100
@@ -162,16 +162,12 @@
     <!-- MAP relevant themes -->
     <theme name="WSPLGENS" type="virtual">
         <fields>
-            <field name="wsplgen_cat1" type="Color" display="Hintergrund"
-                default="178, 201, 215" />
-            <field name="wsplgen_cat2" type="Color" display="Hintergrund"
-                default="111, 147, 170" />
-            <field name="wsplgen_cat3" type="Color" display="Hintergrund"
-                default="66, 111, 139" />
-            <field name="wsplgen_cat4" type="Color" display="Hintergrund"
-                default="33, 79, 108" />
-            <field name="wsplgen_cat5" type="Color" display="Hintergrund"
-                default="2, 27, 42" />
+            <field name="startcolor" type="Color"
+                display="Farbverlauf Startfarbe" default="178, 201, 215" />
+            <field name="endcolor" type="Color"
+                display="Farbverlauf Endfarbe" default="2, 27, 42" />
+            <field name="numclasses" type="int" display="Anzahl Klassen"
+                default="5" />
         </fields>
     </theme>
 
diff -r bafb2e81a14a -r 11545c3b9111 flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Thu Nov 29 10:29:34 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java	Thu Nov 29 15:34:33 2012 +0100
@@ -10,12 +10,8 @@
 import java.awt.Color;
 import java.awt.Font;
 
-import javax.xml.xpath.XPathConstants;
-
 import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
 
 
 /**
@@ -118,13 +114,13 @@
             "/theme[@name='WSPLGEN']/field";
 
     public final static String XPATH_WSPLGEN_STARTCOLOR =
-            "/theme/field[@name='startcolor'/@default";
+            "/theme/field[@name='startcolor']/@default";
 
     public final static String XPATH_WSPLGEN_ENDCOLOR =
-            "/theme/field[@name='endcolor'/@default";
+            "/theme/field[@name='endcolor']/@default";
 
     public final static String XPATH_WSPLGEN_NUMCLASSES =
-            "/theme/field[@name='numclasses'/@default";
+            "/theme/field[@name='numclasses']/@default";
 
     /** XPATH to bandwidth field. */
     public final static String XPATH_BANDWIDTH =
@@ -630,12 +626,12 @@
     public static String createWSPLGENStyle(Document theme) {
         MapserverStyle ms = new MapserverStyle();
 
-        Color startColor = parseColor(
-                XMLUtils.xpathString(theme, XPATH_WSPLGEN_STARTCOLOR, null));
-        Color endColor = parseColor(
-                XMLUtils.xpathString(theme, XPATH_WSPLGEN_ENDCOLOR, null));
-        int numClasses = Integer.parseInt(
-                XMLUtils.xpathString(theme, XPATH_WSPLGEN_NUMCLASSES, null));
+        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;
 
         if (numClasses < 5) {
             numClasses = 5;
@@ -644,9 +640,9 @@
             numClasses = 20;
         }
 
-        int rd = (startColor.getRed()   - endColor.getRed())   / numClasses;
-        int gd = (startColor.getGreen() - endColor.getGreen()) / numClasses;
-        int bd = (startColor.getBlue()  - endColor.getBlue())  / numClasses;
+        int rd = (endColor.getRed()   - startColor.getRed())   / numClasses;
+        int gd = (endColor.getGreen() - startColor.getGreen()) / numClasses;
+        int bd = (endColor.getBlue()  - startColor.getBlue())  / numClasses;
 
         for (int n = 0; n < numClasses; n++) {
             StringBuilder newColor = new StringBuilder();
@@ -656,74 +652,30 @@
             newColor.append(' ');
             newColor.append(startColor.getBlue()  + n * bd);
 
-            Clazz c = new Clazz("Klasse " + n + " (FIXME)");
+            String expr = createWSPLGENExpression(n + 1, numClasses);
+
+            Clazz c = new Clazz(expr);
             Style s = new Style();
             s.setColor(newColor.toString());
             s.setSize(5);
 
-            c.addItem(new Expression("Klasse " + n));
-            c.addItem(s);
-
-            ms.addClazz(c);
-        }
-
-        NodeList categories = (NodeList) XMLUtils.xpath(
-                theme,
-                XPATH_WSPLGEN_FIELDS,
-                XPathConstants.NODESET);
-
-        return createWSPLGENStyle(categories).toString();
-    }
-
-    /**
-     * Creates a style for the Mapfile template used by MapfileGenerator
-     * to generate floodmaps.
-     * @param categories
-     * @return
-     */
-    protected static MapserverStyle createWSPLGENStyle(NodeList categories) {
-        MapserverStyle ms = new MapserverStyle();
-
-        for (int i = 0, n = categories.getLength(); i < n; i++) {
-            Element  cat = (Element) categories.item(i);
-            String color = cat.getAttribute("default");
-            String name  = cat.getAttribute("name");
-
-            String expr;
-
-            try {
-                int length = name.length();
-                int idx    = Integer.parseInt(name.substring(length-1, length));
-
-                expr = createWSPLGENExpression(idx);
-            }
-            catch (NumberFormatException nfe) {
-                logger.warn("Error while parsing WSPLGEN category.", nfe);
-                continue;
-            }
-
-            Clazz      c = new Clazz(expr);
-            Style      s = new Style();
-            s.setColor(color.replace(",", ""));
-            s.setSize(5);
-
             c.addItem(new Expression("(" + expr + ")"));
             c.addItem(s);
 
             ms.addClazz(c);
         }
 
-        return ms;
+        return ms.toString();
     }
 
 
-    protected static String createWSPLGENExpression(int idx) {
-        if (idx < 5) {
+    protected static String createWSPLGENExpression(int idx, int maxIdx) {
+        if (idx < maxIdx) {
             int lower = idx - 1;
             return "[DIFF] >= " + lower + " AND  [DIFF] < " + idx;
         }
         else {
-            return "[DIFF] >= 4";
+            return "[DIFF] >= " + (maxIdx - 1);
         }
     }
 


More information about the Dive4elements-commits mailing list