comparison src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 43:ef7ca23c4233

Added comments, done some code styling and removed typos.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 15 Apr 2011 15:44:54 +0200
parents 395307e8b7ee
children 9b5fb5e5914d
comparison
equal deleted inserted replaced
42:395307e8b7ee 43:ef7ca23c4233
24 import edu.umn.gis.mapscript.MS_SYMBOL_TYPE; 24 import edu.umn.gis.mapscript.MS_SYMBOL_TYPE;
25 25
26 import de.intevation.mxd.utils.XMLUtils; 26 import de.intevation.mxd.utils.XMLUtils;
27 27
28 /** 28 /**
29 * The MXD file reader. 29 * The Mapfile Writer.
30 * This Writer uses the MapScript Java API to create Mapfiles from a DOM.
30 * 31 *
31 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> 32 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
32 */ 33 */
33 public class MapScriptWriter 34 public class MapScriptWriter
34 implements IWriter 35 implements IWriter
35 { 36 {
37 /**
38 * The Logger.
39 */
40 private static final Logger logger = Logger.getLogger(MapScriptWriter.class);
41
42 /**
43 * Private member.
44 */
36 private Document root; 45 private Document root;
37 private mapObj map; 46 private mapObj map;
38 47
39 private static final Logger logger = Logger.getLogger(MapScriptWriter.class);
40 48
41 public MapScriptWriter() { 49 public MapScriptWriter() {
42 map = new mapObj(""); 50 map = new mapObj("");
43 } 51 }
44 52
45 public MapScriptWriter(String path) { 53 public MapScriptWriter(String path) {
46 map = new mapObj(path); 54 map = new mapObj(path);
47 } 55 }
48 56
57 /**
58 * Write the mapfile.
59 * @param doc The root document containin the map attributes.
60 *
61 * @return Currently always true.
62 */
49 public boolean write(Document doc) { 63 public boolean write(Document doc) {
50 logger.debug("write()"); 64 logger.debug("write()");
51 this.root = doc; 65 this.root = doc;
52 66
53 //Get the filename. 67 //Get the filename.
67 mapObj cloneMap = map.cloneMap(); 81 mapObj cloneMap = map.cloneMap();
68 cloneMap.save(filename); 82 cloneMap.save(filename);
69 return true; 83 return true;
70 } 84 }
71 85
86 /**
87 * Create the map object and set the attributes.
88 */
72 private void writeMap() { 89 private void writeMap() {
73 logger.debug("writeMap()"); 90 logger.debug("writeMap()");
74 //Get the map. 91 //Get the map.
75 Element mapNode = (Element)XMLUtils.xpath( 92 Element mapNode = (Element)XMLUtils.xpath(
76 root, 93 root,
124 141
125 //TODO: Find out whats the correct scale value. 142 //TODO: Find out whats the correct scale value.
126 //map.setScaledenom(Double.parseDouble(mapNode.getAttribute("scale"))); 143 //map.setScaledenom(Double.parseDouble(mapNode.getAttribute("scale")));
127 } 144 }
128 145
146 /**
147 * Create layer objects and set the attributes.
148 */
129 private void writeLayer() { 149 private void writeLayer() {
130 logger.debug("writeLayer()"); 150 logger.debug("writeLayer()");
131 Element mapNode = (Element)XMLUtils.xpath( 151 Element mapNode = (Element)XMLUtils.xpath(
132 root, 152 root,
133 "/mxd/map", 153 "/mxd/map",
192 writeSymbol(co, classElement); 212 writeSymbol(co, classElement);
193 } 213 }
194 } 214 }
195 215
196 /** 216 /**
197 * Adds teh symbols and styles to the mapfile. 217 * Adds the symbols and styles to the mapfile.
198 * @param co Mapscript class object. 218 * @param co Mapscript class object.
199 * @param classElement Dom element containing the style and symbol 219 * @param classElement Dom element containing the style and symbol
200 * attributes. 220 * attributes.
201 */ 221 */
202 private void writeSymbol(classObj co, Element classElement) { 222 private void writeSymbol(classObj co, Element classElement) {
218 col.getRed(), 238 col.getRed(),
219 col.getGreen(), 239 col.getGreen(),
220 col.getBlue(), 240 col.getBlue(),
221 -4); 241 -4);
222 style.setColor(color); 242 style.setColor(color);
223 style.setSize(Double.parseDouble(symbolElement.getAttribute("size"))); 243 style.setSize(Double.parseDouble(
244 symbolElement.getAttribute("size")));
224 Color oCol = Color.decode( 245 Color oCol = Color.decode(
225 symbolElement.getAttribute("outline_color")); 246 symbolElement.getAttribute("outline_color"));
226 colorObj outlineColor = new colorObj( 247 colorObj outlineColor = new colorObj(
227 oCol.getRed(), 248 oCol.getRed(),
228 oCol.getGreen(), 249 oCol.getGreen(),
229 oCol.getBlue(), 250 oCol.getBlue(),
230 -4); 251 -4);
231 style.setOutlinecolor(outlineColor); 252 style.setOutlinecolor(outlineColor);
232 style.setOutlinewidth( 253 style.setOutlinewidth(Double.parseDouble(
233 Double.parseDouble(symbolElement.getAttribute("outline_size"))); 254 symbolElement.getAttribute("outline_size")));
234 style.setSymbolByName(map, symbolElement.getAttribute("name")); 255
235 256 String name = symbolElement.getAttribute("name");
236 symbolObj sym = symbolSet.getSymbolByName(symbolElement.getAttribute("name")); 257 style.setSymbolByName(map, name);
258 symbolObj sym = symbolSet.getSymbolByName(name);
259
237 String symType = symbolElement.getAttribute("style"); 260 String symType = symbolElement.getAttribute("style");
238 if(symType.equals("point")) { 261 if(symType.equals("point")) {
239 lineObj points = new lineObj(); 262 lineObj points = new lineObj();
240 points.add(new pointObj(1,1,0)); 263 points.add(new pointObj(1,1,0));
241 sym.setType(MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue()); 264 sym.setType(MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue());
246 saveSymbolSet(symbolSet); 269 saveSymbolSet(symbolSet);
247 } 270 }
248 271
249 /** 272 /**
250 * Save the symbol set. 273 * Save the symbol set.
251 * @param 274 * @param symbols The symbol set.
252 */ 275 */
253 private void saveSymbolSet(symbolSetObj symbols) { 276 private void saveSymbolSet(symbolSetObj symbols) {
254 Element fileNode = (Element)XMLUtils.xpath( 277 Element fileNode = (Element)XMLUtils.xpath(
255 root, 278 root,
256 "/mxd/file", 279 "/mxd/file",
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)