annotate src/java/de/intevation/mxd/reader/MapReader.java @ 170:b9ee44070056

Manage projections and units.
author vc11884admin@VC11884.win.bsh.de
date Wed, 06 Jul 2011 15:17:05 +0200
parents 9f74f4d36822
children 0bde090506f9
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){
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
65 logger.error("Could not create DOM element. Aborting.");
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
66 throw new IOException("Error creating DOM element.");
31
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.
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
70 try {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
71 mapElement.setAttribute("name", map.getName());
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
72 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
73 catch(IOException ioe) {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
74 logger.warn(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
75 "Could not read map name." +
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
76 " Setting map name to \"default-map\"");
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
77 mapElement.setAttribute("name", "default-map");
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
78 }
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
79
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
80 //Read map extent.
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
81 try {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
82 IEnvelope ext = map.getExtent();
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
83 mapElement.setAttribute(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
84 "extent_max_x",
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
85 String.valueOf(ext.getXMax()));
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
86 mapElement.setAttribute(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
87 "extent_max_y",
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
88 String.valueOf(ext.getYMax()));
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
89 mapElement.setAttribute(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
90 "extent_min_x",
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
91 String.valueOf(ext.getXMin()));
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
92 mapElement.setAttribute(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
93 "extent_min_y",
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
94 String.valueOf(ext.getYMin()));
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
95 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
96 catch(IOException ioe) {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
97 logger.warn("Could not read map extend. Setting to 0, 0, 0, 0.");
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
98 mapElement.setAttribute("extend_max_x", "0");
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
99 mapElement.setAttribute("extend_min_x", "0");
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
100 mapElement.setAttribute("extend_max_y", "0");
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
101 mapElement.setAttribute("extend_min_y", "0");
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
102 }
39
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 map units.
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
105 int units = 0;
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
106 try {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
107 units = map.getMapUnits();
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
108 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
109 catch(IOException ioe) {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
110 logger.warn(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
111 "Could not read map units." +
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
112 " Setting map units to unknown.");
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
113 units = 0;
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
114 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
115
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
116 String s_units;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
117 switch(units) {
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
118 case 1: s_units = "inches"; break;
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
119 case 2: s_units = "points"; break;
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
120 case 3: s_units = "feet"; break;
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
121 case 4: s_units = "yards"; break;
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
122 case 5: s_units = "miles"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
123 case 6: s_units = "nauticalmiles"; break;
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
124 case 7: s_units = "millimeters"; break;
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
125 case 8: s_units = "centimeters"; break;
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
126 case 9: s_units = "meters"; break;
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
127 case 10: s_units = "kilometers"; break;
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
128 case 11: s_units = "degree"; break;
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
129 case 12: s_units = "decimeters"; break;
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
130 case 13: s_units = "units_last"; break;
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
131 default : s_units = "unknown"; break;
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
132 }
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
133 mapElement.setAttribute("units", s_units);
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
134
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
135 if(units == 0) {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
136 logger.warn(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
137 "Unknown units." +
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
138 " Please edit units in resulting mapfile.");
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
139 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
140
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
141 //TODO: Find out whats the correct scale value.
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
142 try {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
143 mapElement.setAttribute(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
144 "scale",
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
145 String.valueOf(map.getMaxScale()));
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
146 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
147 catch(IOException ioe) {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
148 logger.warn("Could not read map scale. Setting map scale to 1000");
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
149 mapElement.setAttribute("scale", "1000");
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
150 }
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
151
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
152 //Read the projection.
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
153 try {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
154 ISpatialReference sr = map.getSpatialReference();
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 121
diff changeset
155 int projection = 0;
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
156 if(sr instanceof ProjectedCoordinateSystem) {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
157 ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr;
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 121
diff changeset
158 projection = pcs.getFactoryCode();
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
159 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
160 else if(sr instanceof GeographicCoordinateSystem) {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
161 GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr;
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 121
diff changeset
162 projection = gcs.getFactoryCode();
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
163 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
164 else if(sr instanceof UnknownCoordinateSystem) {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
165 UnknownCoordinateSystem ucs = (UnknownCoordinateSystem)sr;
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 121
diff changeset
166 projection = 0;
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
167 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
168 else{
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
169 logger.debug(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
170 "Unknown SpatialReference: " +
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
171 sr.getClass().toString());
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
172 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
173
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 121
diff changeset
174 if(projection == 0) {
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
175 logger.warn(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
176 "Unknown projection." +
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
177 " Please edit projection in resulting mapfile.");
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
178 }
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 121
diff changeset
179 mapElement.setAttribute("projection", String.valueOf(projection));
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
180 }
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
181 catch(IOException ioe) {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
182 logger.warn(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
183 "Could not read map projection." +
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
184 " Setting map projection to unknown.");
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
185 mapElement.setAttribute("projection", "Unknown");
27
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
186 }
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
187 }
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
188
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
189 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
190 * Set the utilities.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
191 */
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
192 public void setUtil(MapToXMLUtils util) {
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
193 this.util = util;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
194 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
195 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
196 // 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)