Mercurial > mxd2map
annotate src/java/de/intevation/mxd/writer/FillStyleWriter.java @ 134:acc9e5430177
Handle SDE connection attributes and expressions.
author | vc11884admin@VC11884.win.bsh.de |
---|---|
date | Wed, 22 Jun 2011 12:01:28 +0200 |
parents | cd18c61cbcf6 |
children | b2c5a66022f1 |
rev | line source |
---|---|
97 | 1 package de.intevation.mxd.writer; |
2 | |
3 import java.io.IOException; | |
4 import java.awt.Color; | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.w3c.dom.Element; | |
8 import org.w3c.dom.NodeList; | |
9 | |
10 import edu.umn.gis.mapscript.mapObj; | |
11 import edu.umn.gis.mapscript.layerObj; | |
12 import edu.umn.gis.mapscript.classObj; | |
13 import edu.umn.gis.mapscript.styleObj; | |
14 import edu.umn.gis.mapscript.colorObj; | |
15 import edu.umn.gis.mapscript.symbolObj; | |
16 import edu.umn.gis.mapscript.symbolSetObj; | |
17 import edu.umn.gis.mapscript.lineObj; | |
18 import edu.umn.gis.mapscript.pointObj; | |
19 | |
20 | |
21 /** | |
22 * The interface to the mapfile writer. | |
23 * | |
24 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
25 */ | |
26 public class FillStyleWriter { | |
27 | |
28 /** | |
29 * The Logger. | |
30 */ | |
31 private static final Logger logger = | |
32 Logger.getLogger(FillStyleWriter.class); | |
33 | |
34 private mapObj map; | |
35 private classObj cl; | |
36 private styleObj style; | |
37 | |
38 public FillStyleWriter (mapObj map, classObj cl) { | |
39 logger.debug("contructor(mapObj, classObj)"); | |
40 this.map = map; | |
41 this.cl = cl; | |
42 this.style = new styleObj(cl); | |
43 } | |
44 | |
45 /** | |
46 * Write the content. | |
47 */ | |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
101
diff
changeset
|
48 public boolean write(Element symbolElement) { |
123
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
49 logger.debug("write()Element"); |
97 | 50 symbolSetObj symbolSet = map.getSymbolset(); |
51 | |
52 if(symbolElement.hasChildNodes()) { | |
53 NodeList symbols = symbolElement.getChildNodes(); | |
54 for (int i = 0; i < symbols.getLength(); i++) { | |
55 Element nextSym = (Element)symbols.item(i); | |
56 String type = nextSym.getAttribute("type"); | |
57 | |
58 if(((symbols.getLength() > 1 && i == 0) || | |
59 (symbols.getLength() == 1 && | |
60 !symbolElement.hasAttribute("hatch"))) && | |
61 type.equals("line")) { | |
62 writeOutline(nextSym); | |
63 if (symbols.getLength() == 1) { | |
64 writeSimple(symbolElement); | |
65 } | |
66 } | |
67 else if(nextSym.getTagName().equals("symbol") && | |
68 !symbolElement.hasAttribute("hatch") || | |
69 (i == 1 && type.equals("marker"))) { | |
70 double gap = 0; | |
71 if(symbolElement.hasAttribute("xseparation")) { | |
72 gap = Double.parseDouble( | |
73 symbolElement.getAttribute("xseparation")); | |
74 } | |
75 writeMarker(nextSym, gap); | |
76 } | |
77 else if (nextSym.getTagName().equals("symbol") && | |
78 symbolElement.hasAttribute("hatch")) { | |
79 if(symbolElement.hasAttribute("angle")) { | |
80 nextSym.setAttribute( | |
81 "angle", | |
82 symbolElement.getAttribute("angle")); | |
83 } | |
84 if(symbolElement.hasAttribute("separation")) { | |
85 nextSym.setAttribute( | |
86 "size", | |
87 symbolElement.getAttribute("separation")); | |
88 } | |
89 writeMarker(nextSym, -1); | |
90 } | |
91 else { | |
92 writeSimple(symbolElement); | |
93 } | |
94 } | |
95 } | |
96 else { | |
97 writeSimple(symbolElement); | |
98 if(symbolElement.hasAttribute("outline_color")) { | |
99 Color oCol = Color.decode( | |
100 symbolElement.getAttribute("outline_color")); | |
101 colorObj outlineColor = new colorObj( | |
102 oCol.getRed(), | |
103 oCol.getGreen(), | |
104 oCol.getBlue(), | |
105 -4); | |
106 style.setOutlinecolor(outlineColor); | |
107 style.setOutlinewidth(Double.parseDouble( | |
108 symbolElement.getAttribute("outline_size"))); | |
109 } | |
110 | |
111 } | |
112 | |
113 return true; | |
114 } | |
115 | |
116 /** | |
117 * Write the outline for a polygon. | |
118 */ | |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
101
diff
changeset
|
119 private void writeOutline(Element symbolElement) { |
97 | 120 logger.debug("writeOutline()"); |
121 //write transparent outline | |
122 colorObj color = new colorObj(-1, -1, -1, -4); | |
131
cd18c61cbcf6
Do not write lines or outlines if their width is smaller than 1.0.
vc11884admin@VC11884.win.bsh.de
parents:
123
diff
changeset
|
123 if(symbolElement.hasAttribute("width")) { |
cd18c61cbcf6
Do not write lines or outlines if their width is smaller than 1.0.
vc11884admin@VC11884.win.bsh.de
parents:
123
diff
changeset
|
124 double w = Double.parseDouble(symbolElement.getAttribute("width")); |
cd18c61cbcf6
Do not write lines or outlines if their width is smaller than 1.0.
vc11884admin@VC11884.win.bsh.de
parents:
123
diff
changeset
|
125 if (w < 1.0) { |
cd18c61cbcf6
Do not write lines or outlines if their width is smaller than 1.0.
vc11884admin@VC11884.win.bsh.de
parents:
123
diff
changeset
|
126 return; |
cd18c61cbcf6
Do not write lines or outlines if their width is smaller than 1.0.
vc11884admin@VC11884.win.bsh.de
parents:
123
diff
changeset
|
127 } |
cd18c61cbcf6
Do not write lines or outlines if their width is smaller than 1.0.
vc11884admin@VC11884.win.bsh.de
parents:
123
diff
changeset
|
128 } |
97 | 129 //write new style for the outline |
130 //TODO write further attribute like pattern etc. | |
131 Color oCol = Color.decode( | |
132 symbolElement.getAttribute("color")); | |
133 | |
134 styleObj outline = new styleObj (cl); | |
135 | |
136 colorObj outlinecolor = new colorObj( | |
137 oCol.getRed(), | |
138 oCol.getGreen(), | |
139 oCol.getBlue(), | |
140 -4); | |
141 outline.setOutlinecolor(outlinecolor); | |
142 outline.setOutlinewidth(Double.parseDouble( | |
143 symbolElement.getAttribute("width"))); | |
123
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
144 if(symbolElement.hasAttribute("linestyle")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
145 String ls = symbolElement.getAttribute("linestyle"); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
146 double[] vals; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
147 if(ls.equals("dash")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
148 outline.setPatternlength(2); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
149 vals = new double[] {4.0, 4.0, 0, 0, 0, 0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
150 outline.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
151 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
152 else if(ls.equals("dot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
153 outline.setPatternlength(2); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
154 vals = new double[] {1.0, 3.0, 0, 0, 0, 0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
155 outline.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
156 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
157 else if(ls.equals("dashdot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
158 outline.setPatternlength(4); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
159 vals = new double[] {4.0, 3.0, 1.0, 3.0, 0, 0, 0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
160 outline.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
161 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
162 else if (ls.equals("dashdotdot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
163 outline.setPatternlength(6); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
164 vals = new double[] {5.0, 3.0, 1.0, 3.0, 1.0, 4.0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
165 outline.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
166 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
167 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
168 |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
169 |
97 | 170 } |
171 | |
172 /** | |
173 * Write marker attributes and a symbol for the polygon fill. | |
174 */ | |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
101
diff
changeset
|
175 private void writeMarker(Element symbolElement, double gap) { |
97 | 176 logger.debug("writeMarker()"); |
177 String name = symbolElement.getAttribute("name"); | |
178 String type = symbolElement.getAttribute("type"); | |
179 if (symbolElement.hasAttribute("angle")) { | |
180 style.setAngle( | |
181 Double.parseDouble(symbolElement.getAttribute("angle"))); | |
182 } | |
183 if(symbolElement.hasAttribute("color")) { | |
184 String c = symbolElement.getAttribute("color"); | |
185 Color col = Color.decode(c); | |
186 colorObj color = new colorObj( | |
187 col.getRed(), | |
188 col.getGreen(), | |
189 col.getBlue(), | |
190 -4); | |
191 style.setColor(color); | |
192 } | |
193 if (symbolElement.hasAttribute ("size")) { | |
194 double size = Double.parseDouble( | |
195 symbolElement.getAttribute("size")); | |
196 style.setSize(size); | |
197 //In arcgis the separation goes from center to center, so the gap is | |
198 //the separation - size | |
199 if (gap > 0) { | |
200 style.setGap(gap - size); | |
201 } | |
202 } | |
203 if(symbolElement.hasAttribute("outline_color")) { | |
204 Color oCol = Color.decode( | |
205 symbolElement.getAttribute("outline_color")); | |
206 colorObj outlineColor = new colorObj( | |
207 oCol.getRed(), | |
208 oCol.getGreen(), | |
209 oCol.getBlue(), | |
210 -4); | |
211 style.setOutlinecolor(outlineColor); | |
212 style.setOutlinewidth(Double.parseDouble( | |
213 symbolElement.getAttribute("outline_size"))); | |
214 } | |
215 if(type.equals("marker")) { | |
216 style.setSymbolByName(map, name); | |
217 SymbolWriter sw = new SymbolWriter(this.map, this.cl); | |
218 sw.write(symbolElement); | |
219 } | |
220 else if(type.equals("line")) { | |
221 style.setSymbolByName(map, "hatch"); | |
222 SymbolWriter sw = new SymbolWriter(this.map, this.cl); | |
223 symbolElement.setAttribute("name", "hatch"); | |
224 sw.write(symbolElement); | |
123
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
225 if(symbolElement.hasAttribute("linestyle")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
226 String ls = symbolElement.getAttribute("linestyle"); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
227 double[] vals; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
228 if(ls.equals("dash")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
229 style.setPatternlength(2); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
230 vals = new double[] {4.0, 4.0, 0, 0, 0, 0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
231 style.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
232 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
233 else if(ls.equals("dot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
234 style.setPatternlength(2); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
235 vals = new double[] {1.0, 3.0, 0, 0, 0, 0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
236 style.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
237 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
238 else if(ls.equals("dashdot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
239 style.setPatternlength(4); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
240 vals = new double[] {4.0, 3.0, 1.0, 3.0, 0, 0, 0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
241 style.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
242 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
243 else if (ls.equals("dashdotdot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
244 style.setPatternlength(6); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
245 vals = new double[] {5.0, 3.0, 1.0, 3.0, 1.0, 4.0, 0, 0, 0, 0}; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
246 style.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
247 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
248 } |
97 | 249 } |
250 } | |
251 | |
252 /** | |
253 * Write simple fill attributes. | |
254 */ | |
255 private void writeSimple(Element symbolElement) { | |
256 logger.debug("writeSimple(Element)"); | |
257 if(symbolElement.hasAttribute("transparency")) { | |
258 double value = Double.parseDouble( | |
259 symbolElement.getAttribute("transparency")); | |
260 int opacity = (int)(value/255) * 100; | |
261 if(value >= 0) { | |
262 style.setOpacity(opacity); | |
263 } | |
264 } | |
265 if(symbolElement.hasAttribute("color")) { | |
266 String c = symbolElement.getAttribute("color"); | |
267 Color col = Color.decode(c); | |
268 colorObj color = new colorObj( | |
269 col.getRed(), | |
270 col.getGreen(), | |
271 col.getBlue(), | |
272 -4); | |
273 style.setColor(color); | |
274 } | |
275 } | |
276 } | |
277 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |