annotate src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 42:395307e8b7ee

First MapScript Writer that generates valid mapfiles.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 15 Apr 2011 14:14:49 +0200
parents 60ed2164035a
children ef7ca23c4233
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 /**
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 * The MXD file reader.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 *
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32 */
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 public class MapScriptWriter
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 implements IWriter
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 private Document root;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 private mapObj map;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
39 private static final Logger logger = Logger.getLogger(MapScriptWriter.class);
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() {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 map = new mapObj("");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 }
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(String path) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
46 map = new mapObj(path);
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47 }
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 boolean write(Document doc) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50 logger.debug("write()");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51 this.root = doc;
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 //Get the filename.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54 Element fileNode = (Element)XMLUtils.xpath(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 root,
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 "/mxd/file",
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 XPathConstants.NODE);
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58 String filename = fileNode.getAttribute("name");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 if(filename.endsWith(".mxd")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 filename = filename.replace(".mxd", ".map");
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 //Write the map attributes.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 writeMap();
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
64 //Write the layers.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
65 writeLayer();
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 //Save the map.
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
67 mapObj cloneMap = map.cloneMap();
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
68 cloneMap.save(filename);
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 return true;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
70 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
71
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 private void writeMap() {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 logger.debug("writeMap()");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
74 //Get the map.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75 Element mapNode = (Element)XMLUtils.xpath(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
76 root,
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
77 "/mxd/map",
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
78 XPathConstants.NODE);
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
79
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
80 //TODO Get the following values from a template.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
81 map.setShapepath("/home/intevation/mxd-testbed/testdata-frida");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
82 map.setHeight(700);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
83 map.setWidth(800);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
84 map.setProjection("EPSG:4326");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
85
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
86 //Set the name.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
87 map.setName(mapNode.getAttribute("name"));
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
88 map.setMetaData("wms_title", mapNode.getAttribute("name"));
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
89 //Set the extent.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
90 map.setExtent(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
91 Double.parseDouble(mapNode.getAttribute("extent_min_x")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
92 Double.parseDouble(mapNode.getAttribute("extent_min_y")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
93 Double.parseDouble(mapNode.getAttribute("extent_max_x")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
94 Double.parseDouble(mapNode.getAttribute("extent_max_y")));
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 units.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
97 String units = mapNode.getAttribute("units");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
98 MS_UNITS msu;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
99 if(units.equals("feet")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
100 msu = MS_UNITS.MS_FEET;
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 else if(units.equals("inches")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
103 msu = MS_UNITS.MS_INCHES;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
104 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
105 else if(units.equals("kilometers")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
106 msu = MS_UNITS.MS_KILOMETERS;
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("meters")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
109 msu = MS_UNITS.MS_METERS;
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("miles")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
112 msu = MS_UNITS.MS_MILES;
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("nauticalmiles")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
115 msu = MS_UNITS.MS_NAUTICALMILES;
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("points")) {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
118 msu = MS_UNITS.MS_PIXELS;
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 {
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
121 msu = MS_UNITS.MS_DD;
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 map.setUnits(msu);
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 //TODO: Find out whats the correct scale value.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
126 //map.setScaledenom(Double.parseDouble(mapNode.getAttribute("scale")));
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
127 }
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 private void writeLayer() {
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
130 logger.debug("writeLayer()");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
131 Element mapNode = (Element)XMLUtils.xpath(
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
132 root,
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
133 "/mxd/map",
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
134 XPathConstants.NODE);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
135 NodeList list = mapNode.getElementsByTagName("layer");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
136 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
137 Element layerElement = (Element)list.item(i);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
138 layerObj layer = new layerObj(map);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
139
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
140 //The layer name.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
141 layer.setName(layerElement.getAttribute("name"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
142
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
143 //The layer status.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
144 String stat = layerElement.getAttribute("status");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
145 if (stat.equals("on")) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
146 layer.setStatus(1);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
147 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
148 else {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
149 layer.setStatus(0);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
150 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
151
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
152 //The scale.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
153 double maxScale =
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
154 Double.parseDouble(layerElement.getAttribute("max_scale"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
155 double minScale =
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
156 Double.parseDouble(layerElement.getAttribute("min_scale"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
157 layer.setMaxscaledenom(maxScale);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
158 layer.setMinscaledenom(minScale);
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 //The layer type.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
161 String type = layerElement.getAttribute("type");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
162 if(type.equals("point")) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
163 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
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 layer datasource.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
167 layer.setData(layerElement.getAttribute("data_source"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
168
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
169 //Write classes.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
170 writeClass(layer, layerElement);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
171 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
172
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
173 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
174
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
175 /**
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
176 * Adds the classes to the layer.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
177 * @param layer Mapscript layer object.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
178 * @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
179 */
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
180 private void writeClass(layerObj layer, Element layerElement) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
181 //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
182 //mapfile.)
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
183 NodeList list = layerElement.getElementsByTagName("renderer");
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
184
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
185 //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
186 //each class.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
187 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
188 Element classElement = (Element)list.item(i);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
189 classObj co = new classObj(layer);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
190 co.setName(classElement.getAttribute("name"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
191 //Write symbols and styles.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
192 writeSymbol(co, classElement);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
193 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
194 }
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 /**
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
197 * Adds teh symbols and styles to the mapfile.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
198 * @param co Mapscript class object.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
199 * @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
200 * attributes.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
201 */
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
202 private void writeSymbol(classObj co, Element classElement) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
203 //Get all symbol elements from dom.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
204 NodeList list = classElement.getElementsByTagName("symbol");
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
205
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
206 //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
207 symbolSetObj symbolSet = map.getSymbolset();
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
208
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
209 //
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
210 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
211 Element symbolElement = (Element) list.item(i);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
212 styleObj style = new styleObj(co);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
213 style.setAngle(
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
214 Double.parseDouble(symbolElement.getAttribute("angle")));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
215 String c = symbolElement.getAttribute("color");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
216 Color col = Color.decode(c);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
217 colorObj color = new colorObj(
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
218 col.getRed(),
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
219 col.getGreen(),
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
220 col.getBlue(),
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
221 -4);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
222 style.setColor(color);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
223 style.setSize(Double.parseDouble(symbolElement.getAttribute("size")));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
224 Color oCol = Color.decode(
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
225 symbolElement.getAttribute("outline_color"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
226 colorObj outlineColor = new colorObj(
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
227 oCol.getRed(),
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
228 oCol.getGreen(),
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
229 oCol.getBlue(),
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
230 -4);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
231 style.setOutlinecolor(outlineColor);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
232 style.setOutlinewidth(
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
233 Double.parseDouble(symbolElement.getAttribute("outline_size")));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
234 style.setSymbolByName(map, symbolElement.getAttribute("name"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
235
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
236 symbolObj sym = symbolSet.getSymbolByName(symbolElement.getAttribute("name"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
237 String symType = symbolElement.getAttribute("style");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
238 if(symType.equals("point")) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
239 lineObj points = new lineObj();
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
240 points.add(new pointObj(1,1,0));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
241 sym.setType(MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue());
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
242 sym.setPoints(points);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
243 sym.setFilled(1);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
244 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
245 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
246 saveSymbolSet(symbolSet);
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
247 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
248
42
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 * Save the symbol set.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
251 * @param
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
252 */
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
253 private void saveSymbolSet(symbolSetObj symbols) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
254 Element fileNode = (Element)XMLUtils.xpath(
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
255 root,
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
256 "/mxd/file",
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
257 XPathConstants.NODE);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
258 String filename = fileNode.getAttribute("name");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
259 String path = "";
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
260 if(filename.contains("/")) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
261 path = filename.substring(0, filename.lastIndexOf("/"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
262 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
263 else if(filename.contains("\\")) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
264 path = filename.substring(0, filename.lastIndexOf("\\"));
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
265 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
266 symbols.save(path + "/symbols.sym");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
267 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
268 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
269
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)