# HG changeset patch # User Raimund Renkert # Date 1302772175 -7200 # Node ID f807c9c81019c96dfd40f3c75386258181dc26f7 # Parent 27577294f9ca2ab55c5e62da286d88cd6e1fb780 Read further map attributes. diff -r 27577294f9ca -r f807c9c81019 ChangeLog --- a/ChangeLog Thu Apr 14 11:04:59 2011 +0200 +++ b/ChangeLog Thu Apr 14 11:09:35 2011 +0200 @@ -1,4 +1,9 @@ -2011-04-12 Raimund Renkert +2011-04-14 Raimund Renkert + + * src/java/de/intevation/mxd/reader/MapReader.java: + Read further map attributes. + +2011-04-14 Raimund Renkert * src/java/de/intevation/mxd/utils/MapToXMLUtils.java: Added root element to document and save the filename in the XML tree. diff -r 27577294f9ca -r f807c9c81019 src/java/de/intevation/mxd/reader/MapReader.java --- a/src/java/de/intevation/mxd/reader/MapReader.java Thu Apr 14 11:04:59 2011 +0200 +++ b/src/java/de/intevation/mxd/reader/MapReader.java Thu Apr 14 11:09:35 2011 +0200 @@ -5,11 +5,13 @@ import org.apache.log4j.Logger; import com.esri.arcgis.carto.IMap; +import com.esri.arcgis.carto.Map; import com.esri.arcgis.geometry.ISpatialReference; import com.esri.arcgis.geometry.ProjectedCoordinateSystem; import com.esri.arcgis.geometry.GeographicCoordinateSystem; import com.esri.arcgis.geometry.UnknownCoordinateSystem; import com.esri.arcgis.geometry.Projection; +import com.esri.arcgis.geometry.IEnvelope; import org.w3c.dom.Element; @@ -23,15 +25,21 @@ public class MapReader{ //Member - private IMap map; + private Map map; private MapToXMLUtils util; private static final Logger logger = Logger.getLogger(MapReader.class); //Constructor - public MapReader(IMap map){ + public MapReader(IMap map) + throws Exception { logger.debug("constructor()"); - this.map = map; + if(map instanceof Map) { + this.map = (Map)map; + } + else { + throw new Exception("Not an instance of \"Map\"!"); + } } @@ -45,8 +53,7 @@ if(util == null) throw new IOException("Can not write to document."); -// XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(document, -// "", ""); + //Create XML Element for map. Element mapElement; try{ mapElement = util.createMap(); @@ -55,8 +62,47 @@ e.printStackTrace(); return; } + + //Read map name. + mapElement.setAttribute("name", map.getName()); + + //Read map extent. + IEnvelope ext = map.getExtent(); + mapElement.setAttribute( + "extent_max_x", + String.valueOf(ext.getXMax())); + mapElement.setAttribute( + "extent_max_y", + String.valueOf(ext.getYMax())); + mapElement.setAttribute( + "extent_min_x", + String.valueOf(ext.getXMin())); + mapElement.setAttribute( + "extent_min_y", + String.valueOf(ext.getYMin())); + + //Read map units. + int units = map.getMapUnits(); + String s_units; + switch(units) { + case 3: s_units = "feet"; break; + case 1: s_units = "inches"; break; + case 10: s_units = "kilometers"; break; + case 9: s_units = "meters"; break; + case 5: s_units = "miles"; break; + case 6: s_units = "nauticalmiles"; break; + case 2: s_units = "points"; break; + default : s_units = "not supported"; break; + } + mapElement.setAttribute("units", s_units); + + //TODO: Find out whats the correct scale value. + mapElement.setAttribute( + "scale", + String.valueOf(map.getMaxScale())); + + //Read the projection. ISpatialReference sr = map.getSpatialReference(); - logger.debug("Instance: " + sr.getClass().toString()); if(sr instanceof ProjectedCoordinateSystem){ ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr; Projection p = (Projection)pcs.getProjection();