changeset 165:87afe66f7d88

Merged with raimunds changes
author Stephan Holl <stephan.holl@intevation.de>
date Thu, 30 Jun 2011 14:59:44 +0200
parents ba2252ceb6f9 (current diff) 7ed49420ee5a (diff)
children 51c99594346e
files ChangeLog
diffstat 8 files changed, 269 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jun 30 14:57:41 2011 +0200
+++ b/ChangeLog	Thu Jun 30 14:59:44 2011 +0200
@@ -1,8 +1,52 @@
 2011-06-29  Stephan Holl  <stephan.holl@intevation.de>
+	* ttf-fonts/DejaVuSans.ttf: New.
+		* ttf-fonts/fonts.txt: Added FreeSans-Font as fallback for
+	  displaying Labels
 
-	* ttf-fonts/DejaVuSans.ttf: New.
-	* ttf-fonts/fonts.txt: Added FreeSans-Font as fallback for
-	  displaying Labels
+2011-06-30  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/writer/MapScriptWriter.java:
+	  Changed min and max scale. Mapserver uses MAXSCALEDENOM to set the
+	  upper bound for drawing a layer, ArcGIS uses the min scale to set
+	  this bound.
+
+2011-06-30  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/writer/MapScriptWriter.java:
+	  Write a ">=" expression operator for the first minimum value
+	  expression.
+
+2011-06-30  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java:
+	  Read all classes with this reader, including the last one.
+
+2011-06-29  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java:
+	  Read transparency from symbol color.
+
+	* src/java/de/intevation/mxd/writer/FillStyleWriter.java:
+	  Write outline in the same color as the fill if the outline width < 1
+	  and outline is transparent.
+
+2011-06-29  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/reader/MXDReader.java:
+	  Read layers of type GroupLayer.
+
+	* src/java/de/intevation/mxd/reader/GroupLayerReader.java:
+	  New. Reads all layers in a group layer.
+
+	* src/java/de/intevation/mxd/writer/MapScriptWriter.java:
+	  Write group name for layer to mapfile if a group layer is used in
+	  the MXD.
+
+2011-06-29  Raimund Renkert  <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/writer/LineStyleWriter.java:
+	  A symbol name is written to the mapfile only if it is a marker
+	  symbol.
 
 2011-06-29  Stephan Holl  <stephan.holl@intevation.de>
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/reader/GroupLayerReader.java	Thu Jun 30 14:59:44 2011 +0200
@@ -0,0 +1,157 @@
+package de.intevation.mxd.reader;
+
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+
+import com.esri.arcgis.carto.ILayer;
+import com.esri.arcgis.carto.FeatureLayer;
+import com.esri.arcgis.carto.GdbRasterCatalogLayer;
+import com.esri.arcgis.carto.IFeatureRenderer;
+import com.esri.arcgis.carto.SimpleRenderer;
+import com.esri.arcgis.carto.ClassBreaksRenderer;
+import com.esri.arcgis.carto.UniqueValueRenderer;
+import com.esri.arcgis.carto.GroupLayer;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import de.intevation.mxd.ArcGISInitializer;
+import de.intevation.mxd.utils.MapToXMLUtils;
+
+
+/**
+ * Reads Layer information.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class GroupLayerReader
+implements ILayerReader {
+
+    /**
+     * The logger.
+     */
+    private static final Logger logger =
+        Logger.getLogger(FeatureLayerReader.class);
+
+    /**
+     * Privte member.
+     */
+    private GroupLayer  layer;
+    private MapToXMLUtils util;
+    private int invalidLayerCount;
+
+    public GroupLayerReader(ILayer layer)
+    throws Exception {
+        if(layer instanceof GroupLayer) {
+            this.layer = (GroupLayer)layer;
+            invalidLayerCount = 0;
+        }
+        else {
+            throw new Exception("Not an instance of GroupLayer: " +
+                layer.getClass().toString());
+        }
+    }
+
+    /**
+     * Setter for XML document helper.
+     *
+     * @param util The helper for storing map information.
+     */
+    public void setUtil(MapToXMLUtils util) {
+        this.util = util;
+    }
+
+    /**
+     * Reads the Layer content.
+     *
+     * @return The layer XML element.
+     */
+    public Element read()
+    throws IOException{
+        logger.debug("read()");
+	Element layerElement = null;
+        for(int i = 0; i < layer.getCount();i++) {
+            ILayer lay = layer.getLayer(i);
+            try {
+                if (lay instanceof FeatureLayer) {
+                    FeatureLayerReader lr = new FeatureLayerReader(lay);
+                    lr.setUtil(util);
+                    layerElement = lr.read();
+                    if (layerElement == null) {
+                        continue;
+                    }
+		    layerElement.setAttribute("group", layer.getName());
+                    IFeatureRenderer renderer =
+                        ((FeatureLayer)lay).getRenderer();
+                    IRendererReader rreader;
+                    if(renderer instanceof SimpleRenderer) {
+                        rreader = new SimpleRendererReader(renderer);
+                        rreader.setParent(layerElement);
+                        rreader.setUtil(util);
+                        rreader.read();
+                    }
+                    else if(renderer instanceof ClassBreaksRenderer) {
+                        rreader = new ClassBreakRendererReader(renderer);
+                        rreader.setParent(layerElement);
+                        rreader.setUtil(util);
+                        rreader.read();
+                    }
+                    else if(renderer instanceof UniqueValueRenderer) {
+                        rreader = new UniqueValueRendererReader(renderer);
+                        rreader.setParent(layerElement);
+                        rreader.setUtil(util);
+                        rreader.read();
+                    }
+                    else{
+                        logger.debug("Not a known renderer type " +
+                                     renderer.getClass().toString());
+                    }
+                }
+                else if(lay instanceof GdbRasterCatalogLayer) {
+                    GdbRasterCatalogLayerReader gclr =
+                        new GdbRasterCatalogLayerReader(lay);
+                    gclr.setUtil(util);
+                    layerElement = gclr.read();
+		    layerElement.setAttribute("group", layer.getName());
+                    IFeatureRenderer renderer =
+                        ((GdbRasterCatalogLayer)lay).getRenderer();
+                    IRendererReader rreader;
+                    if(renderer instanceof SimpleRenderer) {
+                        rreader = new SimpleRendererReader(renderer);
+                        rreader.setParent(layerElement);
+                        rreader.setUtil(util);
+                        rreader.read();
+                    }
+                    else if(renderer instanceof ClassBreaksRenderer) {
+                        rreader = new ClassBreakRendererReader(renderer);
+                        rreader.setParent(layerElement);
+                        rreader.setUtil(util);
+                        rreader.read();
+                    }
+                    else if(renderer instanceof UniqueValueRenderer) {
+                        rreader = new UniqueValueRendererReader(renderer);
+                        rreader.setParent(layerElement);
+                        rreader.setUtil(util);
+                        rreader.read();
+                    }
+                    else {
+                        logger.debug("Not a known renderer type " +
+                                     renderer.getClass().toString());
+                    }
+                }
+	    }
+	    catch(Exception e) {
+	        invalidLayerCount++;
+                if(i == 0 && (i + 1) == layer.getCount() ||
+                    invalidLayerCount == layer.getCount()) {
+                    throw new IOException(
+                        "No valid layer in MXD file." +
+                        " Aborting.");
+                }
+	    }
+	}
+	return layerElement;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/reader/MXDReader.java	Thu Jun 30 14:57:41 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/MXDReader.java	Thu Jun 30 14:59:44 2011 +0200
@@ -13,6 +13,7 @@
 import com.esri.arcgis.carto.SimpleRenderer;
 import com.esri.arcgis.carto.ClassBreaksRenderer;
 import com.esri.arcgis.carto.UniqueValueRenderer;
+import com.esri.arcgis.carto.GroupLayer;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -189,6 +190,19 @@
                                          renderer.getClass().toString());
                         }
                     }
