comparison src/java/de/intevation/mxd/reader/MXDReader.java @ 27:e5fdc37f8f94

Added XMLUtils to store map information.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 08 Apr 2011 14:21:45 +0200
parents 3e24fffdf2bb
children 77cfa8092611
comparison
equal deleted inserted replaced
26:3e24fffdf2bb 27:e5fdc37f8f94
19 import com.esri.arcgis.geometry.ISpatialReference; 19 import com.esri.arcgis.geometry.ISpatialReference;
20 import com.esri.arcgis.geometry.ProjectedCoordinateSystem; 20 import com.esri.arcgis.geometry.ProjectedCoordinateSystem;
21 import com.esri.arcgis.geometry.IProjection; 21 import com.esri.arcgis.geometry.IProjection;
22 import com.esri.arcgis.geometry.Projection; 22 import com.esri.arcgis.geometry.Projection;
23 23
24 import org.w3c.dom.Document;
25 import org.w3c.dom.Element;
26
24 /** 27 /**
25 * The MXD file reader. 28 * The MXD file reader.
26 * 29 *
27 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 30 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
28 */ 31 */
30 33
31 //Member 34 //Member
32 private String filename = ""; 35 private String filename = "";
33 private ArcGISInitializer initializer = null; 36 private ArcGISInitializer initializer = null;
34 private IMap map; 37 private IMap map;
38 private Document mapInfo;
35 39
36 private static final Logger logger = Logger.getLogger(MXDReader.class); 40 private static final Logger logger = Logger.getLogger(MXDReader.class);
37 41
38 //Constructor 42 //Constructor
39 public MXDReader() throws IOException{ 43 public MXDReader() throws IOException{
40 logger.debug("constructor()"); 44 logger.debug("constructor()");
41 initializer = new ArcGISInitializer(); 45 initializer = new ArcGISInitializer();
46 mapInfo = XMLUtils.newDocument();
42 } 47 }
43 48
44 49
45 //Methods 50 //Methods
46 51
74 public void setFilename(String name){ 79 public void setFilename(String name){
75 logger.debug("setFilename()"); 80 logger.debug("setFilename()");
76 filename = name; 81 filename = name;
77 } 82 }
78 83
84
85 private void openMapDocument() throws IOException{
86 MapDocument m = new MapDocument();
87 if(!m.isMapDocument(filename)){
88 throw new IOException(filename + " is not a map!");
89 }
90 m.open(filename, null);
91 map = m.getMap(0);
92 }
79 /** 93 /**
80 * Read the MXD file content. 94 * Read the MXD file content.
81 */ 95 */
82 public boolean read() throws IOException{ 96 public boolean read() throws IOException{
83 logger.debug("read()"); 97 logger.debug("read()");
84 if(filename == ""){ 98 if(filename == ""){
85 throw new IOException("Please set filename!"); 99 throw new IOException("Please set filename!");
86 } 100 }
87 else{ 101 else{
88 MapDocument m = new MapDocument(); 102 openMapDocument();
89 if(!m.isMapDocument(filename)){
90 throw new IOException(filename + " is not a map!");
91 }
92 m.open(filename, null);
93 map = m.getMap(0);
94 MapReader mreader = new MapReader (map); 103 MapReader mreader = new MapReader (map);
104 mreader.setDocument(mapInfo);
95 mreader.read(); 105 mreader.read();
106
96 for(int i = 0; i < map.getLayerCount();i++){ 107 for(int i = 0; i < map.getLayerCount();i++){
97 ILayer layer = map.getLayer(0); 108 ILayer layer = map.getLayer(i);
98 ILayerReader lr = new FeatureLayerReader(layer); 109 try{
99 lr.read(); 110 ILayerReader lr = new FeatureLayerReader(layer);
100 if (layer instanceof FeatureLayer){ 111 lr.read();
101 IFeatureRenderer renderer = ((FeatureLayer)layer).getRenderer(); 112 if (layer instanceof FeatureLayer){
102 IRendererReader rreader; 113 IFeatureRenderer renderer = ((FeatureLayer)layer).getRenderer();
103 try{ 114 IRendererReader rreader;
104 if(renderer instanceof SimpleRenderer){ 115 if(renderer instanceof SimpleRenderer){
105 rreader = new SimpleRendererReader(renderer); 116 rreader = new SimpleRendererReader(renderer);
106 rreader.read(); 117 rreader.read();
107 } 118 }
108 else if(renderer instanceof ClassBreaksRenderer){ 119 else if(renderer instanceof ClassBreaksRenderer){
117 System.out.println("No known renderer!"); 128 System.out.println("No known renderer!");
118 System.out.println("Implement new renderer for " + 129 System.out.println("Implement new renderer for " +
119 renderer.getClass().toString()); 130 renderer.getClass().toString());
120 } 131 }
121 } 132 }
122 catch(Exception e){ 133 }
123 e.printStackTrace(); 134 catch(Exception e){
124 } 135 e.printStackTrace();
125 } 136 }
126 } 137 }
127 } 138 }
128 return true; 139 return true;
129 } 140 }
130 141
142
131 /** 143 /**
132 * Get the mapinformation as DOM document. TODO: implement me! 144 * Get the mapinformation as DOM document. TODO: implement me!
133 */ 145 */
134 public void getMapDocument(){ 146 public Document getMapDocument(){
135 logger.debug("getMapDocument() -> not implemented jet."); 147 logger.debug("getMapDocument()");
148 return mapInfo;
136 } 149 }
137 } 150 }
138 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 151 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)