changeset 126:ff0354265a7d

Write the correct expression for double values.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 17 Jun 2011 18:22:40 +0200
parents 69a346c45836
children 5ba8bf865dc7
files ChangeLog src/java/de/intevation/mxd/reader/ClassBreakRendererReader.java src/java/de/intevation/mxd/writer/MapScriptWriter.java
diffstat 3 files changed, 66 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Jun 17 14:32:17 2011 +0200
+++ b/ChangeLog	Fri Jun 17 18:22:40 2011 +0200
@@ -1,3 +1,13 @@
+2011-06-17  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	Write the correct expression for double values.
+
+	* src/java/de/intevation/mxd/reader/ClassBreakRendererReader.java:
+	  Read the lower bound of the breaks.
+
+	* src/java/de/intevation/mxd/writer/MapScriptWriter.java:
+	  Write expressions for double values as range to the mapfile.
+
 2011-06-17  Stephan Holl  <stephan.holl@intevation.de>
 
 	* mxd/projections/DHDN-projection-dataframe.mxd: Added testcase
--- a/src/java/de/intevation/mxd/reader/ClassBreakRendererReader.java	Fri Jun 17 14:32:17 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/ClassBreakRendererReader.java	Fri Jun 17 18:22:40 2011 +0200
@@ -98,7 +98,7 @@
                 }
                 rendererElement.setAttribute(
                     "min_value",
-                    String.valueOf(renderer.getMinimumBreak()));
+                    String.valueOf(renderer.getLowBreak(i)));
                 rendererElement.setAttribute("expression_operator", "<=");
 
                 ISymbol sym = renderer.getSymbol(i);
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Fri Jun 17 14:32:17 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Fri Jun 17 18:22:40 2011 +0200
@@ -219,14 +219,18 @@
             if(classElement.hasAttribute("field_count")) {
                 int count =
                     Integer.parseInt(classElement.getAttribute("field_count"));
-                String exp = "";
-                for(int j = 0; j < count; j++) {
-                    //TODO Find a way to create Expressions.
-                    exp = "([" + classElement.getAttribute("expression_field_" + j);
-                    exp += "] " + classElement.getAttribute("expression_operator");
-                    exp += " " + classElement.getAttribute("value") + ")";
+                int type = 0;
+                try {
+                    Double.parseDouble(classElement.getAttribute("value"));
+                    type = 1;
                 }
-                co.setExpression(exp);
+                catch(Exception e) {
+                    type = 2;
+                    logger.info("not a double");
+                }
+                if (type == 1) {
+                    co.setExpression(createDoubleExpression(classElement, count));
+                }
             }
             //Write symbols and styles.
             NodeList l = classElement.getChildNodes();
@@ -249,5 +253,49 @@
             }
         }
     }
+
+    private String createDoubleExpression (Element classElement, int count) {
+        String exp = "";
+        String op = classElement.getAttribute("expression_operator");
+        String op1 = "";
+        String op2 = "";
+        if (op.equals("<=")) {
+            op1 = ">=";
+            op2 = op;
+            for(int j = 0; j < count; j++) {
+                if (classElement.getAttribute("min_value").equals(
+                    classElement.getAttribute("value"))) {
+                    exp = "([" +
+                          classElement.getAttribute(
+                              "expression_field_" + j) +
+                          "] == " +
+                          classElement.getAttribute("value") +
+                          ")";
+                }
+                else {
+                    exp = "([";
+                    exp += classElement.getAttribute(
+                                "expression_field_" + j);
+                    exp += "] " + op1;
+                    exp += " " + classElement.getAttribute("min_value");
+                    exp += " AND [" + classElement.getAttribute(
+                            "expression_field_" + j);
+                    exp += "] " + op2 + " ";
+                    exp += classElement.getAttribute("value");
+                    exp += ")";
+                }
+            }
+        }
+        else if (op.equals("==")) {
+            op1 = op;
+            for(int j = 0; j < count; j++) {
+               exp = "([" +
+                     classElement.getAttribute("expression_field_" + j) +
+                     "] == " +
+                     classElement.getAttribute("value") + ")";
+            }
+        }
+        return exp;
+    }
 }
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)