+                    else if(layer instanceof GroupLayer) {
+                        GroupLayerReader gl = new GroupLayerReader(layer);
+                        gl.setUtil(util);
+                        Element layerElement = gl.read();
+                        if(layerElement == null) {
+                            throw new IOException ("Error reading grouplayer.");
+                        }
+                    }
+                    else {
+                        logger.info(
+                            "Layertype not known: " +
+                            layer.getClass().toString());
+                    }
                 }
                 catch(Exception e) {
                     invalidLayerCount++;
--- a/src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java	Thu Jun 30 14:57:41 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/SimpleLineSymbolReader.java	Thu Jun 30 14:59:44 2011 +0200
@@ -80,6 +80,9 @@
                     color.getGreen(),
                     color.getBlue());
                 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
+                symbolElement.setAttribute(
+                    "transparency",
+                    String.valueOf(c.getTransparency()));
             }
             else {
                 RgbColor col = new RgbColor();
@@ -89,6 +92,9 @@
                     col.getGreen(),
                     col.getBlue());
                 symbolElement.setAttribute("color", String.valueOf(c.getRGB()));
+                symbolElement.setAttribute(
+                    "transparency",
+                    String.valueOf(c.getTransparency()));
             }
         }
         catch(IOException ioe) {
--- a/src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java	Thu Jun 30 14:57:41 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/UniqueValueRendererReader.java	Thu Jun 30 14:59:44 2011 +0200
@@ -79,7 +79,7 @@
                 " Stopped reading renderer.");
             return layer;
         }
-        for(int i = 0; i < count - 1; i++) {
+        for(int i = 0; i < count; i++) {
             Element rendererElement = util.addRenderer(layer);
 
             try {
--- a/src/java/de/intevation/mxd/writer/FillStyleWriter.java	Thu Jun 30 14:57:41 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/FillStyleWriter.java	Thu Jun 30 14:59:44 2011 +0200
@@ -34,6 +34,7 @@
     private mapObj map;
     private classObj cl;
     private styleObj style;
+    private colorObj fill;
 
     public FillStyleWriter (mapObj map, classObj cl) {
         logger.debug("contructor(mapObj, classObj)");
@@ -59,6 +60,15 @@
                     (symbols.getLength() == 1 &&
                      !symbolElement.hasAttribute("hatch"))) &&
                    type.equals("line")) {
+                    if(symbolElement.hasAttribute("color")) {
+                        Color oCol = Color.decode(
+                        symbolElement.getAttribute("color"));
+                        fill = new colorObj(
+                            oCol.getRed(),
+                            oCol.getGreen(),
+                            oCol.getBlue(),
+                            -4);
+                    }
                     writeOutline(nextSym);
                     if (symbols.getLength() == 1) {
                         writeSimple(symbolElement);
@@ -131,17 +141,18 @@
         logger.debug("writeOutline()");
         //write transparent outline
         colorObj color = new colorObj(-1, -1, -1, -4);
+        double w = 0;
+        double transp = -1;
         if(symbolElement.hasAttribute("width")) {
-            double w = 0;
             try {
                 w = Double.parseDouble(symbolElement.getAttribute("width"));
+                transp = Double.parseDouble(
+                    symbolElement.getAttribute("transparency"));
             }
             catch(NumberFormatException nfe) {
-                logger.warn("Error setting outline width.");
+                logger.warn("Error setting outline width or transparency.");
                 w = 0;
-            }
-            if (w < 1.0) {
-                return;
+                transp = -1;
             }
         }
         //write new style for the outline
@@ -150,13 +161,18 @@
             symbolElement.getAttribute("color"));
 
         styleObj outline = new styleObj (cl);
-
-        colorObj outlinecolor = new colorObj(
-            oCol.getRed(),
-            oCol.getGreen(),
-            oCol.getBlue(),
-            -4);
-        outline.setOutlinecolor(outlinecolor);
+        if (w < 1.0 && transp > 0) {
+            symbolElement.setAttribute("width", "1");
+            outline.setOutlinecolor(fill);
+        }
+        else {
+            colorObj outlinecolor = new colorObj(
+                oCol.getRed(),
+                oCol.getGreen(),
+                oCol.getBlue(),
+                -4);
+            outline.setOutlinecolor(outlinecolor);
+        }
         try {
             outline.setOutlinewidth(Double.parseDouble(
                 symbolElement.getAttribute("width")));
--- a/src/java/de/intevation/mxd/writer/LineStyleWriter.java	Thu Jun 30 14:57:41 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/LineStyleWriter.java	Thu Jun 30 14:59:44 2011 +0200
@@ -90,10 +90,10 @@
         if(type.equals("marker")) {
             SymbolWriter sw = new SymbolWriter(this.map, this.cl);
             sw.write(symbolElement);
+            String name = symbolElement.getAttribute("name");
+            style.setSymbolByName(map, name);
+            symbolObj sym = symbolSet.getSymbolByName(name);
         }
-        String name = symbolElement.getAttribute("name");
-        style.setSymbolByName(map, name);
-        symbolObj sym = symbolSet.getSymbolByName(name);
 
         //The following lines are for dashed and/or dotted lines.
         if(symbolElement.hasAttribute("linestyle")) {
@@ -158,10 +158,6 @@
                 logger.warn("Could not write PATTERN.");
             }
         }
-
-
-
-
         return false;
     }
 }
--- a/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Thu Jun 30 14:57:41 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Thu Jun 30 14:59:44 2011 +0200
@@ -152,7 +152,9 @@
             lname = lname.replaceAll(" ", "");
             layer.setName(lname);
             layer.setMetaData("wms_title", layerElement.getAttribute("name"));
-
+            if(layerElement.hasAttribute("group")) {
+	    	layer.setGroup(layerElement.getAttribute("group"));
+	    }
             //The layer status.
             String stat = layerElement.getAttribute("status");
             if (stat.equals("on")) {
@@ -167,9 +169,9 @@
             double minScale = 0;
             try {
                 maxScale =
+                    Double.parseDouble(layerElement.getAttribute("min_scale"));
+                minScale =
                     Double.parseDouble(layerElement.getAttribute("max_scale"));
-                minScale =
-                    Double.parseDouble(layerElement.getAttribute("min_scale"));
             }
             catch(NumberFormatException nfe) {
                 logger.warn("Error setting scale.");
@@ -270,7 +272,7 @@
             }
             co.setName (name);
             if(classElement.hasAttribute("field_count")) {
-                co.setExpression(createExpression(classElement));
+                co.setExpression(createExpression(classElement, i));
             }
             //Write symbols and styles.
             NodeList l = classElement.getChildNodes();
@@ -295,7 +297,7 @@
     }
 
 
-    private String createExpression(Element ce) {
+    private String createExpression(Element ce, int index) {
         String expression = "(";
         int count = 0;
         try {
@@ -315,7 +317,12 @@
                 expression += "[" + pre;
                 expression += ce.getAttribute("expression_field_0") + "]";
                 if(ce.hasAttribute("min_value")) {
-                    expression += " > " + ce.getAttribute("min_value");
+		    if(index == 0) {
+		        expression += " >= " + ce.getAttribute("min_value");
+		    }
+		    else {
+                        expression += " > " + ce.getAttribute("min_value");
+		    }
                     expression += " AND [";
                     expression += ce.getAttribute("expression_field_0")+ "]";
                 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)