[MXD2map-commits] r301:2cb2d8eb56ed

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Wed Sep 5 16:19:23 CEST 2012


details:   http://hg.intevation.org/geospatial/mxd2map/rev/2cb2d8eb56ed

changeset: 301:2cb2d8eb56ed

user:      Andre Heinecke <aheinecke at intevation.de>

date:      Wed Sep 05 16:19:18 2012 +0200

description:
Add WMS Support in the Reader classes and
add new Reader classes for WMS Layers


diffstat:

 ChangeLog                                                  |    8 +
 src/java/de/intevation/mxd/reader/MXDReader.java           |   27 +
 src/java/de/intevation/mxd/reader/WMSGroupLayerReader.java |  125 ++++++++
 src/java/de/intevation/mxd/reader/WMSLayerReader.java      |  182 +++++++++++++
 src/java/de/intevation/mxd/reader/WMSMapLayerReader.java   |  126 +++++++++
 5 files changed, 468 insertions(+), 0 deletions(-)

diffs (504 lines):

diff -r 215ae6199b95 -r 2cb2d8eb56ed ChangeLog
--- a/ChangeLog	Wed Sep 05 16:15:03 2012 +0200
+++ b/ChangeLog	Wed Sep 05 16:19:18 2012 +0200
@@ -1,3 +1,11 @@
+2012-09-05  Andre Heinecke <aheinecke at intevation.de>
+
+	* src/java/de/intevation/mxd/reader/WMSGroupLayerReader.java,
+	  src/java/de/intevation/mxd/reader/WMSMapLayerReader.java,
+	  src/java/de/intevation/mxd/reader/WMSLayerReader.java:
+	New: Add reader classes for WMSGroupLayer, WMSMapLayer and
+	WMSLayer
+
 2012-09-05  Andre Heinecke <aheinecke at intevation.de>
 
 	* src/java/de/intevation/mxd/writer/MapScriptWriter.java:
diff -r 215ae6199b95 -r 2cb2d8eb56ed src/java/de/intevation/mxd/reader/MXDReader.java
--- a/src/java/de/intevation/mxd/reader/MXDReader.java	Wed Sep 05 16:15:03 2012 +0200
+++ b/src/java/de/intevation/mxd/reader/MXDReader.java	Wed Sep 05 16:19:18 2012 +0200
@@ -33,6 +33,9 @@
 import com.esri.arcgis.carto.ClassBreaksRenderer;
 import com.esri.arcgis.carto.UniqueValueRenderer;
 import com.esri.arcgis.carto.GroupLayer;
+import com.esri.arcgis.carto.WMSMapLayer;
+import com.esri.arcgis.carto.WMSGroupLayer;
+import com.esri.arcgis.carto.WMSLayer;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -224,6 +227,30 @@
                             throw new IOException ("Error reading grouplayer.");
                         }
                     }
+                    else if(layer instanceof WMSMapLayer) {
+                        WMSMapLayerReader lr = new WMSMapLayerReader(layer);
+                        lr.setUtil(util);
+                        Element layerElement = lr.read("");
+                        if(layerElement == null) {
+                            throw new IOException ("Error reading WMSMapLayer.");
+                        }
+                    }
+                    else if(layer instanceof WMSGroupLayer) {
+                        WMSGroupLayerReader lr = new WMSGroupLayerReader(layer);
+                        lr.setUtil(util);
+                        Element layerElement = lr.read("");
+                        if(layerElement == null) {
+                            throw new IOException ("Error reading WMSGrouplayer.");
+                        }
+                    }
+                    else if(layer instanceof WMSLayer) {
+                        WMSLayerReader lr = new WMSLayerReader(layer);
+                        lr.setUtil(util);
+                        Element layerElement = lr.read();
+                        if(layerElement == null) {
+                            throw new IOException ("Error reading WMSlayer.");
+                        }
+                    }
                     else {
                         logger.info(
                             "Layertype not known: " +
diff -r 215ae6199b95 -r 2cb2d8eb56ed src/java/de/intevation/mxd/reader/WMSGroupLayerReader.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/reader/WMSGroupLayerReader.java	Wed Sep 05 16:19:18 2012 +0200
@@ -0,0 +1,125 @@
+/*
+ * 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 java.io.IOException;
+
+import org.apache.log4j.Logger;
+
+import com.esri.arcgis.carto.ILayer;
+import com.esri.arcgis.carto.IFeatureRenderer;
+import com.esri.arcgis.carto.WMSMapLayer;
+import com.esri.arcgis.carto.WMSGroupLayer;
+import com.esri.arcgis.carto.WMSLayer;
+import com.esri.arcgis.gisclient.IWMSServiceDescription;
+import com.esri.arcgis.geometry.Envelope;
+
+import org.w3c.dom.Element;
+
+import de.intevation.mxd.utils.MapToXMLUtils;
+
+
+/**
+ * Reads Layer information.
+ *
+ * @author <a href="mailto:aheinecke at intevation.de">Andre Heinecke</a>
+ */
+public class WMSGroupLayerReader {
+
+    /**
+     * The logger.
+     */
+    private static final Logger logger =
+        Logger.getLogger(FeatureLayerReader.class);
+
+    /**
+     * Privte member.
+     */
+    private WMSGroupLayer  layer;
+    private MapToXMLUtils util;
+    private int invalidLayerCount;
+
+    /**
+     * Constructor with layer.
+     *
+     * @param layer The ArcGIS layer object.
+     */
+    public WMSGroupLayerReader(ILayer layer)
+    throws Exception {
+        if(layer instanceof WMSGroupLayer) {
+            this.layer = (WMSGroupLayer)layer;
+            invalidLayerCount = 0;
+        }
+        else {
+            throw new Exception("Not an instance of WMSGroupLayer: " +
+                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(String group)
+    throws IOException{
+        logger.debug("read()");
+        Element layerElement = null;
+        for(int i = 0; i < layer.getCount();i++) {
+            try {
+                ILayer lay = layer.getLayer(i);
+                logger.debug("Reading sublayer " + i + " Name: " + lay.getName());
+                if(lay instanceof WMSMapLayer) {
+                    WMSMapLayerReader lr = new WMSMapLayerReader (lay);
+                    lr.setUtil(this.util);
+                    layerElement = lr.read("/" + layer.getName());
+                } else if(lay instanceof WMSGroupLayer) {
+                    WMSGroupLayerReader lr = new WMSGroupLayerReader (lay);
+                    lr.setUtil(this.util);
+                    layerElement = lr.read("/" + layer.getName());
+                }  else if(lay instanceof WMSLayer) {
+                    WMSLayerReader lr = new WMSLayerReader (lay);
+                    lr.setUtil(this.util);
+                    layerElement = lr.read();
+                } else {
+                    logger.error("Sublayer not handled: " + lay.getClass().toString());
+                }
+                if (layerElement != null) {
+                    layerElement.setAttribute("group", group + "/" + layer.getName());
+                }
+            }
+            catch(Exception e) {
+                logger.debug(e);
+                logger.error("Error reading sublayers. Stop reading: " + layer.getName());
+            }
+        }
+        return layerElement;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 215ae6199b95 -r 2cb2d8eb56ed src/java/de/intevation/mxd/reader/WMSLayerReader.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/reader/WMSLayerReader.java	Wed Sep 05 16:19:18 2012 +0200
@@ -0,0 +1,182 @@
+/*
+ * 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 java.io.IOException;
+
+import org.apache.log4j.Logger;
+
+import com.esri.arcgis.carto.ILayer;
+import com.esri.arcgis.carto.IFeatureRenderer;
+import com.esri.arcgis.carto.WMSMapLayer;
+import com.esri.arcgis.carto.WMSGroupLayer;
+import com.esri.arcgis.carto.WMSLayer;
+import com.esri.arcgis.gisclient.IWMSServiceDescription;
+import com.esri.arcgis.gisclient.IWMSLayerDescription;
+import com.esri.arcgis.geometry.Envelope;
+
+import org.w3c.dom.Element;
+
+import de.intevation.mxd.utils.MapToXMLUtils;
+
+
+/**
+ * Reads Layer information.
+ *
+ * @author <a href="mailto:aheinecke at intevation.de">Andre Heinecke</a>
+ */
+public class WMSLayerReader {
+
+    /**
+     * The logger.
+     */
+    private static final Logger logger =
+        Logger.getLogger(FeatureLayerReader.class);
+
+    /**
+     * Privte member.
+     */
+    private WMSLayer  layer;
+    private MapToXMLUtils util;
+    private int invalidLayerCount;
+
+    /**
+     * Constructor with layer.
+     *
+     * @param layer The ArcGIS layer object.
+     */
+    public WMSLayerReader(ILayer layer)
+    throws Exception {
+        if(layer instanceof WMSLayer) {
+            this.layer = (WMSLayer)layer;
+            invalidLayerCount = 0;
+        }
+        else {
+            throw new Exception("Not an instance of WMSLayer: " +
+                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;
+        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");
+        }
+
+        layerElement.setAttribute("connection_type", "WMS");
+
+        try{
+            // Set the WMS Connection parameters
+            IWMSServiceDescription wmsconn = layer.getWMSServiceDescription();
+
+            String connectionURL = wmsconn.getBaseURL("GetMap", "Get");
+            if (!connectionURL.endsWith("?")) {
+                connectionURL += "?";
+            }
+            layerElement.setAttribute("connection", connectionURL);
+            logger.debug(connectionURL);
+            layerElement.setAttribute("imageType",  wmsconn.getImageFormat(0));
+            logger.debug(wmsconn.getImageFormat(0));
+            if (wmsconn.getSRSCount() > 0) {
+                layerElement.setAttribute("projection", wmsconn.getSRS(0));
+                logger.debug(wmsconn.getSRS(0));
+            }
+            layerElement.setAttribute("wms_server_version", wmsconn.getWMSVersion());
+            logger.debug(wmsconn.getWMSVersion());
+        }
+        catch(Exception e) {
+            logger.debug(e);
+            logger.error("Error Setting Connection parameters. " + layer.getName());
+        }
+
+        try{
+            // Set the WMS Layer parameters
+            IWMSLayerDescription wmslayer = layer.getWMSLayerDescription();
+            layerElement.setAttribute("wms_name", wmslayer.getName());
+        }
+        catch(Exception e) {
+            logger.debug(e);
+            logger.error("Error Setting Layer parameters. " + layer.getName());
+        }
+        return layerElement;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 215ae6199b95 -r 2cb2d8eb56ed src/java/de/intevation/mxd/reader/WMSMapLayerReader.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/reader/WMSMapLayerReader.java	Wed Sep 05 16:19:18 2012 +0200
@@ -0,0 +1,126 @@
+/*
+ * 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 java.io.IOException;
+
+import org.apache.log4j.Logger;
+
+import com.esri.arcgis.carto.ILayer;
+import com.esri.arcgis.carto.IFeatureRenderer;
+import com.esri.arcgis.carto.WMSMapLayer;
+import com.esri.arcgis.carto.WMSGroupLayer;
+import com.esri.arcgis.carto.WMSLayer;
+import com.esri.arcgis.gisclient.IWMSServiceDescription;
+import com.esri.arcgis.geometry.Envelope;
+
+import org.w3c.dom.Element;
+
+import de.intevation.mxd.utils.MapToXMLUtils;
+
+
+/**
+ * Reads Layer information.
+ *
+ * @author <a href="mailto:aheinecke at intevation.de">Andre Heinecke</a>
+ */
+public class WMSMapLayerReader {
+
+    /**
+     * The logger.
+     */
+    private static final Logger logger =
+        Logger.getLogger(FeatureLayerReader.class);
+
+    /**
+     * Privte member.
+     */
+    private WMSMapLayer  layer;
+    private MapToXMLUtils util;
+    private int invalidLayerCount;
+
+    /**
+     * Constructor with layer.
+     *
+     * @param layer The ArcGIS layer object.
+     */
+    public WMSMapLayerReader(ILayer layer)
+    throws Exception {
+        if(layer instanceof WMSMapLayer) {
+            this.layer = (WMSMapLayer)layer;
+            invalidLayerCount = 0;
+        }
+        else {
+            throw new Exception("Not an instance of WMSMapLayer: " +
+                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(String group)
+    throws IOException{
+        logger.debug("read()");
+        Element layerElement = null;
+        for(int i = 0; i < layer.getCount();i++) {
+            try {
+                ILayer lay = layer.getLayer(i);
+                logger.debug("Stepping down into sublayer " + i + " Name: " + lay.getName());
+                logger.debug("Class is: " + lay.getClass().toString());
+                if(lay instanceof WMSMapLayer) {
+                    WMSMapLayerReader lr = new WMSMapLayerReader (lay);
+                    lr.setUtil(this.util);
+                    layerElement = lr.read("/" + layer.getName());
+                } else if(lay instanceof WMSGroupLayer) {
+                    WMSGroupLayerReader lr = new WMSGroupLayerReader (lay);
+                    lr.setUtil(this.util);
+                    layerElement = lr.read("/" + layer.getName());
+                } else if(lay instanceof WMSLayer) {
+                    WMSLayerReader lr = new WMSLayerReader (lay);
+                    lr.setUtil(this.util);
+                    layerElement = lr.read();
+                } else {
+                    logger.error("Sublayer not handled: " + lay.getClass().toString());
+                }
+                if (layerElement != null) {
+                    layerElement.setAttribute("group", group + "/" + layer.getName());
+                }
+            }
+            catch(Exception e) {
+                logger.debug(e);
+                logger.error("Error reading sublayers. Stop reading: " + layer.getName());
+            }
+        }
+        return layerElement;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :


More information about the MXD2map-commits mailing list