changeset 95:1ae8e05b863f

Use the line style writer to write simple lines and marker lines.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 01 Jun 2011 14:07:56 +0200
parents 273e49f51cfb
children c285ed08b72c
files ChangeLog src/java/de/intevation/mxd/writer/LineStyleWriter.java src/java/de/intevation/mxd/writer/MapScriptWriter.java
diffstat 3 files changed, 119 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Jun 01 11:52:53 2011 +0200
+++ b/ChangeLog	Wed Jun 01 14:07:56 2011 +0200
@@ -1,3 +1,11 @@
+2011-06-01  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/writer/MapScriptWriter.java:
+	  Use the line style writer to write simple lines and marker lines.
+
+	* src/java/de/intevation/mxd/writer/LineStyleWriter.java:
+	  New. Writes line styles to the mapfile.
+
 2011-06-01  Raimund Renkert  <raimund.renkert@intevation.de>
 
 	* src/java/de/intevation/mxd/reader/CharacterMarkerSymbolReader.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/writer/LineStyleWriter.java	Wed Jun 01 14:07:56 2011 +0200
@@ -0,0 +1,109 @@
+package de.intevation.mxd.writer;
+
+import java.awt.Color;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Element;
+
+import edu.umn.gis.mapscript.mapObj;
+import edu.umn.gis.mapscript.classObj;
+import edu.umn.gis.mapscript.styleObj;
+import edu.umn.gis.mapscript.colorObj;
+import edu.umn.gis.mapscript.symbolObj;
+import edu.umn.gis.mapscript.symbolSetObj;
+
+
+/**
+ * The interface to the mapfile writer.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class LineStyleWriter {
+
+    /**
+     * The Logger.
+     */
+    private static final Logger logger = Logger.getLogger(LineStyleWriter.class);
+
+    private mapObj map;
+    private classObj cl;
+    private styleObj style;
+
+    public LineStyleWriter (mapObj map, classObj cl) {
+        this.map = map;
+        this.cl = cl;
+        this.style = new styleObj(cl);
+    }
+
+    /**
+     * Write the content.
+     */
+    public boolean write(Element symbolElement)
+    throws Exception {
+        logger.debug("write(Element)");
+        symbolSetObj symbolSet = map.getSymbolset();
+        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);
+            colorObj color = new colorObj(
+                col.getRed(),
+                col.getGreen(),
+                col.getBlue(),
+                -4);
+            style.setColor(color);
+        }
+        if(symbolElement.hasAttribute("width")) {
+            style.setWidth((int)Double.parseDouble(
+                symbolElement.getAttribute("width")));
+        }
+        if(symbolElement.hasAttribute("size")) {
+            style.setSize((int)Double.parseDouble(
+                symbolElement.getAttribute("size")));
+        }
+        String name = symbolElement.getAttribute("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.(Remove the "&& false"
+        //to use this block).
+        if(symbolElement.hasAttribute("linestyle") && false) {
+            String ls = symbolElement.getAttribute("linestyle");
+            double[] vals;
+            if(ls.equals("dash")) {
+                style.setPatternlength(2);
+                vals = new double[] {2.0, 2.0};
+                style.setPattern(vals);
+            }
+            else if(ls.equals("dot")) {
+                style.setPatternlength(2);
+                vals = new double[] {1.0, 2.0};
+                style.setPattern(vals);
+            }
+            else if(ls.equals("dashdot")) {
+                style.setPatternlength(4);
+                vals = new double[] {2.0, 2.0, 1.0, 2.0};
+                style.setPattern(vals);
+            }
+            else if (ls.equals("dashdotdot")) {
+                style.setPatternlength(6);
+                vals = new double[] {2.0, 2.0, 1.0, 2.0, 1.0, 2.0};
+                style.setPattern(vals);
+            }
+        }
+        String type = symbolElement.getAttribute("type");
+
+        if(type.equals("marker")) {
+            style.setSymbolByName(map, name);
+            SymbolWriter sw = new SymbolWriter(this.map, this.cl);
+            sw.write(symbolElement);
+        }
+        return false;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Wed Jun 01 11:52:53 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Wed Jun 01 14:07:56 2011 +0200
@@ -232,8 +232,8 @@
             else if(type.equals("line")) {
                 for(int j = 0; j < slist.getLength(); j++){
                     Element symbolElement = (Element) slist.item(j);
-//                    LineStyleWriter swriter = new LineStyleWriter (this.map, co);
-//                    swriter.write (symbolElement);
+                    LineStyleWriter swriter = new LineStyleWriter (this.map, co);
+                    swriter.write (symbolElement);
                 }
             }
         }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)