Mercurial > mxd2map
diff src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 311:c8b8f887ef80
Add write support for Fgdb layers and make it possible
to remove a prefix from the expressions. The expressions
returned by arcgis for Fgdb data contain the data source
name as a prefix. Mapserver does not need it and does not
match those expressions so they have to be removed
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 14 Sep 2012 11:54:03 +0200 |
parents | 1c949a309940 |
children | cd3cb1a7f35a |
line wrap: on
line diff
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java Fri Sep 14 11:50:40 2012 +0200 +++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java Fri Sep 14 11:54:03 2012 +0200 @@ -527,6 +527,10 @@ layer.setConnectionType(MS_CONNECTION_TYPE.MS_WMS.swigValue(), ""); layer.setMetaData("wms_name", layerElement.getAttribute("wms_name")); + } else if(con_type.equals("ogr")) { + layer.setConnectionType(MS_CONNECTION_TYPE.MS_OGR.swigValue(), ""); + layer.setConnection(layerElement.getAttribute("connection")); + layer.setData(layerElement.getAttribute("data_source")); } if(!type.equals("raster")) { layer.setTemplate("PleaseInsertAValidTemplateForGFI"); @@ -544,6 +548,14 @@ String expr = label.getAttribute("expression"); expr = expr.replaceAll("\\[", ""); expr = expr.replaceAll("\\]", ""); + if (con_type == "ogr") { + // ogr expression fields come prefixed from arcgis + // the prefix has to be removed in order to work with + // mapserver + String unwantedPrefix = layerElement.getAttribute("data") + "."; + logger.debug("Removing expression Prefix: " + unwantedPrefix); + expr = expr.replace(unwantedPrefix, ""); + } if(!prefix.equals("")) { expr = prefix + "." + expr; } @@ -593,7 +605,8 @@ //Create definition expression. if(classElement.hasAttribute("field_count")) { - co.setExpression(createExpression(classElement, i)); + String unwantedPrefix = layerElement.getAttribute("data") + "."; + co.setExpression(createExpression(classElement, i, unwantedPrefix)); } //Write symbols and styles. @@ -701,8 +714,10 @@ * * @param ce DOM elementcontaining the class expression information. * @param index Index to determine the correct expression operator. + * @param prefixToRemove A string that will be removed from the start of + * expression fields. */ - private String createExpression(Element ce, int index) { + private String createExpression(Element ce, int index, String prefixToRemove) { String expression = "("; int count = 0; try { @@ -723,7 +738,8 @@ pre = prefix + "."; } expression += "[" + pre; - expression += ce.getAttribute("expression_field_0") + "]"; + expression += ce.getAttribute("expression_field_0").replace( + prefixToRemove, "") + "]"; if(ce.hasAttribute("min_value")) { if(index == 0) { expression += " >= " + ce.getAttribute("min_value"); @@ -732,7 +748,8 @@ expression += " > " + ce.getAttribute("min_value"); } expression += " AND [" + pre; - expression += ce.getAttribute("expression_field_0"); + expression += ce.getAttribute("expression_field_0").replace( + prefixToRemove, ""); expression += "]"; } expression += " " + ce.getAttribute("expression_operator"); @@ -740,13 +757,15 @@ } catch(NumberFormatException nfe) { //The expression value is a strings. - String exp = ce.getAttribute("expression_field_0"); + String exp = ce.getAttribute("expression_field_0").replace( + prefixToRemove, ""); String pre = ""; if (!prefix.equals("") && !exp.startsWith(prefix)) { pre = prefix + "."; } expression += "\"[" + pre; - expression += ce.getAttribute("expression_field_0") + "]\""; + expression += ce.getAttribute("expression_field_0").replace( + prefixToRemove, "") + "]\""; expression += " " + ce.getAttribute("expression_operator"); expression += " \"" + ce.getAttribute("value") + "\")"; } @@ -761,13 +780,15 @@ //If no exception is thrown, the expression values are //numbers. Double.parseDouble(ce.getAttribute("value_" + i)); - String exp = ce.getAttribute("expression_field_" + i); + String exp = ce.getAttribute("expression_field_" + i).replace( + prefixToRemove, ""); String pre = ""; if (!prefix.equals("") && !exp.startsWith(prefix)) { pre = prefix + "."; } expression += "[" + pre; - expression += ce.getAttribute("expression_field_" + i); + expression += ce.getAttribute("expression_field_" + i).replace( + prefixToRemove, ""); expression += "]"; expression += " " + ce.getAttribute("expression_operator"); expression += " " + ce.getAttribute("value_" + i); @@ -780,13 +801,15 @@ } catch (NumberFormatException nfe) { //The expression values are strings. - String exp = ce.getAttribute("expression_field_" + i); + String exp = ce.getAttribute("expression_field_" + i).replace( + prefixToRemove, ""); String pre = ""; if (!prefix.equals("") && !exp.startsWith(prefix)) { pre = prefix + "."; } expression += "\"[" + pre; - expression += ce.getAttribute("expression_field_" + i); + expression += ce.getAttribute("expression_field_" + i).replace( + prefixToRemove, ""); expression += "]\""; expression += " " + ce.getAttribute("expression_operator"); expression += " \"" + ce.getAttribute("value_" + i);