changeset 62:e468cf8701ea

Prepared the converter to handle and write line symbols.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 24 May 2011 14:16:25 +0200
parents e00deee347a5
children 5c5ef5768893
files ChangeLog src/java/de/intevation/mxd/reader/FeatureLayerReader.java src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java src/java/de/intevation/mxd/writer/MapScriptWriter.java
diffstat 4 files changed, 63 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon May 23 13:16:42 2011 +0200
+++ b/ChangeLog	Tue May 24 14:16:25 2011 +0200
@@ -1,3 +1,14 @@
+2011-05-24  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/reader/FeatureLayerReader.java:
+	  Set the layer type to line when reading a line layer.
+
+	* src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java:
+	  Added style option and renamed xml node "style" to "linestyle".
+
+	* src/java/de/intevation/mxd/writer/MapScriptWriter.java:
+	  Prepared the mapfile writer to write line symbols.
+
 2011-05-23  Raimund Renkert  <raimund.renkert@intevation.de>
 
 	Added first line symbol reader.
--- a/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Mon May 23 13:16:42 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Tue May 24 14:16:25 2011 +0200
@@ -87,8 +87,9 @@
 
         int type = layer.getShapeType();
         switch (type) {
-            case 0: layerElement.setAttribute("type", "none");
-            case 1: layerElement.setAttribute("type", "point");
+            case 0: layerElement.setAttribute("type", "none"); break;
+            case 1: layerElement.setAttribute("type", "point"); break;
+            case 3: layerElement.setAttribute("type", "line"); break;
         }
 
         layerElement.setAttribute("definition_query",
--- a/src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java	Mon May 23 13:16:42 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java	Tue May 24 14:16:25 2011 +0200
@@ -83,6 +83,7 @@
         }
 
         symbolElement.setAttribute("name", symbol.getNameString());
+        symbolElement.setAttribute("style", "line");
         symbolElement.setAttribute("type", "simple");
         if(symbol.getColor() instanceof IRgbColor) {
             IRgbColor color = (IRgbColor)symbol.getColor();
@@ -107,16 +108,16 @@
         int style = symbol.getStyle();
         switch(style) {
             case esriSimpleLineStyle.esriSLSSolid:
-                    symbolElement.setAttribute("style", "solid"); break;
+                    symbolElement.setAttribute("linestyle", "solid"); break;
             case esriSimpleLineStyle.esriSLSDash:
-                    symbolElement.setAttribute("style", "dash"); break;
+                    symbolElement.setAttribute("linestyle", "dash"); break;
             case esriSimpleLineStyle.esriSLSDot:
-                    symbolElement.setAttribute("style", "dot"); break;
+                    symbolElement.setAttribute("linestyle", "dot"); break;
             case esriSimpleLineStyle.esriSLSDashDot:
-                    symbolElement.setAttribute("style", "dashdot"); break;
+                    symbolElement.setAttribute("linestyle", "dashdot"); break;
             case esriSimpleLineStyle.esriSLSDashDotDot:
-                    symbolElement.setAttribute("style", "dashdotdot"); break;
-            default: symbolElement.setAttribute ("style", "none");
+                    symbolElement.setAttribute("linestyle", "dashdotdot"); break;
+            default: symbolElement.setAttribute ("linestyle", "none");
         }
         return symbolElement;
     }
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Mon May 23 13:16:42 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Tue May 24 14:16:25 2011 +0200
@@ -174,6 +174,9 @@
             if(type.equals("point")) {
                 layer.setType(MS_LAYER_TYPE.MS_LAYER_POINT);
             }
+            else if (type.equals("line")) {
+                layer.setType(MS_LAYER_TYPE.MS_LAYER_LINE);
+            }
 
             //The layer datasource.
             layer.setData(layerElement.getAttribute("data_source"));
@@ -230,12 +233,13 @@
         //Get the symbol set from the map object.
         symbolSetObj symbolSet = map.getSymbolset();
 
-        //
         for(int i = 0; i < list.getLength(); i++){
             Element symbolElement = (Element) list.item(i);
             styleObj style = new styleObj(co);
-            style.setAngle(
-                Double.parseDouble(symbolElement.getAttribute("angle")));
+            if (symbolElement.hasAttribute("angle")) {
+                style.setAngle(
+                    Double.parseDouble(symbolElement.getAttribute("angle")));
+            }
             if(symbolElement.hasAttribute("color")) {
                 String c = symbolElement.getAttribute("color");
                 Color col = Color.decode(c);
@@ -246,8 +250,10 @@
                     -4);
                 style.setColor(color);
             }
-            style.setSize(Double.parseDouble(
-                symbolElement.getAttribute("size")));
+            if (symbolElement.hasAttribute ("size")) {
+                style.setSize(Double.parseDouble(
+                    symbolElement.getAttribute("size")));
+            }
             if(symbolElement.hasAttribute("outline_color")) {
                 Color oCol = Color.decode(
                     symbolElement.getAttribute("outline_color"));
@@ -260,10 +266,26 @@
                 style.setOutlinewidth(Double.parseDouble(
                     symbolElement.getAttribute("outline_size")));
             }
+            //Section for line symbols
+            //Setting the width
+            if(symbolElement.hasAttribute("width")) {
+                style.setWidth((int)Double.parseDouble(
+                    symbolElement.getAttribute("width")));
+            }
             String name = symbolElement.getAttribute("name");
             style.setSymbolByName(map, name);
             symbolObj sym = symbolSet.getSymbolByName(name);
 
+            //The following lines are for dashed and/or dotted lines.
+            //These lines throw an "incorrect array size" error.
+            //TODO Find out how to set the pattern correctly.
+//            style.setPatternlength(2);
+//            double[] vals = new double[] {1.0, 2.0, 3.0};
+//            vals[0] = 1.0;
+//            vals[1] = 2.0;
+//            vals[2] = 3.0;
+//            vals[3] = 4.0;
+//            style.setPattern(vals);
             String symType = symbolElement.getAttribute("style");
             if(symType.equals("point")) {
                 writePointSymbol(sym, symbolElement);
@@ -274,6 +296,9 @@
             else if (symType.equals("char")) {
                 writeCharSymbol(sym, symbolElement);
             }
+            else if(symType.equals("line")) {
+                writeSimpleLineSymbol(sym, symbolElement);
+            }
         }
         saveSymbolSet(symbolSet);
     }
@@ -328,6 +353,18 @@
     }
 
 
+    private void writeSimpleLineSymbol(
+        symbolObj symbol,
+        Element symbolElement) {
+        logger.debug("writeSimpleLineSymbol()");
+        symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_SIMPLE.swigValue());
+        String ls = symbolElement.getAttribute("linestyle");
+        if(ls.equals("solid")) {
+            symbol.setFilled(1);
+        }
+    }
+
+
     /**
      * Save the symbol set.
      * @param symbols The symbol set.
@@ -337,7 +374,6 @@
             root,
             "/mxd/file",
             XPathConstants.NODE);
-        String mapFilename = fileNode.getAttribute("name");
         String path = "";
         if(mapFilename.contains("/")) {
             path = mapFilename.substring(0, mapFilename.lastIndexOf("/"));
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)