annotate src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 132:02df1dbc2166

Remove all whitespaces in layer name.
author vc11884admin@VC11884.win.bsh.de
date Mon, 20 Jun 2011 17:54:09 +0200
parents 5991c1f90f91
children acc9e5430177
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
98
4696d0769f9c Write the absolute path to the data source of the layer.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
9 import java.io.File;
4696d0769f9c Write the absolute path to the data source of the layer.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
10
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 import javax.xml.xpath.XPathConstants;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 import edu.umn.gis.mapscript.mapObj;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 import edu.umn.gis.mapscript.layerObj;
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
15 import edu.umn.gis.mapscript.classObj;
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
16
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17 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
18 import edu.umn.gis.mapscript.MS_LAYER_TYPE;
130
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
19 import edu.umn.gis.mapscript.MS_CONNECTION_TYPE;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21 import de.intevation.mxd.utils.XMLUtils;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23 /**
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
24 * The Mapfile Writer.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
25 * 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
26 *
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 */
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 public class MapScriptWriter
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 implements IWriter
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 {
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
32 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
33 * The Logger.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
34 */
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
35 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
36
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 * Private member.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
39 */
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40 private Document root;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 private mapObj map;
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
42 private String mapFilename;
130
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
43 private String MS_BINDIR = "c:/ms_6.1-dev/bin";
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 public MapScriptWriter() {
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
46 map = new mapObj("");
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
47 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
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
50 public MapScriptWriter(String templ, String filename) {
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
51 map = new mapObj(templ);
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
52 mapFilename = filename;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
55 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
56 * Write the mapfile.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
57 * @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
58 *
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
59 * @return Currently always true.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
60 */
120
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 102
diff changeset
61 public boolean write(Document doc) {
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 logger.debug("write()");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 this.root = doc;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 //Get the filename.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 Element fileNode = (Element)XMLUtils.xpath(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 root,
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 "/mxd/file",
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 XPathConstants.NODE);
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 //Write the map attributes.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 writeMap();
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
72 //Write the layers.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
73 writeLayer();
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 //Save the map.
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
75 mapObj cloneMap = map.cloneMap();
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
76 cloneMap.save(mapFilename);
120
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 102
diff changeset
77 logger.info("Mapfile successfully created.");
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 return true;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
81 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
82 * 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
83 */
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84 private void writeMap() {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 logger.debug("writeMap()");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
86 //Get the map.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87 Element mapNode = (Element)XMLUtils.xpath(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
88 root,
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 "/mxd/map",
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
90 XPathConstants.NODE);
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
91
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
92 //Set the name.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
93 map.setName(mapNode.getAttribute("name"));
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
94 map.setMetaData("wms_title", mapNode.getAttribute("name"));
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
95 //Set the extent.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
96 map.setExtent(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
97 Double.parseDouble(mapNode.getAttribute("extent_min_x")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
98 Double.parseDouble(mapNode.getAttribute("extent_min_y")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
99 Double.parseDouble(mapNode.getAttribute("extent_max_x")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
100 Double.parseDouble(mapNode.getAttribute("extent_max_y")));
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
101
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
102 //Set the units.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
103 String units = mapNode.getAttribute("units");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
104 MS_UNITS msu;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
105 if(units.equals("feet")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
106 msu = MS_UNITS.MS_FEET;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
107 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
108 else if(units.equals("inches")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
109 msu = MS_UNITS.MS_INCHES;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
110 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
111 else if(units.equals("kilometers")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
112 msu = MS_UNITS.MS_KILOMETERS;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
113 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
114 else if(units.equals("meters")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
115 msu = MS_UNITS.MS_METERS;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
116 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
117 else if(units.equals("miles")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
118 msu = MS_UNITS.MS_MILES;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
119 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
120 else if(units.equals("nauticalmiles")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
121 msu = MS_UNITS.MS_NAUTICALMILES;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
122 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
123 else if(units.equals("points")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
124 msu = MS_UNITS.MS_PIXELS;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
125 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
126 else {
57
8da6555f1c12 Set the projection "EPSG:31467" and units "METERS" as default values.
Raimund Renkert <rrenkert@intevation.de>
parents: 55
diff changeset
127 msu = MS_UNITS.MS_METERS;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
128 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
129 map.setUnits(msu);
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
130
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
131 //TODO: Find out whats the correct scale value.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
132 //map.setScaledenom(Double.parseDouble(mapNode.getAttribute("scale")));
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
133 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
134
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
135 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
136 * 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
137 */
120
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 102
diff changeset
138 private void writeLayer() {
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
139 logger.debug("writeLayer()");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
140 Element mapNode = (Element)XMLUtils.xpath(
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
141 root,
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
142 "/mxd/map",
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
143 XPathConstants.NODE);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
144 NodeList list = mapNode.getElementsByTagName("layer");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
145 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
146 Element layerElement = (Element)list.item(i);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
147 layerObj layer = new layerObj(map);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
148
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
149 //The layer name.
132
02df1dbc2166 Remove all whitespaces in layer name.
vc11884admin@VC11884.win.bsh.de
parents: 130
diff changeset
150 String lname = layerElement.getAttribute("name");
02df1dbc2166 Remove all whitespaces in layer name.
vc11884admin@VC11884.win.bsh.de
parents: 130
diff changeset
151 lname = lname.replaceAll(" ", "");
02df1dbc2166 Remove all whitespaces in layer name.
vc11884admin@VC11884.win.bsh.de
parents: 130
diff changeset
152 layer.setName(lname);
128
1616622a8c8d Insert metadata for layer title for getCapabilities request.
Raimund Renkert <rrenkert@intevation.de>
parents: 127
diff changeset
153 layer.setMetaData("wms_title", layerElement.getAttribute("name"));
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
154
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
155 //The layer status.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
156 String stat = layerElement.getAttribute("status");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
157 if (stat.equals("on")) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
158 layer.setStatus(1);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
159 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
160 else {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
161 layer.setStatus(0);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
162 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
163
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
164 //The scale.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
165 double maxScale =
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
166 Double.parseDouble(layerElement.getAttribute("max_scale"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
167 double minScale =
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
168 Double.parseDouble(layerElement.getAttribute("min_scale"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
169 layer.setMaxscaledenom(maxScale);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
170 layer.setMinscaledenom(minScale);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
171
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
172 //The layer type.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
173 String type = layerElement.getAttribute("type");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
174 if(type.equals("point")) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
175 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
176 }
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
177 else if (type.equals("line")) {
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
178 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
179 }
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
180 else if (type.equals("polygon")) {
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
181 layer.setType(MS_LAYER_TYPE.MS_LAYER_POLYGON);
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
182 }
102
3ca2ec55fb3b Set TILEITEM to an empty string.
Raimund Renkert <rrenkert@intevation.de>
parents: 99
diff changeset
183 layer.setTileitem("");
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
184
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
185 //The layer datasource.
130
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
186 String con_type = layerElement.getAttribute("connection_type");
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
187 if(con_type.equals("local")) {
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
188 String datasource = "";
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
189 if(layerElement.hasAttribute("workspace")) {
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
190 datasource = layerElement.getAttribute("workspace");
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
191 datasource += File.separator;
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
192 }
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
193 datasource += layerElement.getAttribute("data_source");
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
194 layer.setData(datasource);
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
195 }
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
196 else if(con_type.equals("SDE")) {
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
197 logger.info(
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
198 "SDE datasource found." +
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
199 " Please edit password in mapfile.");
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
200 layer.setConnectionType(
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
201 MS_CONNECTION_TYPE.MS_PLUGIN.swigValue(),
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
202 MS_BINDIR + "/ms/plugins/msplugin_sde_93.dll");
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
203 layer.setConnection(
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
204 layerElement.getAttribute("server") + "," +
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
205 "port:" + layerElement.getAttribute("instance") + "," +
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
206 layerElement.getAttribute("database") + "," +
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
207 layerElement.getAttribute("user") + ",<PASSWORD>");
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
208 layer.setData(
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
209 layerElement.getAttribute("data_source") +
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
210 ",SHAPE," +
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
211 layerElement.getAttribute("version"));
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
212 layer.setProcessing("CLOSE_CONNECTION=defer");
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
213 layer.setProcessing("ATTRIBUTE_QUALIFIED=TRUE");
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
214 layer.setProcessing(
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
215 "JOINTABLE=" +
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
216 layerElement.getAttribute("join_table"));
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
217 layer.setFilter(
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
218 "where " +
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
219 layerElement.getAttribute("definition_query") +
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
220 " AND " +
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
221 layerElement.getAttribute("join_table_target") + "." +
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
222 layerElement.getAttribute("join_field_target") + "=" +
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
223 layerElement.getAttribute("join_table") + "." +
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
224 layerElement.getAttribute("join_field"));
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
225
130
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
226 }
129
0b119169618f Insert TEMPLATE entry for GFI request.
Raimund Renkert <rrenkert@intevation.de>
parents: 128
diff changeset
227 layer.setTemplate("PleaseInsertAValidTemplateForGFI");
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
228 //Write classes.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
229 writeClass(layer, layerElement);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
230 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
231
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
232 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
233
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
234 /**
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
235 * Adds the classes to the layer.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
236 * @param layer Mapscript layer object.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
237 * @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
238 */
120
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 102
diff changeset
239 private void writeClass(layerObj layer, Element layerElement) {
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
240 logger.debug("writeClass(layerObj, Element)");
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
241 //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
242 //mapfile.)
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
243 NodeList list = layerElement.getElementsByTagName("renderer");
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
244
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
245 //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
246 //each class.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
247 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
248 Element classElement = (Element)list.item(i);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
249 classObj co = new classObj(layer);
124
0f5819732288 Set label text as class name in mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 120
diff changeset
250 String name = classElement.getAttribute("label");
99
d6d2a4058ebf Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents: 98
diff changeset
251 if (name.equals("")) {
d6d2a4058ebf Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents: 98
diff changeset
252 name = layerElement.getAttribute("name");
d6d2a4058ebf Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents: 98
diff changeset
253 if (list.getLength() > 1) {
d6d2a4058ebf Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents: 98
diff changeset
254 name += "-" + i;
d6d2a4058ebf Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents: 98
diff changeset
255 }
d6d2a4058ebf Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents: 98
diff changeset
256 }
d6d2a4058ebf Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents: 98
diff changeset
257 co.setName (name);
44
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
258 if(classElement.hasAttribute("field_count")) {
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
259 int count =
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
260 Integer.parseInt(classElement.getAttribute("field_count"));
126
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
261 int type = 0;
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
262 try {
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
263 Double.parseDouble(classElement.getAttribute("value"));
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
264 type = 1;
44
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
265 }
126
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
266 catch(Exception e) {
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
267 type = 2;
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
268 }
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
269 if (type == 1) {
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
270 co.setExpression(createDoubleExpression(classElement, count));
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
271 }
127
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
272 else if (type == 2) {
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
273 co.setExpression(createStringExpression(classElement, count));
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
274 }
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
275
44
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
276 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
277 //Write symbols and styles.
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
278 NodeList l = classElement.getChildNodes();
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
279 for (int j = 0; j < l.getLength(); j++) {
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
280 Element elem = (Element)l.item(j);
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
281
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
282 String type = layerElement.getAttribute("type");
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
283 if(type.equals("point") && elem.getTagName().equals("symbol")) {
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
284 MarkerStyleWriter swriter = new MarkerStyleWriter (this.map, co);
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
285 swriter.write (elem);
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
286 }
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
287 else if(type.equals("line") && elem.getTagName().equals("symbol")) {
95
1ae8e05b863f Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents: 91
diff changeset
288 LineStyleWriter swriter = new LineStyleWriter (this.map, co);
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
289 swriter.write (elem);
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
290 }
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
291 else if(type.equals("polygon") && elem.getTagName().equals("symbol")) {
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
292 FillStyleWriter swriter = new FillStyleWriter (this.map, co);
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
293 swriter.write (elem);
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
294 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
295 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
296 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
297 }
126
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
298
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
299 private String createDoubleExpression (Element classElement, int count) {
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
300 String exp = "";
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
301 String op = classElement.getAttribute("expression_operator");
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
302 String op1 = "";
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
303 String op2 = "";
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
304 if (op.equals("<=")) {
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
305 op1 = ">=";
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
306 op2 = op;
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
307 for(int j = 0; j < count; j++) {
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
308 if (classElement.getAttribute("min_value").equals(
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
309 classElement.getAttribute("value"))) {
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
310 exp = "([" +
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
311 classElement.getAttribute(
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
312 "expression_field_" + j) +
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
313 "] == " +
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
314 classElement.getAttribute("value") +
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
315 ")";
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
316 }
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
317 else {
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
318 exp = "([";
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
319 exp += classElement.getAttribute(
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
320 "expression_field_" + j);
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
321 exp += "] " + op1;
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
322 exp += " " + classElement.getAttribute("min_value");
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
323 exp += " AND [" + classElement.getAttribute(
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
324 "expression_field_" + j);
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
325 exp += "] " + op2 + " ";
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
326 exp += classElement.getAttribute("value");
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
327 exp += ")";
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
328 }
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
329 }
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
330 }
127
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
331 else if (op.equals("=")) {
126
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
332 op1 = op;
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
333 for(int j = 0; j < count; j++) {
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
334 exp = "([" +
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
335 classElement.getAttribute("expression_field_" + j) +
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
336 "] == " +
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
337 classElement.getAttribute("value") + ")";
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
338 }
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
339 }
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
340 return exp;
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
341 }
127
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
342
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
343 private String createStringExpression (Element classElement, int count) {
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
344 String exp = "";
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
345 String op = classElement.getAttribute("expression_operator");
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
346 if (op.equals("=")) {
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
347 for(int j = 0; j < count; j++) {
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
348 exp = "(\"[";
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
349 exp += classElement.getAttribute(
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
350 "expression_field_" + j);
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
351 exp += "]\" " + op;
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
352 exp += " \"" + classElement.getAttribute("value");
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
353 exp += "\")";
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
354 }
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
355 }
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
356 return exp;
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
357 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
358 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
359
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)