annotate 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
rev   line source
33
c51376f8e24c Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents: 31
diff changeset
1 package de.intevation.mxd.reader;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
2
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
3 import java.io.IOException;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
4
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
5 import org.apache.log4j.Logger;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
6
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
7 import com.esri.arcgis.carto.IMap;
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
8 import com.esri.arcgis.carto.Map;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9 import com.esri.arcgis.geometry.ISpatialReference;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10 import com.esri.arcgis.geometry.ProjectedCoordinateSystem;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 import com.esri.arcgis.geometry.GeographicCoordinateSystem;
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
12 import com.esri.arcgis.geometry.UnknownCoordinateSystem;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 import com.esri.arcgis.geometry.Projection;
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
14 import com.esri.arcgis.geometry.IEnvelope;
27
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
15
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
16 import org.w3c.dom.Element;
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
17
33
c51376f8e24c Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents: 31
diff changeset
18 import de.intevation.mxd.utils.MapToXMLUtils;
c51376f8e24c Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents: 31
diff changeset
19
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 /**
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21 * Reads map information.
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 *
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24 */
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25 public class MapReader{
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27 //Member
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
28 private Map map;
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
29 private MapToXMLUtils util;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 private static final Logger logger = Logger.getLogger(MapReader.class);
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 //Constructor
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
34 public MapReader(IMap map)
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
35 throws Exception {
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 logger.debug("constructor()");
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
37 if(map instanceof Map) {
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
38 this.map = (Map)map;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
39 }
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
40 else {
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
41 throw new Exception("Not an instance of \"Map\"!");
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
42 }
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
46 //Methods
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
48 /**
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49 * Reads the Map attributes.
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50 */
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51 public void read() throws IOException{
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 logger.debug("read()");
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
53 if(util == null)
27
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
54 throw new IOException("Can not write to document.");
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
55
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
56 //Create XML Element for map.
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
57 Element mapElement;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
58 try{
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
59 mapElement = util.createMap();
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
60 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
61 catch(Exception e){
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
62 e.printStackTrace();
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
63 return;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
64 }
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
65
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
66 //Read map name.
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
67 mapElement.setAttribute("name", map.getName());
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
68
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
69 //Read map extent.
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
70 IEnvelope ext = map.getExtent();
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
71 mapElement.setAttribute(
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
72 "extent_max_x",
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
73 String.valueOf(ext.getXMax()));
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
74 mapElement.setAttribute(
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
75 "extent_max_y",
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
76 String.valueOf(ext.getYMax()));
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
77 mapElement.setAttribute(
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
78 "extent_min_x",
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
79 String.valueOf(ext.getXMin()));
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
80 mapElement.setAttribute(
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
81 "extent_min_y",
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
82 String.valueOf(ext.getYMin()));
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
83
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
84 //Read map units.
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
85 int units = map.getMapUnits();
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
86 String s_units;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
87 switch(units) {
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
88 case 3: s_units = "feet"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
89 case 1: s_units = "inches"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
90 case 10: s_units = "kilometers"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
91 case 9: s_units = "meters"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
92 case 5: s_units = "miles"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
93 case 6: s_units = "nauticalmiles"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
94 case 2: s_units = "points"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
95 default : s_units = "not supported"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
96 }
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
97 mapElement.setAttribute("units", s_units);
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
98
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
99 //TODO: Find out whats the correct scale value.
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
100 mapElement.setAttribute(
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
101 "scale",
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
102 String.valueOf(map.getMaxScale()));
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
103
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
104 //Read the projection.
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
105 ISpatialReference sr = map.getSpatialReference();
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
106 if(sr instanceof ProjectedCoordinateSystem){
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
107 ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
108 Projection p = (Projection)pcs.getProjection();
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
109 mapElement.setAttribute("projection", p.getName());
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
110 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
111 else if(sr instanceof GeographicCoordinateSystem){
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
112 GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr;
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
113 mapElement.setAttribute("projection", gcs.getName());
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
114 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
115 else if(sr instanceof UnknownCoordinateSystem) {
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
116 UnknownCoordinateSystem ucs = (UnknownCoordinateSystem)sr;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
117 mapElement.setAttribute("projection", sr.getName());
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
118 }
27
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
119 else{
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
120 throw new IOException("Unknown SpatialReference: " +
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
121 sr.getClass().toString());
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
122 }
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
123 }
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
124
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
125 public void setUtil(MapToXMLUtils util){
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
126 this.util = util;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
127 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
128 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
129 // 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)