annotate src/java/de/intevation/mxd/reader/MapReader.java @ 250:d10fd4de02aa

Documented a bunch of new features * Support of picture-marker symbol (issue343) * Support for ArcGIS named groups (issue381) * GLOBAL and Layer extents and SRS (issue 379)
author Stephan Holl <stephan.holl@intevation.de>
date Fri, 12 Aug 2011 09:15:34 +0200
parents df4e0946ef02
children 5a2b5bc066eb
rev   line source
243
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
1 /*
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
2 * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de>
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
3 *
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
4 * This file is part of MXD2map.
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
5 *
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
6 * This program is free software under the LGPL (>=v2.1)
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
7 * Read the file LICENCE.txt coming with the software for details
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
8 * or visit http://www.gnu.org/licenses/ if it does not exist.
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
9 *
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
10 * MXD2map has been developed on behalf of the
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
11 * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
12 * by Intevation GmbH.
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
13 *
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
14 * Authors:
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
15 * Raimund Renkert <raimund.renkert@intevation.de>
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
16 * Bjoern Schilberg <bjoern.schilberg@intevation.de>
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
17 * Stephan Holl <stephan.holl@intevation.de>
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
18 */
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 181
diff changeset
19
33
c51376f8e24c Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents: 31
diff changeset
20 package de.intevation.mxd.reader;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 import java.io.IOException;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24 import org.apache.log4j.Logger;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 import com.esri.arcgis.carto.IMap;
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
27 import com.esri.arcgis.carto.Map;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 import com.esri.arcgis.geometry.ISpatialReference;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 import com.esri.arcgis.geometry.ProjectedCoordinateSystem;
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 import com.esri.arcgis.geometry.GeographicCoordinateSystem;
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
31 import com.esri.arcgis.geometry.UnknownCoordinateSystem;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32 import com.esri.arcgis.geometry.Projection;
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
33 import com.esri.arcgis.geometry.IEnvelope;
27
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
34
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
35 import org.w3c.dom.Element;
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
36
33
c51376f8e24c Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents: 31
diff changeset
37 import de.intevation.mxd.utils.MapToXMLUtils;
c51376f8e24c Separated converter components into packages.
Raimund Renkert <rrenkert@intevation.de>
parents: 31
diff changeset
38
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39 /**
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 * Reads map information.
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 *
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 * @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
43 */
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
44 public class MapReader {
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
45 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
46 * The Logger.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
47 */
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
48 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
49
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
50 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
51 * Private member.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
52 */
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
53 private Map map;
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
54 private MapToXMLUtils util;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 170
diff changeset
56 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 170
diff changeset
57 * Constructor with ArcGIS map.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 170
diff changeset
58 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 170
diff changeset
59 * @param map The ArcGIS map object.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 170
diff changeset
60 */
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
61 public MapReader(IMap map)
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
62 throws Exception {
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 logger.debug("constructor()");
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
64 if(map instanceof Map) {
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
65 this.map = (Map)map;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
66 }
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
67 else {
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
68 throw new Exception("Not an instance of \"Map\"!");
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
69 }
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 /**
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 * Reads the Map attributes.
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 */
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
75 public void read()
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
76 throws IOException {
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
77 logger.debug("read()");
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
78 if(util == null) {
27
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
79 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
80 }
27
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
81
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
82 //Create XML Element for map.
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
83 Element mapElement;
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
84 try{
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
85 mapElement = util.createMap();
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
86 }
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
87 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
88 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
89 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
90 }
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
91
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
92 //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
93 try {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
94 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
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(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
98 "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
99 " 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
100 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
101 }
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
102
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
103 //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
104 try {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
105 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
106 mapElement.setAttribute(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
107 "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
108 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
109 mapElement.setAttribute(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
110 "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
111 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
112 mapElement.setAttribute(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
113 "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
114 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
115 mapElement.setAttribute(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
116 "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
117 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
118 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
119 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
120 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
121 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
122 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
123 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
124 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
125 }
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
126
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
127 //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
128 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
129 try {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
130 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
131 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
132 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
133 logger.warn(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
134 "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
135 " 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
136 units = 0;
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
137 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
138
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
139 String s_units;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
140 switch(units) {
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
141 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
142 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
143 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
144 case 4: s_units = "yards"; break;
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
145 case 5: s_units = "miles"; break;
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
146 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154 default : s_units = "unknown"; break;
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
155 }
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
156 mapElement.setAttribute("units", s_units);
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
157
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
158 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
159 logger.warn(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
160 "Unknown units." +
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
161 " 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
162 }
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 try {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
165 mapElement.setAttribute(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
166 "scale",
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
167 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
168 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
169 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
170 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
171 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
172 }
39
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
173
f807c9c81019 Read further map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 34
diff changeset
174 //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
175 try {
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
176 ISpatialReference sr = map.getSpatialReference();
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 121
diff changeset
177 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
178 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
179 ProjectedCoordinateSystem pcs = (ProjectedCoordinateSystem)sr;
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 121
diff changeset
180 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
181 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
182 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
183 GeographicCoordinateSystem gcs = (GeographicCoordinateSystem)sr;
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 121
diff changeset
184 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
185 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
186 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
187 UnknownCoordinateSystem ucs = (UnknownCoordinateSystem)sr;
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 121
diff changeset
188 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
189 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
190 else{
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
191 logger.debug(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
192 "Unknown SpatialReference: " +
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
193 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
194 }
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
195
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 121
diff changeset
196 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
197 logger.warn(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
198 "Unknown projection." +
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
199 " 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
200 }
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 121
diff changeset
201 mapElement.setAttribute("projection", String.valueOf(projection));
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
202 }
121
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
203 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
204 logger.warn(
9f74f4d36822 Set default values and improved logging and exception handling for map reader.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
205 "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
206 " 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
207 mapElement.setAttribute("projection", "Unknown");
27
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
208 }
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
209 }
e5fdc37f8f94 Added XMLUtils to store map information.
Raimund Renkert <rrenkert@intevation.de>
parents: 26
diff changeset
210
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
211 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
212 * Set the utilities.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
213 */
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 39
diff changeset
214 public void setUtil(MapToXMLUtils util) {
31
40c0b4e5f91a Added utility class to store map attributes.
Raimund Renkert <rrenkert@intevation.de>
parents: 27
diff changeset
215 this.util = util;
25
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
216 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
217 }
cbd67b1100d8 Initial commit of the first prototype.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
218 // 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)