Mercurial > mxd2map
annotate src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 124:0f5819732288
Set label text as class name in mapfile.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Fri, 17 Jun 2011 14:13:25 +0200 |
parents | 11d63bf00326 |
children | ff0354265a7d |
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; |
41
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 import de.intevation.mxd.utils.XMLUtils; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
21 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
22 /** |
43
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
23 * The Mapfile Writer. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
24 * 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
|
25 * |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
26 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
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 public class MapScriptWriter |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
29 implements IWriter |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
30 { |
43
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 * The Logger. |
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 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
|
35 |
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 * Private member. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
38 */ |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
39 private Document root; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
40 private mapObj map; |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
41 private String mapFilename; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
42 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
43 public MapScriptWriter() { |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
44 map = new mapObj(""); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
45 mapFilename = ""; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
46 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
47 |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
48 public MapScriptWriter(String templ, String filename) { |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
49 map = new mapObj(templ); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
50 mapFilename = filename; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
51 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
52 |
43
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
53 /** |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
54 * Write the mapfile. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
55 * @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
|
56 * |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
57 * @return Currently always true. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
58 */ |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
102
diff
changeset
|
59 public boolean write(Document doc) { |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
60 logger.debug("write()"); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
61 this.root = doc; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
62 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
63 //Get the filename. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
64 Element fileNode = (Element)XMLUtils.xpath( |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
65 root, |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
66 "/mxd/file", |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
67 XPathConstants.NODE); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
68 //Write the map attributes. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
69 writeMap(); |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
70 //Write the layers. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
71 writeLayer(); |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
72 //Save the map. |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
73 mapObj cloneMap = map.cloneMap(); |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
74 cloneMap.save(mapFilename); |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
102
diff
changeset
|
75 logger.info("Mapfile successfully created."); |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
76 return true; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
77 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
78 |
43
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
79 /** |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
80 * 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
|
81 */ |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
82 private void writeMap() { |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
83 logger.debug("writeMap()"); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
84 //Get the map. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
85 Element mapNode = (Element)XMLUtils.xpath( |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
86 root, |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
87 "/mxd/map", |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
88 XPathConstants.NODE); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
89 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
90 //Set the name. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
91 map.setName(mapNode.getAttribute("name")); |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
92 map.setMetaData("wms_title", mapNode.getAttribute("name")); |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
93 //Set the extent. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
94 map.setExtent( |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
95 Double.parseDouble(mapNode.getAttribute("extent_min_x")), |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
96 Double.parseDouble(mapNode.getAttribute("extent_min_y")), |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
97 Double.parseDouble(mapNode.getAttribute("extent_max_x")), |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
98 Double.parseDouble(mapNode.getAttribute("extent_max_y"))); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
99 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
100 //Set the units. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
101 String units = mapNode.getAttribute("units"); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
102 MS_UNITS msu; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
103 if(units.equals("feet")) { |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
104 msu = MS_UNITS.MS_FEET; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
105 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
106 else if(units.equals("inches")) { |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
107 msu = MS_UNITS.MS_INCHES; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
108 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
109 else if(units.equals("kilometers")) { |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
110 msu = MS_UNITS.MS_KILOMETERS; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
111 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
112 else if(units.equals("meters")) { |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
113 msu = MS_UNITS.MS_METERS; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
114 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
115 else if(units.equals("miles")) { |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
116 msu = MS_UNITS.MS_MILES; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
117 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
118 else if(units.equals("nauticalmiles")) { |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
119 msu = MS_UNITS.MS_NAUTICALMILES; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
120 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
121 else if(units.equals("points")) { |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
122 msu = MS_UNITS.MS_PIXELS; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
123 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
124 else { |
57
8da6555f1c12
Set the projection "EPSG:31467" and units "METERS" as default values.
Raimund Renkert <rrenkert@intevation.de>
parents:
55
diff
changeset
|
125 msu = MS_UNITS.MS_METERS; |
41
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 map.setUnits(msu); |
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 //TODO: Find out whats the correct scale value. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
130 //map.setScaledenom(Double.parseDouble(mapNode.getAttribute("scale"))); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
131 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
132 |
43
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
133 /** |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
134 * 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
|
135 */ |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
102
diff
changeset
|
136 private void writeLayer() { |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
137 logger.debug("writeLayer()"); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
138 Element mapNode = (Element)XMLUtils.xpath( |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
139 root, |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
140 "/mxd/map", |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
141 XPathConstants.NODE); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
142 NodeList list = mapNode.getElementsByTagName("layer"); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
143 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
|
144 Element layerElement = (Element)list.item(i); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
145 layerObj layer = new layerObj(map); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
146 |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
147 //The layer name. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
148 layer.setName(layerElement.getAttribute("name")); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
149 |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
150 //The layer status. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
151 String stat = layerElement.getAttribute("status"); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
152 if (stat.equals("on")) { |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
153 layer.setStatus(1); |
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 else { |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
156 layer.setStatus(0); |
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 |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
159 //The scale. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
160 double maxScale = |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
161 Double.parseDouble(layerElement.getAttribute("max_scale")); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
162 double minScale = |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
163 Double.parseDouble(layerElement.getAttribute("min_scale")); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
164 layer.setMaxscaledenom(maxScale); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
165 layer.setMinscaledenom(minScale); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
166 |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
167 //The layer type. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
168 String type = layerElement.getAttribute("type"); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
169 if(type.equals("point")) { |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
170 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
|
171 } |
62
e468cf8701ea
Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
59
diff
changeset
|
172 else if (type.equals("line")) { |
e468cf8701ea
Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
59
diff
changeset
|
173 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
|
174 } |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
175 else if (type.equals("polygon")) { |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
176 layer.setType(MS_LAYER_TYPE.MS_LAYER_POLYGON); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
177 } |
102
3ca2ec55fb3b
Set TILEITEM to an empty string.
Raimund Renkert <rrenkert@intevation.de>
parents:
99
diff
changeset
|
178 layer.setTileitem(""); |
42
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 //The layer datasource. |
98
4696d0769f9c
Write the absolute path to the data source of the layer.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
181 String datasource = ""; |
4696d0769f9c
Write the absolute path to the data source of the layer.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
182 if(layerElement.hasAttribute("workspace")) { |
4696d0769f9c
Write the absolute path to the data source of the layer.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
183 datasource = layerElement.getAttribute("workspace"); |
4696d0769f9c
Write the absolute path to the data source of the layer.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
184 datasource += File.separator; |
4696d0769f9c
Write the absolute path to the data source of the layer.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
185 } |
4696d0769f9c
Write the absolute path to the data source of the layer.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
186 datasource += layerElement.getAttribute("data_source"); |
4696d0769f9c
Write the absolute path to the data source of the layer.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
187 layer.setData(datasource); |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
188 |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
189 //Write classes. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
190 writeClass(layer, layerElement); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
191 } |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
192 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
193 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
194 |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
195 /** |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
196 * Adds the classes to the layer. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
197 * @param layer Mapscript layer object. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
198 * @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
|
199 */ |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
102
diff
changeset
|
200 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
|
201 logger.debug("writeClass(layerObj, Element)"); |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
202 //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
|
203 //mapfile.) |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
204 NodeList list = layerElement.getElementsByTagName("renderer"); |
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 //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
|
207 //each class. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
208 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
|
209 Element classElement = (Element)list.item(i); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
210 classObj co = new classObj(layer); |
124
0f5819732288
Set label text as class name in mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
211 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
|
212 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
|
213 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
|
214 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
|
215 name += "-" + i; |
d6d2a4058ebf
Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents:
98
diff
changeset
|
216 } |
d6d2a4058ebf
Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents:
98
diff
changeset
|
217 } |
d6d2a4058ebf
Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents:
98
diff
changeset
|
218 co.setName (name); |
44
9b5fb5e5914d
Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
219 if(classElement.hasAttribute("field_count")) { |
9b5fb5e5914d
Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
220 int count = |
9b5fb5e5914d
Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
221 Integer.parseInt(classElement.getAttribute("field_count")); |
9b5fb5e5914d
Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
222 String exp = ""; |
9b5fb5e5914d
Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
223 for(int j = 0; j < count; j++) { |
9b5fb5e5914d
Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
224 //TODO Find a way to create Expressions. |
9b5fb5e5914d
Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
225 exp = "([" + classElement.getAttribute("expression_field_" + j); |
46
34a93dad7604
Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents:
44
diff
changeset
|
226 exp += "] " + classElement.getAttribute("expression_operator"); |
34a93dad7604
Added MultiLayerMarkerSymbol(ArrowMarkerSymbol) support.
Raimund Renkert <rrenkert@intevation.de>
parents:
44
diff
changeset
|
227 exp += " " + classElement.getAttribute("value") + ")"; |
44
9b5fb5e5914d
Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
228 } |
9b5fb5e5914d
Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
229 co.setExpression(exp); |
9b5fb5e5914d
Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
230 } |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
231 //Write symbols and styles. |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
232 NodeList l = classElement.getChildNodes(); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
233 for (int j = 0; j < l.getLength(); j++) { |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
234 Element elem = (Element)l.item(j); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
235 |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
236 String type = layerElement.getAttribute("type"); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
237 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
|
238 MarkerStyleWriter swriter = new MarkerStyleWriter (this.map, co); |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
239 swriter.write (elem); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
62
diff
changeset
|
240 } |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
241 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
|
242 LineStyleWriter swriter = new LineStyleWriter (this.map, co); |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
243 swriter.write (elem); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
244 } |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
245 else if(type.equals("polygon") && elem.getTagName().equals("symbol")) { |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
246 FillStyleWriter swriter = new FillStyleWriter (this.map, co); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
247 swriter.write (elem); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
62
diff
changeset
|
248 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
62
diff
changeset
|
249 } |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
250 } |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
251 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
252 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
253 |