annotate src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 96:c285ed08b72c

Removed needless imports.
author Raimund Renkert <rrenkert@intevation.de>
date Wed, 01 Jun 2011 14:21:24 +0200
parents 1ae8e05b863f
children 18e4f143896b
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;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 import edu.umn.gis.mapscript.mapObj;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 import edu.umn.gis.mapscript.layerObj;
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
13 import edu.umn.gis.mapscript.classObj;
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
14
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15 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
16 import edu.umn.gis.mapscript.MS_LAYER_TYPE;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
18 import de.intevation.mxd.utils.XMLUtils;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
19
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 /**
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
21 * The Mapfile Writer.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
22 * 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
23 *
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
24 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
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 public class MapScriptWriter
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27 implements IWriter
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 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
30 * The Logger.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
31 */
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
32 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
33
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 member.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
36 */
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 private Document root;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 private mapObj map;
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
39 private String mapFilename;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
40
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
41 public MapScriptWriter() {
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
42 map = new mapObj("");
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
43 mapFilename = "";
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
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
46 public MapScriptWriter(String templ, String filename) {
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
47 map = new mapObj(templ);
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
48 mapFilename = filename;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
51 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
52 * Write the mapfile.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
53 * @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
54 *
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
55 * @return Currently always true.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
56 */
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
57 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
58 throws Exception {
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 logger.debug("write()");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 this.root = doc;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 //Get the filename.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 Element fileNode = (Element)XMLUtils.xpath(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64 root,
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 "/mxd/file",
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 XPathConstants.NODE);
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67 //Write the map attributes.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 writeMap();
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
69 //Write the layers.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
70 writeLayer();
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71 //Save the map.
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
72 mapObj cloneMap = map.cloneMap();
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
73 cloneMap.save(mapFilename);
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 return true;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
77 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
78 * 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
79 */
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80 private void writeMap() {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
81 logger.debug("writeMap()");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 //Get the map.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
83 Element mapNode = (Element)XMLUtils.xpath(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84 root,
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 "/mxd/map",
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
86 XPathConstants.NODE);
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
88 //Set the name.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 map.setName(mapNode.getAttribute("name"));
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
90 map.setMetaData("wms_title", mapNode.getAttribute("name"));
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
91 //Set the extent.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
92 map.setExtent(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
93 Double.parseDouble(mapNode.getAttribute("extent_min_x")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
94 Double.parseDouble(mapNode.getAttribute("extent_min_y")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
95 Double.parseDouble(mapNode.getAttribute("extent_max_x")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
96 Double.parseDouble(mapNode.getAttribute("extent_max_y")));
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
97
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
98 //Set the units.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
99 String units = mapNode.getAttribute("units");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
100 MS_UNITS msu;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
101 if(units.equals("feet")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
102 msu = MS_UNITS.MS_FEET;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
103 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
104 else if(units.equals("inches")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
105 msu = MS_UNITS.MS_INCHES;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
106 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
107 else if(units.equals("kilometers")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
108 msu = MS_UNITS.MS_KILOMETERS;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
109 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
110 else if(units.equals("meters")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
111 msu = MS_UNITS.MS_METERS;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
112 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
113 else if(units.equals("miles")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
114 msu = MS_UNITS.MS_MILES;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
115 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
116 else if(units.equals("nauticalmiles")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
117 msu = MS_UNITS.MS_NAUTICALMILES;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
118 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
119 else if(units.equals("points")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
120 msu = MS_UNITS.MS_PIXELS;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
121 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
122 else {
57
8da6555f1c12 Set the projection "EPSG:31467" and units "METERS" as default values.
Raimund Renkert <rrenkert@intevation.de>
parents: 55
diff changeset
123 msu = MS_UNITS.MS_METERS;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
124 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
125 map.setUnits(msu);
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 //TODO: Find out whats the correct scale value.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
128 //map.setScaledenom(Double.parseDouble(mapNode.getAttribute("scale")));
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
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
131 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
132 * 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
133 */
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
134 private void writeLayer()
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
135 throws Exception {
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
136 logger.debug("writeLayer()");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
137 Element mapNode = (Element)XMLUtils.xpath(
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
138 root,
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
139 "/mxd/map",
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
140 XPathConstants.NODE);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
141 NodeList list = mapNode.getElementsByTagName("layer");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
142 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
143 Element layerElement = (Element)list.item(i);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
144 layerObj layer = new layerObj(map);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
145
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
146 //The layer name.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
147 layer.setName(layerElement.getAttribute("name"));
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 status.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
150 String stat = layerElement.getAttribute("status");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
151 if (stat.equals("on")) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
152 layer.setStatus(1);
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 else {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
155 layer.setStatus(0);
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
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
158 //The scale.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
159 double maxScale =
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
160 Double.parseDouble(layerElement.getAttribute("max_scale"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
161 double minScale =
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
162 Double.parseDouble(layerElement.getAttribute("min_scale"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
163 layer.setMaxscaledenom(maxScale);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
164 layer.setMinscaledenom(minScale);
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 layer type.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
167 String type = layerElement.getAttribute("type");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
168 if(type.equals("point")) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
169 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
170 }
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
171 else if (type.equals("line")) {
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
172 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
173 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
174
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
175 //The layer datasource.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
176 layer.setData(layerElement.getAttribute("data_source"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
177
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
178 //Write classes.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
179 writeClass(layer, layerElement);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
180 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
181
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
182 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
183
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 * Adds the classes to the layer.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
186 * @param layer Mapscript layer object.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
187 * @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
188 */
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
189 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
190 throws Exception {
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
191 logger.debug("writeClass(layerObj, Element)");
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
192 //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
193 //mapfile.)
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
194 NodeList list = layerElement.getElementsByTagName("renderer");
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
195
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
196 //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
197 //each class.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
198 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
199 Element classElement = (Element)list.item(i);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
200 classObj co = new classObj(layer);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
201 co.setName(classElement.getAttribute("name"));
44
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
202 if(classElement.hasAttribute("field_count")) {
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
203 int count =
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
204 Integer.parseInt(classElement.getAttribute("field_count"));
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
205 String exp = "";
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
206 for(int j = 0; j < count; j++) {
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
207 //TODO Find a way to create Expressions.
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
208 exp = "([" + classElement.getAttribute("expression_field_" + j);
46
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
209 exp += "] " + classElement.getAttribute("expression_operator");
34a93dad7604 Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents: 44
diff changeset
210 exp += " " + classElement.getAttribute("value") + ")";
44
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
211 }
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
212 co.setExpression(exp);
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
213 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
214 //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
215 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
216 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
217 if(type.equals("point")) {
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
218 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
219 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
220 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
221 swriter.write (symbolElement);
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
222 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
223 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
224 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
225 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
226 Element symbolElement = (Element) slist.item(j);
95
1ae8e05b863f Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents: 91
diff changeset
227 LineStyleWriter swriter = new LineStyleWriter (this.map, co);
1ae8e05b863f Use the line style writer to write simple lines and marker lines.
Raimund Renkert <rrenkert@intevation.de>
parents: 91
diff changeset
228 swriter.write (symbolElement);
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
229 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
230 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
231 }
41
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 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
234
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)