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.carto.IMap; rrenkert@25: import com.esri.arcgis.carto.Map; rrenkert@25: import com.esri.arcgis.geometry.ISpatialReference; rrenkert@25: import com.esri.arcgis.geometry.ProjectedCoordinateSystem; rrenkert@25: import com.esri.arcgis.geometry.GeographicCoordinateSystem; rrenkert@25: import com.esri.arcgis.geometry.IProjection; rrenkert@25: import com.esri.arcgis.geometry.Projection; rrenkert@27: rrenkert@27: import org.w3c.dom.Document; rrenkert@27: import org.w3c.dom.Element; rrenkert@27: rrenkert@25: /** rrenkert@25: * Reads map information. rrenkert@25: * rrenkert@25: * @author Raimund Renkert rrenkert@25: */ rrenkert@25: public class MapReader{ rrenkert@25: rrenkert@25: //Member rrenkert@27: private IMap map; rrenkert@27: private Document document; rrenkert@25: rrenkert@25: private static final Logger logger = Logger.getLogger(MapReader.class); rrenkert@25: rrenkert@25: //Constructor rrenkert@25: public MapReader(IMap map){ rrenkert@25: logger.debug("constructor()"); rrenkert@25: this.map = map; rrenkert@25: } rrenkert@25: rrenkert@25: rrenkert@25: //Methods rrenkert@25: rrenkert@25: /** rrenkert@25: * Reads the Map attributes. rrenkert@25: */ rrenkert@25: public void read() throws IOException{ rrenkert@25: logger.debug("read()"); rrenkert@27: if(document == null) rrenkert@27: throw new IOException("Can not write to document."); rrenkert@27: rrenkert@27: XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(document, rrenkert@27: "", ""); rrenkert@27: Element mapElement = creator.create("map"); rrenkert@25: ISpatialReference sr = map.getSpatialReference(); rrenkert@25: logger.debug("Instance: " + sr.getClass().toString()); rrenkert@25: if(sr instanceof ProjectedCoordinateSystem){ rrenkert@25: ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr; rrenkert@25: Projection p = (Projection)pcs.getProjection(); rrenkert@27: creator.addAttr(mapElement, "projection", p.getName()); rrenkert@25: } rrenkert@25: else if(sr instanceof GeographicCoordinateSystem){ rrenkert@25: GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr; rrenkert@27: creator.addAttr(mapElement, "projection", gcs.getName()); rrenkert@25: } rrenkert@27: else{ rrenkert@27: throw new IOException("Unknown SpatialReference: " + rrenkert@27: sr.getClass().toString()); rrenkert@27: } rrenkert@27: document.appendChild(mapElement); rrenkert@27: } rrenkert@27: rrenkert@27: public void setDocument(Document doc){ rrenkert@27: this.document = doc; rrenkert@25: } rrenkert@25: } rrenkert@25: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :