comparison src/java/de/intevation/mxd/reader/MapReader.java @ 39:f807c9c81019

Read further map attributes.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 14 Apr 2011 11:09:35 +0200
parents 7a927921eb6c
children ef7ca23c4233
comparison
equal deleted inserted replaced
38:27577294f9ca 39:f807c9c81019
3 import java.io.IOException; 3 import java.io.IOException;
4 4
5 import org.apache.log4j.Logger; 5 import org.apache.log4j.Logger;
6 6
7 import com.esri.arcgis.carto.IMap; 7 import com.esri.arcgis.carto.IMap;
8 import com.esri.arcgis.carto.Map;
8 import com.esri.arcgis.geometry.ISpatialReference; 9 import com.esri.arcgis.geometry.ISpatialReference;
9 import com.esri.arcgis.geometry.ProjectedCoordinateSystem; 10 import com.esri.arcgis.geometry.ProjectedCoordinateSystem;
10 import com.esri.arcgis.geometry.GeographicCoordinateSystem; 11 import com.esri.arcgis.geometry.GeographicCoordinateSystem;
11 import com.esri.arcgis.geometry.UnknownCoordinateSystem; 12 import com.esri.arcgis.geometry.UnknownCoordinateSystem;
12 import com.esri.arcgis.geometry.Projection; 13 import com.esri.arcgis.geometry.Projection;
14 import com.esri.arcgis.geometry.IEnvelope;
13 15
14 import org.w3c.dom.Element; 16 import org.w3c.dom.Element;
15 17
16 import de.intevation.mxd.utils.MapToXMLUtils; 18 import de.intevation.mxd.utils.MapToXMLUtils;
17 19
21 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 23 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
22 */ 24 */
23 public class MapReader{ 25 public class MapReader{
24 26
25 //Member 27 //Member
26 private IMap map; 28 private Map map;
27 private MapToXMLUtils util; 29 private MapToXMLUtils util;
28 30
29 private static final Logger logger = Logger.getLogger(MapReader.class); 31 private static final Logger logger = Logger.getLogger(MapReader.class);
30 32
31 //Constructor 33 //Constructor
32 public MapReader(IMap map){ 34 public MapReader(IMap map)
35 throws Exception {
33 logger.debug("constructor()"); 36 logger.debug("constructor()");
34 this.map = map; 37 if(map instanceof Map) {
38 this.map = (Map)map;
39 }
40 else {
41 throw new Exception("Not an instance of \"Map\"!");
42 }
35 } 43 }
36 44
37 45
38 //Methods 46 //Methods
39 47
43 public void read() throws IOException{ 51 public void read() throws IOException{
44 logger.debug("read()"); 52 logger.debug("read()");
45 if(util == null) 53 if(util == null)
46 throw new IOException("Can not write to document."); 54 throw new IOException("Can not write to document.");
47 55
48 // XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(document, 56 //Create XML Element for map.
49 // "", "");
50 Element mapElement; 57 Element mapElement;
51 try{ 58 try{
52 mapElement = util.createMap(); 59 mapElement = util.createMap();
53 } 60 }
54 catch(Exception e){ 61 catch(Exception e){
55 e.printStackTrace(); 62 e.printStackTrace();
56 return; 63 return;
57 } 64 }
65
66 //Read map name.
67 mapElement.setAttribute("name", map.getName());
68
69 //Read map extent.
70 IEnvelope ext = map.getExtent();
71 mapElement.setAttribute(
72 "extent_max_x",
73 String.valueOf(ext.getXMax()));
74 mapElement.setAttribute(
75 "extent_max_y",
76 String.valueOf(ext.getYMax()));
77 mapElement.setAttribute(
78 "extent_min_x",
79 String.valueOf(ext.getXMin()));
80 mapElement.setAttribute(
81 "extent_min_y",
82 String.valueOf(ext.getYMin()));
83
84 //Read map units.
85 int units = map.getMapUnits();
86 String s_units;
87 switch(units) {
88 case 3: s_units = "feet"; break;
89 case 1: s_units = "inches"; break;
90 case 10: s_units = "kilometers"; break;
91 case 9: s_units = "meters"; break;
92 case 5: s_units = "miles"; break;
93 case 6: s_units = "nauticalmiles"; break;
94 case 2: s_units = "points"; break;
95 default : s_units = "not supported"; break;
96 }
97 mapElement.setAttribute("units", s_units);
98
99 //TODO: Find out whats the correct scale value.
100 mapElement.setAttribute(
101 "scale",
102 String.valueOf(map.getMaxScale()));
103
104 //Read the projection.
58 ISpatialReference sr = map.getSpatialReference(); 105 ISpatialReference sr = map.getSpatialReference();
59 logger.debug("Instance: " + sr.getClass().toString());
60 if(sr instanceof ProjectedCoordinateSystem){ 106 if(sr instanceof ProjectedCoordinateSystem){
61 ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr; 107 ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr;
62 Projection p = (Projection)pcs.getProjection(); 108 Projection p = (Projection)pcs.getProjection();
63 mapElement.setAttribute("projection", p.getName()); 109 mapElement.setAttribute("projection", p.getName());
64 } 110 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)