comparison src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 41:60ed2164035a

Introduced MapScript writer.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 14 Apr 2011 11:31:29 +0200
parents
children 395307e8b7ee
comparison
equal deleted inserted replaced
40:a1bc7220efe7 41:60ed2164035a
1 package de.intevation.mxd.writer;
2
3 import org.apache.log4j.Logger;
4
5 import org.w3c.dom.Document;
6 import org.w3c.dom.Element;
7 import org.w3c.dom.Node;
8 import org.w3c.dom.NodeList;
9 import javax.xml.xpath.XPathConstants;
10
11 import edu.umn.gis.mapscript.mapObj;
12 import edu.umn.gis.mapscript.layerObj;
13 import edu.umn.gis.mapscript.MS_UNITS;
14
15 import de.intevation.mxd.utils.XMLUtils;
16
17 /**
18 * The MXD file reader.
19 *
20 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
21 */
22 public class MapScriptWriter
23 implements IWriter
24 {
25 private Document root;
26 private mapObj map;
27
28 private static final Logger logger = Logger.getLogger(MapScriptWriter.class);
29
30 public MapScriptWriter() {
31 map = new mapObj("");
32 }
33
34 public MapScriptWriter(String path) {
35 map = new mapObj(path);
36 }
37
38 public boolean write(Document doc) {
39 logger.debug("write()");
40 this.root = doc;
41
42 //Get the filename.
43 Element fileNode = (Element)XMLUtils.xpath(
44 root,
45 "/mxd/file",
46 XPathConstants.NODE);
47 String filename = fileNode.getAttribute("name");
48 if(filename.endsWith(".mxd")) {
49 filename = filename.replace(".mxd", ".map");
50 }
51 //Write the map attributes.
52 writeMap();
53
54 //Save the map.
55 map.save(filename);
56 return true;
57 }
58
59 private void writeMap() {
60 logger.debug("writeMap()");
61 //Get the map.
62 Element mapNode = (Element)XMLUtils.xpath(
63 root,
64 "/mxd/map",
65 XPathConstants.NODE);
66
67 //Set the name.
68 map.setName(mapNode.getAttribute("name"));
69
70 //Set the extent.
71 map.setExtent(
72 Double.parseDouble(mapNode.getAttribute("extent_min_x")),
73 Double.parseDouble(mapNode.getAttribute("extent_min_y")),
74 Double.parseDouble(mapNode.getAttribute("extent_max_x")),
75 Double.parseDouble(mapNode.getAttribute("extent_max_y")));
76
77 //Set the units.
78 String units = mapNode.getAttribute("units");
79 MS_UNITS msu;
80 if(units.equals("feet")) {
81 msu = MS_UNITS.MS_FEET;
82 }
83 else if(units.equals("inches")) {
84 msu = MS_UNITS.MS_INCHES;
85 }
86 else if(units.equals("kilometers")) {
87 msu = MS_UNITS.MS_KILOMETERS;
88 }
89 else if(units.equals("meters")) {
90 msu = MS_UNITS.MS_METERS;
91 }
92 else if(units.equals("miles")) {
93 msu = MS_UNITS.MS_MILES;
94 }
95 else if(units.equals("nauticalmiles")) {
96 msu = MS_UNITS.MS_NAUTICALMILES;
97 }
98 else if(units.equals("points")) {
99 msu = MS_UNITS.MS_PIXELS;
100 }
101 else {
102 msu = MS_UNITS.MS_DD;
103 }
104 map.setUnits(msu);
105
106 //TODO: Find out whats the correct scale value.
107 //map.setScaledenom(Double.parseDouble(mapNode.getAttribute("scale")));
108 }
109
110 private void writeLayer() {
111
112 }
113
114 private void writeClass() {
115
116 }
117
118 private void writeSymbol() {
119
120 }
121
122 }
123
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)