annotate src/java/de/intevation/mxd/reader/MapReader.java @ 53:691864097eb1

* src/java/de/intevation/mxd/writer/MapScriptWriter.java: Added the (currently) hard-coded template-path to the mapObj-constructor; removed some TODO-settings.
author Stephan Holl <stephan.holl@intevation.de>
date Wed, 11 May 2011 10:10:18 +0200
parents ef7ca23c4233
children 8da6555f1c12
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 */
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
25 public class MapReader {
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
26 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
27 * The Logger.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
28 */
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
29 private static final Logger logger = Logger.getLogger(MapReader.class);
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
31 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
32 * Private member.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
33 */
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
34 private Map map;
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
35 private MapToXMLUtils util;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
38 public MapReader(IMap map)
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
39 throws Exception {
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 logger.debug("constructor()");
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
41 if(map instanceof Map) {
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
42 this.map = (Map)map;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
43 }
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
44 else {
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
45 throw new Exception("Not an instance of \"Map\"!");
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
46 }
25
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 /**
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50 * Reads the Map attributes.
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51 */
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
52 public void read()
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
53 throws IOException {
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54 logger.debug("read()");
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
55 if(util == null) {
27
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
56 throw new IOException("Can not write to document.");
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
57 }
27
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
58
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
59 //Create XML Element for map.
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
60 Element mapElement;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
61 try{
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
62 mapElement = util.createMap();
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
63 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
64 catch(Exception e){
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
65 e.printStackTrace();
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
66 return;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
67 }
39
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 name.
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
70 mapElement.setAttribute("name", map.getName());
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
71
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
72 //Read map extent.
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
73 IEnvelope ext = map.getExtent();
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_x",
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
76 String.valueOf(ext.getXMax()));
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_max_y",
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
79 String.valueOf(ext.getYMax()));
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_x",
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
82 String.valueOf(ext.getXMin()));
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
83 mapElement.setAttribute(
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
84 "extent_min_y",
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
85 String.valueOf(ext.getYMin()));
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
86
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
87 //Read map units.
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
88 int units = map.getMapUnits();
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
89 String s_units;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
90 switch(units) {
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
91 case 3: s_units = "feet"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
92 case 1: s_units = "inches"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
93 case 10: s_units = "kilometers"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
94 case 9: s_units = "meters"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
95 case 5: s_units = "miles"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
96 case 6: s_units = "nauticalmiles"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
97 case 2: s_units = "points"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
98 default : s_units = "not supported"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
99 }
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
100 mapElement.setAttribute("units", s_units);
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
101
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
102 //TODO: Find out whats the correct scale value.
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
103 mapElement.setAttribute(
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
104 "scale",
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
105 String.valueOf(map.getMaxScale()));
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
106
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
107 //Read the projection.
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
108 ISpatialReference sr = map.getSpatialReference();
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
109 if(sr instanceof ProjectedCoordinateSystem) {
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
110 ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
111 Projection p = (Projection)pcs.getProjection();
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
112 mapElement.setAttribute("projection", p.getName());
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
113 }
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
114 else if(sr instanceof GeographicCoordinateSystem) {
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
115 GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr;
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
116 mapElement.setAttribute("projection", gcs.getName());
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
117 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
118 else if(sr instanceof UnknownCoordinateSystem) {
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
119 UnknownCoordinateSystem ucs = (UnknownCoordinateSystem)sr;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
120 mapElement.setAttribute("projection", sr.getName());
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
121 }
27
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
122 else{
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
123 throw new IOException("Unknown SpatialReference: " +
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
124 sr.getClass().toString());
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
125 }
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
126 }
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
127
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
128 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
129 * Set the utilities.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
130 */
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
131 public void setUtil(MapToXMLUtils util) {
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
132 this.util = util;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
133 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
134 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
135 // 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)