Mercurial > mxd2map
annotate src/java/de/intevation/mxd/writer/SymbolWriter.java @ 174:707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
author | raimund.renkert@intevation.de |
---|---|
date | Wed, 06 Jul 2011 18:38:40 +0200 |
parents | b2c5a66022f1 |
children | f11d13940626 |
rev | line source |
---|---|
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.mxd.writer; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
2 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
3 import org.apache.log4j.Logger; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
4 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
5 import org.w3c.dom.Element; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
6 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
7 import edu.umn.gis.mapscript.mapObj; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
8 import edu.umn.gis.mapscript.classObj; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
9 import edu.umn.gis.mapscript.styleObj; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
10 import edu.umn.gis.mapscript.symbolObj; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
11 import edu.umn.gis.mapscript.symbolSetObj; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
12 import edu.umn.gis.mapscript.lineObj; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
13 import edu.umn.gis.mapscript.pointObj; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
14 import edu.umn.gis.mapscript.MS_SYMBOL_TYPE; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
15 |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
16 import java.io.File; |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
17 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
18 /** |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
19 * The interface to the mapfile writer. |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
20 * |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
21 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
22 */ |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
23 public class SymbolWriter { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
24 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
25 /** |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
26 * The Logger. |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
27 */ |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
28 private static final Logger logger = Logger.getLogger(SymbolWriter.class); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
29 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
30 private mapObj map; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
31 private classObj cl; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
32 private styleObj style; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
33 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
34 public SymbolWriter (mapObj map, classObj cl) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
35 this.map = map; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
36 this.cl = cl; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
37 this.style = new styleObj(cl); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
38 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
39 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
40 /** |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
41 * Write the content. |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
42 */ |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
43 public boolean write(Element symbolElement) { |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
44 logger.debug("write(Element)"); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
45 symbolSetObj symbolSet = map.getSymbolset(); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
46 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
47 String name = symbolElement.getAttribute("name"); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
48 symbolObj sym = symbolSet.getSymbolByName(name); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
49 String symType = symbolElement.getAttribute("style"); |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
50 String type = symbolElement.getAttribute("type"); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
51 if(symType.equals("point")) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
52 writeSimple(sym); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
53 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
54 else if (symType.equals("arrow")) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
55 writeArrow(sym, symbolElement); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
56 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
57 else if (symType.equals("char")) { |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
58 int exists = symbolExists(symbolElement); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
59 if(exists == -1) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
60 String old = symbolElement.getAttribute("name"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
61 symbolElement.setAttribute( |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
62 "name", |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
63 old + symbolSet.getNumsymbols() + 1); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
64 writeCharacter(sym, symbolElement); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
65 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
66 else { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
67 symbolElement.setAttribute( |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
68 "name", |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
69 symbolSet.getSymbol(exists).getName()); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
70 } |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
71 } |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
72 else if (type.equals("line")) { |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
73 writeHatch(sym); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
74 } |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
75 else { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
76 return false; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
77 } |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
78 |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
79 try { |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
80 saveSymbolSet(symbolSet); |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
81 } |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
82 catch(Exception e) { |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
83 logger.error("Error saving symbol set."); |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
84 return false; |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
85 } |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
86 |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
87 return true; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
88 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
89 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
90 private void writeSimple(symbolObj symbol) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
91 logger.debug("writeSimple(symbolObj)"); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
92 lineObj points = new lineObj(); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
93 points.add(new pointObj(1,1,0)); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
94 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue()); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
95 symbol.setPoints(points); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
96 symbol.setFilled(1); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
97 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
98 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
99 private void writeArrow(symbolObj symbol, Element symbolElement) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
100 logger.debug("writeArrow(symbolObj, Element)"); |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
101 double len = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
102 double width = 1; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
103 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
104 len = |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
105 Double.parseDouble(symbolElement.getAttribute("length")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
106 width = |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
107 Double.parseDouble(symbolElement.getAttribute("width")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
108 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
109 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
110 logger.warn ("Error setting arrow symbol."); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
111 return; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
112 } |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
113 double ratio = len/width; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
114 lineObj points = new lineObj(); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
115 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
116 points.add(new pointObj(0, 0, 0)); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
117 points.add(new pointObj((1*ratio), 0.5, 0)); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
118 points.add(new pointObj(0, 1, 0)); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
119 points.add(new pointObj(0, 0, 0)); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
120 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_VECTOR.swigValue()); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
121 symbol.setPoints(points); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
122 symbol.setFilled(1); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
123 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
124 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
125 private void writeCharacter(symbolObj symbol, Element symbolElement) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
126 logger.debug("writeCharacter(symbolObj, Element)"); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
127 //TODO Write the symbol correctly. See Issue 3885 on trac.osgeo.org |
93
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
128 String font = symbolElement.getAttribute("font"); |
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
129 //Remove all blank character to match the mapserver fonts.txt. |
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
130 font = font.replaceAll(" ", ""); |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
131 symbol.setName(symbolElement.getAttribute("name")); |
93
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
132 symbol.setFont(font); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
133 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue()); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
134 symbol.setAntialias(1); |
93
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
135 symbol.setCharacter("&#" + symbolElement.getAttribute("char") + ";"); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
136 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
137 |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
138 private void writeHatch(symbolObj symbol) { |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
139 logger.debug("writeHatch(symbolObj)"); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
140 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_HATCH.swigValue()); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
141 } |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
142 |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
143 public boolean canWrite(String type) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
144 if (type.equals("point") || |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
145 type.equals("arrow") || |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
146 type.equals("char") || |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
147 type.equals("line")) { |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
148 return true; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
149 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
150 else { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
151 return false; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
152 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
153 } |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
154 |
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
155 private void saveSymbolSet(symbolSetObj symbols) |
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
156 throws Exception { |
93
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
157 String path = this.map.getMappath(); |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
158 if(path.equals("")) { |
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
159 return; |
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
160 } |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
161 |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
162 if (path.endsWith(".map")) { |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
163 path = path.substring(0, path.lastIndexOf(File.separator) + 1); |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
164 path += "symbols.sym"; |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
165 } |
93
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
166 else { |
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
167 path += "symbols.sym"; |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
168 } |
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
169 symbols.save(path); |
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
170 } |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
171 |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
172 private int symbolExists (Element elem) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
173 symbolSetObj symbolSet = map.getSymbolset(); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
174 for (int i = 0; i < symbolSet.getNumsymbols(); i++) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
175 symbolObj sym = symbolSet.getSymbol(i); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
176 int stype = sym.getType(); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
177 String etype = elem.getAttribute("style"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
178 if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue () && |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
179 etype.equals("point")) { |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
180 return i; |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
181 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
182 else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_VECTOR.swigValue () && |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
183 etype.equals("arrow")) { |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
184 return i; |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
185 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
186 else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue () && |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
187 etype.equals("char")) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
188 String font = elem.getAttribute("font"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
189 font = font.replaceAll(" ", ""); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
190 String c = elem.getAttribute("char"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
191 c = "&#" + c + ";"; |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
192 if (font.equals(sym.getFont()) && |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
193 c.equals(sym.getCharacter())) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
194 return i; |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
195 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
196 |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
197 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
198 else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_HATCH.swigValue () && |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
199 etype.equals("hatch")) { |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
200 return i; |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
201 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
202 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
203 return -1; |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
204 } |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
205 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
206 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |