annotate src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 339:ef1cac2854e3

* src/java/de/intevation/mxd/writer/MapScriptWriter.java: Use Relative Paths in Mapfile
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 08 Nov 2012 12:46:16 +0100
parents b3048df06b66
children dbfcb0b69a63
rev   line source
243
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
1 /*
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
2 * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de>
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
3 *
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
4 * This file is part of MXD2map.
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
5 *
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
6 * This program is free software under the LGPL (>=v2.1)
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
7 * Read the file LICENCE.txt coming with the software for details
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
8 * or visit http://www.gnu.org/licenses/ if it does not exist.
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
9 *
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
10 * MXD2map has been developed on behalf of the
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
11 * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
12 * by Intevation GmbH.
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
13 *
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
14 * Authors:
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
15 * Raimund Renkert <raimund.renkert@intevation.de>
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
16 * Bjoern Schilberg <bjoern.schilberg@intevation.de>
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
17 * Stephan Holl <stephan.holl@intevation.de>
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
18 */
df4e0946ef02 Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents: 239
diff changeset
19
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 package de.intevation.mxd.writer;
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 import org.apache.log4j.Logger;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
24 import java.awt.Color;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
25
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 import org.w3c.dom.Document;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27 import org.w3c.dom.Element;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 import org.w3c.dom.NodeList;
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
29
98
4696d0769f9c Write the absolute path to the data source of the layer.
Raimund Renkert <rrenkert@intevation.de>
parents: 97
diff changeset
30 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
31
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32 import javax.xml.xpath.XPathConstants;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 import edu.umn.gis.mapscript.mapObj;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 import edu.umn.gis.mapscript.layerObj;
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
36 import edu.umn.gis.mapscript.classObj;
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
37 import edu.umn.gis.mapscript.labelObj;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
38 import edu.umn.gis.mapscript.colorObj;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
39 import edu.umn.gis.mapscript.fontSetObj;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
40 import edu.umn.gis.mapscript.hashTableObj;
315
1d77ea6a915d Add basic support for Graphics Layers. For now this is restricted
Andre Heinecke <aheinecke@intevation.de>
parents: 314
diff changeset
41 import edu.umn.gis.mapscript.shapeObj;
1d77ea6a915d Add basic support for Graphics Layers. For now this is restricted
Andre Heinecke <aheinecke@intevation.de>
parents: 314
diff changeset
42 import edu.umn.gis.mapscript.pointObj;
1d77ea6a915d Add basic support for Graphics Layers. For now this is restricted
Andre Heinecke <aheinecke@intevation.de>
parents: 314
diff changeset
43 import edu.umn.gis.mapscript.lineObj;
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
44
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 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
46 import edu.umn.gis.mapscript.MS_LAYER_TYPE;
130
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
47 import edu.umn.gis.mapscript.MS_CONNECTION_TYPE;
315
1d77ea6a915d Add basic support for Graphics Layers. For now this is restricted
Andre Heinecke <aheinecke@intevation.de>
parents: 314
diff changeset
48 import edu.umn.gis.mapscript.MS_SHAPE_TYPE;
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
49 import edu.umn.gis.mapscript.MS_FONT_TYPE;
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
50 import edu.umn.gis.mapscript.MS_POSITIONS_ENUM;
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 import de.intevation.mxd.utils.XMLUtils;
259
8fe9ccc77962 Introduced a MapScript helper class and improved metadata handling.
raimund renkert <raimund.renkert@intevation.de>
parents: 258
diff changeset
53 import de.intevation.mxd.utils.MapScriptUtils;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 /**
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
56 * The Mapfile Writer.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
57 * 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
58 *
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60 */
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
61 public class MapScriptWriter
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
62 implements IWriter
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
63 {
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
64 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
65 * The Logger.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
66 */
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
67 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
68
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
69 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
70 * Private member.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
71 */
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 private Document root;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
73 private mapObj map;
259
8fe9ccc77962 Introduced a MapScript helper class and improved metadata handling.
raimund renkert <raimund.renkert@intevation.de>
parents: 258
diff changeset
74 private MapScriptUtils msutils;
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
75 private String mapFilename;
324
5e7e6d99f997 Make mapserver install location version independent
Andre Heinecke <aheinecke@intevation.de>
parents: 322
diff changeset
76 private String MS_BINDIR = "c:/mapserver/bin";
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
77 private String prefix = "";
339
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
78 private boolean useRelativePaths = true;
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
79 private MS_UNITS units = MS_UNITS.MS_METERS;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
81 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
82 * Default constructor.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
83 * Creates a mapscript writer object with an empty map.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
84 */
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85 public MapScriptWriter() {
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
86 map = new mapObj("");
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
87 msutils = new MapScriptUtils();
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
88 mapFilename = "";
41
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
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
91 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
92 * Contructor with template and output filename.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
93 * Creates a mapscript writer object with the given template that saves the
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
94 * map to the filename.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
95 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
96 * @param templ Mapfile template.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
97 * @param filename Output file name.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
98 */
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
99 public MapScriptWriter(String templ, String filename) {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
100 String path = System.getProperty("user.dir");
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
101 map = new mapObj(templ);
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
102 msutils = new MapScriptUtils();
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
103 File f = new File(filename);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
104 mapFilename = filename;
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
105 if(f.isAbsolute()) {
174
707f13cfba74 Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents: 172
diff changeset
106 map.setMappath(mapFilename);
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
107 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
108 else {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
109 map.setMappath(
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
110 System.getProperty("user.dir") +
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
111 File.separator +
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
112 mapFilename);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
113 mapFilename = System.getProperty("user.dir") +
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
114 File.separator +
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
115 mapFilename;
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
116 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
117 String fontSetPath = map.getFontset().getFilename();
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
118 File fonts = new File(fontSetPath);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
119 String fontSet = fonts.getAbsolutePath();
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
120 fontSet = fontSet.replaceAll("\\\\", "/");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
121 map.setFontSet(fontSet);
41
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
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
124 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
125 * Write the mapfile.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
126 * @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
127 *
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
128 * @return Currently always true.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
129 */
120
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 102
diff changeset
130 public boolean write(Document doc) {
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
131 logger.debug("write()");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
132 this.root = doc;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
133
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
134 //Get the filename.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
135 Element fileNode = (Element)XMLUtils.xpath(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
136 root,
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
137 "/mxd/file",
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
138 XPathConstants.NODE);
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
139 //Write the map attributes.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
140 writeMap();
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
141 //Write the layers.
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
142 boolean ret = writeLayer();
339
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
143
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
144 // Replace the filenames if necessary
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
145 if (useRelativePaths) {
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
146 try {
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
147 map.setFontSet(pathForMapfile(map.getFontset().getFilename()));
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
148 } catch (Exception e) {
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
149 // Exception is expected because our working dir is not
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
150 // necessarily the same as the one of the Mapfile
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
151 }
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
152 try {
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
153 map.setSymbolSet(pathForMapfile(map.getSymbolset().getFilename()));
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
154 } catch (Exception e) {
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
155 }
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
156
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
157 }
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
158
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
159 //Save the map.
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
160 if (ret) {
196
5350621a0294 Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents: 190
diff changeset
161 mapObj cloneMap = map.cloneMap();
5350621a0294 Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents: 190
diff changeset
162 cloneMap.save(mapFilename);
5350621a0294 Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents: 190
diff changeset
163 logger.info("Mapfile created: " + mapFilename);
5350621a0294 Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents: 190
diff changeset
164 return true;
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
165 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
166 return false;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
167 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
168
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
169 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
170 * 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
171 */
297
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
172 private void writeMap()
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
173 throws UnknownError
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
174 {
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
175 logger.debug("writeMap()");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
176 //Get the map.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
177 Element mapNode = (Element)XMLUtils.xpath(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
178 root,
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
179 "/mxd/map",
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
180 XPathConstants.NODE);
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 //Set the name.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
183 map.setName(mapNode.getAttribute("name"));
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
184 map.setMetaData("wms_title", mapNode.getAttribute("name"));
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
185 //Set the extent.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
186 map.setExtent(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
187 Double.parseDouble(mapNode.getAttribute("extent_min_x")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
188 Double.parseDouble(mapNode.getAttribute("extent_min_y")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
189 Double.parseDouble(mapNode.getAttribute("extent_max_x")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
190 Double.parseDouble(mapNode.getAttribute("extent_max_y")));
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
191
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
192 map.setMetaData(
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
193 "ows_extent",
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
194 mapNode.getAttribute("extent_min_x") + ", " +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
195 mapNode.getAttribute("extent_min_y") + ", " +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
196 mapNode.getAttribute("extent_max_x") + ", " +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
197 mapNode.getAttribute("extent_max_y"));
246
87e92debc53f Added extent and projection as ows metadata to the mapfile.
raimund renkert <raimund.renkert@intevation.de>
parents: 245
diff changeset
198
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
199 map.setSize(800, 600);
257
1ac277053049 Set map size after setting map extent to avoid the extent to be modified
raimund renkert <raimund.renkert@intevation.de>
parents: 253
diff changeset
200
172
929e09649b08 Handle unknown projections.
vc11884admin@VC11884.win.bsh.de
parents: 170
diff changeset
201 //Set the units and projection.
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
202 int proj = Integer.parseInt(mapNode.getAttribute("projection"));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
203 if(proj != 0) {
297
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
204 try {
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
205 map.setProjection("epsg:" + mapNode.getAttribute("projection"));
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
206 }
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
207 catch(UnknownError e) {
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
208 logger.error( "Could not set projection: " + mapNode.getAttribute("projection") +
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
209 ". Please ensure that it is described in your espg file.");
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
210 throw e;
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
211 }
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
212 }
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
213 String u = mapNode.getAttribute("units");
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
214 if(u.equals("feet")) {
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
215 units = MS_UNITS.MS_FEET;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
216 }
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
217 else if(u.equals("inches")) {
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
218 units = MS_UNITS.MS_INCHES;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
219 }
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
220 else if(u.equals("kilometers")) {
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
221 units = MS_UNITS.MS_KILOMETERS;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
222 }
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
223 else if(u.equals("meters")) {
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
224 units = MS_UNITS.MS_METERS;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
225 }
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
226 else if(u.equals("miles")) {
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
227 units = MS_UNITS.MS_MILES;
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
228 }
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
229 else if(u.equals("nauticalmiles")) {
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
230 units = MS_UNITS.MS_NAUTICALMILES;
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
231 }
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
232 else if(u.equals("points")) {
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
233 units = MS_UNITS.MS_PIXELS;
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
234 }
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
235 else if(u.equals("degree")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
236 units = MS_UNITS.MS_DD;
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
237 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
238 else {
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
239 units = MS_UNITS.MS_METERS;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
240 }
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
241 map.setUnits(units);
246
87e92debc53f Added extent and projection as ows metadata to the mapfile.
raimund renkert <raimund.renkert@intevation.de>
parents: 245
diff changeset
242
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
243 String mproj = mapNode.getAttribute("projection");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
244 if(mproj != null && !mproj.equals("") && ! mproj.equals("0")) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
245 MapScriptUtils msu = new MapScriptUtils();
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
246 String wmssrs = msu.getMetaData(map, "wms_srs");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
247 String owssrs = msu.getMetaData(map, "ows_srs");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
248 if(wmssrs.indexOf(mproj) < 0) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
249 if(wmssrs.equals("")) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
250 wmssrs = "EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
251 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
252 else {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
253 wmssrs += " EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
254 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
255 wmssrs += mproj;
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
256 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
257 if(owssrs.indexOf(mproj) < 0) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
258 if(owssrs.equals("")) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
259 owssrs = "EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
260 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
261 else {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
262 owssrs += " EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
263 }
259
8fe9ccc77962 Introduced a MapScript helper class and improved metadata handling.
raimund renkert <raimund.renkert@intevation.de>
parents: 258
diff changeset
264 owssrs += mproj;
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
265 }
259
8fe9ccc77962 Introduced a MapScript helper class and improved metadata handling.
raimund renkert <raimund.renkert@intevation.de>
parents: 258
diff changeset
266 map.setMetaData("ows_srs", owssrs);
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
267 map.setMetaData("wms_srs", wmssrs);
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
268 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
269 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
270
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
271 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
272 * 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
273 */
196
5350621a0294 Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents: 190
diff changeset
274 private boolean writeLayer() {
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
275 logger.debug("writeLayer()");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
276 Element mapNode = (Element)XMLUtils.xpath(
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
277 root,
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
278 "/mxd/map",
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
279 XPathConstants.NODE);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
280 NodeList list = mapNode.getElementsByTagName("layer");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
281 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
282 Element layerElement = (Element)list.item(i);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
283 layerObj layer = new layerObj(map);
190
c640fb351f66 Do not write layer with empty CLASS objects.
raimund renkert <raimund.renkert@intevation.de>
parents: 189
diff changeset
284 NodeList renderer = layerElement.getElementsByTagName("renderer");
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
285
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
286 //The layer name.
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
287 String group = "";
148
2bf35f0babd0 Implemented new group layer functionality.
vc11884admin@VC11884.win.bsh.de
parents: 145
diff changeset
288 if(layerElement.hasAttribute("group")) {
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
289 group = layerElement.getAttribute("group");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
290 String[] splitted = group.split("/");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
291 String cleangroup = "";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
292 for(int j = 0; j < splitted.length; j++) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
293 if(!splitted[j].equals("")) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
294 splitted[j] = msutils.replaceUmlauts(splitted[j]);
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
295 cleangroup += "/" +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
296 msutils.removeSpecialChars(splitted[j]);
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
297 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
298 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
299 group = cleangroup;
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
300 }
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
301 String lname = layerElement.getAttribute("name");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
302 lname = msutils.removeSpecialChars(lname);
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
303 lname = msutils.replaceUmlauts(lname);
299
c4fb04f6422f Write GROUP into grouped maps
Andre Heinecke <aheinecke@intevation.de>
parents: 298
diff changeset
304 String ulgroup = group.replaceAll("/", ".");
c4fb04f6422f Write GROUP into grouped maps
Andre Heinecke <aheinecke@intevation.de>
parents: 298
diff changeset
305 String ulname = ulgroup + "." + lname;
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
306 if(ulname.startsWith(".")) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
307 ulname = ulname.substring(1);
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
308 }
299
c4fb04f6422f Write GROUP into grouped maps
Andre Heinecke <aheinecke@intevation.de>
parents: 298
diff changeset
309 if(ulgroup.startsWith(".")) {
c4fb04f6422f Write GROUP into grouped maps
Andre Heinecke <aheinecke@intevation.de>
parents: 298
diff changeset
310 ulgroup = ulgroup.substring(1);
c4fb04f6422f Write GROUP into grouped maps
Andre Heinecke <aheinecke@intevation.de>
parents: 298
diff changeset
311 }
244
276f63c86f1c Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents: 243
diff changeset
312 layer.setName(ulname);
205
07b991b940ab Concatenate grouplayer name and layer name to have a unique identifier for each
raimund renkert <raimund.renkert@intevation.de>
parents: 204
diff changeset
313 layer.setUnits(units.swigValue());
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
314 if(!group.equals("")) {
305
ebf974199309 Only write group if layer is part of a group
Andre Heinecke <aheinecke@intevation.de>
parents: 304
diff changeset
315 layer.setGroup(ulgroup);
245
2eeeae07aaa2 Set the group attribute to the correct wms metadata.
raimund renkert <raimund.renkert@intevation.de>
parents: 244
diff changeset
316 layer.setMetaData("wms_layer_group", group);
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
317 }
245
2eeeae07aaa2 Set the group attribute to the correct wms metadata.
raimund renkert <raimund.renkert@intevation.de>
parents: 244
diff changeset
318 layer.setMetaData("wms_title", ulname);
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
319
307
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
320 //Set the projection for the Layers
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
321 if (layerElement.hasAttribute("projection")) {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
322 int proj = Integer.parseInt(layerElement.getAttribute("projection"));
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
323 if(proj != 0) {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
324 try {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
325 layer.setProjection("epsg:" + layerElement.getAttribute("projection"));
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
326 }
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
327 catch(UnknownError e) {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
328 logger.error( "Could not set projection in layer: " + layerElement.getAttribute("projection") +
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
329 ". Please ensure that it is described in your espg file.");
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
330 throw e;
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
331 }
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
332 }
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
333 }
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
334 // Projection metadata.
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
335 String mproj = mapNode.getAttribute("projection");
307
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
336 if (layerElement.hasAttribute("projection")) {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
337 // Overwrite the Map Projection in the layer
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
338 mproj = layerElement.getAttribute("projection");
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
339 }
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
340 if(mproj != null && !mproj.equals("") && !mproj.equals("0")) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
341 String wmssrs = layer.getMetaData("wms_srs");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
342 String owssrs = layer.getMetaData("ows_srs");
259
8fe9ccc77962 Introduced a MapScript helper class and improved metadata handling.
raimund renkert <raimund.renkert@intevation.de>
parents: 258
diff changeset
343 if(wmssrs == null) {
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
344 wmssrs = "EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
345 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
346 else {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
347 wmssrs += " EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
348 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
349 if(owssrs == null) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
350 owssrs = "EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
351 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
352 else {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
353 owssrs += " EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
354 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
355 wmssrs += mproj;
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
356 owssrs += mproj;
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
357 layer.setMetaData("wms_srs", wmssrs);
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
358 layer.setMetaData("ows_srs", owssrs);
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
359 }
259
8fe9ccc77962 Introduced a MapScript helper class and improved metadata handling.
raimund renkert <raimund.renkert@intevation.de>
parents: 258
diff changeset
360
300
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
361 // WMS Version
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
362 if (layerElement.hasAttribute("wms_server_version")) {
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
363 layer.setMetaData("wms_server_version",
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
364 layerElement.getAttribute("wms_server_version"));
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
365 }
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
366
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
367 // WMS Version
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
368 if (layerElement.hasAttribute("imageType")) {
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
369 layer.setMetaData("wms_format",
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
370 layerElement.getAttribute("imageType"));
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
371 }
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
372
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
373 // The layer extent metadata.
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
374 if(layerElement.hasAttribute("extent_min_x") &&
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
375 layerElement.hasAttribute("extent_max_x") &&
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
376 layerElement.hasAttribute("extent_min_y") &&
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
377 layerElement.hasAttribute("extent_max_y")) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
378 layer.setMetaData(
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
379 "ows_extent",
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
380 layerElement.getAttribute("extent_min_x") + ", " +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
381 layerElement.getAttribute("extent_min_y") + ", " +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
382 layerElement.getAttribute("extent_max_x") + ", " +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
383 layerElement.getAttribute("extent_max_y"));
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
384 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
385 //The layer status.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
386 String stat = layerElement.getAttribute("status");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
387 if (stat.equals("on")) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
388 layer.setStatus(1);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
389 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
390 else {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
391 layer.setStatus(0);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
392 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
393
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
394 //The scale.
145
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
395 double maxScale = 0;
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
396 double minScale = 0;
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
397 try {
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
398 maxScale =
153
7ed49420ee5a Changed min scale and max scale in writer.
vc11884admin@VC11884.win.bsh.de
parents: 152
diff changeset
399 Double.parseDouble(layerElement.getAttribute("min_scale"));
7ed49420ee5a Changed min scale and max scale in writer.
vc11884admin@VC11884.win.bsh.de
parents: 152
diff changeset
400 minScale =
145
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
401 Double.parseDouble(layerElement.getAttribute("max_scale"));
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
402 }
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
403 catch(NumberFormatException nfe) {
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
404 logger.warn("Error setting scale.");
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
405 maxScale = 0;
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
406 minScale = 0;
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
407 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
408 layer.setMaxscaledenom(maxScale);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
409 layer.setMinscaledenom(minScale);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
410
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
411 //The layer type.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
412 String type = layerElement.getAttribute("type");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
413 if(type.equals("point")) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
414 layer.setType(MS_LAYER_TYPE.MS_LAYER_POINT);
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
415 layer.setTileitem("");
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
416 }
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
417 else if (type.equals("line")) {
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
418 layer.setType(MS_LAYER_TYPE.MS_LAYER_LINE);
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
419 layer.setTileitem("");
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
420 }
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
421 else if (type.equals("polygon")) {
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
422 layer.setType(MS_LAYER_TYPE.MS_LAYER_POLYGON);
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
423 layer.setTileitem("");
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
424 }
320
9289b7c1b4ce Minor style fix
Andre Heinecke <aheinecke@intevation.de>
parents: 317
diff changeset
425 else if (type.equals("raster")) {
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
426 layer.setType(MS_LAYER_TYPE.MS_LAYER_RASTER);
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
427 }
317
5a2b5bc066eb Implement Label Styles and Labels with background
Andre Heinecke <aheinecke@intevation.de>
parents: 315
diff changeset
428 else if (type == "annotation") {
5a2b5bc066eb Implement Label Styles and Labels with background
Andre Heinecke <aheinecke@intevation.de>
parents: 315
diff changeset
429 layer.setType(MS_LAYER_TYPE.MS_LAYER_ANNOTATION);
5a2b5bc066eb Implement Label Styles and Labels with background
Andre Heinecke <aheinecke@intevation.de>
parents: 315
diff changeset
430 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
431
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
432 //The layer datasource.
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
433 String con_type = layerElement.getAttribute("connection_type");
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
434 if(con_type.equals("local")) {
304
50031b1ae8e6 No longer ignore Layers without classes
Andre Heinecke <aheinecke@intevation.de>
parents: 300
diff changeset
435 // The data source is a local file. (.shp or Image)
130
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
436 String datasource = "";
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
437 if(layerElement.hasAttribute("workspace")) {
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
438 datasource = layerElement.getAttribute("workspace");
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
439 datasource += File.separator;
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
440 }
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
441 datasource += layerElement.getAttribute("data_source");
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
442 datasource = datasource.replaceAll("\\\\", "/");
339
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
443 layer.setData(pathForMapfile(datasource));
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
444 }
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
445 else if(con_type.equals("SDE") && !type.equals("raster")) {
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
446 // The data source is a sde database.
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
447 logger.info(
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
448 "SDE datasource found." +
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
449 " Please edit password in mapfile.");
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
450 layer.setConnectionType(
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
451 MS_CONNECTION_TYPE.MS_PLUGIN.swigValue(),
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
452 MS_BINDIR + "/ms/plugins/msplugin_sde_93.dll");
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
453 String database_auth = layerElement.getAttribute("database");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
454 if (database_auth.equals("") || database_auth == null) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
455 logger.warn("Could not set the database connection user." +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
456 " Setting to \"sde\" as default.");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
457 database_auth = "sde";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
458 }
238
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
459
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
460 String port = layerElement.getAttribute("instance");
238
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
461 StringBuffer strBuff = new StringBuffer();
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
462 char c;
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
463
238
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
464 for (int j = 0; j < port.length() ; j++) {
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
465 c = port.charAt(j);
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
466
238
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
467 if(Character.isDigit(c)) {
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
468 strBuff.append(c);
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
469 }
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
470 }
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
471
130
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
472 layer.setConnection(
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
473 layerElement.getAttribute("server") + "," +
238
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
474 "port:" + strBuff.toString() + "," +
197
cdbf2f2dca35 Check for database connectio user parameter for SDE connections.
raimund renkert <raimund.renkert@intevation.de>
parents: 196
diff changeset
475 database_auth + "," +
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
476 layerElement.getAttribute("user") + ",<PASSWORD>");
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
477 layer.setData(
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
478 layerElement.getAttribute("data_source") +
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
479 ",SHAPE," +
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
480 layerElement.getAttribute("version"));
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
481 layer.setProcessing("CLOSE_CONNECTION=defer");
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
482 layer.setProcessing("ATTRIBUTE_QUALIFIED=TRUE");
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
483 if(layerElement.hasAttribute("join_table")) {
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
484 logger.info(
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
485 "The layer " +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
486 layer.getName() +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
487 " contains a jointable attribute." +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
488 " Please verify the attribute parameters.");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
489 String join = layerElement.getAttribute("join_table");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
490
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
491 layer.setProcessing(
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
492 "JOINTABLE=" +
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
493 layerElement.getAttribute("join_table"));
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
494 layer.setFilter(
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
495 "where " +
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
496 layerElement.getAttribute("definition_query") +
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
497 " AND " +
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
498 layerElement.getAttribute("join_table_target") + "." +
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
499 layerElement.getAttribute("join_field_target") + "=" +
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
500 layerElement.getAttribute("join_table") + "." +
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
501 layerElement.getAttribute("join_field"));
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
502 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
503 else {
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
504 prefix = layerElement.getAttribute("data_source");
314
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
505 if (!prefix.isEmpty()) {
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
506 prefix += ".";
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
507 }
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
508 if(layerElement.hasAttribute("definition_query") &&
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
509 !layerElement.getAttribute("definition_query")
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
510 .equals("")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
511 layer.setFilter("where " +
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
512 layerElement.getAttribute("definition_query"));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
513 }
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
514 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
515 }
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
516 else if(con_type.equals("SDE") && type.equals("raster")) {
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
517 // The data source is a sde database.
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
518 logger.info(
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
519 "SDE datasource found." +
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
520 " Please edit password in mapfile.");
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
521 String database_auth = layerElement.getAttribute("database");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
522 if (database_auth.equals("") || database_auth == null) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
523 logger.warn("Could not set the database connection user." +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
524 " Setting to \"sde\" as default.");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
525 database_auth = "sde";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
526 }
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
527
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
528 String port = layerElement.getAttribute("instance");
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
529 StringBuffer strBuff = new StringBuffer();
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
530 char c;
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
531
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
532 for (int j = 0; j < port.length() ; j++) {
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
533 c = port.charAt(j);
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
534 if(Character.isDigit(c)) {
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
535 strBuff.append(c);
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
536 }
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
537 }
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
538
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
539 layer.setData(
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
540 "SDE:" + layerElement.getAttribute("server") +
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
541 "," + strBuff +
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
542 "," + layerElement.getAttribute("database") +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
543 "," + layerElement.getAttribute("user") +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
544 ",<PASSWORD>," + layerElement.getAttribute("dataset"));
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
545 layer.setType(MS_LAYER_TYPE.MS_LAYER_RASTER);
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
546 if(layerElement.hasAttribute("definition_query") &&
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
547 !layerElement.getAttribute("definition_query").equals("")) {
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
548 layer.setFilter("where " +
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
549 layerElement.getAttribute("definition_query"));
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
550 }
300
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
551 } else if(con_type.equals("WMS")) {
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
552 layer.setType(MS_LAYER_TYPE.MS_LAYER_RASTER);
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
553 layer.setConnection(layerElement.getAttribute("connection"));
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
554 layer.setConnectionType(MS_CONNECTION_TYPE.MS_WMS.swigValue(), "");
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
555 layer.setMetaData("wms_name",
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
556 layerElement.getAttribute("wms_name"));
311
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
557 } else if(con_type.equals("ogr")) {
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
558 layer.setConnectionType(MS_CONNECTION_TYPE.MS_OGR.swigValue(), "");
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
559 layer.setConnection(layerElement.getAttribute("connection"));
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
560 layer.setData(layerElement.getAttribute("data_source"));
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
561 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
562 if(!type.equals("raster")) {
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
563 layer.setTemplate("PleaseInsertAValidTemplateForGFI");
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
564 }
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
565
308
1c949a309940 Wirte offsite values for raster layers
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
566 // Set Offsite value for raster layer
1c949a309940 Wirte offsite values for raster layers
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
567 if(type == "raster") {
1c949a309940 Wirte offsite values for raster layers
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
568 layer.setOffsite(new colorObj(255,255,255,-4));
1c949a309940 Wirte offsite values for raster layers
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
569 }
1c949a309940 Wirte offsite values for raster layers
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
570
338
b3048df06b66 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 335
diff changeset
571 if (mapNode.hasAttribute("referencescale")) {
b3048df06b66 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 335
diff changeset
572 layer.setSymbolscaledenom(Double.parseDouble(
b3048df06b66 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 335
diff changeset
573 mapNode.getAttribute("referencescale")));
b3048df06b66 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 335
diff changeset
574 }
b3048df06b66 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 335
diff changeset
575
321
b6c0fbae16dc Expand Graphics Layer Support
Andre Heinecke <aheinecke@intevation.de>
parents: 320
diff changeset
576 // Set scaling properties for layer and add Processing
317
5a2b5bc066eb Implement Label Styles and Labels with background
Andre Heinecke <aheinecke@intevation.de>
parents: 315
diff changeset
577 if(type == "annotation") {
321
b6c0fbae16dc Expand Graphics Layer Support
Andre Heinecke <aheinecke@intevation.de>
parents: 320
diff changeset
578 layer.addProcessing("ITEMS=classId");
b6c0fbae16dc Expand Graphics Layer Support
Andre Heinecke <aheinecke@intevation.de>
parents: 320
diff changeset
579 layer.setClassitem("classId");
317
5a2b5bc066eb Implement Label Styles and Labels with background
Andre Heinecke <aheinecke@intevation.de>
parents: 315
diff changeset
580 }
5a2b5bc066eb Implement Label Styles and Labels with background
Andre Heinecke <aheinecke@intevation.de>
parents: 315
diff changeset
581
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
582 // Create labelitem
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
583 NodeList labels = layerElement.getElementsByTagName("label");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
584 if(labels.getLength() > 0) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
585 Element label = (Element)labels.item(0);
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
586 String expr = label.getAttribute("expression");
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
587 expr = expr.replaceAll("\\[", "");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
588 expr = expr.replaceAll("\\]", "");
311
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
589 if (con_type == "ogr") {
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
590 // ogr expression fields come prefixed from arcgis
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
591 // the prefix has to be removed in order to work with
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
592 // mapserver
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
593 String unwantedPrefix = layerElement.getAttribute("data") + ".";
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
594 logger.debug("Removing expression Prefix: " + unwantedPrefix);
314
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
595 boolean isShapeFile = false;
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
596 if (layerElement.getAttribute("connection_type") == "local") {
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
597 isShapeFile = true;
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
598 }
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
599 expr = sanitizeAttribute(expr,
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
600 unwantedPrefix, prefix, isShapeFile);
311
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
601 }
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
602 if(!prefix.equals("")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
603 expr = prefix + "." + expr;
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
604 }
199
c56547b228f9 Remove leading and trailing whitespaces from labelitem.
raimund renkert <raimund.renkert@intevation.de>
parents: 197
diff changeset
605 layer.setLabelitem(expr.trim());
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
606 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
607
315
1d77ea6a915d Add basic support for Graphics Layers. For now this is restricted
Andre Heinecke <aheinecke@intevation.de>
parents: 314
diff changeset
608 //Write elements.
1d77ea6a915d Add basic support for Graphics Layers. For now this is restricted
Andre Heinecke <aheinecke@intevation.de>
parents: 314
diff changeset
609 writeFeatures(layer, layerElement);
1d77ea6a915d Add basic support for Graphics Layers. For now this is restricted
Andre Heinecke <aheinecke@intevation.de>
parents: 314
diff changeset
610
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
611 //Write classes.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
612 writeClass(layer, layerElement);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
613 }
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
614 return true;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
615 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
616
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
617 /**
314
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
618 * Adds the elements (Features) to the layer.
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
619 * @param layer Mapscript layer object.
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
620 * @param layerElement Dom element containing the feature attributes.
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
621 */
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
622 private void writeFeatures(layerObj layer, Element layerElement) {
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
623 NodeList list = layerElement.getElementsByTagName("feature");
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
624 for(int i = 0; i < list.getLength(); i++) {
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
625 logger.debug("Writing an element");
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
626 Element feature = (Element)list.item(i);
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
627 pointObj poi = new pointObj(
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
628 Double.parseDouble(feature.getAttribute("X")),
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
629 Double.parseDouble(feature.getAttribute("Y")),
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
630 0.0, -2e38);
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
631 lineObj line = new lineObj();
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
632 line.add(poi);
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
633 logger.debug("Set the line");
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
634
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
635 shapeObj shape = new shapeObj(MS_SHAPE_TYPE.MS_SHAPE_POINT.swigValue());
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
636 shape.add(line);
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
637 shape.setText(feature.getAttribute("text"));
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
638
321
b6c0fbae16dc Expand Graphics Layer Support
Andre Heinecke <aheinecke@intevation.de>
parents: 320
diff changeset
639 shape.initValues(1);
b6c0fbae16dc Expand Graphics Layer Support
Andre Heinecke <aheinecke@intevation.de>
parents: 320
diff changeset
640 shape.setValue(0, feature.getAttribute("classId"));
b6c0fbae16dc Expand Graphics Layer Support
Andre Heinecke <aheinecke@intevation.de>
parents: 320
diff changeset
641
b6c0fbae16dc Expand Graphics Layer Support
Andre Heinecke <aheinecke@intevation.de>
parents: 320
diff changeset
642 // Write the Style / Symbol for each element as a single class
b6c0fbae16dc Expand Graphics Layer Support
Andre Heinecke <aheinecke@intevation.de>
parents: 320
diff changeset
643 // TODO build a hash of the style/symbol and check if classes can be
b6c0fbae16dc Expand Graphics Layer Support
Andre Heinecke <aheinecke@intevation.de>
parents: 320
diff changeset
644 // grouped
b6c0fbae16dc Expand Graphics Layer Support
Andre Heinecke <aheinecke@intevation.de>
parents: 320
diff changeset
645
b6c0fbae16dc Expand Graphics Layer Support
Andre Heinecke <aheinecke@intevation.de>
parents: 320
diff changeset
646 classObj co = new classObj(layer);
b6c0fbae16dc Expand Graphics Layer Support
Andre Heinecke <aheinecke@intevation.de>
parents: 320
diff changeset
647 writeLabel(co, feature, layerElement.getAttribute("type"));
b6c0fbae16dc Expand Graphics Layer Support
Andre Heinecke <aheinecke@intevation.de>
parents: 320
diff changeset
648 co.setExpression("\"" + feature.getAttribute("classId") + "\"");
b6c0fbae16dc Expand Graphics Layer Support
Andre Heinecke <aheinecke@intevation.de>
parents: 320
diff changeset
649 LabelStyleWriter swriter = new LabelStyleWriter (this.map, co);
b6c0fbae16dc Expand Graphics Layer Support
Andre Heinecke <aheinecke@intevation.de>
parents: 320
diff changeset
650 swriter.write((Element)feature.getFirstChild());
314
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
651 layer.addFeature(shape);
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
652 }
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
653 }
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
654
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
655 /**
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
656 * Adds the classes to the layer.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
657 * @param layer Mapscript layer object.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
658 * @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
659 */
120
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 102
diff changeset
660 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
661 logger.debug("writeClass(layerObj, Element)");
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
662 //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
663 //mapfile.)
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
664 NodeList list = layerElement.getElementsByTagName("renderer");
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
665
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
666 //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
667 //each class.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
668 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
669 Element classElement = (Element)list.item(i);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
670 classObj co = new classObj(layer);
124
0f5819732288 Set label text as class name in mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 120
diff changeset
671 String name = classElement.getAttribute("label");
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
672 name = msutils.replaceUmlauts(name);
99
d6d2a4058ebf Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents: 98
diff changeset
673 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
674 name = layerElement.getAttribute("name");
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
675 name = msutils.replaceUmlauts(name);
99
d6d2a4058ebf Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents: 98
diff changeset
676 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
677 name += "-" + i;
d6d2a4058ebf Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents: 98
diff changeset
678 }
d6d2a4058ebf Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents: 98
diff changeset
679 }
d6d2a4058ebf Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents: 98
diff changeset
680 co.setName (name);
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
681
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
682 //Create label object.
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
683 NodeList labels = layerElement.getElementsByTagName("label");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
684 if(labels.getLength() > 0) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
685 Element labelElement = (Element)labels.item(0);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
686 String layerType = layerElement.getAttribute("type");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
687 writeLabel(co, labelElement, layerType);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
688 }
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
689
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
690 //Create definition expression.
44
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
691 if(classElement.hasAttribute("field_count")) {
311
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
692 String unwantedPrefix = layerElement.getAttribute("data") + ".";
314
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
693 boolean isShapeFile = false;
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
694 if (layerElement.getAttribute("connection_type") == "local") {
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
695 isShapeFile = true;
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
696 }
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
697 co.setExpression(createExpression(classElement, i, unwantedPrefix, isShapeFile));
44
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
698 }
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
699
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
700 //Write symbols and styles.
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
701 NodeList l = classElement.getChildNodes();
141
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 137
diff changeset
702 for (int j = l.getLength() - 1; j >= 0; j--) {
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
703 Element elem = (Element)l.item(j);
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
704
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
705 String type = layerElement.getAttribute("type");
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
706 if(type.equals("point") &&
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
707 elem.getTagName().equals("symbol")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
708 MarkerStyleWriter swriter =
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
709 new MarkerStyleWriter (this.map, co);
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
710 swriter.write (elem);
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
711 }
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
712 else if(type.equals("line") &&
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
713 elem.getTagName().equals("symbol")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
714 LineStyleWriter swriter =
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
715 new LineStyleWriter (this.map, co);
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
716 swriter.write (elem);
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
717 }
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
718 else if(type.equals("polygon") &&
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
719 elem.getTagName().equals("symbol")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
720 FillStyleWriter swriter =
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
721 new FillStyleWriter (this.map, co);
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
722 swriter.write (elem);
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
723 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
724 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
725 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
726 }
126
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
727
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
728 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
729 * Create a label object in a class object.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
730 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
731 * @param co Class object.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
732 * @param labelElement DOM element containing label attributes.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
733 * @param layertype The layer type. Used to define the label position.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
734 */
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
735 private void writeLabel(
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
736 classObj co,
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
737 Element labelElement,
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
738 String layerType) {
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
739
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
740 //Get the label object. Each class has a predefined labelobject.
335
4cf94b919725 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 332
diff changeset
741 labelObj label = new labelObj();
4cf94b919725 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 332
diff changeset
742 co.addLabel(label);
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
743
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
744 //Get the label text symbol attributes from DOM.
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
745 Element symbol = (Element)labelElement.getFirstChild();
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
746 if(symbol != null && symbol.getTagName().equals("symbol")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
747 String type = symbol.getAttribute("type");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
748 if(type.equals("text")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
749 label.setType(MS_FONT_TYPE.MS_TRUETYPE);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
750 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
751 label.setSize(Double.parseDouble(symbol.getAttribute("size")));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
752
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
753 if(symbol.hasAttribute("color")) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
754 String c = symbol.getAttribute("color");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
755 Color col = Color.decode(c);
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
756 colorObj color = new colorObj(
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
757 col.getRed(),
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
758 col.getGreen(),
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
759 col.getBlue(),
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
760 -4);
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
761 label.setColor(color);
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
762 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
763 if(symbol.hasAttribute("font")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
764 String font = symbol.getAttribute("font");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
765 fontSetObj fso = this.map.getFontset();
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
766 hashTableObj fonts = fso.getFonts();
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
767 String mapFont = fonts.get(font,"");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
768 if(mapFont != null && !mapFont.equals("")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
769 label.setFont(font);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
770 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
771 else {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
772 logger.info(
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
773 "Could not find font " + font + " in font set. " +
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
774 "Using FreeSans for labels.");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
775 label.setFont("FreeSans");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
776 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
777 }
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
778
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
779 if(labelElement.hasAttribute("max_scale")) {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
780 double min =
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
781 Double.parseDouble(labelElement.getAttribute("max_scale"));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
782 if(min > 0) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
783 label.setMinscaledenom(min);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
784 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
785 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
786 if(labelElement.hasAttribute("min_scale")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
787 double max =
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
788 Double.parseDouble(labelElement.getAttribute("min_scale"));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
789 if(max > 0) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
790 label.setMaxscaledenom(max);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
791 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
792 }
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
793
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
794 //Set the label position.
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
795 if(layerType.equals("point")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
796 label.setPosition(MS_POSITIONS_ENUM.MS_UC.swigValue());
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
797 }
317
5a2b5bc066eb Implement Label Styles and Labels with background
Andre Heinecke <aheinecke@intevation.de>
parents: 315
diff changeset
798
5a2b5bc066eb Implement Label Styles and Labels with background
Andre Heinecke <aheinecke@intevation.de>
parents: 315
diff changeset
799 //Set annotation specific values
5a2b5bc066eb Implement Label Styles and Labels with background
Andre Heinecke <aheinecke@intevation.de>
parents: 315
diff changeset
800 if (layerType == "annotation") {
5a2b5bc066eb Implement Label Styles and Labels with background
Andre Heinecke <aheinecke@intevation.de>
parents: 315
diff changeset
801 label.setPosition(MS_POSITIONS_ENUM.MS_CC.swigValue());
5a2b5bc066eb Implement Label Styles and Labels with background
Andre Heinecke <aheinecke@intevation.de>
parents: 315
diff changeset
802 label.setOffsetx(2);
5a2b5bc066eb Implement Label Styles and Labels with background
Andre Heinecke <aheinecke@intevation.de>
parents: 315
diff changeset
803 label.setOffsety(-2);
5a2b5bc066eb Implement Label Styles and Labels with background
Andre Heinecke <aheinecke@intevation.de>
parents: 315
diff changeset
804 }
5a2b5bc066eb Implement Label Styles and Labels with background
Andre Heinecke <aheinecke@intevation.de>
parents: 315
diff changeset
805
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
806 }
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
807 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
808
314
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
809 /** Sanitze an attribute
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
810 *
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
811 * Fixes invalid Field names and/or adds and removes a prefix
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
812 *
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
813 * @param attribute The Attribute to sanitize
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
814 * @param prefixToRemove A Prefix that should be removed (empty otherwise)
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
815 * @param prefixToAdd A Prefix that should be added (empty otherwise)
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
816 * @param enforceShpLimit True if the attribute should follow shapefile
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
817 * format restrictions.
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
818 */
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
819 private String sanitizeAttribute(String attribute, String prefixToRemove,
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
820 String prefixToAdd, boolean enforceShpLimit) {
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
821 if (enforceShpLimit) {
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
822 /* Workaround for non standard conform shapefile implementations
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
823 * like the one used by ArcGis that appends the field type after the
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
824 * eleventh character. Although the standard actually defines 10
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
825 * as the maximum length of Field Names GDAL handles the case where
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
826 * the terminating 0 is actually a Character allowing for Field
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
827 * names of up to 11 characters.
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
828 */
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
829 if (attribute.length() > 10) {
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
830 // Just remove the Type Delimiter
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
831 if (attribute.endsWith("C") ||
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
832 attribute.endsWith("D") ||
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
833 attribute.endsWith("N") ||
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
834 attribute.endsWith("L") ||
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
835 attribute.endsWith("M")) {
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
836 attribute = attribute.substring(0, attribute.length() - 1);
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
837 }
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
838 }
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
839 }
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
840 if (!prefixToRemove.isEmpty() && attribute.startsWith(prefixToRemove)) {
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
841 attribute = attribute.replace(prefixToRemove, "");
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
842 }
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
843 if (!prefixToAdd.isEmpty() && !attribute.startsWith(prefixToAdd)) {
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
844 attribute = prefixToAdd + attribute;
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
845 }
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
846 return attribute;
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
847 }
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
848
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
849 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
850 * Create definition expression.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
851 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
852 * @param ce DOM elementcontaining the class expression information.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
853 * @param index Index to determine the correct expression operator.
311
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
854 * @param prefixToRemove A string that will be removed from the start of
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
855 * expression fields.
314
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
856 * @param isShapeFile true if shapefile attribute limits should be enforced
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
857 */
314
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
858 private String createExpression(Element ce, int index, String prefixToRemove,
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
859 boolean isShapeFile) {
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
860 String expression = "(";
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
861 int count = 0;
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
862 try {
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
863 count = Integer.parseInt(ce.getAttribute("field_count"));
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
864 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
865 catch(NumberFormatException nfe) {
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
866 return "";
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
867 }
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
868
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
869 if(count == 1) {
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
870 //Create single field expression.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
871 try {
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
872 //If no exception is thrown, the expression value is a number.
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
873 Double.parseDouble(ce.getAttribute("value"));
314
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
874 expression += "[" +
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
875 sanitizeAttribute(ce.getAttribute("expression_field_0"),
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
876 prefixToRemove, prefix, isShapeFile) + "]";
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
877 if(ce.hasAttribute("min_value")) {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
878 if(index == 0) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
879 expression += " >= " + ce.getAttribute("min_value");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
880 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
881 else {
152
8a87c796bf47 Fixed expression for the first min value.
vc11884admin@VC11884.win.bsh.de
parents: 148
diff changeset
882 expression += " > " + ce.getAttribute("min_value");
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
883 }
314
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
884 expression += " AND [" +
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
885 sanitizeAttribute(ce.getAttribute("expression_field_0"),
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
886 prefixToRemove, prefix, isShapeFile) + "]";
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
887 expression += "]";
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
888 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
889 expression += " " + ce.getAttribute("expression_operator");
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
890 expression += " " + ce.getAttribute("value") + ")";
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
891 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
892 catch(NumberFormatException nfe) {
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
893 //The expression value is a strings.
314
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
894 expression += "\"[";
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
895 expression += sanitizeAttribute(ce.getAttribute("expression_field_0"),
322
40442cbfbcc7 Fix invalid quoting for string expressions
Andre Heinecke <aheinecke@intevation.de>
parents: 321
diff changeset
896 prefixToRemove, prefix, isShapeFile) + "]\"";
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
897 expression += " " + ce.getAttribute("expression_operator");
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
898 expression += " \"" + ce.getAttribute("value") + "\")";
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
899 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
900 catch(Exception e) {
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
901 e.printStackTrace();
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
902 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
903 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
904 else {
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
905 //Create a multi field expression.
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
906 for (int i = 0; i < count; i++) {
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
907 try {
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
908 //If no exception is thrown, the expression values are
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
909 //numbers.
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
910 Double.parseDouble(ce.getAttribute("value_" + i));
314
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
911 expression += "[";
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
912 expression += sanitizeAttribute(ce.getAttribute("expression_field_" + i),
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
913 prefixToRemove, prefix, isShapeFile);
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
914 expression += "]";
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
915 expression += " " + ce.getAttribute("expression_operator");
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
916 expression += " " + ce.getAttribute("value_" + i);
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
917 if (i < count - 1) {
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
918 expression += " AND ";
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
919 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
920 else {
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
921 expression += ")";
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
922 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
923 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
924 catch (NumberFormatException nfe) {
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
925 //The expression values are strings.
314
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
926 expression += "\"[";
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
927 expression += sanitizeAttribute(ce.getAttribute("expression_field_" + i),
cd3cb1a7f35a Workaround a bug in ArcGIS causing FieldNames of shape files that
Andre Heinecke <aheinecke@intevation.de>
parents: 311
diff changeset
928 prefixToRemove, prefix, isShapeFile);
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
929 expression += "]\"";
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
930 expression += " " + ce.getAttribute("expression_operator");
186
1391f911ee39 Add quotes to an expression if the value is a string.
raimund renkert <raimund.renkert@intevation.de>
parents: 181
diff changeset
931 expression += " \"" + ce.getAttribute("value_" + i);
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
932 if (i < count - 1) {
186
1391f911ee39 Add quotes to an expression if the value is a string.
raimund renkert <raimund.renkert@intevation.de>
parents: 181
diff changeset
933 expression += "\" AND ";
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
934 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
935 else {
186
1391f911ee39 Add quotes to an expression if the value is a string.
raimund renkert <raimund.renkert@intevation.de>
parents: 181
diff changeset
936 expression += "\")";
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
937 }
126
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
938 }
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
939 }
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
940 }
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
941 return expression;
127
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
942 }
339
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
943
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
944 /**
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
945 * Get a Path that should be used in a mapfile.
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
946 * Depending on the value of useRelativePaths this returns either
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
947 * an absolute path to a file or a relative location
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
948 *
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
949 * @param path The Path that you want to use
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
950 * @return The Path that should be written to the mapfile
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
951 */
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
952 public String pathForMapfile(String path) {
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
953 if (useRelativePaths) {
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
954 logger.debug(new File(mapFilename).toURI());
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
955 logger.debug(new File(path).toURI().getPath());
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
956 // Find the lowest common directory.
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
957 // where relativize returns a relative part
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
958 File candidate = new File(path);
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
959 File commonPath = new File(mapFilename).getParentFile();
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
960 File pathfile = new File(path);
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
961 String dirUps = "";
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
962 int count = 0;
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
963 while (commonPath != null && commonPath.getParentFile() != null
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
964 && candidate.isAbsolute()) {
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
965 candidate = new File(commonPath.toURI().relativize(
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
966 pathfile.toURI()).getPath());
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
967 commonPath = commonPath.getParentFile();
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
968 count++;
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
969 }
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
970 for (int i=0; i < count - 1; i++) {
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
971 /* The last loop already was correct*/
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
972 dirUps += "../";
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
973 }
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
974 if (candidate.isAbsolute()) {
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
975 return path;
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
976 }
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
977 return dirUps + candidate.getPath();
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
978 } else {
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
979 return path;
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
980 }
ef1cac2854e3 * src/java/de/intevation/mxd/writer/MapScriptWriter.java:
Andre Heinecke <aheinecke@intevation.de>
parents: 338
diff changeset
981 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
982 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)