Mercurial > mxd2map
annotate src/java/de/intevation/mxd/writer/LineStyleWriter.java @ 108:3c58c07cee6b
added hints for connecting to ArcSDE
author | Stephan Holl <stephan.holl@intevation.de> |
---|---|
date | Tue, 14 Jun 2011 12:35:36 +0200 |
parents | 1ae8e05b863f |
children | 11d63bf00326 |
rev | line source |
---|---|
95
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.mxd.writer; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
2 |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
3 import java.awt.Color; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
4 |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
5 import org.apache.log4j.Logger; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
6 |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
7 import org.w3c.dom.Element; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
8 |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
9 import edu.umn.gis.mapscript.mapObj; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
10 import edu.umn.gis.mapscript.classObj; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
11 import edu.umn.gis.mapscript.styleObj; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
12 import edu.umn.gis.mapscript.colorObj; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
13 import edu.umn.gis.mapscript.symbolObj; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
14 import edu.umn.gis.mapscript.symbolSetObj; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
15 |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
16 |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
17 /** |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
18 * The interface to the mapfile writer. |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
19 * |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
20 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
21 */ |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
22 public class LineStyleWriter { |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
23 |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
24 /** |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
25 * The Logger. |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
26 */ |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
27 private static final Logger logger = Logger.getLogger(LineStyleWriter.class); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
28 |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
29 private mapObj map; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
30 private classObj cl; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
31 private styleObj style; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
32 |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
33 public LineStyleWriter (mapObj map, classObj cl) { |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
34 this.map = map; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
35 this.cl = cl; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
36 this.style = new styleObj(cl); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
37 } |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
38 |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
39 /** |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
40 * Write the content. |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
41 */ |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
42 public boolean write(Element symbolElement) |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
43 throws Exception { |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
44 logger.debug("write(Element)"); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
45 symbolSetObj symbolSet = map.getSymbolset(); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
46 if(symbolElement.hasAttribute("angle")) { |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
47 style.setAngle( |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
48 Double.parseDouble(symbolElement.getAttribute("angle"))); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
49 } |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
50 if(symbolElement.hasAttribute("color")) { |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
51 String c = symbolElement.getAttribute("color"); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
52 Color col = Color.decode(c); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
53 colorObj color = new colorObj( |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
54 col.getRed(), |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
55 col.getGreen(), |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
56 col.getBlue(), |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
57 -4); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
58 style.setColor(color); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
59 } |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
60 if(symbolElement.hasAttribute("width")) { |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
61 style.setWidth((int)Double.parseDouble( |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
62 symbolElement.getAttribute("width"))); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
63 } |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
64 if(symbolElement.hasAttribute("size")) { |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
65 style.setSize((int)Double.parseDouble( |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
66 symbolElement.getAttribute("size"))); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
67 } |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
68 String name = symbolElement.getAttribute("name"); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
69 symbolObj sym = symbolSet.getSymbolByName(name); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
70 |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
71 //The following lines are for dashed and/or dotted lines. |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
72 //These lines throw an "incorrect array size" error. |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
73 //TODO Find out how to set the pattern correctly.(Remove the "&& false" |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
74 //to use this block). |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
75 if(symbolElement.hasAttribute("linestyle") && false) { |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
76 String ls = symbolElement.getAttribute("linestyle"); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
77 double[] vals; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
78 if(ls.equals("dash")) { |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
79 style.setPatternlength(2); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
80 vals = new double[] {2.0, 2.0}; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
81 style.setPattern(vals); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
82 } |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
83 else if(ls.equals("dot")) { |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
84 style.setPatternlength(2); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
85 vals = new double[] {1.0, 2.0}; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
86 style.setPattern(vals); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
87 } |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
88 else if(ls.equals("dashdot")) { |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
89 style.setPatternlength(4); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
90 vals = new double[] {2.0, 2.0, 1.0, 2.0}; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
91 style.setPattern(vals); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
92 } |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
93 else if (ls.equals("dashdotdot")) { |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
94 style.setPatternlength(6); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
95 vals = new double[] {2.0, 2.0, 1.0, 2.0, 1.0, 2.0}; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
96 style.setPattern(vals); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
97 } |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
98 } |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
99 String type = symbolElement.getAttribute("type"); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
100 |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
101 if(type.equals("marker")) { |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
102 style.setSymbolByName(map, name); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
103 SymbolWriter sw = new SymbolWriter(this.map, this.cl); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
104 sw.write(symbolElement); |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
105 } |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
106 return false; |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
107 } |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
108 } |
1ae8e05b863f
Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
109 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |