Mercurial > mxd2map
diff src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 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 | 0f5819732288 |
children | 5ba8bf865dc7 |
line wrap: on
line diff
--- 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; + } }