Mercurial > mxd2map
comparison src/java/de/intevation/mxd/writer/SymbolWriter.java @ 87:7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 31 May 2011 17:54:43 +0200 |
parents | |
children | 82a1f39214fd |
comparison
equal
deleted
inserted
replaced
86:e19c5eb43099 | 87:7d4cf2db43f1 |
---|---|
1 package de.intevation.mxd.writer; | |
2 | |
3 import org.apache.log4j.Logger; | |
4 | |
5 import org.w3c.dom.Element; | |
6 | |
7 import edu.umn.gis.mapscript.mapObj; | |
8 import edu.umn.gis.mapscript.classObj; | |
9 import edu.umn.gis.mapscript.styleObj; | |
10 import edu.umn.gis.mapscript.symbolObj; | |
11 import edu.umn.gis.mapscript.symbolSetObj; | |
12 import edu.umn.gis.mapscript.lineObj; | |
13 import edu.umn.gis.mapscript.pointObj; | |
14 import edu.umn.gis.mapscript.MS_SYMBOL_TYPE; | |
15 | |
16 | |
17 /** | |
18 * The interface to the mapfile writer. | |
19 * | |
20 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
21 */ | |
22 public class SymbolWriter { | |
23 | |
24 /** | |
25 * The Logger. | |
26 */ | |
27 private static final Logger logger = Logger.getLogger(SymbolWriter.class); | |
28 | |
29 private mapObj map; | |
30 private classObj cl; | |
31 private styleObj style; | |
32 | |
33 public SymbolWriter (mapObj map, classObj cl) { | |
34 this.map = map; | |
35 this.cl = cl; | |
36 this.style = new styleObj(cl); | |
37 } | |
38 | |
39 /** | |
40 * Write the content. | |
41 */ | |
42 public boolean write(Element symbolElement) | |
43 throws Exception { | |
44 logger.debug("write(Element)"); | |
45 symbolSetObj symbolSet = map.getSymbolset(); | |
46 | |
47 String name = symbolElement.getAttribute("name"); | |
48 symbolObj sym = symbolSet.getSymbolByName(name); | |
49 | |
50 String symType = symbolElement.getAttribute("style"); | |
51 if(symType.equals("point")) { | |
52 writeSimple(sym); | |
53 } | |
54 else if (symType.equals("arrow")) { | |
55 writeArrow(sym, symbolElement); | |
56 } | |
57 else if (symType.equals("char")) { | |
58 //TODO Does not work at all... waiting for fix. | |
59 writeCharacter(sym, symbolElement); | |
60 } | |
61 else { | |
62 return false; | |
63 } | |
64 return true; | |
65 } | |
66 | |
67 private void writeSimple(symbolObj symbol) { | |
68 logger.debug("writeSimple(symbolObj)"); | |
69 lineObj points = new lineObj(); | |
70 points.add(new pointObj(1,1,0)); | |
71 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue()); | |
72 symbol.setPoints(points); | |
73 symbol.setFilled(1); | |
74 } | |
75 | |
76 private void writeArrow(symbolObj symbol, Element symbolElement) { | |
77 logger.debug("writeArrow(symbolObj, Element)"); | |
78 double len = Double.parseDouble(symbolElement.getAttribute("length")); | |
79 double width = Double.parseDouble(symbolElement.getAttribute("width")); | |
80 double ratio = len/width; | |
81 lineObj points = new lineObj(); | |
82 | |
83 points.add(new pointObj(0, 0, 0)); | |
84 points.add(new pointObj((1*ratio), 0.5, 0)); | |
85 points.add(new pointObj(0, 1, 0)); | |
86 points.add(new pointObj(0, 0, 0)); | |
87 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_VECTOR.swigValue()); | |
88 symbol.setPoints(points); | |
89 symbol.setFilled(1); | |
90 } | |
91 | |
92 private void writeCharacter(symbolObj symbol, Element symbolElement) { | |
93 logger.debug("writeCharacter(symbolObj, Element)"); | |
94 //TODO Write the symbol correctly. See Issue 3885 on trac.osgeo.org | |
95 symbol.setFont(symbolElement.getAttribute("font")); | |
96 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue()); | |
97 symbol.setAntialias(1); | |
98 symbol.setCharacter("#&" + symbolElement.getAttribute("char") + ";"); | |
99 } | |
100 | |
101 public boolean canWrite(String type) { | |
102 if (type.equals("point") || | |
103 type.equals("arrow") || | |
104 type.equals("char")) { | |
105 return true; | |
106 } | |
107 else { | |
108 return false; | |
109 } | |
110 } | |
111 } | |
112 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |