Mercurial > mxd2map
annotate src/java/de/intevation/mxd/writer/FillStyleWriter.java @ 150:7b1433d3b574
Handle outlines with width < 1 and transparent color.
author | vc11884admin@VC11884.win.bsh.de |
---|---|
date | Wed, 29 Jun 2011 19:29:14 +0200 |
parents | b2c5a66022f1 |
children | b1e4a871033e |
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; | |
150
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
37 private colorObj fill; |
97 | 38 |
39 public FillStyleWriter (mapObj map, classObj cl) { | |
40 logger.debug("contructor(mapObj, classObj)"); | |
41 this.map = map; | |
42 this.cl = cl; | |
43 this.style = new styleObj(cl); | |
44 } | |
45 | |
46 /** | |
47 * Write the content. | |
48 */ | |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
101
diff
changeset
|
49 public boolean write(Element symbolElement) { |
123
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
50 logger.debug("write()Element"); |
97 | 51 symbolSetObj symbolSet = map.getSymbolset(); |
52 | |
53 if(symbolElement.hasChildNodes()) { | |
54 NodeList symbols = symbolElement.getChildNodes(); | |
55 for (int i = 0; i < symbols.getLength(); i++) { | |
56 Element nextSym = (Element)symbols.item(i); | |
57 String type = nextSym.getAttribute("type"); | |
58 | |
59 if(((symbols.getLength() > 1 && i == 0) || | |
60 (symbols.getLength() == 1 && | |
61 !symbolElement.hasAttribute("hatch"))) && | |
62 type.equals("line")) { | |
150
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
63 if(symbolElement.hasAttribute("color")) { |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
64 Color oCol = Color.decode( |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
65 symbolElement.getAttribute("color")); |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
66 fill = new colorObj( |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
67 oCol.getRed(), |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
68 oCol.getGreen(), |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
69 oCol.getBlue(), |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
70 -4); |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
71 } |
97 | 72 writeOutline(nextSym); |
73 if (symbols.getLength() == 1) { | |
74 writeSimple(symbolElement); | |
75 } | |
76 } | |
77 else if(nextSym.getTagName().equals("symbol") && | |
78 !symbolElement.hasAttribute("hatch") || | |
79 (i == 1 && type.equals("marker"))) { | |
80 double gap = 0; | |
81 if(symbolElement.hasAttribute("xseparation")) { | |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
82 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
83 gap = Double.parseDouble( |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
84 symbolElement.getAttribute("xseparation")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
85 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
86 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
87 gap = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
88 } |
97 | 89 } |
90 writeMarker(nextSym, gap); | |
91 } | |
92 else if (nextSym.getTagName().equals("symbol") && | |
93 symbolElement.hasAttribute("hatch")) { | |
94 if(symbolElement.hasAttribute("angle")) { | |
95 nextSym.setAttribute( | |
96 "angle", | |
97 symbolElement.getAttribute("angle")); | |
98 } | |
99 if(symbolElement.hasAttribute("separation")) { | |
100 nextSym.setAttribute( | |
101 "size", | |
102 symbolElement.getAttribute("separation")); | |
103 } | |
104 writeMarker(nextSym, -1); | |
105 } | |
106 else { | |
107 writeSimple(symbolElement); | |
108 } | |
109 } | |
110 } | |
111 else { | |
112 writeSimple(symbolElement); | |
113 if(symbolElement.hasAttribute("outline_color")) { | |
114 Color oCol = Color.decode( | |
115 symbolElement.getAttribute("outline_color")); | |
116 colorObj outlineColor = new colorObj( | |
117 oCol.getRed(), | |
118 oCol.getGreen(), | |
119 oCol.getBlue(), | |
120 -4); | |
121 style.setOutlinecolor(outlineColor); | |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
122 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
123 style.setOutlinewidth(Double.parseDouble( |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
124 symbolElement.getAttribute("outline_size"))); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
125 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
126 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
127 logger.warn("Error setting outline width."); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
128 style.setOutlinewidth(0.0); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
129 } |
97 | 130 } |
131 | |
132 } | |
133 | |
134 return true; | |
135 } | |
136 | |
137 /** | |
138 * Write the outline for a polygon. | |
139 */ | |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
101
diff
changeset
|
140 private void writeOutline(Element symbolElement) { |
97 | 141 logger.debug("writeOutline()"); |
142 //write transparent outline | |
143 colorObj color = new colorObj(-1, -1, -1, -4); | |
150
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
144 double w = 0; |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
145 double transp = -1; |
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
|
146 if(symbolElement.hasAttribute("width")) { |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
147 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
148 w = Double.parseDouble(symbolElement.getAttribute("width")); |
150
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
149 transp = Double.parseDouble( |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
150 symbolElement.getAttribute("transparency")); |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
151 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
152 catch(NumberFormatException nfe) { |
150
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
153 logger.warn("Error setting outline width or transparency."); |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
154 w = 0; |
150
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
155 transp = -1; |
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
|
156 } |
cd18c61cbcf6
Do not write lines or outlines if their width is smaller than 1.0.
vc11884admin@VC11884.win.bsh.de
parents:
123
diff
changeset
|
157 } |
97 | 158 //write new style for the outline |
159 //TODO write further attribute like pattern etc. | |
160 Color oCol = Color.decode( | |
161 symbolElement.getAttribute("color")); | |
162 | |
163 styleObj outline = new styleObj (cl); | |
150
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
164 if (w < 1.0 && transp > 0) { |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
165 symbolElement.setAttribute("width", "1"); |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
166 outline.setOutlinecolor(fill); |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
167 } |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
168 else { |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
169 colorObj outlinecolor = new colorObj( |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
170 oCol.getRed(), |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
171 oCol.getGreen(), |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
172 oCol.getBlue(), |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
173 -4); |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
174 outline.setOutlinecolor(outlinecolor); |
7b1433d3b574
Handle outlines with width < 1 and transparent color.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
175 } |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
176 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
177 outline.setOutlinewidth(Double.parseDouble( |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
178 symbolElement.getAttribute("width"))); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
179 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
180 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
181 logger.warn("Error setting outline width."); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
182 outline.setOutlinewidth(0.0); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
183 } |
123
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
184 if(symbolElement.hasAttribute("linestyle")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
185 String ls = symbolElement.getAttribute("linestyle"); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
186 double[] vals; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
187 if(ls.equals("dash")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
188 outline.setPatternlength(2); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
189 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
|
190 outline.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
191 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
192 else if(ls.equals("dot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
193 outline.setPatternlength(2); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
194 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
|
195 outline.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
196 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
197 else if(ls.equals("dashdot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
198 outline.setPatternlength(4); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
199 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
|
200 outline.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
201 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
202 else if (ls.equals("dashdotdot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
203 outline.setPatternlength(6); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
204 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
|
205 outline.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
206 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
207 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
208 |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
209 |
97 | 210 } |
211 | |
212 /** | |
213 * Write marker attributes and a symbol for the polygon fill. | |
214 */ | |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
101
diff
changeset
|
215 private void writeMarker(Element symbolElement, double gap) { |
97 | 216 logger.debug("writeMarker()"); |
217 String name = symbolElement.getAttribute("name"); | |
218 String type = symbolElement.getAttribute("type"); | |
219 if (symbolElement.hasAttribute("angle")) { | |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
220 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
221 style.setAngle( |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
222 Double.parseDouble(symbolElement.getAttribute("angle"))); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
223 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
224 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
225 logger.warn("Error setting angle."); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
226 style.setAngle(0.0); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
227 } |
97 | 228 } |
229 if(symbolElement.hasAttribute("color")) { | |
230 String c = symbolElement.getAttribute("color"); | |
231 Color col = Color.decode(c); | |
232 colorObj color = new colorObj( | |
233 col.getRed(), | |
234 col.getGreen(), | |
235 col.getBlue(), | |
236 -4); | |
237 style.setColor(color); | |
238 } | |
239 if (symbolElement.hasAttribute ("size")) { | |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
240 double size = 1; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
241 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
242 size = Double.parseDouble(symbolElement.getAttribute("size")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
243 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
244 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
245 size = 1.0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
246 } |
97 | 247 style.setSize(size); |
248 //In arcgis the separation goes from center to center, so the gap is | |
249 //the separation - size | |
250 if (gap > 0) { | |
251 style.setGap(gap - size); | |
252 } | |
253 } | |
254 if(symbolElement.hasAttribute("outline_color")) { | |
255 Color oCol = Color.decode( | |
256 symbolElement.getAttribute("outline_color")); | |
257 colorObj outlineColor = new colorObj( | |
258 oCol.getRed(), | |
259 oCol.getGreen(), | |
260 oCol.getBlue(), | |
261 -4); | |
262 style.setOutlinecolor(outlineColor); | |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
263 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
264 style.setOutlinewidth(Double.parseDouble( |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
265 symbolElement.getAttribute("outline_size"))); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
266 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
267 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
268 logger.warn("Error setting angle."); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
269 style.setOutlinewidth(0.0); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
270 } |
97 | 271 } |
272 if(type.equals("marker")) { | |
273 style.setSymbolByName(map, name); | |
274 SymbolWriter sw = new SymbolWriter(this.map, this.cl); | |
275 sw.write(symbolElement); | |
276 } | |
277 else if(type.equals("line")) { | |
278 style.setSymbolByName(map, "hatch"); | |
279 SymbolWriter sw = new SymbolWriter(this.map, this.cl); | |
280 symbolElement.setAttribute("name", "hatch"); | |
281 sw.write(symbolElement); | |
123
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
282 if(symbolElement.hasAttribute("linestyle")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
283 String ls = symbolElement.getAttribute("linestyle"); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
284 double[] vals; |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
285 if(ls.equals("dash")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
286 style.setPatternlength(2); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
287 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
|
288 style.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
289 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
290 else if(ls.equals("dot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
291 style.setPatternlength(2); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
292 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
|
293 style.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
294 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
295 else if(ls.equals("dashdot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
296 style.setPatternlength(4); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
297 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
|
298 style.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
299 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
300 else if (ls.equals("dashdotdot")) { |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
301 style.setPatternlength(6); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
302 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
|
303 style.setPattern(vals); |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
304 } |
3c792458a716
Write PATTERN for polygon outlines and hatch symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
305 } |
97 | 306 } |
307 } | |
308 | |
309 /** | |
310 * Write simple fill attributes. | |
311 */ | |
312 private void writeSimple(Element symbolElement) { | |
313 logger.debug("writeSimple(Element)"); | |
314 if(symbolElement.hasAttribute("transparency")) { | |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
315 double value = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
316 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
317 value = Double.parseDouble( |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
318 symbolElement.getAttribute("transparency")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
319 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
320 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
321 value = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
131
diff
changeset
|
322 } |
97 | 323 int opacity = (int)(value/255) * 100; |
324 if(value >= 0) { | |
325 style.setOpacity(opacity); | |
326 } | |
327 } | |
328 if(symbolElement.hasAttribute("color")) { | |
329 String c = symbolElement.getAttribute("color"); | |
330 Color col = Color.decode(c); | |
331 colorObj color = new colorObj( | |
332 col.getRed(), | |
333 col.getGreen(), | |
334 col.getBlue(), | |
335 -4); | |
336 style.setColor(color); | |
337 } | |
338 } | |
339 } | |
340 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |