changeset 148:2bf35f0babd0

Implemented new group layer functionality.
author vc11884admin@VC11884.win.bsh.de
date Wed, 29 Jun 2011 17:45:50 +0200
parents 03daf386f19a
children 07e2033dd60e
files ChangeLog src/java/de/intevation/mxd/reader/GroupLayerReader.java src/java/de/intevation/mxd/reader/MXDReader.java src/java/de/intevation/mxd/writer/MapScriptWriter.java
diffstat 4 files changed, 186 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Jun 29 17:36:07 2011 +0200
+++ b/ChangeLog	Wed Jun 29 17:45:50 2011 +0200
@@ -1,3 +1,15 @@
+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:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/reader/GroupLayerReader.java	Wed Jun 29 17:45:50 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	Wed Jun 29 17:36:07 2011 +0200
+++ b/src/java/de/intevation/mxd/reader/MXDReader.java	Wed Jun 29 17:45:50 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/writer/MapScriptWriter.java	Wed Jun 29 17:36:07 2011 +0200
+++ b/src/java/de/intevation/mxd/writer/MapScriptWriter.java	Wed Jun 29 17:45:50 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")) {
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)