[MXD2map-commits] r317:5a2b5bc066eb

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Thu Sep 20 17:58:34 CEST 2012


details:   http://hg.intevation.org/geospatial/mxd2map/rev/5a2b5bc066eb

changeset: 317:5a2b5bc066eb

user:      Andre Heinecke <aheinecke at intevation.de>

date:      Thu Sep 20 12:55:21 2012 +0200

description:
Implement Label Styles and Labels with background


diffstat:

 ChangeLog                                               |   17 +
 src/java/de/intevation/mxd/reader/MapReader.java        |    8 +
 src/java/de/intevation/mxd/reader/TextSymbolReader.java |   49 +++-
 src/java/de/intevation/mxd/writer/LabelStyleWriter.java |  186 ++++++++++++++++
 src/java/de/intevation/mxd/writer/MapScriptWriter.java  |   21 +-
 5 files changed, 277 insertions(+), 4 deletions(-)

diffs (369 lines):

diff -r 5e3a40a84539 -r 5a2b5bc066eb ChangeLog
--- a/ChangeLog	Mon Sep 17 17:10:44 2012 +0200
+++ b/ChangeLog	Thu Sep 20 12:55:21 2012 +0200
@@ -1,3 +1,20 @@
+2012-09-20  Andre Heinecke <aheinecke at intevation.de>
+
+	Implement Label Styles and Labels with background
+
+	* src/java/de/intevation/mxd/writer/LableStyleWriter.java:
+	New, based on MarkerStyleWriter, writes the style of a label
+
+	* src/java/de/intevation/mxd/reader/MapReader.java:
+	Read Reference scale of map
+
+	* src/java/de/intevation/mxd/reader/TextSymbolReader.java:
+	Add support for LineCallout backgrounds and read bg_color
+
+	* src/java/de/intevation/mxd/writer/MapScriptWriter.java:
+	Write Symbolscaledenom for annotation layers and write label
+	styles with labelstylewriter.
+
 2012-09-17  Andre Heinecke <aheinecke at intevation.de>
 
 	* src/java/de/intevation/mxd/reader/FeatureLayerReader.java:
diff -r 5e3a40a84539 -r 5a2b5bc066eb src/java/de/intevation/mxd/reader/MapReader.java
--- a/src/java/de/intevation/mxd/reader/MapReader.java	Mon Sep 17 17:10:44 2012 +0200
+++ b/src/java/de/intevation/mxd/reader/MapReader.java	Thu Sep 20 12:55:21 2012 +0200
@@ -206,6 +206,14 @@
                 " Setting map projection to unknown.");
             mapElement.setAttribute("projection", "Unknown");
         }
+
+        // read the reference scale
+        try {
+            mapElement.setAttribute("referencescale", String.valueOf(
+                        map.getReferenceScale()));
+        } catch (Exception e) {
+            logger.warn("Could not read referencescale of map");
+        }
     }
 
     /**
diff -r 5e3a40a84539 -r 5a2b5bc066eb src/java/de/intevation/mxd/reader/TextSymbolReader.java
--- a/src/java/de/intevation/mxd/reader/TextSymbolReader.java	Mon Sep 17 17:10:44 2012 +0200
+++ b/src/java/de/intevation/mxd/reader/TextSymbolReader.java	Thu Sep 20 12:55:21 2012 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011 by Intevation GmbH, Germany <info at intevation.de>
+ * Copyright (c) 2012 by Intevation GmbH, Germany <info at intevation.de>
  *
  * This file is part of MXD2map.
  *
@@ -15,6 +15,7 @@
  * Raimund Renkert <raimund.renkert at intevation.de>
  * Bjoern Schilberg <bjoern.schilberg at intevation.de>
  * Stephan Holl <stephan.holl at intevation.de>
+ * Andre Heinecke <aheinecke at intevation.de>
  */
 
 package de.intevation.mxd.reader;
@@ -27,6 +28,9 @@
 import com.esri.arcgis.display.TextSymbol;
 import com.esri.arcgis.display.IRgbColor;
 import com.esri.arcgis.display.RgbColor;
+import com.esri.arcgis.display.LineCallout;
+import com.esri.arcgis.display.ITextBackground;
+import com.esri.arcgis.display.IColor;
 import com.esri.arcgis.support.ms.stdole.Font;
 
 import org.w3c.dom.Element;
@@ -119,8 +123,8 @@
                 String.valueOf(symbol.getSize()));
         }
         catch(IOException ioe) {
-            logger.warn("Could not read size. Setting size to 1.");
-            symbolElement.setAttribute("size", "1");
+            logger.warn("Could not read size. Setting size to 10.");
+            symbolElement.setAttribute("size", "10");
         }
 
         try {
@@ -158,6 +162,45 @@
             symbolElement.setAttribute("font", "FreeSans");
         }
         symbolElement.setAttribute("type", "text");
+
+        // Background
+        try {
+            ITextBackground background = symbol.getBackground();
+            if (background != null) {
+                if (background instanceof LineCallout) {
+                    LineCallout lc = (LineCallout)background;
+                    IColor pcolor = lc.getBorder().getColor();
+                    if(pcolor instanceof IRgbColor) {
+                        IRgbColor color = (IRgbColor)pcolor;
+                        Color c = new Color (
+                            color.getRed(),
+                            color.getGreen(),
+                            color.getBlue());
+                        symbolElement.setAttribute("bg_color", String.valueOf(c.getRGB()));
+                        symbolElement.setAttribute("bg_transparency",
+                            String.valueOf(color.getTransparency()));
+                    }
+                    else {
+                        RgbColor col = new RgbColor();
+                        col.setRGB(pcolor.getRGB());
+                        Color c = new Color (
+                            col.getRed(),
+                            col.getGreen(),
+                            col.getBlue());
+                        symbolElement.setAttribute("bg_color", String.valueOf(c.getRGB()));
+                        symbolElement.setAttribute("bg_transparency",
+                            String.valueOf(col.getTransparency()));
+                    }
+                } else {
+                    logger.warn("Unhandled background of class: " +
+                            background.getClass().toString());
+                }
+            }
+        }
+        catch(Exception e) {
+            logger.warn("Could not read backgroundcolor.");
+        }
+
         return symbolElement;
     }
 }
diff -r 5e3a40a84539 -r 5a2b5bc066eb src/java/de/intevation/mxd/writer/LabelStyleWriter.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/writer/LabelStyleWriter.java	Thu Sep 20 12:55:21 2012 +0200
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2012 by Intevation GmbH, Germany <info at intevation.de>
+ *
+ * This file is part of MXD2map.
+ *
+ * This program is free software under the LGPL (>=v2.1)
+ * Read the file LICENCE.txt coming with the software for details
+ * or visit http://www.gnu.org/licenses/ if it does not exist.
+ *
+ * MXD2map has been developed on behalf of the
+ * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg
+ * by Intevation GmbH.
+ *
+ * Authors:
+ * Raimund Renkert <raimund.renkert at intevation.de>
+ * Bjoern Schilberg <bjoern.schilberg at intevation.de>
+ * Stephan Holl <stephan.holl at intevation.de>
+ */
+
+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.labelObj;
+import edu.umn.gis.mapscript.symbolSetObj;
+
+
+/**
+ * The interface to the mapfile writer.
+ *
+ * @author <a href="mailto:aheinecke at intevation.de">Andre Heinecke</a>
+ */
+public class LabelStyleWriter {
+
+    /**
+     * The Logger.
+     */
+    private static final Logger logger = Logger.getLogger(LabelStyleWriter.class);
+
+    /**
+     * Private member.
+     */
+    private mapObj map;
+    private classObj cl;
+    private styleObj style;
+
+    /**
+     * Contructor with map object and class object.
+     *
+     * @param map The map object.
+     * @param cl  The class object containing the style.
+     */
+    public LabelStyleWriter(mapObj map, classObj cl) {
+        this.map = map;
+        this.cl = cl;
+        this.style = new styleObj(cl);
+    }
+
+    /**
+     * Write the content.
+     *
+     * @param symbolElement DOM element containing style attributes.
+     */
+    public boolean write(Element symbolElement) {
+        logger.debug("write(Element)");
+
+        style.setGeomTransform("labelpoly");
+        cl.getLabel().insertStyle(style, -1);
+
+        symbolSetObj symbolSet = map.getSymbolset();
+
+        if (symbolElement.hasAttribute("angle")) {
+            try {
+                style.setAngle(
+                    Double.parseDouble(symbolElement.getAttribute("angle")));
+            }
+            catch(NumberFormatException nfe) {
+                logger.warn("Error setting angle.");
+                style.setAngle(0.0);
+            }
+        }
+        if(symbolElement.hasAttribute("angleBinding")) {
+            style.setBinding(2,
+                    symbolElement.getAttribute("angleBinding"));
+        }
+        if (symbolElement.hasAttribute("bg_color")) {
+            // Background color takes precedence over the color as
+            // background color can be archived by geomtransform
+            String c = symbolElement.getAttribute("bg_color");
+            Color col = Color.decode(c);
+            colorObj color = new colorObj(
+                col.getRed(),
+                col.getGreen(),
+                col.getBlue(),
+                -4);
+            style.setColor(color);
+        } else 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")) {
+            try {
+                style.setSize(Double.parseDouble(
+                    symbolElement.getAttribute("size")));
+            }
+            catch(NumberFormatException nfe) {
+                logger.warn("Error setting size. Setting to deafult: 1.");
+                style.setSize(1);
+            }
+        }
+        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);
+            try {
+                style.setOutlinewidth(Double.parseDouble(
+                    symbolElement.getAttribute("outline_size")));
+            }
+            catch(NumberFormatException nfe) {
+                logger.warn("Error setting outline width.");
+            }
+        }
+
+        if (symbolElement.hasAttribute("x_offset")) {
+            try {
+                double val = 
+                    Double.parseDouble(symbolElement.getAttribute("x_offset"));
+                double r = Math.round(val);
+                style.setOffsetx(r);
+            }
+            catch (NumberFormatException nfe) {
+                logger.warn("Error setting the symbol x-offset");
+            }
+        }
+        if (symbolElement.hasAttribute("y_offset")) {
+            try {
+                double val =
+                    Double.parseDouble(symbolElement.getAttribute("y_offset"));
+                double r = Math.round(val);
+                //In ArcGIS positive y offset values move the symbol upwards,
+                //in Mapserver positive values move downwards.
+                r = -r;
+                style.setOffsety(r);
+            }
+            catch (NumberFormatException nfe) {
+                logger.warn("Error setting the symbol y-offset.");
+            }
+        }
+        String symType = symbolElement.getAttribute("style");
+        if(symType.equals("point") ||
+           symType.equals("arrow") ||
+           symType.equals("char") ||
+           symType.equals("picture")) {
+           SymbolWriter sw = new SymbolWriter(this.map, this.cl);
+           sw.write(symbolElement);
+        }
+        else {
+            return false;
+        }
+
+        String name = symbolElement.getAttribute("name");
+        style.setSymbolByName(map, name);
+
+        return true;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 5e3a40a84539 -r 5a2b5bc066eb src/java/de/intevation/mxd/writer/MapScriptWriter.java
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Mon Sep 17 17:10:44 2012 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Thu Sep 20 12:55:21 2012 +0200
@@ -408,6 +408,9 @@
             else if(type.equals("raster")) {
                 layer.setType(MS_LAYER_TYPE.MS_LAYER_RASTER);
             }
+            else if (type == "annotation") {
+                layer.setType(MS_LAYER_TYPE.MS_LAYER_ANNOTATION);
+            }
 
             //The layer datasource.
             String con_type = layerElement.getAttribute("connection_type");
@@ -548,6 +551,14 @@
                 layer.setOffsite(new colorObj(255,255,255,-4));
             }
 
+            // Set scaling properties for layer
+            if(type == "annotation") {
+                if (mapNode.hasAttribute("referencescale")) {
+                    layer.setSymbolscaledenom(Double.parseDouble(
+                            mapNode.getAttribute("referencescale")));
+                }
+            }
+
             // Create labelitem
             NodeList labels = layerElement.getElementsByTagName("label");
             if(labels.getLength() > 0) {
@@ -609,7 +620,7 @@
             if ( i == 0 ) {
                 classObj co = new classObj(layer);
                 writeLabel(co, feature, layerElement.getAttribute("type"));
-                MarkerStyleWriter swriter = new MarkerStyleWriter (this.map, co);
+                LabelStyleWriter swriter = new LabelStyleWriter (this.map, co);
                 swriter.write((Element)feature.getFirstChild());
             }
             layer.addFeature(shape);
@@ -758,6 +769,14 @@
             if(layerType.equals("point")) {
                 label.setPosition(MS_POSITIONS_ENUM.MS_UC.swigValue());
             }
+
+            //Set annotation specific values
+            if (layerType == "annotation") {
+                label.setPosition(MS_POSITIONS_ENUM.MS_CC.swigValue());
+                label.setOffsetx(2);
+                label.setOffsety(-2);
+            }
+
         }
     }
 


More information about the MXD2map-commits mailing list