annotate src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 87:7d4cf2db43f1

Added new writer classes to be flexible in creating mapfiles.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 31 May 2011 17:54:43 +0200
parents e468cf8701ea
children df2eb0e7d229
rev   line source
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
1 package de.intevation.mxd.writer;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
2
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
3 import org.apache.log4j.Logger;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
4
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
5 import org.w3c.dom.Document;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
6 import org.w3c.dom.Element;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
7 import org.w3c.dom.NodeList;
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
8
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9 import javax.xml.xpath.XPathConstants;
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
10 import java.awt.Color;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 import edu.umn.gis.mapscript.mapObj;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 import edu.umn.gis.mapscript.layerObj;
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
14 import edu.umn.gis.mapscript.classObj;
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
15 import edu.umn.gis.mapscript.styleObj;
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
16 import edu.umn.gis.mapscript.colorObj;
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
17 import edu.umn.gis.mapscript.symbolObj;
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
18 import edu.umn.gis.mapscript.symbolSetObj;
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
19 import edu.umn.gis.mapscript.lineObj;
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
20 import edu.umn.gis.mapscript.pointObj;
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
21
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 import edu.umn.gis.mapscript.MS_UNITS;
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
23 import edu.umn.gis.mapscript.MS_LAYER_TYPE;
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
24 import edu.umn.gis.mapscript.MS_SYMBOL_TYPE;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
25
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 import de.intevation.mxd.utils.XMLUtils;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 /**
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
29 * The Mapfile Writer.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
30 * This Writer uses the MapScript Java API to create Mapfiles from a DOM.
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 *
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 */
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 public class MapScriptWriter
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 implements IWriter
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 {
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
37 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
38 * The Logger.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
39 */
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
40 private static final Logger logger = Logger.getLogger(MapScriptWriter.class);
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
41
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
42 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
43 * Private member.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
44 */
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 private Document root;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
46 private mapObj map;
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
47 private String mapFilename;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
48
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49 public MapScriptWriter() {
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
50 map = new mapObj("");
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
51 mapFilename = "";
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
54 public MapScriptWriter(String templ, String filename) {
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
55 map = new mapObj(templ);
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
56 mapFilename = filename;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
59 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
60 * Write the mapfile.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
61 * @param doc The root document containin the map attributes.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
62 *
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
63 * @return Currently always true.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
64 */
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
65 public boolean write(Document doc)
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
66 throws Exception {
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 logger.debug("write()");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 this.root = doc;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 //Get the filename.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 Element fileNode = (Element)XMLUtils.xpath(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 root,
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 "/mxd/file",
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 XPathConstants.NODE);
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 //Write the map attributes.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 writeMap();
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
77 //Write the layers.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
78 writeLayer();
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79 //Save the map.
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
80 mapObj cloneMap = map.cloneMap();
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
81 cloneMap.save(mapFilename);
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 return true;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
83 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
85 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
86 * Create the map object and set the attributes.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
87 */
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
88 private void writeMap() {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 logger.debug("writeMap()");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
90 //Get the map.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
91 Element mapNode = (Element)XMLUtils.xpath(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
92 root,
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
93 "/mxd/map",
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
94 XPathConstants.NODE);
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
95
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
96 //Set the name.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
97 map.setName(mapNode.getAttribute("name"));
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
98 map.setMetaData("wms_title", mapNode.getAttribute("name"));
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
99 //Set the extent.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
100 map.setExtent(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
101 Double.parseDouble(mapNode.getAttribute("extent_min_x")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
102 Double.parseDouble(mapNode.getAttribute("extent_min_y")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
103 Double.parseDouble(mapNode.getAttribute("extent_max_x")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
104 Double.parseDouble(mapNode.getAttribute("extent_max_y")));
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
105
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
106 //Set the units.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
107 String units = mapNode.getAttribute("units");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
108 MS_UNITS msu;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
109 if(units.equals("feet")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
110 msu = MS_UNITS.MS_FEET;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
111 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
112 else if(units.equals("inches")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
113 msu = MS_UNITS.MS_INCHES;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
114 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
115 else if(units.equals("kilometers")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
116 msu = MS_UNITS.MS_KILOMETERS;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
117 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
118 else if(units.equals("meters")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
119 msu = MS_UNITS.MS_METERS;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
120 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
121 else if(units.equals("miles")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
122 msu = MS_UNITS.MS_MILES;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
123 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
124 else if(units.equals("nauticalmiles")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
125 msu = MS_UNITS.MS_NAUTICALMILES;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
126 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
127 else if(units.equals("points")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
128 msu = MS_UNITS.MS_PIXELS;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
129 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
130 else {
57
8da6555f1c12 Set the projection "EPSG:31467" and units "METERS" as default values.
Raimund Renkert <rrenkert@intevation.de>
parents: 55
diff changeset
131 msu = MS_UNITS.MS_METERS;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
132 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
133 map.setUnits(msu);
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
134
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
135 //TODO: Find out whats the correct scale value.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
136 //map.setScaledenom(Double.parseDouble(mapNode.getAttribute("scale")));
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
137 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
138
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
139 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
140 * Create layer objects and set the attributes.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
141 */
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
142 private void writeLayer()
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
143 throws Exception {
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
144 logger.debug("writeLayer()");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
145 Element mapNode = (Element)XMLUtils.xpath(
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
146 root,
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
147 "/mxd/map",
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
148 XPathConstants.NODE);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
149 NodeList list = mapNode.getElementsByTagName("layer");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
150 for(int i = 0; i < list.getLength(); i++) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
151 Element layerElement = (Element)list.item(i);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
152 layerObj layer = new layerObj(map);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
153
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
154 //The layer name.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
155 layer.setName(layerElement.getAttribute("name"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
156
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
157 //The layer status.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
158 String stat = layerElement.getAttribute("status");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
159 if (stat.equals("on")) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
160 layer.setStatus(1);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
161 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
162 else {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
163 layer.setStatus(0);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
164 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
165
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
166 //The scale.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
167 double maxScale =
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
168 Double.parseDouble(layerElement.getAttribute("max_scale"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
169 double minScale =
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
170 Double.parseDouble(layerElement.getAttribute("min_scale"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
171 layer.setMaxscaledenom(maxScale);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
172 layer.setMinscaledenom(minScale);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
173
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
174 //The layer type.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
175 String type = layerElement.getAttribute("type");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
176 if(type.equals("point")) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
177 layer.setType(MS_LAYER_TYPE.MS_LAYER_POINT);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
178 }
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
179 else if (type.equals("line")) {
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
180 layer.setType(MS_LAYER_TYPE.MS_LAYER_LINE);
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
181 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
182
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
183 //The layer datasource.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
184 layer.setData(layerElement.getAttribute("data_source"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
185
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
186 //Write classes.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
187 writeClass(layer, layerElement);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
188 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
189
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
190 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
191
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
192 /**
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
193 * Adds the classes to the layer.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
194 * @param layer Mapscript layer object.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
195 * @param layerElement Dom element containing the class attributes.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
196 */
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
197 private void writeClass(layerObj layer, Element layerElement)
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
198 throws Exception {
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
199 logger.debug("writeClass(layerObj, Element)");
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
200 //Get all renderer elements (renderer in arcgis equals class in the
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
201 //mapfile.)
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
202 NodeList list = layerElement.getElementsByTagName("renderer");
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
203
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
204 //Create all found class objects and write the symbols and styles for
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
205 //each class.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
206 for(int i = 0; i < list.getLength(); i++) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
207 Element classElement = (Element)list.item(i);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
208 classObj co = new classObj(layer);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
209 co.setName(classElement.getAttribute("name"));
44
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
210 if(classElement.hasAttribute("field_count")) {
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
211 int count =
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
212 Integer.parseInt(classElement.getAttribute("field_count"));
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
213 String exp = "";
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
214 for(int j = 0; j < count; j++) {
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
215 //TODO Find a way to create Expressions.
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
216 exp = "([" + classElement.getAttribute("expression_field_" + j);
46
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
217 exp += "] " + classElement.getAttribute("expression_operator");
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
218 exp += " " + classElement.getAttribute("value") + ")";
44
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
219 }
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
220 co.setExpression(exp);
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
221 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
222 //Write symbols and styles.
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
223 NodeList slist = classElement.getElementsByTagName("symbol");
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
224 String type = layerElement.getAttribute("type");
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
225 if(type.equals("point")) {
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
226 for(int j = 0; j < slist.getLength(); j++){
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
227 Element symbolElement = (Element) slist.item(j);
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
228 MarkerStyleWriter swriter = new MarkerStyleWriter (this.map, co);
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
229 swriter.write (symbolElement);
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
230 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
231 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
232 else if(type.equals("line")) {
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
233 for(int j = 0; j < slist.getLength(); j++){
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
234 Element symbolElement = (Element) slist.item(j);
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
235 LineStyleWriter swriter = new LineStyleWriter (this.map, co);
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
236 swriter.write (symbolElement);
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
237 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
238 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
239 symbolSetObj symbolSet = map.getSymbolset();
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
240 saveSymbolSet(symbolSet);
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
241 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
242 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
243
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
244 /**
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
245 * Adds the symbols and styles to the mapfile.
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
246 * @param co Mapscript class object.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
247 * @param classElement Dom element containing the style and symbol
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
248 * attributes.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
249 */
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
250 private void writeSymbol(classObj co, Element classElement) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
251 //Get all symbol elements from dom.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
252 NodeList list = classElement.getElementsByTagName("symbol");
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
253
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
254 //Get the symbol set from the map object.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
255 symbolSetObj symbolSet = map.getSymbolset();
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
256
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
257 for(int i = 0; i < list.getLength(); i++){
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
258 Element symbolElement = (Element) list.item(i);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
259 styleObj style = new styleObj(co);
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
260 if (symbolElement.hasAttribute("angle")) {
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
261 style.setAngle(
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
262 Double.parseDouble(symbolElement.getAttribute("angle")));
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
263 }
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
264 if(symbolElement.hasAttribute("color")) {
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
265 String c = symbolElement.getAttribute("color");
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
266 Color col = Color.decode(c);
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
267 colorObj color = new colorObj(
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
268 col.getRed(),
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
269 col.getGreen(),
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
270 col.getBlue(),
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
271 -4);
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
272 style.setColor(color);
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
273 }
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
274 if (symbolElement.hasAttribute ("size")) {
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
275 style.setSize(Double.parseDouble(
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
276 symbolElement.getAttribute("size")));
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
277 }
46
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
278 if(symbolElement.hasAttribute("outline_color")) {
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
279 Color oCol = Color.decode(
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
280 symbolElement.getAttribute("outline_color"));
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
281 colorObj outlineColor = new colorObj(
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
282 oCol.getRed(),
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
283 oCol.getGreen(),
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
284 oCol.getBlue(),
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
285 -4);
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
286 style.setOutlinecolor(outlineColor);
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
287 style.setOutlinewidth(Double.parseDouble(
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
288 symbolElement.getAttribute("outline_size")));
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
289 }
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
290 //Section for line symbols
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
291 //Setting the width
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
292 if(symbolElement.hasAttribute("width")) {
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
293 style.setWidth((int)Double.parseDouble(
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
294 symbolElement.getAttribute("width")));
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
295 }
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
296 String name = symbolElement.getAttribute("name");
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
297 style.setSymbolByName(map, name);
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
298 symbolObj sym = symbolSet.getSymbolByName(name);
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
299
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
300 //The following lines are for dashed and/or dotted lines.
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
301 //These lines throw an "incorrect array size" error.
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
302 //TODO Find out how to set the pattern correctly.
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
303 // style.setPatternlength(2);
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
304 // double[] vals = new double[] {1.0, 2.0, 3.0};
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
305 // vals[0] = 1.0;
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
306 // vals[1] = 2.0;
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
307 // vals[2] = 3.0;
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
308 // vals[3] = 4.0;
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
309 // style.setPattern(vals);
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
310 String symType = symbolElement.getAttribute("style");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
311 if(symType.equals("point")) {
49
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
312 writePointSymbol(sym, symbolElement);
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
313 }
46
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
314 else if (symType.equals("arrow")) {
49
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
315 writeArrowSymbol(sym, symbolElement);
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
316 }
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
317 else if (symType.equals("char")) {
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
318 writeCharSymbol(sym, symbolElement);
46
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
319 }
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
320 else if(symType.equals("line")) {
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
321 writeSimpleLineSymbol(sym, symbolElement);
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
322 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
323 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
324 saveSymbolSet(symbolSet);
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
325 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
326
49
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
327
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
328 /**
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
329 * Write point symbols to the map.
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
330 * @param symbol The symbol object.
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
331 * @param symbolElement The DOM object containing the attributes.
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
332 */
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
333 private void writePointSymbol(symbolObj symbol, Element symbolElement) {
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
334 lineObj points = new lineObj();
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
335 points.add(new pointObj(1,1,0));
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
336 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue());
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
337 symbol.setPoints(points);
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
338 symbol.setFilled(1);
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
339 }
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
340
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
341
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
342 /**
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
343 * Write arrow symbol to the map.
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
344 * @param symbol The symbol object.
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
345 * @param symbolElement The DOM object containig the attributes.
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
346 */
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
347 private void writeArrowSymbol(symbolObj symbol, Element symbolElement) {
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
348 double len = Double.parseDouble(symbolElement.getAttribute("length"));
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
349 double width = Double.parseDouble(symbolElement.getAttribute("width"));
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
350 double ratio = len/width;
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
351 lineObj points = new lineObj();
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
352
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
353 points.add(new pointObj(0, 0, 0));
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
354 points.add(new pointObj((1*ratio), 0.5, 0));
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
355 points.add(new pointObj(0, 1, 0));
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
356 points.add(new pointObj(0, 0, 0));
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
357 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_VECTOR.swigValue());
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
358 symbol.setPoints(points);
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
359 symbol.setFilled(1);
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
360 }
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
361
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
362
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
363 /**
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
364 * Write font symbols to the map.
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
365 * @param symbol The symbol object.
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
366 * @param symbolElement The DOM object containing the attributes.
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
367 */
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
368 private void writeCharSymbol(symbolObj symbol, Element symbolElement) {
59
ef1ee8e752b2 Write the symbols-file to the mapfile path.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
369 //TODO Write the symbol correctly. See Issue 3885 on trac.osgeo.org
49
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
370 symbol.setFont(symbolElement.getAttribute("font"));
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
371 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue());
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
372 symbol.setAntialias(1);
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
373 symbol.setCharacter("#&" + symbolElement.getAttribute("char") + ";");
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
374 }
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
375
0fecdcc28b1b Created one method for each symbol type in the writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 46
diff changeset
376
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
377 private void writeSimpleLineSymbol(
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
378 symbolObj symbol,
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
379 Element symbolElement) {
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
380 logger.debug("writeSimpleLineSymbol()");
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
381 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_SIMPLE.swigValue());
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
382 String ls = symbolElement.getAttribute("linestyle");
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
383 if(ls.equals("solid")) {
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
384 symbol.setFilled(1);
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
385 }
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
386 }
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
387
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
388
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
389 /**
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
390 * Save the symbol set.
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
391 * @param symbols The symbol set.
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
392 */
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
393 private void saveSymbolSet(symbolSetObj symbols) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
394 Element fileNode = (Element)XMLUtils.xpath(
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
395 root,
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
396 "/mxd/file",
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
397 XPathConstants.NODE);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
398 String path = "";
59
ef1ee8e752b2 Write the symbols-file to the mapfile path.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
399 if(mapFilename.contains("/")) {
ef1ee8e752b2 Write the symbols-file to the mapfile path.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
400 path = mapFilename.substring(0, mapFilename.lastIndexOf("/"));
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
401 }
59
ef1ee8e752b2 Write the symbols-file to the mapfile path.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
402 else if(mapFilename.contains("\\")) {
ef1ee8e752b2 Write the symbols-file to the mapfile path.
Raimund Renkert <rrenkert@intevation.de>
parents: 57
diff changeset
403 path = mapFilename.substring(0, mapFilename.lastIndexOf("\\"));
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
404 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
405 symbols.save(path + "/symbols.sym");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
406 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
407 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
408
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)