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@31: import com.esri.arcgis.geometry.UnknownCoordinateSystem; 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@31: private MapToXMLUtils util; 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@31: if(util == null) rrenkert@27: throw new IOException("Can not write to document."); rrenkert@27: rrenkert@31: // XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(document, rrenkert@31: // "", ""); rrenkert@31: Element mapElement; rrenkert@31: try{ rrenkert@31: mapElement = util.createMap(); rrenkert@31: } rrenkert@31: catch(Exception e){ rrenkert@31: e.printStackTrace(); rrenkert@31: return; rrenkert@31: } 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@31: mapElement.setAttribute("projection", p.getName()); rrenkert@25: } rrenkert@25: else if(sr instanceof GeographicCoordinateSystem){ rrenkert@25: GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr; rrenkert@31: mapElement.setAttribute("projection", gcs.getName()); rrenkert@31: } rrenkert@31: else if(sr instanceof UnknownCoordinateSystem) { rrenkert@31: UnknownCoordinateSystem ucs = (UnknownCoordinateSystem)sr; rrenkert@31: mapElement.setAttribute("projection", sr.getName()); rrenkert@25: } rrenkert@27: else{ rrenkert@27: throw new IOException("Unknown SpatialReference: " + rrenkert@27: sr.getClass().toString()); rrenkert@27: } rrenkert@27: } rrenkert@27: rrenkert@31: public void setUtil(MapToXMLUtils util){ rrenkert@31: this.util = util; rrenkert@25: } rrenkert@25: } rrenkert@25: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :