changeset 25:cbd67b1100d8

Initial commit of the first prototype.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 08 Apr 2011 11:47:59 +0200
parents c0060abb7457
children 3e24fffdf2bb
files ChangeLog build.xml conf/log4j.properties properties.xml src/java/de/intevation/mxd/ArcGISInitializer.java src/java/de/intevation/mxd/ClassBreakRendererReader.java src/java/de/intevation/mxd/Converter.java src/java/de/intevation/mxd/FeatureLayerReader.java src/java/de/intevation/mxd/ILayerReader.java src/java/de/intevation/mxd/IReader.java src/java/de/intevation/mxd/IRendererReader.java src/java/de/intevation/mxd/ISymbolReader.java src/java/de/intevation/mxd/MXDReader.java src/java/de/intevation/mxd/MapReader.java src/java/de/intevation/mxd/SimpleMarkerSymbolReader.java src/java/de/intevation/mxd/SimpleRendererReader.java src/java/de/intevation/mxd/UniqueValueRendererReader.java
diffstat 17 files changed, 899 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Apr 04 20:01:25 2011 +0200
+++ b/ChangeLog	Fri Apr 08 11:47:59 2011 +0200
@@ -1,3 +1,24 @@
+2011-04-08  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* src/java/de/intevation/mxd/Converter.java: Initial implementation for the
+	  MXD-Converter.
+
+	* src/java/de/intevation/mxd/ArcGISInitializer.java,
+	  src/java/de/intevation/mxd/IReader.java,
+	  src/java/de/intevation/mxd/MXDReader.java,
+	  src/java/de/intevation/mxd/MapReader.java,
+	  src/java/de/intevation/mxd/ILayerReader.java,
+	  src/java/de/intevation/mxd/IRendererReader.java,
+	  src/java/de/intevation/mxd/ISymbolReader.java,
+	  src/java/de/intevation/mxd/FeatureLayerReader.java,
+	  src/java/de/intevation/mxd/SimpleMarkerSymbolReader.java,
+	  src/java/de/intevation/mxd/SimpleRendererReader.java,
+	  src/java/de/intevation/mxd/UniqueValueRendererReader.java,
+	  src/java/de/intevation/mxd/ClassBreakRendererReader.java:
+	  New. Initial implementation for the MXD converter.
+
+	* conf/log4j.properties: New. Contains the log4j configuration.
+
 2011-04-04  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/java/de/intevation/mxd/Converter.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/build.xml	Fri Apr 08 11:47:59 2011 +0200
@@ -0,0 +1,93 @@
+<?xml version="1.0"?>
+<!DOCTYPE project[
+  <!ENTITY properties SYSTEM "properties.xml">
+]>
+<!-- :mode=ant -->
+
+<project name="MXD-Konverter" default="all" basedir=".">
+  <!-- import external XML fragments -->
+  &properties;
+  <!-- import sample properties -->
+  <!-- TODO: edit sample.properties file before importing -->
+  <property file="sample.properties"/>
+  <path id="compile.classpath">
+    <pathelement location="${arcobjects.jar}"/>
+    <fileset dir="${libs.dir}">
+      <include name="**/*.jar"/>
+    </fileset>
+  </path>
+  <path id="run.classpath">
+    <path refid="compile.classpath"/>
+    <pathelement location="${class.dir}"/>
+    <pathelement location="${src.dir}"/>
+  </path>
+
+  <!-- ========================================= -->
+  <!-- private targets -->
+  <!-- ========================================= -->
+  <target name="init">
+    <!-- create the time stamp -->
+    <tstamp/>
+    <!-- create the build directory structure used by compile -->
+    <mkdir dir="${build.dir}"/>
+    <mkdir dir="${class.dir}"/>
+  </target>
+
+  <target name="validate-runtime" depends="init">
+    <condition property="runtimeAvailable">
+      <isset property="runtime.home"/>
+    </condition>
+    <fail message="No runtime installed. You need to install ArcGIS Engine, Desktop or Server to run this sample." unless="runtimeAvailable"/>
+  </target>
+
+  <target name="compile" depends="validate-runtime">
+  <!-- javac resolver needed to run inside of Websphere Studio -->
+    <available classname="org.eclipse.core.launcher.Main" property="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter" classpath="${java.class.path}" />
+    <!-- compile the java code from ${src.dir} into ${class.dir} -->
+    <javac srcdir="${src.dir}" destdir="${class.dir}" debug="on">
+      <classpath refid="compile.classpath"/>
+    </javac>
+    <copy todir="${class.dir}">
+      <fileset dir="${src.dir}" includes="**/icons/*" />
+    </copy>
+  </target>
+
+  <target name="jar" depends="compile">
+    <mkdir dir="${dist.dir}" />
+    <jar jarfile="${dist.dir}/${sample.dir}.jar" compress="true" basedir="${class.dir}">
+      <manifest>
+        <attribute name="Main-Class" value="${main.class}"/>
+      </manifest>	
+    </jar>
+  </target>
+
+  <target name="usage">
+    <echo message="Execute 'ant -projecthelp' for the build file help"/>
+    <echo message="Execute 'ant -help' for Ant help"/>
+  </target>
+
+  <target name="execute" depends="compile">
+    <java classname="Converter" failonerror="true" fork="true">
+      <jvmarg value="-Xss2m"/>
+      <classpath refid="run.classpath"/>
+    </java>
+  </target>
+
+  <!-- ========================================= -->
+  <!-- public targets -->
+  <!-- ========================================= -->
+
+  <target name="all" depends="compile" description="build everything">
+    <echo message="application built"/>
+  </target>
+
+  <target name="clean" description="clean all build products">
+    <!-- delete the ${build} directory trees -->
+    <delete dir="${build.dir}"/>
+    <echo message="build directory gone!"/>
+  </target>
+
+  <target name="help" depends="usage" description="usage" />
+  <target name="dist" depends="jar" description="create distributable products" />
+  <target name="run-sample" depends="execute" description="execute the sample with args set in sample.properties"/>
+</project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/conf/log4j.properties	Fri Apr 08 11:47:59 2011 +0200
@@ -0,0 +1,9 @@
+#### Log just errors and warnings to a file.
+log4j.rootLogger=ALL, BSH
+
+log4j.appender.BSH=org.apache.log4j.RollingFileAppender
+log4j.appender.BSH.File=./logs/mxd-converter.log
+log4j.appender.BSH.MaxFileSize=5000KB
+log4j.appender.BSH.MaxBackupIndex=1
+log4j.appender.BSH.layout=org.apache.log4j.PatternLayout
+log4j.appender.BSH.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/properties.xml	Fri Apr 08 11:47:59 2011 +0200
@@ -0,0 +1,30 @@
+<!-- ========================================= -->
+<!-- load environment variables -->
+<!-- ========================================= -->
+<property environment="env"/>
+<condition property="runtime.home" value="${env.AGSENGINEJAVA}">
+    <available file="arcobjects.jar" filepath="${env.AGSENGINEJAVA}/java/lib" />
+</condition>
+<condition property="runtime.home" value="${env.AGSDESKTOPJAVA}">
+    <not>
+    <isset property="runtime.home"/>
+    </not>
+</condition>
+<property name="devkit.home" value="${env.AGSDEVKITJAVA}" />
+<property name="ant.home" value="${devkit.home}/java/tools/ant"/>
+
+<!-- ========================================= -->
+<!-- directory mappings -->
+<!-- ========================================= -->
+<property name="root.dir" location="${basedir}"/>
+<basename property="sample.dir" file="${basedir}" />
+<property name="src.dir" location="src"/>
+<property name="build.dir" location="build"/>
+<property name="class.dir" location="${build.dir}/classes"/>
+<property name="dist.dir" location="${build.dir}/dist"/>
+<property name="libs.dir" location="lib"/>
+
+<!-- ========================================= -->
+<!-- jar file mapping -->
+<!-- ========================================= -->
+<property name="arcobjects.jar" location="${runtime.home}/java/lib/arcobjects.jar"/>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/ArcGISInitializer.java	Fri Apr 08 11:47:59 2011 +0200
@@ -0,0 +1,78 @@
+//package de.intevation.mxd;
+
+import java.io.IOException;
+
+import com.esri.arcgis.system.AoInitialize;
+import com.esri.arcgis.system.EngineInitializer;
+import com.esri.arcgis.system.esriLicenseProductCode;
+import com.esri.arcgis.system.esriLicenseStatus;
+
+/**
+ * Initializes the ArcGIS Engine and Objects.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class ArcGISInitializer{
+
+    //Member
+    private AoInitialize    aoInit;
+    private String          engineInstallDir = "";
+
+
+    //Methods
+    /**
+     * Init ArcGIS Java Objects.
+     */
+    public boolean initArcGIS () throws IOException{
+        EngineInitializer.initializeEngine();
+        aoInit              = new AoInitialize();
+        engineInstallDir    = System.getenv("AGSENGINEJAVA");
+        return true;
+    }
+
+    /**
+     * Init ArcGIS License.
+     */
+    public void initArcGISLicenses() throws IOException{
+        if(aoInit.isProductCodeAvailable
+           (esriLicenseProductCode.esriLicenseProductCodeEngine) ==
+           esriLicenseStatus.esriLicenseAvailable){
+           aoInit.initialize
+               (esriLicenseProductCode.esriLicenseProductCodeEngine);
+        }
+        else if (aoInit.isProductCodeAvailable
+                 (esriLicenseProductCode.esriLicenseProductCodeArcView) ==
+                 esriLicenseStatus.esriLicenseAvailable){
+                 aoInit.initialize
+                     (esriLicenseProductCode.esriLicenseProductCodeArcView);
+        }
+        else{
+            System.err.println("Engine Runtime or ArcView license not initialized.");
+            System.err.println("Exiting application.");
+            System.exit(-1);
+        }
+    }
+
+    /**
+     * Shutdown the ArcGIS Objects.
+     */
+    public boolean shutdownArcGIS() throws IOException{
+        if(aoInit != null){
+            aoInit.shutdown();
+            return true;
+        }
+        else{
+            return false;
+        }
+    }
+
+    /**
+     * Get the ArcGIS Engine Directory.
+     */
+    public String getEngineDirectory() throws Exception{
+        if(engineInstallDir == "")
+            throw new Exception("Call initArcGIS() first!");
+        else
+            return engineInstallDir;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/ClassBreakRendererReader.java	Fri Apr 08 11:47:59 2011 +0200
@@ -0,0 +1,56 @@
+//package de.intevation.mxd.renderer;
+
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+
+import com.esri.arcgis.carto.IFeatureRenderer;
+import com.esri.arcgis.carto.ClassBreaksRenderer;
+
+/**
+ * Reads the ClassBreaksRender Object Attributes.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class ClassBreakRendererReader implements IRendererReader{
+
+    //Member
+    private static final Logger logger =
+        Logger.getLogger(ClassBreakRendererReader.class);
+
+    private ClassBreaksRenderer renderer;
+
+    //Constructor
+    public ClassBreakRendererReader(IFeatureRenderer renderer) throws Exception{
+        logger.debug("contructor()");
+        if(renderer instanceof ClassBreaksRenderer)
+            this.renderer = (ClassBreaksRenderer)renderer;
+        else
+            throw new Exception("Not a ClassBreaksRenderer!");
+    }
+
+
+    //Methods
+    public boolean read() throws IOException{
+        logger.debug("read()");
+        System.out.println("--------------------");
+        System.out.println("Renderer information:");
+        System.out.println("Ramp\t\t = " + renderer.getColorRamp());
+        System.out.println("Class count\t\t = " + renderer.getClassCount());
+
+        for(int i = 0; i < renderer.getClassCount(); i++){
+            System.out.println("Class " + i + "\t\t = " + renderer.esri_getClass(i));
+        }
+        System.out.println("Break count\t\t = " + renderer.getBreakCount());
+        for(int i = 0; i < renderer.getBreakCount(); i++){
+            System.out.println("Break " + i + "\t\t = " + renderer.getBreak(i));
+        }
+        System.out.println("");
+        return true;
+    }
+
+    public void getRenderer() throws IOException{
+        logger.debug("getRenderer() -> not implemented jet.");
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/src/java/de/intevation/mxd/Converter.java	Mon Apr 04 20:01:25 2011 +0200
+++ b/src/java/de/intevation/mxd/Converter.java	Fri Apr 08 11:47:59 2011 +0200
@@ -1,5 +1,14 @@
-package de.intevation.mxd;
+//package de.intevation.mxd;
 
+import java.io.IOException;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+import java.net.MalformedURLException;
 
 /**
  * The entry point of the MXD converter tool.
@@ -8,8 +17,68 @@
  */
 public class Converter {
 
+    /**
+     * The logging is done via Log4j. To configure the logging
+     * a file 'log4j.properties' is search in the configuration
+     * directory.
+     */
+    public static final String LOG4J_PROPERTIES = "log4j.properties";
+
+    /**
+     *
+     * The path of the configuration directory.
+     */
+    public static final String CONFIG_PATH = System.getProperty("config.dir",
+                                                                "conf");
+
+
+    /**
+     * The logger used in this class.
+     */
+    private static Logger logger;
+
+    static {
+        configureLogging();
+        logger = Logger.getLogger(Converter.class);
+    }
+
+
+    /**
+     * Trys to load the Log4j configuration
+     * from ${config.dir}/log4j.properties.
+     */
+    public static final void configureLogging() {
+        File configDir = new File(CONFIG_PATH);
+        File propFile  = new File(configDir, LOG4J_PROPERTIES);
+        if (propFile.isFile() && propFile.canRead()) {
+            try {
+                PropertyConfigurator.configure(propFile.toURI().toURL());
+            }
+            catch (MalformedURLException mue) {
+                mue.printStackTrace(System.err);
+            }
+        }
+    }
+
+    /**
+     * Entrypoint for the application.
+     */
     public static void main(String[] args) {
-        // TODO FILL ME
+        try{
+            IReader reader = new MXDReader();
+            reader.init();
+//            reader.setFilename("testdata/SubsurfaceSediments-Internet.mxd");
+//            reader.setFilename("testdata/p_single_4pt_c255-0-0.mxd");
+//            reader.setFilename("testdata/Facilities-Internet.mxd");
+//            reader.setFilename("testdata/fernerkundung_albedo.mxd");
+            reader.setFilename("testdata/gevu.mxd");
+
+            reader.read();
+            reader.shutdown();
+        }
+        catch(IOException e){
+            e.printStackTrace();
+        }
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/FeatureLayerReader.java	Fri Apr 08 11:47:59 2011 +0200
@@ -0,0 +1,66 @@
+//package de.intevation.mxd.layer;
+
+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.geometry.ISpatialReference;
+import com.esri.arcgis.geometry.ProjectedCoordinateSystem;
+import com.esri.arcgis.geometry.IProjection;
+import com.esri.arcgis.geometry.Projection;
+import com.esri.arcgis.display.ISymbol;
+import com.esri.arcgis.display.SimpleMarkerSymbol;
+/**
+ * Reads Layer information..
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class FeatureLayerReader implements ILayerReader{
+
+    private static final Logger logger = Logger.getLogger(FeatureLayerReader.class);
+
+    private ILayer layer;
+
+    //Constructor
+    public FeatureLayerReader(ILayer layer){
+        this.layer = layer;
+    }
+
+    //Methods
+    /**
+     * Reads the Layer content.
+     */
+    public boolean read() throws IOException{
+        logger.debug("read()");
+        if(layer instanceof FeatureLayer){
+            FeatureLayer fl = (FeatureLayer)layer;
+            System.out.println("--------------------");
+            System.out.println("Layer information:");
+            System.out.println("Layername\t\t = " + fl.getName());
+            System.out.println("Min-/Maxscale\t = " + fl.getMinimumScale() +
+                               "/" + fl.getMaximumScale());
+            ISymbol symbol = fl.getSelectionSymbol();
+            if(symbol instanceof SimpleMarkerSymbol)
+                System.out.println("Symboltype\t\t = " +
+                                   ((SimpleMarkerSymbol)symbol).getNameString());
+
+            System.out.println("Status\t\t = " + fl.isVisible());
+            System.out.println("Definition Query\t = " + fl.getDefinitionExpression());
+            System.out.println("");
+            return true;
+        }
+        else{
+            System.out.println("Layer type unknown! " + layer.getClass().toString());
+        }
+
+        return false;
+    }
+
+    public void getLayer() throws IOException{
+        logger.debug("getLayer() -> not implemented jet.");
+        return;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/ILayerReader.java	Fri Apr 08 11:47:59 2011 +0200
@@ -0,0 +1,16 @@
+//package de.intevation.mxd.layer;
+
+import java.io.IOException;
+
+/**
+ * The interface to the layer reader.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public interface ILayerReader{
+
+  public boolean read() throws IOException;
+  public void getLayer() throws IOException;
+
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/IReader.java	Fri Apr 08 11:47:59 2011 +0200
@@ -0,0 +1,36 @@
+//package de.intevation.mxd.layer;
+
+import java.io.IOException;
+
+/**
+ * The interface to the MXD-Reader.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public interface IReader {
+    /**
+     * Initializes the reader component.
+     */
+    boolean init() throws IOException;
+
+    /**
+     * Method to perform actions at the of reader usage.
+     */
+    boolean shutdown() throws IOException;
+
+    /**
+     * Set the filename.
+     */
+    void setFilename(String name);
+
+    /**
+     * Read the content.
+     */
+    boolean read() throws IOException;
+
+    /**
+     * Request DOM Document containing the map data.
+     */
+    void getMapDocument();
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/IRendererReader.java	Fri Apr 08 11:47:59 2011 +0200
@@ -0,0 +1,18 @@
+//package de.intevation.mxd.renderer;
+
+import java.io.IOException;
+
+import com.esri.arcgis.carto.IFeatureRenderer;
+
+/**
+ * The interface to the renderer reader.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public interface IRendererReader{
+
+    public boolean read() throws IOException;
+    public void getRenderer() throws IOException;
+
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/ISymbolReader.java	Fri Apr 08 11:47:59 2011 +0200
@@ -0,0 +1,16 @@
+//package de.intevation.mxd.symbol;
+
+import java.io.IOException;
+
+/**
+ * The interface to the symbol reader.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public interface ISymbolReader{
+
+  public boolean read() throws IOException;
+  public void getSymbol() throws IOException;
+
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/MXDReader.java	Fri Apr 08 11:47:59 2011 +0200
@@ -0,0 +1,138 @@
+//package de.intevation.mxd;
+
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+
+import com.esri.arcgis.geodatabase.IClass;
+import com.esri.arcgis.carto.ILayer;
+import com.esri.arcgis.carto.IMap;
+import com.esri.arcgis.carto.MapDocument;
+import com.esri.arcgis.carto.FeatureLayer;
+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.geodatabase.IFeatureClass;
+import com.esri.arcgis.geodatabase.FeatureClass;
+import com.esri.arcgis.geometry.ISpatialReference;
+import com.esri.arcgis.geometry.ProjectedCoordinateSystem;
+import com.esri.arcgis.geometry.IProjection;
+import com.esri.arcgis.geometry.Projection;
+
+/**
+ * The MXD file reader.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class MXDReader implements IReader {
+
+    //Member
+    private String filename = "";
+    private ArcGISInitializer initializer = null;
+    private IMap map;
+
+    private static final Logger logger = Logger.getLogger(MXDReader.class);
+
+    //Constructor
+    public MXDReader() throws IOException{
+        logger.debug("constructor()");
+        initializer = new ArcGISInitializer();
+    }
+
+
+    //Methods
+
+    /**
+     * Initialize the ArcGIS Objects.
+     */
+    public boolean init() throws IOException{
+        logger.debug("init()");
+        initializer.initArcGIS();
+        initializer.initArcGISLicenses();
+        return true;
+    }
+
+    /**
+     * Shutdown the ArcGIS Objects.
+     */
+    public boolean shutdown() throws IOException{
+        logger.debug("shutdown()");
+        if(initializer == null){
+            throw new IOException("Faild to shutdown!");
+        }
+        else{
+            initializer.shutdownArcGIS();
+            return true;
+        }
+    }
+
+    /**
+     * Set the path and filename to the MXD-File.
+     */
+    public void setFilename(String name){
+        logger.debug("setFilename()");
+        filename = name;
+    }
+
+    /**
+     * Read the MXD file content.
+     */
+    public boolean read() throws IOException{
+        logger.debug("read()");
+        if(filename == ""){
+            throw new IOException("Please set filename!");
+        }
+        else{
+            MapDocument m = new MapDocument();
+            if(!m.isMapDocument(filename)){
+                throw new IOException(filename + " is not a map!");
+            }
+            m.open(filename, null);
+            map = m.getMap(0);
+            MapReader mreader = new MapReader (map);
+            mreader.read();
+            for(int i = 0; i < map.getLayerCount();i++){
+                ILayer layer = map.getLayer(0);
+                ILayerReader lr = new FeatureLayerReader(layer);
+                lr.read();
+                if (layer instanceof FeatureLayer){
+                    IFeatureRenderer renderer = ((FeatureLayer)layer).getRenderer();
+                    IRendererReader rreader;
+                    try{
+                        if(renderer instanceof SimpleRenderer){
+                            rreader = new SimpleRendererReader(renderer);
+                            rreader.read();
+                        }
+                        else if(renderer instanceof ClassBreaksRenderer){
+                            rreader = new ClassBreakRendererReader(renderer);
+                            rreader.read();
+                        }
+                        else if(renderer instanceof UniqueValueRenderer){
+                            rreader = new UniqueValueRendererReader(renderer);
+                            rreader.read();
+                        }
+                        else{
+                            System.out.println("No known renderer!");
+                            System.out.println("Implement new renderer for " +
+                                               renderer.getClass().toString());
+                        }
+                    }
+                    catch(Exception e){
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
+        return true;
+    }
+
+    /**
+     * Get the mapinformation as DOM document. TODO: implement me!
+     */
+    public void getMapDocument(){
+        logger.debug("getMapDocument() -> not implemented jet.");
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/MapReader.java	Fri Apr 08 11:47:59 2011 +0200
@@ -0,0 +1,53 @@
+//package de.intevation.mxd;
+
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+
+import com.esri.arcgis.carto.IMap;
+import com.esri.arcgis.carto.Map;
+import com.esri.arcgis.geometry.ISpatialReference;
+import com.esri.arcgis.geometry.ProjectedCoordinateSystem;
+import com.esri.arcgis.geometry.GeographicCoordinateSystem;
+import com.esri.arcgis.geometry.IProjection;
+import com.esri.arcgis.geometry.Projection;
+/**
+ * Reads map information.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class MapReader{
+
+    //Member
+    IMap map;
+
+    private static final Logger logger = Logger.getLogger(MapReader.class);
+
+    //Constructor
+    public MapReader(IMap map){
+        logger.debug("constructor()");
+        this.map = map;
+    }
+
+
+    //Methods
+
+    /**
+     * Reads the Map attributes.
+     */
+    public void read() throws IOException{
+        logger.debug("read()");
+        ISpatialReference sr = map.getSpatialReference();
+        logger.debug("Instance: " + sr.getClass().toString());
+        if(sr instanceof ProjectedCoordinateSystem){
+            ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr;
+            Projection p = (Projection)pcs.getProjection();
+            System.out.println("Projection       = " + p.getName());
+        }
+        else if(sr instanceof GeographicCoordinateSystem){
+            GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr;
+            System.out.println("Name             = " + gcs.getName());
+        }
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/SimpleMarkerSymbolReader.java	Fri Apr 08 11:47:59 2011 +0200
@@ -0,0 +1,80 @@
+//package de.intevation.mxd.symbol;
+
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+
+import com.esri.arcgis.display.ISymbol;
+import com.esri.arcgis.display.SimpleMarkerSymbol;
+import com.esri.arcgis.display.esriSimpleMarkerStyle;
+import com.esri.arcgis.display.IRgbColor;
+import com.esri.arcgis.display.RgbColor;
+
+/**
+ * Reads simple marker symbol information.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class SimpleMarkerSymbolReader implements ISymbolReader{
+
+    //Member
+    private static final Logger logger = Logger.getLogger(SimpleMarkerSymbolReader.class);
+
+    private SimpleMarkerSymbol symbol;
+
+    //Constructor
+    public SimpleMarkerSymbolReader(ISymbol symbol) throws Exception{
+        logger.debug("contructor()");
+        if(symbol instanceof SimpleMarkerSymbol)
+            this.symbol = (SimpleMarkerSymbol)symbol;
+        else
+            throw new Exception("Not a SimpleMarkerSymbol!");
+    }
+
+
+    //Methods
+    public boolean read() throws IOException{
+        logger.debug("read()");
+        System.out.println("--------------------");
+        System.out.println("Symbol information:");
+        System.out.println("Name\t\t = " + symbol.getNameString());
+
+        if(symbol.getStyle() == esriSimpleMarkerStyle.esriSMSCircle)
+            System.out.println("Style\t\t = Point");
+        if(symbol.getColor() instanceof IRgbColor){
+            IRgbColor color = (IRgbColor)symbol.getColor();
+            System.out.println("Color\t\t = (" + color.getRed() + 
+                               "," + color.getGreen() +
+                               "," + color.getBlue() + ")");
+            System.out.println("Transparency\t = " + color.getTransparency());
+        }
+        else{
+            System.out.println("Color type unknown! " +
+                               symbol.getColor().getClass().toString());
+        }
+        if(symbol.getOutlineColor() instanceof RgbColor){
+            RgbColor color = (RgbColor)symbol.getOutlineColor();
+            System.out.println("Outlinecolor\t = (" + color.getRed() +
+                               "," + color.getGreen() +
+                               "," + color.getBlue() + ")");
+            System.out.println("Transparency\t = " + color.getTransparency());
+        }
+        else{
+            System.out.println("Color type unknown! " +
+                               symbol.getOutlineColor().getClass().toString());
+        }
+
+        System.out.println("Size\t\t = " + symbol.getSize());
+        System.out.println("OutlineSize\t\t = " + symbol.getOutlineSize());
+        System.out.println("Angle\t\t = " + symbol.getAngle());
+        System.out.println("Offset\t\t = " + symbol.getXOffset() +
+                           "," + symbol.getYOffset());
+        System.out.println("");
+        return true;
+    }
+
+    public void getSymbol() throws IOException{
+        logger.debug("getSymbol() -> not implemented jet.");
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/SimpleRendererReader.java	Fri Apr 08 11:47:59 2011 +0200
@@ -0,0 +1,57 @@
+//package de.intevation.mxd.renderer;
+
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+
+import com.esri.arcgis.carto.IFeatureRenderer;
+import com.esri.arcgis.display.ISymbol;
+import com.esri.arcgis.carto.SimpleRenderer;
+import com.esri.arcgis.display.SimpleMarkerSymbol;
+
+/**
+ * Reads simple renderer information.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class SimpleRendererReader implements IRendererReader{
+
+    //Member
+    private ISymbol symbol;
+    private IFeatureRenderer renderer;
+    private static final Logger logger = Logger.getLogger(FeatureLayerReader.class);
+
+    //Constructor
+    public SimpleRendererReader(IFeatureRenderer renderer){
+        this.renderer = renderer;
+    }
+
+
+    //Methods
+    public boolean read() throws IOException{
+        logger.debug("read()");
+        if(renderer instanceof SimpleRenderer){
+            SimpleRenderer sr = (SimpleRenderer)renderer;
+            System.out.println("--------------------");
+            System.out.println("Renderer inforamtion:");
+            System.out.println("Label\t\t = " + sr.getLabel());
+            System.out.println("Description\t\t = " + sr.getDescription());
+            System.out.println("");
+            symbol = sr.getSymbol();
+            try{
+                ISymbolReader isr= new SimpleMarkerSymbolReader(symbol);
+                isr.read();
+                return true;
+            }
+            catch(Exception e){
+                e.printStackTrace();
+            }
+        }
+        return false;
+    }
+
+    public void getRenderer() throws IOException{
+        logger.debug("getRenderer() -> not implemented jet.");
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/de/intevation/mxd/UniqueValueRendererReader.java	Fri Apr 08 11:47:59 2011 +0200
@@ -0,0 +1,61 @@
+//package de.intevation.mxd.renderer;
+
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+
+import com.esri.arcgis.carto.IFeatureRenderer;
+import com.esri.arcgis.display.ISymbol;
+import com.esri.arcgis.carto.UniqueValueRenderer;
+
+/**
+ * Reads unique vaule renderer information.
+ *
+ * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
+ */
+public class UniqueValueRendererReader implements IRendererReader{
+
+    //Member
+    private ISymbol symbol;
+    private IFeatureRenderer renderer;
+    private static final Logger logger = Logger.getLogger(FeatureLayerReader.class);
+
+    //Constructor
+    public UniqueValueRendererReader(IFeatureRenderer renderer){
+        this.renderer = renderer;
+    }
+
+
+    //Methods
+    public boolean read() throws IOException{
+        logger.debug("read()");
+        if(renderer instanceof UniqueValueRenderer){
+            UniqueValueRenderer sr = (UniqueValueRenderer)renderer;
+            System.out.println("--------------------");
+            System.out.println("Renderer inforamtion:");
+            System.out.println("Value count\t\t = " + sr.getValueCount());
+            for(int i = 0; i < sr.getValueCount(); i++){
+                String val = sr.getValue(i);
+                System.out.println("Value\t\t = " + val);
+                System.out.println("Label\t\t = " + sr.getLabel(val));
+                System.out.println("Description\t\t = " + sr.getDescription(val));
+            }
+            System.out.println("");
+            symbol = sr.getDefaultSymbol();
+            try{
+                ISymbolReader isr= new SimpleMarkerSymbolReader(symbol);
+                isr.read();
+                return true;
+            }
+            catch(Exception e){
+                e.printStackTrace();
+            }
+        }
+        return false;
+    }
+
+    public void getRenderer() throws IOException{
+        logger.debug("getRenderer() -> not implemented jet.");
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)