[MXD2map-commits] r303:a9684178cb29

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Wed Sep 5 17:19:25 CEST 2012


details:   http://hg.intevation.org/geospatial/mxd2map/rev/a9684178cb29

changeset: 303:a9684178cb29

user:      Andre Heinecke <aheinecke at intevation.de>

date:      Wed Sep 05 17:16:41 2012 +0200

description:
Add RasterLayer Reader


diffstat:

 ChangeLog                                                |    8 +
 src/java/de/intevation/mxd/reader/MXDReader.java         |   34 +++
 src/java/de/intevation/mxd/reader/RasterLayerReader.java |  160 +++++++++++++++
 3 files changed, 202 insertions(+), 0 deletions(-)

diffs (230 lines):

diff -r f5ac467e2863 -r a9684178cb29 ChangeLog
--- a/ChangeLog	Wed Sep 05 17:16:17 2012 +0200
+++ b/ChangeLog	Wed Sep 05 17:16:41 2012 +0200
@@ -1,3 +1,11 @@
+2012-09-05  Andre Heinecke <aheinecke at intevation.de>
+
+	* src/java/de/intevation/mxd/reader/RasterLayerReader.java:
+	New add support for reading reaster Layers
+
+	* src/java/de/intevation/mxd/reader/MXDReader.java:
+	Add Checks for the new Raster Reader class
+
 2012-09-05  Andre Heinecke <aheinecke at intevation.de>
 
 	* src/java/de/intevation/mxd/reader/WMSGroupLayerReader.java,
diff -r f5ac467e2863 -r a9684178cb29 src/java/de/intevation/mxd/reader/MXDReader.java
--- a/src/java/de/intevation/mxd/reader/MXDReader.java	Wed Sep 05 17:16:17 2012 +0200
+++ b/src/java/de/intevation/mxd/reader/MXDReader.java	Wed Sep 05 17:16:41 2012 +0200
@@ -36,6 +36,7 @@
 import com.esri.arcgis.carto.WMSMapLayer;
 import com.esri.arcgis.carto.WMSGroupLayer;
 import com.esri.arcgis.carto.WMSLayer;
+import com.esri.arcgis.carto.RasterLayer;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -251,6 +252,39 @@
                             throw new IOException ("Error reading WMSlayer.");
                         }
                     }
+                    else if(layer instanceof RasterLayer) {
+                        RasterLayerReader lr =
+                            new RasterLayerReader(layer);
+                        lr.setUtil(util);
+                        Element layerElement = lr.read();
+/* TODO implement support for classes in Raster Layers
+                        IRasterRenderer renderer =
+                            ((RasterLayer)layer).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 {
                         logger.info(
                             "Layertype not known: " +
diff -r f5ac467e2863 -r a9684178cb29 src/java/de/intevation/mxd/reader/RasterLayerReader.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/reader/RasterLayerReader.java	Wed Sep 05 17:16:41 2012 +0200
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2011 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.reader;
+
+import org.apache.log4j.Logger;
+
+import com.esri.arcgis.carto.ILayer;
+import com.esri.arcgis.carto.RasterLayer;
+import com.esri.arcgis.carto.AnnotateLayerPropertiesCollection;
+import com.esri.arcgis.carto.IAnnotateLayerProperties;
+import com.esri.arcgis.carto.LabelEngineLayerProperties;
+import com.esri.arcgis.geodatabase.RasterDatasetName;
+import com.esri.arcgis.system.IName;
+import com.esri.arcgis.system.IPropertySet;
+import com.esri.arcgis.geometry.Envelope;
+
+import org.w3c.dom.Element;
+
+import de.intevation.mxd.utils.MapToXMLUtils;
+import java.io.IOException;
+import com.esri.arcgis.interop.AutomationException;
+/**
+ * Reads Layer information.
+ *
+ * @author <a href="mailto:aheinecke at intevation.de">Andre Heinecke</a>
+ */
+public class RasterLayerReader
+implements ILayerReader {
+
+    /**
+     * The logger.
+     */
+    private static final Logger logger =
+        Logger.getLogger(RasterLayerReader.class);
+
+    /**
+     * Privte member.
+     */
+    private RasterLayer  layer;
+    private MapToXMLUtils util;
+
+    /**
+     * Constructor with layer.
+     *
+     * @param layer The ArcGIS layer object.
+     */
+    public RasterLayerReader(ILayer layer)
+    throws Exception {
+        if(layer instanceof RasterLayer) {
+            this.layer = (RasterLayer)layer;
+        }
+        else {
+            throw new Exception("Not an instance of RasterLayer: " +
+                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;
+        try {
+            layerElement = util.addLayer();
+        }
+        catch(Exception e) {
+            logger.error("Failed to create DOM-Element for Layer.");
+            return null;
+        }
+
+        try {
+            layerElement.setAttribute("name", layer.getName());
+        }
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read layer name." +
+                " Stopped reading layer.");
+            throw new IOException("Error reading layer name.");
+        }
+
+        try {
+            layerElement.setAttribute("min_scale",
+                String.valueOf(layer.getMinimumScale()));
+        }
+        catch(IOException ioe) {
+            logger.warn("Could not read minimum scale.");
+        }
+
+        try {
+            layerElement.setAttribute("max_scale",
+                String.valueOf(layer.getMaximumScale()));
+        }
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read maximum scale.");
+        }
+
+        try {
+            if(layer.isVisible()) {
+                layerElement.setAttribute("status", "on");
+            }
+            else {
+                layerElement.setAttribute("status", "off");
+            }
+        }
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read layer status." +
+                " Setting layer status to \"on\".");
+            layerElement.setAttribute("status", "on");
+        }
+        try {
+            layerElement.setAttribute("data_source", layer.getFilePath());
+        }
+        catch(IOException ioe) {
+            logger.warn(
+                "Could not read datasource." +
+                " Stopped reading layer " + layer.getName() + ".");
+            util.removeLayer(layerElement);
+            return null;
+        }
+
+        // Static Attributes for Raster:
+        layerElement.setAttribute("type", "raster");
+        layerElement.setAttribute("connection_type", "local");
+
+        return layerElement;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :


More information about the MXD2map-commits mailing list