rrenkert@26: //package de.intevation.mxd.reader; rrenkert@25: rrenkert@25: import java.io.IOException; rrenkert@25: rrenkert@25: import org.apache.log4j.Logger; rrenkert@25: rrenkert@25: import com.esri.arcgis.geodatabase.IClass; rrenkert@25: import com.esri.arcgis.carto.ILayer; rrenkert@25: import com.esri.arcgis.carto.IMap; rrenkert@25: import com.esri.arcgis.carto.MapDocument; rrenkert@25: import com.esri.arcgis.carto.FeatureLayer; rrenkert@25: import com.esri.arcgis.carto.IFeatureRenderer; rrenkert@25: import com.esri.arcgis.carto.SimpleRenderer; rrenkert@25: import com.esri.arcgis.carto.ClassBreaksRenderer; rrenkert@25: import com.esri.arcgis.carto.UniqueValueRenderer; rrenkert@25: rrenkert@25: import com.esri.arcgis.geodatabase.IFeatureClass; rrenkert@25: import com.esri.arcgis.geodatabase.FeatureClass; rrenkert@25: import com.esri.arcgis.geometry.ISpatialReference; rrenkert@25: import com.esri.arcgis.geometry.ProjectedCoordinateSystem; rrenkert@25: import com.esri.arcgis.geometry.IProjection; rrenkert@25: import com.esri.arcgis.geometry.Projection; rrenkert@25: rrenkert@27: import org.w3c.dom.Document; rrenkert@27: import org.w3c.dom.Element; rrenkert@30: import org.w3c.dom.Node; rrenkert@27: rrenkert@25: /** rrenkert@25: * The MXD file reader. rrenkert@25: * rrenkert@25: * @author Raimund Renkert rrenkert@25: */ rrenkert@25: public class MXDReader implements IReader { rrenkert@25: rrenkert@25: //Member rrenkert@25: private String filename = ""; rrenkert@25: private ArcGISInitializer initializer = null; rrenkert@25: private IMap map; rrenkert@27: private Document mapInfo; rrenkert@25: rrenkert@25: private static final Logger logger = Logger.getLogger(MXDReader.class); rrenkert@25: rrenkert@25: //Constructor rrenkert@25: public MXDReader() throws IOException{ rrenkert@25: logger.debug("constructor()"); rrenkert@25: initializer = new ArcGISInitializer(); rrenkert@27: mapInfo = XMLUtils.newDocument(); rrenkert@25: } rrenkert@25: rrenkert@25: rrenkert@25: //Methods rrenkert@25: rrenkert@25: /** rrenkert@25: * Initialize the ArcGIS Objects. rrenkert@25: */ rrenkert@25: public boolean init() throws IOException{ rrenkert@25: logger.debug("init()"); rrenkert@25: initializer.initArcGIS(); rrenkert@25: initializer.initArcGISLicenses(); rrenkert@25: return true; rrenkert@25: } rrenkert@25: rrenkert@25: /** rrenkert@25: * Shutdown the ArcGIS Objects. rrenkert@25: */ rrenkert@25: public boolean shutdown() throws IOException{ rrenkert@25: logger.debug("shutdown()"); rrenkert@25: if(initializer == null){ rrenkert@25: throw new IOException("Faild to shutdown!"); rrenkert@25: } rrenkert@25: else{ rrenkert@25: initializer.shutdownArcGIS(); rrenkert@25: return true; rrenkert@25: } rrenkert@25: } rrenkert@25: rrenkert@25: /** rrenkert@25: * Set the path and filename to the MXD-File. rrenkert@25: */ rrenkert@25: public void setFilename(String name){ rrenkert@25: logger.debug("setFilename()"); rrenkert@25: filename = name; rrenkert@25: } rrenkert@25: rrenkert@27: rrenkert@27: private void openMapDocument() throws IOException{ rrenkert@27: MapDocument m = new MapDocument(); rrenkert@27: if(!m.isMapDocument(filename)){ rrenkert@27: throw new IOException(filename + " is not a map!"); rrenkert@27: } rrenkert@27: m.open(filename, null); rrenkert@27: map = m.getMap(0); rrenkert@27: } rrenkert@25: /** rrenkert@25: * Read the MXD file content. rrenkert@25: */ rrenkert@25: public boolean read() throws IOException{ rrenkert@25: logger.debug("read()"); rrenkert@25: if(filename == ""){ rrenkert@25: throw new IOException("Please set filename!"); rrenkert@25: } rrenkert@25: else{ rrenkert@27: openMapDocument(); rrenkert@25: MapReader mreader = new MapReader (map); rrenkert@27: mreader.setDocument(mapInfo); rrenkert@25: mreader.read(); rrenkert@27: rrenkert@25: for(int i = 0; i < map.getLayerCount();i++){ rrenkert@27: ILayer layer = map.getLayer(i); rrenkert@27: try{ rrenkert@29: FeatureLayerReader lr = new FeatureLayerReader(layer); rrenkert@29: lr.setDocument(mapInfo); rrenkert@27: lr.read(); rrenkert@27: if (layer instanceof FeatureLayer){ rrenkert@30: IFeatureClass fc = ((FeatureLayer)layer).getFeatureClass(); rrenkert@30: IClassReader creader = new FeatureClassReader(fc); rrenkert@30: rrenkert@27: IFeatureRenderer renderer = ((FeatureLayer)layer).getRenderer(); rrenkert@27: IRendererReader rreader; rrenkert@25: if(renderer instanceof SimpleRenderer){ rrenkert@25: rreader = new SimpleRendererReader(renderer); rrenkert@25: rreader.read(); rrenkert@25: } rrenkert@25: else if(renderer instanceof ClassBreaksRenderer){ rrenkert@25: rreader = new ClassBreakRendererReader(renderer); rrenkert@25: rreader.read(); rrenkert@25: } rrenkert@25: else if(renderer instanceof UniqueValueRenderer){ rrenkert@25: rreader = new UniqueValueRendererReader(renderer); rrenkert@25: rreader.read(); rrenkert@25: } rrenkert@25: else{ rrenkert@25: System.out.println("No known renderer!"); rrenkert@25: System.out.println("Implement new renderer for " + rrenkert@25: renderer.getClass().toString()); rrenkert@25: } rrenkert@25: } rrenkert@27: } rrenkert@27: catch(Exception e){ rrenkert@27: e.printStackTrace(); rrenkert@25: } rrenkert@25: } rrenkert@29: XMLUtils.toStream(mapInfo, System.out); rrenkert@25: } rrenkert@25: return true; rrenkert@25: } rrenkert@25: rrenkert@27: rrenkert@25: /** rrenkert@25: * Get the mapinformation as DOM document. TODO: implement me! rrenkert@25: */ rrenkert@27: public Document getMapDocument(){ rrenkert@27: logger.debug("getMapDocument()"); rrenkert@27: return mapInfo; rrenkert@25: } rrenkert@25: } rrenkert@25: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :