annotate src/java/de/intevation/mxd/writer/SymbolWriter.java @ 187:ea7858d75459

* website/img/inmenulogo.png ,website/img/logo_single.png ,website/img/logo_single_100.png ,website/img/logo_wide.png: Added new Logo for MXD2map
author Stephan Holl <stephan.holl@intevation.de>
date Wed, 20 Jul 2011 14:06:07 +0200
parents c79c3c6fc99a
children 0dc34dcdaedc
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
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
30 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
31 * Private member.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
32 */
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 private mapObj map;
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 private classObj cl;
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
36 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
37 * Contructor with map object and class object.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
38 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
39 * @param map The map object.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
40 * @param cl The class object containing the style.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
41 */
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 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
43 this.map = map;
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 this.cl = cl;
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 }
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 /**
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
48 * Write the content.
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
49 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
50 * @param symbolElement DOM element containg the style and symbol
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
51 * attributes.
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 */
120
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
53 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
54 logger.debug("write(Element)");
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 symbolSetObj symbolSet = map.getSymbolset();
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 String name = symbolElement.getAttribute("name");
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58 symbolObj sym = symbolSet.getSymbolByName(name);
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 String symType = symbolElement.getAttribute("style");
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
60 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
61 if(symType.equals("point")) {
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 writeSimple(sym);
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 else if (symType.equals("arrow")) {
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 writeArrow(sym, symbolElement);
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 else if (symType.equals("char")) {
141
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
68 int exists = symbolExists(symbolElement);
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
69 if(exists == -1) {
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
70 String old = symbolElement.getAttribute("name");
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
71 symbolElement.setAttribute(
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
72 "name",
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
73 old + symbolSet.getNumsymbols() + 1);
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
74 writeCharacter(sym, symbolElement);
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
75 }
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
76 else {
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
77 symbolElement.setAttribute(
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
78 "name",
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
79 symbolSet.getSymbol(exists).getName());
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
80 }
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
81 }
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
82 else if (type.equals("line")) {
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
83 writeHatch(sym);
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
84 }
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 else {
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
86 return false;
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87 }
90
82a1f39214fd Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents: 87
diff changeset
88
120
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
89 try {
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
90 saveSymbolSet(symbolSet);
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
91 }
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
92 catch(Exception e) {
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
93 logger.error("Error saving symbol set.");
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
94 return false;
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
95 }
90
82a1f39214fd Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents: 87
diff changeset
96
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
97 return true;
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
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
100 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
101 * Create a simple point symbol.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
102 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
103 * @param symbol The symbol object.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
104 */
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
105 private void writeSimple(symbolObj symbol) {
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
106 logger.debug("writeSimple(symbolObj)");
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
107 lineObj points = new lineObj();
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
108 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
109 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
110 symbol.setPoints(points);
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
111 symbol.setFilled(1);
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
112 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
113
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
114 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
115 * Create an arrow symbol.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
116 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
117 * @param symbol The symbol object.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
118 * @param symbolElement DOM element containing symbol attributes.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
119 */
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
120 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
121 logger.debug("writeArrow(symbolObj, Element)");
145
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
122 double len = 0;
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
123 double width = 1;
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
124 try {
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
125 len =
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
126 Double.parseDouble(symbolElement.getAttribute("length"));
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
127 width =
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
128 Double.parseDouble(symbolElement.getAttribute("width"));
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
129 }
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
130 catch(NumberFormatException nfe) {
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
131 logger.warn ("Error setting arrow symbol.");
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
132 return;
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
133 }
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
134 double ratio = len/width;
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
135 lineObj points = new lineObj();
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 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
138 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
139 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
140 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
141 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
142 symbol.setPoints(points);
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
143 symbol.setFilled(1);
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
144 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
145
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
146 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
147 * Create a character marker symbol.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
148 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
149 * @param symbol The symbol object.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
150 * @param symbolElement DOM element containing symbol attributes.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
151 */
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
152 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
153 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
154 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
155 //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
156 font = font.replaceAll(" ", "");
141
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
157 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
158 symbol.setFont(font);
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
159 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
160 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
161 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
162 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
163
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
164 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
165 * Create a hatch symbol for polygon fill.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
166 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
167 * @param symbol The symbol object.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
168 */
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
169 private void writeHatch(symbolObj symbol) {
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
170 logger.debug("writeHatch(symbolObj)");
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
171 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_HATCH.swigValue());
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
172 }
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
173
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
174 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
175 * Determine whether this writer can create the symbol.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
176 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
177 * @param type The symbol type.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
178 */
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
179 public boolean canWrite(String type) {
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
180 if (type.equals("point") ||
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
181 type.equals("arrow") ||
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
182 type.equals("char") ||
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
183 type.equals("line")) {
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
184 return true;
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
185 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
186 else {
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
187 return false;
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
188 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
189 }
90
82a1f39214fd Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents: 87
diff changeset
190
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
191 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
192 * Save the symbol set.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
193 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
194 * @param symbols The symbol set object.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
195 */
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
196 public void saveSymbolSet(symbolSetObj symbols)
90
82a1f39214fd Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents: 87
diff changeset
197 throws Exception {
93
3993b5adf67c Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents: 90
diff changeset
198 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
199 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
200 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
201 String symbolPath = filename + "-symbols.sym";
90
82a1f39214fd Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents: 87
diff changeset
202 if(path.equals("")) {
82a1f39214fd Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents: 87
diff changeset
203 return;
82a1f39214fd Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents: 87
diff changeset
204 }
174
707f13cfba74 Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents: 145
diff changeset
205
707f13cfba74 Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents: 145
diff changeset
206 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
207 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
208 path += symbolPath;
174
707f13cfba74 Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents: 145
diff changeset
209 }
93
3993b5adf67c Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents: 90
diff changeset
210 else {
175
f11d13940626 Handle symbol set and font set paths.
raimund renkert <raimund.renkert@intevation.de>
parents: 174
diff changeset
211 path += symbolPath;
90
82a1f39214fd Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents: 87
diff changeset
212 }
175
f11d13940626 Handle symbol set and font set paths.
raimund renkert <raimund.renkert@intevation.de>
parents: 174
diff changeset
213 path = path.replaceAll("\\\\", "/");
90
82a1f39214fd Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents: 87
diff changeset
214 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
215 this.map.setSymbolSet(path);
90
82a1f39214fd Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents: 87
diff changeset
216 }
141
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
217
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
218 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
219 * Determine whether the symbol exists.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
220 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
221 * @param elem DOM element containing the symbol attributes.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
222 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
223 * @return Returns the symbol index if the symbol exists, else returns -1.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 176
diff changeset
224 */
141
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
225 private int symbolExists (Element elem) {
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
226 symbolSetObj symbolSet = map.getSymbolset();
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
227 for (int i = 0; i < symbolSet.getNumsymbols(); i++) {
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
228 symbolObj sym = symbolSet.getSymbol(i);
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
229 int stype = sym.getType();
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
230 String etype = elem.getAttribute("style");
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
231 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
232 etype.equals("point")) {
145
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
233 return i;
141
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
234 }
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
235 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
236 etype.equals("arrow")) {
145
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
237 return i;
141
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
238 }
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
239 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
240 etype.equals("char")) {
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
241 String font = elem.getAttribute("font");
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
242 font = font.replaceAll(" ", "");
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
243 String c = elem.getAttribute("char");
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
244 c = "&#" + c + ";";
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
245 if (font.equals(sym.getFont()) &&
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
246 c.equals(sym.getCharacter())) {
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
247 return i;
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
248 }
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
249
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
250 }
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
251 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
252 etype.equals("hatch")) {
145
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
253 return i;
141
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
254 }
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
255 }
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
256 return -1;
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 120
diff changeset
257 }
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
258 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
259 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)