Mercurial > mxd2map
view src/java/de/intevation/mxd/reader/MXDReader.java @ 54:2cbf8bdf20b2
* doku/funktionsweise/Makefile,
doku/funktionsweise/funktionsweise-MXD-konverter.svg: New. Added
a schema how the converter works
author | Stephan Holl <stephan.holl@intevation.de> |
---|---|
date | Mon, 16 May 2011 16:20:13 +0200 |
parents | ef7ca23c4233 |
children | b41fcf268827 |
line wrap: on
line source
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.IMap; import com.esri.arcgis.carto.MapDocument; 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 org.w3c.dom.Document; import org.w3c.dom.Element; import de.intevation.mxd.ArcGISInitializer; import de.intevation.mxd.utils.MapToXMLUtils; /** * The MXD file reader. * * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ public class MXDReader implements IReader { /** * The Logger. */ private static final Logger logger = Logger.getLogger(MXDReader.class); /** * Private member. */ private String filename = ""; private ArcGISInitializer initializer = null; private MapToXMLUtils util; private IMap map; public MXDReader() throws IOException { logger.debug("constructor()"); initializer = new ArcGISInitializer(); util = new MapToXMLUtils(); } /** * 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; } private void openMapDocument() throws IOException { MapDocument m = new MapDocument(); if(!m.isMapDocument(filename)) { throw new IOException(filename + " is not a map!"); } m.open(filename, null); map = m.getMap(0); } /** * Read the MXD file content. */ public boolean read() throws IOException { logger.debug("read()"); if(filename == "") { throw new IOException("Please set filename!"); } else { util.addFilename(filename); openMapDocument(); MapReader mreader; try { mreader = new MapReader (map); mreader.setUtil(util); mreader.read(); } catch(Exception e) { e.printStackTrace(); } for(int i = 0; i < map.getLayerCount();i++) { ILayer layer = map.getLayer(i); try { if (layer instanceof FeatureLayer) { FeatureLayerReader lr = new FeatureLayerReader(layer); lr.setUtil(util); Element layerElement = lr.read(); IFeatureRenderer renderer = ((FeatureLayer)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{ System.out.println("No known renderer!"); System.out.println("Implement new renderer for " + renderer.getClass().toString()); } } else if(layer instanceof GdbRasterCatalogLayer) { GdbRasterCatalogLayerReader gclr = new GdbRasterCatalogLayerReader(layer); gclr.setUtil(util); Element layerElement = gclr.read(); IFeatureRenderer renderer = ((GdbRasterCatalogLayer)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 { System.out.println("No known renderer!"); System.out.println("Implement new renderer for " + renderer.getClass().toString()); } } } catch(Exception e) { e.printStackTrace(); } } util.print(); } return true; } /** * Get the root DOM document. */ public Document getMapDocument() { logger.debug("getMapDocument()"); return util.getDocument(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :