Mercurial > mxd2map
annotate src/java/de/intevation/mxd/writer/SymbolWriter.java @ 234:d20477c1a7f8
Fixed link to commits-archive
author | Stephan Holl <stephan.holl@intevation.de> |
---|---|
date | Fri, 05 Aug 2011 08:41:42 +0200 |
parents | 0dc34dcdaedc |
children | df4e0946ef02 |
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; |
192
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
14 import edu.umn.gis.mapscript.fontSetObj; |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
15 import edu.umn.gis.mapscript.hashTableObj; |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
16 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
|
17 |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
18 import java.io.File; |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
19 |
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 * 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
|
22 * |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
23 * @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
|
24 */ |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
25 public class SymbolWriter { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
26 |
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 * The Logger. |
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 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
|
31 |
181 | 32 /** |
33 * Private member. | |
34 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
35 private mapObj map; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
36 private classObj cl; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
37 |
181 | 38 /** |
39 * Contructor with map object and class object. | |
40 * | |
41 * @param map The map object. | |
42 * @param cl The class object containing the style. | |
43 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
44 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
|
45 this.map = map; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
46 this.cl = cl; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
47 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
48 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
49 /** |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
50 * Write the content. |
181 | 51 * |
52 * @param symbolElement DOM element containg the style and symbol | |
53 * attributes. | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
54 */ |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
55 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
|
56 logger.debug("write(Element)"); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
57 symbolSetObj symbolSet = map.getSymbolset(); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
58 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
59 String name = symbolElement.getAttribute("name"); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
60 symbolObj sym = symbolSet.getSymbolByName(name); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
61 String symType = symbolElement.getAttribute("style"); |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
62 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
|
63 if(symType.equals("point")) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
64 writeSimple(sym); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
65 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
66 else if (symType.equals("arrow")) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
67 writeArrow(sym, symbolElement); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
68 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
69 else if (symType.equals("char")) { |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
70 int exists = symbolExists(symbolElement); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
71 if(exists == -1) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
72 String old = symbolElement.getAttribute("name"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
73 symbolElement.setAttribute( |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
74 "name", |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
75 old + symbolSet.getNumsymbols() + 1); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
76 writeCharacter(sym, symbolElement); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
77 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
78 else { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
79 symbolElement.setAttribute( |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
80 "name", |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
81 symbolSet.getSymbol(exists).getName()); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
82 } |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
83 } |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
84 else if (type.equals("line")) { |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
85 writeHatch(sym); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
86 } |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
87 else { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
88 return false; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
89 } |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
90 |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
91 try { |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
92 saveSymbolSet(symbolSet); |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
93 } |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
94 catch(Exception e) { |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
95 logger.error("Error saving symbol set."); |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
96 return false; |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
97 } |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
98 |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
99 return true; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
100 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
101 |
181 | 102 /** |
103 * Create a simple point symbol. | |
104 * | |
105 * @param symbol The symbol object. | |
106 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
107 private void writeSimple(symbolObj symbol) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
108 logger.debug("writeSimple(symbolObj)"); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
109 lineObj points = new lineObj(); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
110 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
|
111 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
|
112 symbol.setPoints(points); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
113 symbol.setFilled(1); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
114 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
115 |
181 | 116 /** |
117 * Create an arrow symbol. | |
118 * | |
119 * @param symbol The symbol object. | |
120 * @param symbolElement DOM element containing symbol attributes. | |
121 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
122 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
|
123 logger.debug("writeArrow(symbolObj, Element)"); |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
124 double len = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
125 double width = 1; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
126 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
127 len = |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
128 Double.parseDouble(symbolElement.getAttribute("length")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
129 width = |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
130 Double.parseDouble(symbolElement.getAttribute("width")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
131 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
132 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
133 logger.warn ("Error setting arrow symbol."); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
134 return; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
135 } |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
136 double ratio = len/width; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
137 lineObj points = new lineObj(); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
138 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 symbol.setPoints(points); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
145 symbol.setFilled(1); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
146 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
147 |
181 | 148 /** |
149 * Create a character marker symbol. | |
150 * | |
151 * @param symbol The symbol object. | |
152 * @param symbolElement DOM element containing symbol attributes. | |
153 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
154 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
|
155 logger.debug("writeCharacter(symbolObj, Element)"); |
93
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
156 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
|
157 //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
|
158 font = font.replaceAll(" ", ""); |
192
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
159 fontSetObj fso = this.map.getFontset(); |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
160 hashTableObj fonts = fso.getFonts(); |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
161 String mapFont = fonts.get(font,""); |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
162 if (mapFont == null || mapFont.equals("")) { |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
163 logger.warn( |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
164 "Could not find font " + font + " in font set. " + |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
165 "Setting FreeSans as symbol font." + |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
166 "Please add " + font + " to fonts.txt and replace the alias " + |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
167 "in symbol \"" + symbolElement.getAttribute("name") + "\"."); |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
168 font = "FreeSans"; |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
169 } |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
170 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
|
171 symbol.setFont(font); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
172 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
|
173 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
|
174 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
|
175 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
176 |
181 | 177 /** |
178 * Create a hatch symbol for polygon fill. | |
179 * | |
180 * @param symbol The symbol object. | |
181 */ | |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
182 private void writeHatch(symbolObj symbol) { |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
183 logger.debug("writeHatch(symbolObj)"); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
184 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_HATCH.swigValue()); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
185 } |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
186 |
181 | 187 /** |
188 * Determine whether this writer can create the symbol. | |
189 * | |
190 * @param type The symbol type. | |
191 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
192 public boolean canWrite(String type) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
193 if (type.equals("point") || |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
194 type.equals("arrow") || |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
195 type.equals("char") || |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
196 type.equals("line")) { |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
197 return true; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
198 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
199 else { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
200 return false; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
201 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
202 } |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
203 |
181 | 204 /** |
205 * Save the symbol set. | |
206 * | |
207 * @param symbols The symbol set object. | |
208 */ | |
184
c79c3c6fc99a
Always save a symbol set, use the mapfile name as prefix for the symbol set and
raimund renkert <raimund.renkert@intevation.de>
parents:
181
diff
changeset
|
209 public void saveSymbolSet(symbolSetObj symbols) |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
210 throws Exception { |
93
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
211 String path = this.map.getMappath(); |
184
c79c3c6fc99a
Always save a symbol set, use the mapfile name as prefix for the symbol set and
raimund renkert <raimund.renkert@intevation.de>
parents:
181
diff
changeset
|
212 String filename = path.substring(path.lastIndexOf(File.separator) + 1, |
c79c3c6fc99a
Always save a symbol set, use the mapfile name as prefix for the symbol set and
raimund renkert <raimund.renkert@intevation.de>
parents:
181
diff
changeset
|
213 path.lastIndexOf(".")); |
c79c3c6fc99a
Always save a symbol set, use the mapfile name as prefix for the symbol set and
raimund renkert <raimund.renkert@intevation.de>
parents:
181
diff
changeset
|
214 String symbolPath = filename + "-symbols.sym"; |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
215 if(path.equals("")) { |
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
216 return; |
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
217 } |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
218 |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
219 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
|
220 path = path.substring(0, path.lastIndexOf(File.separator) + 1); |
175
f11d13940626
Handle symbol set and font set paths.
raimund renkert <raimund.renkert@intevation.de>
parents:
174
diff
changeset
|
221 path += symbolPath; |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
222 } |
93
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
223 else { |
175
f11d13940626
Handle symbol set and font set paths.
raimund renkert <raimund.renkert@intevation.de>
parents:
174
diff
changeset
|
224 path += symbolPath; |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
225 } |
175
f11d13940626
Handle symbol set and font set paths.
raimund renkert <raimund.renkert@intevation.de>
parents:
174
diff
changeset
|
226 path = path.replaceAll("\\\\", "/"); |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
227 symbols.save(path); |
184
c79c3c6fc99a
Always save a symbol set, use the mapfile name as prefix for the symbol set and
raimund renkert <raimund.renkert@intevation.de>
parents:
181
diff
changeset
|
228 this.map.setSymbolSet(path); |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
229 } |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
230 |
181 | 231 /** |
232 * Determine whether the symbol exists. | |
233 * | |
234 * @param elem DOM element containing the symbol attributes. | |
235 * | |
236 * @return Returns the symbol index if the symbol exists, else returns -1. | |
237 */ | |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
238 private int symbolExists (Element elem) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
239 symbolSetObj symbolSet = map.getSymbolset(); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
240 for (int i = 0; i < symbolSet.getNumsymbols(); i++) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
241 symbolObj sym = symbolSet.getSymbol(i); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
242 int stype = sym.getType(); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
243 String etype = elem.getAttribute("style"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
244 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
|
245 etype.equals("point")) { |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
246 return i; |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
247 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
248 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
|
249 etype.equals("arrow")) { |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
250 return i; |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
251 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
252 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
|
253 etype.equals("char")) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
254 String font = elem.getAttribute("font"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
255 font = font.replaceAll(" ", ""); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
256 String c = elem.getAttribute("char"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
257 c = "&#" + c + ";"; |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
258 if (font.equals(sym.getFont()) && |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
259 c.equals(sym.getCharacter())) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
260 return i; |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
261 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
262 |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
263 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
264 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
|
265 etype.equals("hatch")) { |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
266 return i; |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
267 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
268 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
269 return -1; |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
270 } |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
271 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
272 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |