changeset 97:18e4f143896b

Added polygon writer.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 06 Jun 2011 17:24:43 +0200
parents c285ed08b72c
children 4696d0769f9c
files ChangeLog src/java/de/intevation/mxd/reader/CartoLineSymbolReader.java src/java/de/intevation/mxd/reader/FeatureLayerReader.java src/java/de/intevation/mxd/reader/HashLineSymbolReader.java src/java/de/intevation/mxd/reader/LineFillSymbolReader.java src/java/de/intevation/mxd/reader/PictureLineSymbolReader.java src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java src/java/de/intevation/mxd/writer/FillStyleWriter.java src/java/de/intevation/mxd/writer/MapScriptWriter.java src/java/de/intevation/mxd/writer/SymbolWriter.java
diffstat 10 files changed, 287 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Jun 01 14:21:24 2011 +0200
+++ b/ChangeLog	Mon Jun 06 17:24:43 2011 +0200
@@ -1,3 +1,28 @@
+2011-06-06  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	Added polygon writer.
+
+	* src/java/de/intevation/mxd/reader/LineFillSymbolReader.java:
+	  Read the angle from the symbol.
+
+	* src/java/de/intevation/mxd/reader/HashLineSymbolReader.java,
+	  src/java/de/intevation/mxd/reader/CartoLineSymbolReader.java,
+	  src/java/de/intevation/mxd/reader/PictureLineSymbolReader.java,
+	  src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java:
+	  Set type and style for all line symbol reader.
+
+	* src/java/de/intevation/mxd/reader/FeatureLayerReader.java:
+	  Added polygon as layer type.
+
+	* src/java/de/intevation/mxd/writer/SymbolWriter.java:
+	  Added method to write hatch symbols.
+
+	* src/java/de/intevation/mxd/writer/MapScriptWriter.java:
+	  Write the polygon layer.
+
+	* src/java/de/intevation/mxd/writer/FillStyleWriter.java:
+	  New. Writes polygon layer to the mapfile.
+
 2011-06-01  Raimund Renkert  <raimund.renkert@intevation.de>
 
 	* src/java/de/intevation/mxd/Converter.java,
--- a/src/java/de/intevation/mxd/reader/CartoLineSymbolReader.java	Wed Jun 01 14:21:24 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/CartoLineSymbolReader.java	Mon Jun 06 17:24:43 2011 +0200
@@ -68,7 +68,8 @@
         Element symbolElement = util.addSymbol(parent);
 
         symbolElement.setAttribute("name", symbol.getNameString());
-        symbolElement.setAttribute("style", "line");
+        symbolElement.setAttribute("type", "line");
+        symbolElement.setAttribute("style", "carto");
         if(symbol.getColor() instanceof IRgbColor) {
             IRgbColor color = (IRgbColor)symbol.getColor();
             Color c = new Color (
--- a/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Wed Jun 01 14:21:24 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/FeatureLayerReader.java	Mon Jun 06 17:24:43 2011 +0200
@@ -79,6 +79,7 @@
             case 0: layerElement.setAttribute("type", "none"); break;
             case 1: layerElement.setAttribute("type", "point"); break;
             case 3: layerElement.setAttribute("type", "line"); break;
+            case 4: layerElement.setAttribute("type", "polygon"); break;
         }
 
         layerElement.setAttribute("definition_query",
--- a/src/java/de/intevation/mxd/reader/HashLineSymbolReader.java	Wed Jun 01 14:21:24 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/HashLineSymbolReader.java	Mon Jun 06 17:24:43 2011 +0200
@@ -67,7 +67,8 @@
         Element symbolElement = util.addSymbol(parent);
 
         symbolElement.setAttribute("name", symbol.getNameString());
-        symbolElement.setAttribute("style", "line");
+        symbolElement.setAttribute("type", "line");
+        symbolElement.setAttribute("style", "hash");
         if(symbol.getColor() instanceof IRgbColor) {
             IRgbColor color = (IRgbColor)symbol.getColor();
             Color c = new Color (
--- a/src/java/de/intevation/mxd/reader/LineFillSymbolReader.java	Wed Jun 01 14:21:24 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/LineFillSymbolReader.java	Mon Jun 06 17:24:43 2011 +0200
@@ -74,6 +74,7 @@
         symbolElement.setAttribute(
             "separation",
             String.valueOf(symbol.getSeparation()));
+        symbolElement.setAttribute("angle", String.valueOf(symbol.getAngle()));
 
         if(symbol.getColor() instanceof IRgbColor) {
             IRgbColor color = (IRgbColor)symbol.getColor();
@@ -112,6 +113,7 @@
         ILineSymbol ls = symbol.getLineSymbol();
         LineSymbolReader lsr = new LineSymbolReader();
         if(lsr.canRead(ls)) {
+            symbolElement.setAttribute("hatch", "1");
             lsr.setSymbol(ls);
             lsr.setUtil(util);
             lsr.setParent(symbolElement);
--- a/src/java/de/intevation/mxd/reader/PictureLineSymbolReader.java	Wed Jun 01 14:21:24 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/PictureLineSymbolReader.java	Mon Jun 06 17:24:43 2011 +0200
@@ -68,6 +68,7 @@
         Element symbolElement = util.addSymbol(parent);
 
         symbolElement.setAttribute("name", symbol.getNameString());
+        symbolElement.setAttribute("type", "line");
         symbolElement.setAttribute("style", "picture");
         if(symbol.getColor() instanceof IRgbColor) {
             IRgbColor color = (IRgbColor)symbol.getColor();
--- a/src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java	Wed Jun 01 14:21:24 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java	Mon Jun 06 17:24:43 2011 +0200
@@ -65,8 +65,8 @@
         Element symbolElement = util.addSymbol(parent);
 
         symbolElement.setAttribute("name", symbol.getNameString());
-        symbolElement.setAttribute("style", "line");
-        symbolElement.setAttribute("type", "simple");
+        symbolElement.setAttribute("type", "line");
+        symbolElement.setAttribute("style", "simple");
         if(symbol.getColor() instanceof IRgbColor) {
             IRgbColor color = (IRgbColor)symbol.getColor();
             Color c = new Color (
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/writer/FillStyleWriter.java	Mon Jun 06 17:24:43 2011 +0200
@@ -0,0 +1,225 @@
+package de.intevation.mxd.writer;
+
+import java.io.IOException;
+import java.awt.Color;
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import edu.umn.gis.mapscript.mapObj;
+import edu.umn.gis.mapscript.layerObj;
+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;
+import edu.umn.gis.mapscript.lineObj;
+import edu.umn.gis.mapscript.pointObj;
+
+
+/**
+ * The interface to the mapfile writer.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class FillStyleWriter {
+
+    /**
+     * The Logger.
+     */
+    private static final Logger logger =
+        Logger.getLogger(FillStyleWriter.class);
+
+    private mapObj map;
+    private classObj cl;
+    private styleObj style;
+
+    public FillStyleWriter (mapObj map, classObj cl) {
+        logger.debug("contructor(mapObj, classObj)");
+        this.map = map;
+        this.cl = cl;
+        this.style = new styleObj(cl);
+    }
+
+    /**
+     * Write the content.
+     */
+    public boolean write(Element symbolElement)
+    throws Exception {
+        symbolSetObj symbolSet = map.getSymbolset();
+
+        if(symbolElement.hasChildNodes()) {
+            NodeList symbols = symbolElement.getChildNodes();
+            for (int i = 0; i < symbols.getLength(); i++) {
+                Element nextSym = (Element)symbols.item(i);
+                String type = nextSym.getAttribute("type");
+
+                if(((symbols.getLength() > 1 && i == 0) ||
+                    (symbols.getLength() == 1 &&
+                     !symbolElement.hasAttribute("hatch"))) &&
+                   type.equals("line")) {
+                    writeOutline(nextSym);
+                    if (symbols.getLength() == 1) {
+                        writeSimple(symbolElement);
+                    }
+                }
+                else if(nextSym.getTagName().equals("symbol") &&
+                   !symbolElement.hasAttribute("hatch") ||
+                   (i == 1 && type.equals("marker"))) {
+                    double gap = 0;
+                    if(symbolElement.hasAttribute("xseparation")) {
+                        gap = Double.parseDouble(
+                            symbolElement.getAttribute("xseparation"));
+                    }
+                    writeMarker(nextSym, gap);
+                }
+                else if (nextSym.getTagName().equals("symbol") &&
+                         symbolElement.hasAttribute("hatch")) {
+                    if(symbolElement.hasAttribute("angle")) {
+                        nextSym.setAttribute(
+                            "angle",
+                            symbolElement.getAttribute("angle"));
+                    }
+                    if(symbolElement.hasAttribute("separation")) {
+                        nextSym.setAttribute(
+                            "size",
+                            symbolElement.getAttribute("separation"));
+                    }
+                    writeMarker(nextSym, -1);
+                }
+                else {
+                    writeSimple(symbolElement);
+                }
+            }
+        }
+        else {
+            writeSimple(symbolElement);
+            if(symbolElement.hasAttribute("outline_color")) {
+                Color oCol = Color.decode(
+                    symbolElement.getAttribute("outline_color"));
+                colorObj outlineColor = new colorObj(
+                    oCol.getRed(),
+                    oCol.getGreen(),
+                    oCol.getBlue(),
+                    -4);
+                style.setOutlinecolor(outlineColor);
+                style.setOutlinewidth(Double.parseDouble(
+                    symbolElement.getAttribute("outline_size")));
+            }
+
+        }
+
+        return true;
+    }
+
+    /**
+     * Write the outline for a polygon.
+     */
+    private void writeOutline(Element symbolElement)
+    throws Exception {
+        logger.debug("writeOutline()");
+        //write transparent outline
+        colorObj color = new colorObj(-1, -1, -1, -4);
+
+        //write new style for the outline
+        //TODO write further attribute like pattern etc.
+        Color oCol = Color.decode(
+            symbolElement.getAttribute("color"));
+
+        styleObj outline = new styleObj (cl);
+
+        colorObj outlinecolor = new colorObj(
+            oCol.getRed(),
+            oCol.getGreen(),
+            oCol.getBlue(),
+            -4);
+        outline.setOutlinecolor(outlinecolor);
+        outline.setOutlinewidth(Double.parseDouble(
+            symbolElement.getAttribute("width")));
+    }
+
+    /**
+     * Write marker attributes and a symbol for the polygon fill.
+     */
+    private void writeMarker(Element symbolElement, double gap)
+    throws Exception {
+        logger.debug("writeMarker()");
+        String name = symbolElement.getAttribute("name");
+        String type = symbolElement.getAttribute("type");
+        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 ("size")) {
+            double size = Double.parseDouble(
+                symbolElement.getAttribute("size"));
+            style.setSize(size);
+            //In arcgis the separation goes from center to center, so the gap is
+            //the separation - size
+            if (gap > 0) {
+                style.setGap(gap - size);
+            }
+        }
+        if(symbolElement.hasAttribute("outline_color")) {
+            Color oCol = Color.decode(
+                symbolElement.getAttribute("outline_color"));
+            colorObj outlineColor = new colorObj(
+                oCol.getRed(),
+                oCol.getGreen(),
+                oCol.getBlue(),
+                -4);
+            style.setOutlinecolor(outlineColor);
+            style.setOutlinewidth(Double.parseDouble(
+                symbolElement.getAttribute("outline_size")));
+        }
+
+        if(type.equals("marker")) {
+            style.setSymbolByName(map, name);
+            SymbolWriter sw = new SymbolWriter(this.map, this.cl);
+            sw.write(symbolElement);
+        }
+        else if(type.equals("line")) {
+            style.setSymbolByName(map, "hatch");
+            SymbolWriter sw = new SymbolWriter(this.map, this.cl);
+            symbolElement.setAttribute("name", "hatch");
+            sw.write(symbolElement);
+        }
+    }
+
+    /**
+     * Write simple fill attributes.
+     */
+    private void writeSimple(Element symbolElement) {
+        logger.debug("writeSimple(Element)");
+        if(symbolElement.hasAttribute("transparency")) {
+            double value = Double.parseDouble(
+                symbolElement.getAttribute("transparency"));
+            int opacity = (int)(value/255) * 100;
+            if(value >= 0) {
+                style.setOpacity(opacity);
+            }
+        }
+        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);
+        }
+    }
+}
+// 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 14:21:24 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Mon Jun 06 17:24:43 2011 +0200
@@ -171,6 +171,9 @@
             else if (type.equals("line")) {
                 layer.setType(MS_LAYER_TYPE.MS_LAYER_LINE);
             }
+            else if (type.equals("polygon")) {
+                layer.setType(MS_LAYER_TYPE.MS_LAYER_POLYGON);
+            }
 
             //The layer datasource.
             layer.setData(layerElement.getAttribute("data_source"));
@@ -212,20 +215,22 @@
                 co.setExpression(exp);
             }
             //Write symbols and styles.
-            NodeList slist = classElement.getElementsByTagName("symbol");
-            String type = layerElement.getAttribute("type");
-            if(type.equals("point")) {
-                for(int j = 0; j < slist.getLength(); j++){
-                    Element symbolElement = (Element) slist.item(j);
+            NodeList l = classElement.getChildNodes();
+            for (int j = 0; j < l.getLength(); j++) {
+                Element elem = (Element)l.item(j);
+
+                String type = layerElement.getAttribute("type");
+                if(type.equals("point") && elem.getTagName().equals("symbol")) {
                     MarkerStyleWriter swriter = new MarkerStyleWriter (this.map, co);
-                    swriter.write (symbolElement);
+                    swriter.write (elem);
                 }
-            }
-            else if(type.equals("line")) {
-                for(int j = 0; j < slist.getLength(); j++){
-                    Element symbolElement = (Element) slist.item(j);
+                else if(type.equals("line") && elem.getTagName().equals("symbol")) {
                     LineStyleWriter swriter = new LineStyleWriter (this.map, co);
-                    swriter.write (symbolElement);
+                    swriter.write (elem);
+                }
+                else if(type.equals("polygon") && elem.getTagName().equals("symbol")) {
+                    FillStyleWriter swriter = new FillStyleWriter (this.map, co);
+                    swriter.write (elem);
                 }
             }
         }
--- a/src/java/de/intevation/mxd/writer/SymbolWriter.java	Wed Jun 01 14:21:24 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/SymbolWriter.java	Mon Jun 06 17:24:43 2011 +0200
@@ -46,8 +46,8 @@
 
         String name = symbolElement.getAttribute("name");
         symbolObj sym = symbolSet.getSymbolByName(name);
-
         String symType = symbolElement.getAttribute("style");
+        String type = symbolElement.getAttribute("type");
         if(symType.equals("point")) {
             writeSimple(sym);
         }
@@ -58,6 +58,9 @@
             //TODO Does not work at all...  waiting for fix.
             writeCharacter(sym, symbolElement);
         }
+        else if (type.equals("line")) {
+            writeHatch(sym);
+        }
         else {
             return false;
         }
@@ -104,10 +107,16 @@
         symbol.setCharacter("&#" + symbolElement.getAttribute("char") + ";");
     }
 
+    private void writeHatch(symbolObj symbol) {
+        logger.debug("writeHatch(symbolObj)");
+        symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_HATCH.swigValue());
+    }
+
     public boolean canWrite(String type) {
         if (type.equals("point") ||
             type.equals("arrow") ||
-            type.equals("char")) {
+            type.equals("char") ||
+            type.equals("line")) {
             return true;
         }
         else {
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)