Mercurial > mxd2map
diff src/java/de/intevation/mxd/reader/MXDReader.java @ 26:3e24fffdf2bb
Moved reader components to reader folder.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Fri, 08 Apr 2011 12:26:17 +0200 |
parents | src/java/de/intevation/mxd/MXDReader.java@cbd67b1100d8 |
children | e5fdc37f8f94 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java/de/intevation/mxd/reader/MXDReader.java Fri Apr 08 12:26:17 2011 +0200 @@ -0,0 +1,138 @@ +//package de.intevation.mxd.reader; + +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 :