annotate src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 313:9bb629743d2c

Remove uneccessary else and indention
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 14 Sep 2012 17:03:54 +0200
parents c8b8f887ef80
children cd3cb1a7f35a
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;
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
41
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
42 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
43 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
44 import edu.umn.gis.mapscript.MS_CONNECTION_TYPE;
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
45 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
46 import edu.umn.gis.mapscript.MS_POSITIONS_ENUM;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
48 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
49 import de.intevation.mxd.utils.MapScriptUtils;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
51 /**
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
52 * The Mapfile Writer.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
53 * 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
54 *
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
55 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 */
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 public class MapScriptWriter
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58 implements IWriter
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 {
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
60 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
61 * The Logger.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
62 */
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
63 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
64
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
65 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
66 * Private member.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
67 */
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
68 private Document root;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
69 private mapObj map;
259
8fe9ccc77962 Introduced a MapScript helper class and improved metadata handling.
raimund renkert <raimund.renkert@intevation.de>
parents: 258
diff changeset
70 private MapScriptUtils msutils;
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
71 private String mapFilename;
130
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
72 private String MS_BINDIR = "c:/ms_6.1-dev/bin";
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
73 private String prefix = "";
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
74 private MS_UNITS units = MS_UNITS.MS_METERS;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
75
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
76 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
77 * Default constructor.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
78 * Creates a mapscript writer object with an empty map.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
79 */
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
80 public MapScriptWriter() {
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
81 map = new mapObj("");
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
82 msutils = new MapScriptUtils();
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
83 mapFilename = "";
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
85
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
86 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
87 * Contructor with template and output filename.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
88 * Creates a mapscript writer object with the given template that saves the
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
89 * map to the filename.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
90 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
91 * @param templ Mapfile template.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
92 * @param filename Output file name.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
93 */
55
f0c02ff120d6 Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents: 53
diff changeset
94 public MapScriptWriter(String templ, String filename) {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
95 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
96 map = new mapObj(templ);
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
97 msutils = new MapScriptUtils();
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
98 File f = new File(filename);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
99 mapFilename = filename;
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
100 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
101 map.setMappath(mapFilename);
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
102 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
103 else {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
104 map.setMappath(
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
105 System.getProperty("user.dir") +
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
106 File.separator +
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
107 mapFilename);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
108 mapFilename = System.getProperty("user.dir") +
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
109 File.separator +
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
110 mapFilename;
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
111 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
112 String fontSetPath = map.getFontset().getFilename();
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
113 File fonts = new File(fontSetPath);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
114 String fontSet = fonts.getAbsolutePath();
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
115 fontSet = fontSet.replaceAll("\\\\", "/");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
116 map.setFontSet(fontSet);
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
117 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
118
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
119 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
120 * Write the mapfile.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
121 * @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
122 *
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
123 * @return Currently always true.
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
124 */
120
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 102
diff changeset
125 public boolean write(Document doc) {
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
126 logger.debug("write()");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
127 this.root = doc;
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
128
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
129 //Get the filename.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
130 Element fileNode = (Element)XMLUtils.xpath(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
131 root,
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
132 "/mxd/file",
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
133 XPathConstants.NODE);
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
134 //Write the map attributes.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
135 writeMap();
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
136 //Write the layers.
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
137 boolean ret = writeLayer();
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
138 //Save the map.
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
139 if (ret) {
196
5350621a0294 Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents: 190
diff changeset
140 mapObj cloneMap = map.cloneMap();
5350621a0294 Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents: 190
diff changeset
141 cloneMap.save(mapFilename);
5350621a0294 Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents: 190
diff changeset
142 logger.info("Mapfile created: " + mapFilename);
5350621a0294 Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents: 190
diff changeset
143 return true;
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
144 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
145 return false;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
146 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
147
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
148 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
149 * 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
150 */
297
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
151 private void writeMap()
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
152 throws UnknownError
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
153 {
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
154 logger.debug("writeMap()");
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
155 //Get the map.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
156 Element mapNode = (Element)XMLUtils.xpath(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
157 root,
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
158 "/mxd/map",
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
159 XPathConstants.NODE);
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
160
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
161 //Set the name.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
162 map.setName(mapNode.getAttribute("name"));
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
163 map.setMetaData("wms_title", mapNode.getAttribute("name"));
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
164 //Set the extent.
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
165 map.setExtent(
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
166 Double.parseDouble(mapNode.getAttribute("extent_min_x")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
167 Double.parseDouble(mapNode.getAttribute("extent_min_y")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
168 Double.parseDouble(mapNode.getAttribute("extent_max_x")),
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
169 Double.parseDouble(mapNode.getAttribute("extent_max_y")));
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
170
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
171 map.setMetaData(
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
172 "ows_extent",
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
173 mapNode.getAttribute("extent_min_x") + ", " +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
174 mapNode.getAttribute("extent_min_y") + ", " +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
175 mapNode.getAttribute("extent_max_x") + ", " +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
176 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
177
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
178 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
179
172
929e09649b08 Handle unknown projections.
vc11884admin@VC11884.win.bsh.de
parents: 170
diff changeset
180 //Set the units and projection.
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
181 int proj = Integer.parseInt(mapNode.getAttribute("projection"));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
182 if(proj != 0) {
297
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
183 try {
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
184 map.setProjection("epsg:" + mapNode.getAttribute("projection"));
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
185 }
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
186 catch(UnknownError e) {
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
187 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
188 ". 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
189 throw e;
ad05f72ef9e4 Useful debug output when setting the Projection fails
Andre Heinecke <aheinecke@intevation.de>
parents: 261
diff changeset
190 }
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
191 }
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
192 String u = mapNode.getAttribute("units");
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
193 if(u.equals("feet")) {
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
194 units = MS_UNITS.MS_FEET;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
195 }
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
196 else if(u.equals("inches")) {
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
197 units = MS_UNITS.MS_INCHES;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
198 }
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
199 else if(u.equals("kilometers")) {
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
200 units = MS_UNITS.MS_KILOMETERS;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
201 }
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
202 else if(u.equals("meters")) {
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
203 units = MS_UNITS.MS_METERS;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
204 }
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
205 else if(u.equals("miles")) {
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
206 units = MS_UNITS.MS_MILES;
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
207 }
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
208 else if(u.equals("nauticalmiles")) {
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
209 units = MS_UNITS.MS_NAUTICALMILES;
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
210 }
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
211 else if(u.equals("points")) {
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
212 units = MS_UNITS.MS_PIXELS;
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
213 }
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
214 else if(u.equals("degree")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
215 units = MS_UNITS.MS_DD;
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
216 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
217 else {
170
b9ee44070056 Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents: 169
diff changeset
218 units = MS_UNITS.MS_METERS;
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 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
221
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
222 String mproj = mapNode.getAttribute("projection");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
223 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
224 MapScriptUtils msu = new MapScriptUtils();
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
225 String wmssrs = msu.getMetaData(map, "wms_srs");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
226 String owssrs = msu.getMetaData(map, "ows_srs");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
227 if(wmssrs.indexOf(mproj) < 0) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
228 if(wmssrs.equals("")) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
229 wmssrs = "EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
230 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
231 else {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
232 wmssrs += " EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
233 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
234 wmssrs += mproj;
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
235 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
236 if(owssrs.indexOf(mproj) < 0) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
237 if(owssrs.equals("")) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
238 owssrs = "EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
239 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
240 else {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
241 owssrs += " EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
242 }
259
8fe9ccc77962 Introduced a MapScript helper class and improved metadata handling.
raimund renkert <raimund.renkert@intevation.de>
parents: 258
diff changeset
243 owssrs += mproj;
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
244 }
259
8fe9ccc77962 Introduced a MapScript helper class and improved metadata handling.
raimund renkert <raimund.renkert@intevation.de>
parents: 258
diff changeset
245 map.setMetaData("ows_srs", owssrs);
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
246 map.setMetaData("wms_srs", wmssrs);
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
247 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
248 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
249
43
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
250 /**
ef7ca23c4233 Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents: 42
diff changeset
251 * 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
252 */
196
5350621a0294 Verify the SDE databse jointable attribute.
raimund renkert <raimund.renkert@intevation.de>
parents: 190
diff changeset
253 private boolean writeLayer() {
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
254 logger.debug("writeLayer()");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
255 Element mapNode = (Element)XMLUtils.xpath(
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
256 root,
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
257 "/mxd/map",
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
258 XPathConstants.NODE);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
259 NodeList list = mapNode.getElementsByTagName("layer");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
260 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
261 Element layerElement = (Element)list.item(i);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
262 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
263 NodeList renderer = layerElement.getElementsByTagName("renderer");
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
264
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
265 //The layer name.
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
266 String group = "";
148
2bf35f0babd0 Implemented new group layer functionality.
vc11884admin@VC11884.win.bsh.de
parents: 145
diff changeset
267 if(layerElement.hasAttribute("group")) {
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
268 group = layerElement.getAttribute("group");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
269 String[] splitted = group.split("/");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
270 String cleangroup = "";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
271 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
272 if(!splitted[j].equals("")) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
273 splitted[j] = msutils.replaceUmlauts(splitted[j]);
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
274 cleangroup += "/" +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
275 msutils.removeSpecialChars(splitted[j]);
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
276 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
277 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
278 group = cleangroup;
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
279 }
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
280 String lname = layerElement.getAttribute("name");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
281 lname = msutils.removeSpecialChars(lname);
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
282 lname = msutils.replaceUmlauts(lname);
299
c4fb04f6422f Write GROUP into grouped maps
Andre Heinecke <aheinecke@intevation.de>
parents: 298
diff changeset
283 String ulgroup = group.replaceAll("/", ".");
c4fb04f6422f Write GROUP into grouped maps
Andre Heinecke <aheinecke@intevation.de>
parents: 298
diff changeset
284 String ulname = ulgroup + "." + lname;
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
285 if(ulname.startsWith(".")) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
286 ulname = ulname.substring(1);
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
287 }
299
c4fb04f6422f Write GROUP into grouped maps
Andre Heinecke <aheinecke@intevation.de>
parents: 298
diff changeset
288 if(ulgroup.startsWith(".")) {
c4fb04f6422f Write GROUP into grouped maps
Andre Heinecke <aheinecke@intevation.de>
parents: 298
diff changeset
289 ulgroup = ulgroup.substring(1);
c4fb04f6422f Write GROUP into grouped maps
Andre Heinecke <aheinecke@intevation.de>
parents: 298
diff changeset
290 }
244
276f63c86f1c Refactored group layer handling and "wms_title" metadata.
raimund renkert <raimund.renkert@intevation.de>
parents: 243
diff changeset
291 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
292 layer.setUnits(units.swigValue());
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
293 if(!group.equals("")) {
305
ebf974199309 Only write group if layer is part of a group
Andre Heinecke <aheinecke@intevation.de>
parents: 304
diff changeset
294 layer.setGroup(ulgroup);
245
2eeeae07aaa2 Set the group attribute to the correct wms metadata.
raimund renkert <raimund.renkert@intevation.de>
parents: 244
diff changeset
295 layer.setMetaData("wms_layer_group", group);
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
296 }
245
2eeeae07aaa2 Set the group attribute to the correct wms metadata.
raimund renkert <raimund.renkert@intevation.de>
parents: 244
diff changeset
297 layer.setMetaData("wms_title", ulname);
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
298
307
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
299 //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
300 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
301 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
302 if(proj != 0) {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
303 try {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
304 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
305 }
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
306 catch(UnknownError e) {
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
307 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
308 ". 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
309 throw e;
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
310 }
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
311 }
f9e53dcc7424 Add Read/Write Support for Projections on a per Layer basis
Andre Heinecke <aheinecke@intevation.de>
parents: 305
diff changeset
312 }
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
313 // Projection metadata.
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
314 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
315 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
316 // 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
317 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
318 }
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
319 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
320 String wmssrs = layer.getMetaData("wms_srs");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
321 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
322 if(wmssrs == null) {
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
323 wmssrs = "EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
324 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
325 else {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
326 wmssrs += " EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
327 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
328 if(owssrs == null) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
329 owssrs = "EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
330 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
331 else {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
332 owssrs += " EPSG:";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
333 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
334 wmssrs += mproj;
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
335 owssrs += mproj;
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
336 layer.setMetaData("wms_srs", wmssrs);
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
337 layer.setMetaData("ows_srs", owssrs);
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
338 }
259
8fe9ccc77962 Introduced a MapScript helper class and improved metadata handling.
raimund renkert <raimund.renkert@intevation.de>
parents: 258
diff changeset
339
300
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
340 // WMS Version
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
341 if (layerElement.hasAttribute("wms_server_version")) {
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
342 layer.setMetaData("wms_server_version",
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
343 layerElement.getAttribute("wms_server_version"));
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
344 }
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
345
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
346 // WMS Version
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
347 if (layerElement.hasAttribute("imageType")) {
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
348 layer.setMetaData("wms_format",
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
349 layerElement.getAttribute("imageType"));
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
350 }
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
351
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
352 // The layer extent metadata.
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
353 if(layerElement.hasAttribute("extent_min_x") &&
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
354 layerElement.hasAttribute("extent_max_x") &&
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
355 layerElement.hasAttribute("extent_min_y") &&
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
356 layerElement.hasAttribute("extent_max_y")) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
357 layer.setMetaData(
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
358 "ows_extent",
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
359 layerElement.getAttribute("extent_min_x") + ", " +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
360 layerElement.getAttribute("extent_min_y") + ", " +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
361 layerElement.getAttribute("extent_max_x") + ", " +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
362 layerElement.getAttribute("extent_max_y"));
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
363 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
364 //The layer status.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
365 String stat = layerElement.getAttribute("status");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
366 if (stat.equals("on")) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
367 layer.setStatus(1);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
368 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
369 else {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
370 layer.setStatus(0);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
371 }
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
372
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
373 //The scale.
145
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
374 double maxScale = 0;
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
375 double minScale = 0;
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
376 try {
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
377 maxScale =
153
7ed49420ee5a Changed min scale and max scale in writer.
vc11884admin@VC11884.win.bsh.de
parents: 152
diff changeset
378 Double.parseDouble(layerElement.getAttribute("min_scale"));
7ed49420ee5a Changed min scale and max scale in writer.
vc11884admin@VC11884.win.bsh.de
parents: 152
diff changeset
379 minScale =
145
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
380 Double.parseDouble(layerElement.getAttribute("max_scale"));
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
381 }
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
382 catch(NumberFormatException nfe) {
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
383 logger.warn("Error setting scale.");
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
384 maxScale = 0;
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
385 minScale = 0;
b2c5a66022f1 Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents: 141
diff changeset
386 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
387 layer.setMaxscaledenom(maxScale);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
388 layer.setMinscaledenom(minScale);
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 //The layer type.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
391 String type = layerElement.getAttribute("type");
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
392 if(type.equals("point")) {
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
393 layer.setType(MS_LAYER_TYPE.MS_LAYER_POINT);
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
394 layer.setTileitem("");
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
395 }
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
396 else if (type.equals("line")) {
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
397 layer.setType(MS_LAYER_TYPE.MS_LAYER_LINE);
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
398 layer.setTileitem("");
62
e468cf8701ea Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents: 59
diff changeset
399 }
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
400 else if (type.equals("polygon")) {
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
401 layer.setType(MS_LAYER_TYPE.MS_LAYER_POLYGON);
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
402 layer.setTileitem("");
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
403 }
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
404 else if(type.equals("raster")) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
405 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
406 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
407
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
408 //The layer datasource.
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
409 String con_type = layerElement.getAttribute("connection_type");
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
410 if(con_type.equals("local")) {
304
50031b1ae8e6 No longer ignore Layers without classes
Andre Heinecke <aheinecke@intevation.de>
parents: 300
diff changeset
411 // 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
412 String datasource = "";
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
413 if(layerElement.hasAttribute("workspace")) {
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
414 datasource = layerElement.getAttribute("workspace");
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
415 datasource += File.separator;
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
416 }
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
417 datasource += layerElement.getAttribute("data_source");
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
418 datasource = datasource.replaceAll("\\\\", "/");
130
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
419 layer.setData(datasource);
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
420 }
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
421 else if(con_type.equals("SDE") && !type.equals("raster")) {
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
422 // The data source is a sde database.
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
423 logger.info(
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
424 "SDE datasource found." +
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
425 " Please edit password in mapfile.");
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
426 layer.setConnectionType(
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
427 MS_CONNECTION_TYPE.MS_PLUGIN.swigValue(),
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
428 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
429 String database_auth = layerElement.getAttribute("database");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
430 if (database_auth.equals("") || database_auth == null) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
431 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
432 " Setting to \"sde\" as default.");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
433 database_auth = "sde";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
434 }
238
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
435
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
436 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
437 StringBuffer strBuff = new StringBuffer();
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
438 char c;
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
439
238
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
440 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
441 c = port.charAt(j);
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
442
238
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
443 if(Character.isDigit(c)) {
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
444 strBuff.append(c);
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
445 }
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
446 }
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
447
130
5991c1f90f91 Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents: 129
diff changeset
448 layer.setConnection(
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
449 layerElement.getAttribute("server") + "," +
238
e672f5134d6e Remove all non numeric chars from port string.
raimund renkert <raimund.renkert@intevation.de>
parents: 207
diff changeset
450 "port:" + strBuff.toString() + "," +
197
cdbf2f2dca35 Check for database connectio user parameter for SDE connections.
raimund renkert <raimund.renkert@intevation.de>
parents: 196
diff changeset
451 database_auth + "," +
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
452 layerElement.getAttribute("user") + ",<PASSWORD>");
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
453 layer.setData(
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
454 layerElement.getAttribute("data_source") +
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
455 ",SHAPE," +
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
456 layerElement.getAttribute("version"));
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
457 layer.setProcessing("CLOSE_CONNECTION=defer");
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
458 layer.setProcessing("ATTRIBUTE_QUALIFIED=TRUE");
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
459 if(layerElement.hasAttribute("join_table")) {
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
460 logger.info(
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
461 "The layer " +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
462 layer.getName() +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
463 " contains a jointable attribute." +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
464 " Please verify the attribute parameters.");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
465 String join = layerElement.getAttribute("join_table");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
466
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
467 layer.setProcessing(
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
468 "JOINTABLE=" +
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
469 layerElement.getAttribute("join_table"));
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
470 layer.setFilter(
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
471 "where " +
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
472 layerElement.getAttribute("definition_query") +
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
473 " AND " +
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
474 layerElement.getAttribute("join_table_target") + "." +
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
475 layerElement.getAttribute("join_field_target") + "=" +
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
476 layerElement.getAttribute("join_table") + "." +
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
477 layerElement.getAttribute("join_field"));
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
478 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
479 else {
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
480 prefix = layerElement.getAttribute("data_source");
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
481 if(layerElement.hasAttribute("definition_query") &&
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
482 !layerElement.getAttribute("definition_query")
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
483 .equals("")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
484 layer.setFilter("where " +
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
485 layerElement.getAttribute("definition_query"));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
486 }
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
487 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
488 }
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
489 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
490 // The data source is a sde database.
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
491 logger.info(
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
492 "SDE datasource found." +
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
493 " Please edit password in mapfile.");
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
494 String database_auth = layerElement.getAttribute("database");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
495 if (database_auth.equals("") || database_auth == null) {
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
496 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
497 " Setting to \"sde\" as default.");
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
498 database_auth = "sde";
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
499 }
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
500
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
501 String port = layerElement.getAttribute("instance");
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
502 StringBuffer strBuff = new StringBuffer();
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
503 char c;
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
504
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
505 for (int j = 0; j < port.length() ; j++) {
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
506 c = port.charAt(j);
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
507 if(Character.isDigit(c)) {
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
508 strBuff.append(c);
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
509 }
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
510 }
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
511
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
512 layer.setData(
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
513 "SDE:" + layerElement.getAttribute("server") +
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
514 "," + strBuff +
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
515 "," + layerElement.getAttribute("database") +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
516 "," + layerElement.getAttribute("user") +
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
517 ",<PASSWORD>," + layerElement.getAttribute("dataset"));
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
518 layer.setType(MS_LAYER_TYPE.MS_LAYER_RASTER);
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
519 if(layerElement.hasAttribute("definition_query") &&
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
520 !layerElement.getAttribute("definition_query").equals("")) {
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
521 layer.setFilter("where " +
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
522 layerElement.getAttribute("definition_query"));
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
523 }
300
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
524 } else if(con_type.equals("WMS")) {
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
525 layer.setType(MS_LAYER_TYPE.MS_LAYER_RASTER);
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
526 layer.setConnection(layerElement.getAttribute("connection"));
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
527 layer.setConnectionType(MS_CONNECTION_TYPE.MS_WMS.swigValue(), "");
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
528 layer.setMetaData("wms_name",
215ae6199b95 Add WMS Support to the writer
Andre Heinecke <aheinecke@intevation.de>
parents: 299
diff changeset
529 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
530 } 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
531 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
532 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
533 layer.setData(layerElement.getAttribute("data_source"));
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
534 }
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
535 if(!type.equals("raster")) {
252
eae3fe89e669 Added raster layer support.
raimund renkert <raimund.renkert@intevation.de>
parents: 249
diff changeset
536 layer.setTemplate("PleaseInsertAValidTemplateForGFI");
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
537 }
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
538
308
1c949a309940 Wirte offsite values for raster layers
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
539 // Set Offsite value for raster layer
1c949a309940 Wirte offsite values for raster layers
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
540 if(type == "raster") {
1c949a309940 Wirte offsite values for raster layers
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
541 layer.setOffsite(new colorObj(255,255,255,-4));
1c949a309940 Wirte offsite values for raster layers
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
542 }
1c949a309940 Wirte offsite values for raster layers
Andre Heinecke <aheinecke@intevation.de>
parents: 307
diff changeset
543
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
544 // Create labelitem
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
545 NodeList labels = layerElement.getElementsByTagName("label");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
546 if(labels.getLength() > 0) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
547 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
548 String expr = label.getAttribute("expression");
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
549 expr = expr.replaceAll("\\[", "");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
550 expr = expr.replaceAll("\\]", "");
311
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
551 if (con_type == "ogr") {
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
552 // 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
553 // 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
554 // mapserver
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
555 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
556 logger.debug("Removing expression Prefix: " + unwantedPrefix);
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
557 expr = expr.replace(unwantedPrefix, "");
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
558 }
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
559 if(!prefix.equals("")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
560 expr = prefix + "." + expr;
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
561 }
199
c56547b228f9 Remove leading and trailing whitespaces from labelitem.
raimund renkert <raimund.renkert@intevation.de>
parents: 197
diff changeset
562 layer.setLabelitem(expr.trim());
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
563 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
564
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
565 //Write classes.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
566 writeClass(layer, layerElement);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
567 }
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
568 return true;
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
569 }
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
570
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
571 /**
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
572 * Adds the classes to the layer.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
573 * @param layer Mapscript layer object.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
574 * @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
575 */
120
11d63bf00326 Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 102
diff changeset
576 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
577 logger.debug("writeClass(layerObj, Element)");
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
578 //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
579 //mapfile.)
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
580 NodeList list = layerElement.getElementsByTagName("renderer");
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
581
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
582 //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
583 //each class.
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
584 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
585 Element classElement = (Element)list.item(i);
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
586 classObj co = new classObj(layer);
124
0f5819732288 Set label text as class name in mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 120
diff changeset
587 String name = classElement.getAttribute("label");
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
588 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
589 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
590 name = layerElement.getAttribute("name");
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
591 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
592 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
593 name += "-" + i;
d6d2a4058ebf Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents: 98
diff changeset
594 }
d6d2a4058ebf Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents: 98
diff changeset
595 }
d6d2a4058ebf Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents: 98
diff changeset
596 co.setName (name);
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
597
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
598 //Create label object.
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
599 NodeList labels = layerElement.getElementsByTagName("label");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
600 if(labels.getLength() > 0) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
601 Element labelElement = (Element)labels.item(0);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
602 String layerType = layerElement.getAttribute("type");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
603 writeLabel(co, labelElement, layerType);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
604 }
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
605
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
606 //Create definition expression.
44
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
607 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
608 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
609 co.setExpression(createExpression(classElement, i, unwantedPrefix));
44
9b5fb5e5914d Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents: 43
diff changeset
610 }
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
611
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
612 //Write symbols and styles.
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
613 NodeList l = classElement.getChildNodes();
141
8f30f7e802d6 Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents: 137
diff changeset
614 for (int j = l.getLength() - 1; j >= 0; j--) {
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
615 Element elem = (Element)l.item(j);
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
616
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
617 String type = layerElement.getAttribute("type");
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
618 if(type.equals("point") &&
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
619 elem.getTagName().equals("symbol")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
620 MarkerStyleWriter swriter =
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
621 new MarkerStyleWriter (this.map, co);
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
622 swriter.write (elem);
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
623 }
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
624 else if(type.equals("line") &&
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
625 elem.getTagName().equals("symbol")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
626 LineStyleWriter swriter =
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
627 new LineStyleWriter (this.map, co);
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
628 swriter.write (elem);
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
629 }
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
630 else if(type.equals("polygon") &&
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
631 elem.getTagName().equals("symbol")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
632 FillStyleWriter swriter =
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
633 new FillStyleWriter (this.map, co);
97
18e4f143896b Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents: 96
diff changeset
634 swriter.write (elem);
87
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
635 }
7d4cf2db43f1 Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 62
diff changeset
636 }
42
395307e8b7ee First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents: 41
diff changeset
637 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
638 }
126
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
639
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
640 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
641 * Create a label object in a class object.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
642 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
643 * @param co Class object.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
644 * @param labelElement DOM element containing label attributes.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
645 * @param layertype The layer type. Used to define the label position.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
646 */
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
647 private void writeLabel(
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
648 classObj co,
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
649 Element labelElement,
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
650 String layerType) {
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
651
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
652 //Get the label object. Each class has a predefined labelobject.
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
653 labelObj label = co.getLabel();
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
654
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
655 //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
656 Element symbol = (Element)labelElement.getFirstChild();
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
657 if(symbol != null && symbol.getTagName().equals("symbol")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
658 String type = symbol.getAttribute("type");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
659 if(type.equals("text")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
660 label.setType(MS_FONT_TYPE.MS_TRUETYPE);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
661 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
662 label.setSize(Double.parseDouble(symbol.getAttribute("size")));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
663
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
664 if(symbol.hasAttribute("color")) {
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
665 String c = symbol.getAttribute("color");
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
666 Color col = Color.decode(c);
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
667 colorObj color = new colorObj(
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
668 col.getRed(),
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
669 col.getGreen(),
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
670 col.getBlue(),
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
671 -4);
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
672 label.setColor(color);
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
673 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
674 if(symbol.hasAttribute("font")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
675 String font = symbol.getAttribute("font");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
676 fontSetObj fso = this.map.getFontset();
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
677 hashTableObj fonts = fso.getFonts();
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
678 String mapFont = fonts.get(font,"");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
679 if(mapFont != null && !mapFont.equals("")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
680 label.setFont(font);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
681 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
682 else {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
683 logger.info(
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
684 "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
685 "Using FreeSans for labels.");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
686 label.setFont("FreeSans");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
687 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
688 }
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
689
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
690 if(labelElement.hasAttribute("max_scale")) {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
691 double min =
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
692 Double.parseDouble(labelElement.getAttribute("max_scale"));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
693 if(min > 0) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
694 label.setMinscaledenom(min);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
695 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
696 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
697 if(labelElement.hasAttribute("min_scale")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
698 double max =
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
699 Double.parseDouble(labelElement.getAttribute("min_scale"));
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
700 if(max > 0) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
701 label.setMaxscaledenom(max);
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
702 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
703 }
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
704
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
705 //Set the label position.
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
706 if(layerType.equals("point")) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
707 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
708 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
709 }
179
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
710 }
f3a91cd7440b Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents: 175
diff changeset
711
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
712 /**
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
713 * Create definition expression.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
714 *
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
715 * @param ce DOM elementcontaining the class expression information.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
716 * @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
717 * @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
718 * expression fields.
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
719 */
311
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
720 private String createExpression(Element ce, int index, String prefixToRemove) {
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
721 String expression = "(";
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
722 int count = 0;
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
723 try {
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
724 count = Integer.parseInt(ce.getAttribute("field_count"));
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
725 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
726 catch(NumberFormatException nfe) {
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
727 return "";
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
728 }
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
729
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
730 if(count == 1) {
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
731 //Create single field expression.
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
732 try {
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
733 //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
734 Double.parseDouble(ce.getAttribute("value"));
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
735 String exp = ce.getAttribute("expression_field_0");
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
736 String pre = "";
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
737 if (!prefix.equals("") && !exp.startsWith(prefix)) {
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
738 pre = prefix + ".";
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
739 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
740 expression += "[" + pre;
311
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
741 expression += ce.getAttribute("expression_field_0").replace(
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
742 prefixToRemove, "") + "]";
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
743 if(ce.hasAttribute("min_value")) {
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
744 if(index == 0) {
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
745 expression += " >= " + ce.getAttribute("min_value");
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
746 }
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
747 else {
152
8a87c796bf47 Fixed expression for the first min value.
vc11884admin@VC11884.win.bsh.de
parents: 148
diff changeset
748 expression += " > " + ce.getAttribute("min_value");
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
749 }
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
750 expression += " AND [" + pre;
311
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
751 expression += ce.getAttribute("expression_field_0").replace(
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
752 prefixToRemove, "");
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
753 expression += "]";
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
754 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
755 expression += " " + ce.getAttribute("expression_operator");
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
756 expression += " " + ce.getAttribute("value") + ")";
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
757 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
758 catch(NumberFormatException nfe) {
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
759 //The expression value is a strings.
311
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
760 String exp = ce.getAttribute("expression_field_0").replace(
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
761 prefixToRemove, "");
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
762 String pre = "";
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
763 if (!prefix.equals("") && !exp.startsWith(prefix)) {
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
764 pre = prefix + ".";
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
765 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
766 expression += "\"[" + pre;
311
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
767 expression += ce.getAttribute("expression_field_0").replace(
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
768 prefixToRemove, "") + "]\"";
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
769 expression += " " + ce.getAttribute("expression_operator");
298
1cbc278c956b Whitespace Only: unify to 4 Space indention.
Andre Heinecke <aheinecke@intevation.de>
parents: 297
diff changeset
770 expression += " \"" + ce.getAttribute("value") + "\")";
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
771 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
772 catch(Exception e) {
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
773 e.printStackTrace();
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
774 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
775 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
776 else {
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
777 //Create a multi field expression.
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
778 for (int i = 0; i < count; i++) {
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
779 try {
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
780 //If no exception is thrown, the expression values are
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
781 //numbers.
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
782 Double.parseDouble(ce.getAttribute("value_" + i));
311
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
783 String exp = ce.getAttribute("expression_field_" + i).replace(
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
784 prefixToRemove, "");
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
785 String pre = "";
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
786 if (!prefix.equals("") && !exp.startsWith(prefix)) {
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
787 pre = prefix + ".";
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
788 }
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
789 expression += "[" + pre;
311
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
790 expression += ce.getAttribute("expression_field_" + i).replace(
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
791 prefixToRemove, "");
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
792 expression += "]";
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
793 expression += " " + ce.getAttribute("expression_operator");
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
794 expression += " " + ce.getAttribute("value_" + i);
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
795 if (i < count - 1) {
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
796 expression += " AND ";
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
797 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
798 else {
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
799 expression += ")";
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
800 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
801 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
802 catch (NumberFormatException nfe) {
181
0bde090506f9 Added comments.
Raimund Renkert <rrenkert@intevation.de>
parents: 180
diff changeset
803 //The expression values are strings.
311
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
804 String exp = ce.getAttribute("expression_field_" + i).replace(
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
805 prefixToRemove, "");
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
806 String pre = "";
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
807 if (!prefix.equals("") && !exp.startsWith(prefix)) {
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
808 pre = prefix + ".";
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
809 }
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
810 expression += "\"[" + pre;
311
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
811 expression += ce.getAttribute("expression_field_" + i).replace(
c8b8f887ef80 Add write support for Fgdb layers and make it possible
Andre Heinecke <aheinecke@intevation.de>
parents: 308
diff changeset
812 prefixToRemove, "");
180
f4eb506499f5 Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents: 179
diff changeset
813 expression += "]\"";
134
acc9e5430177 Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents: 132
diff changeset
814 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
815 expression += " \"" + ce.getAttribute("value_" + i);
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
816 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
817 expression += "\" AND ";
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
818 }
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
819 else {
186
1391f911ee39 Add quotes to an expression if the value is a string.
raimund renkert <raimund.renkert@intevation.de>
parents: 181
diff changeset
820 expression += "\")";
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
821 }
126
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
822 }
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
823 }
ff0354265a7d Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents: 124
diff changeset
824 }
137
cd55975ba0c4 Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents: 134
diff changeset
825 return expression;
127
5ba8bf865dc7 Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents: 126
diff changeset
826 }
41
60ed2164035a Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
827 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)