Mercurial > mxd2map
annotate src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 180:f4eb506499f5
Done some code styling and removed TODOs.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Mon, 11 Jul 2011 12:11:08 +0200 |
parents | f3a91cd7440b |
children | 0bde090506f9 |
rev | line source |
---|---|
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.mxd.writer; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
2 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
3 import org.apache.log4j.Logger; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
4 |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
5 import java.awt.Color; |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
6 |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
7 import org.w3c.dom.Document; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
8 import org.w3c.dom.Element; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
9 import org.w3c.dom.NodeList; |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
10 |
98
4696d0769f9c
Write the absolute path to the data source of the layer.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
11 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
|
12 |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
13 import javax.xml.xpath.XPathConstants; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
14 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
15 import edu.umn.gis.mapscript.mapObj; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
16 import edu.umn.gis.mapscript.layerObj; |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
17 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
|
18 import edu.umn.gis.mapscript.labelObj; |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
19 import edu.umn.gis.mapscript.colorObj; |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
20 import edu.umn.gis.mapscript.fontSetObj; |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
21 import edu.umn.gis.mapscript.hashTableObj; |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
22 |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
23 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
|
24 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
|
25 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
|
26 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
|
27 import edu.umn.gis.mapscript.MS_POSITIONS_ENUM; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
28 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
29 import de.intevation.mxd.utils.XMLUtils; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
30 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
31 /** |
43
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
32 * The Mapfile Writer. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
33 * 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
|
34 * |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
35 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
36 */ |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
37 public class MapScriptWriter |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
38 implements IWriter |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
39 { |
43
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
40 /** |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
41 * The Logger. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
42 */ |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
43 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
|
44 |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
45 /** |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
46 * Private member. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
47 */ |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
48 private Document root; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
49 private mapObj map; |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
50 private String mapFilename; |
130
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
51 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
|
52 private String prefix = ""; |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
53 private MS_UNITS units = MS_UNITS.MS_METERS; |
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 public MapScriptWriter() { |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
56 map = new mapObj(""); |
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
57 mapFilename = ""; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
58 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
59 |
55
f0c02ff120d6
Read filenames from properties file or commandline arguments.
Raimund Renkert <rrenkert@intevation.de>
parents:
53
diff
changeset
|
60 public MapScriptWriter(String templ, String filename) { |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
61 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
|
62 map = new mapObj(templ); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
63 File f = new File(filename); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
64 mapFilename = filename; |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
65 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
|
66 map.setMappath(mapFilename); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
67 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
68 else { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
69 map.setMappath( |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
70 System.getProperty("user.dir") + |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
71 File.separator + |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
72 mapFilename); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
73 mapFilename = System.getProperty("user.dir") + |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
74 File.separator + |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
75 mapFilename; |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
76 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
77 String fontSetPath = map.getFontset().getFilename(); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
78 File fonts = new File(fontSetPath); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
79 String fontSet = fonts.getAbsolutePath(); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
80 fontSet = fontSet.replaceAll("\\\\", "/"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
81 map.setFontSet(fontSet); |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
82 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
83 |
43
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
84 /** |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
85 * Write the mapfile. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
86 * @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
|
87 * |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
88 * @return Currently always true. |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
89 */ |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
102
diff
changeset
|
90 public boolean write(Document doc) { |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
91 logger.debug("write()"); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
92 this.root = doc; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
93 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
94 //Get the filename. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
95 Element fileNode = (Element)XMLUtils.xpath( |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
96 root, |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
97 "/mxd/file", |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
98 XPathConstants.NODE); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
99 //Write the map attributes. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
100 writeMap(); |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
101 //Write the layers. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
102 writeLayer(); |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
103 //Save the map. |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
104 mapObj cloneMap = map.cloneMap(); |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
172
diff
changeset
|
105 |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
106 cloneMap.save(mapFilename); |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
172
diff
changeset
|
107 logger.info("Mapfile created: " + mapFilename); |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
108 return true; |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
109 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
110 |
43
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
111 /** |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
112 * 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
|
113 */ |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
114 private void writeMap() { |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
115 logger.debug("writeMap()"); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
116 //Get the map. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
117 Element mapNode = (Element)XMLUtils.xpath( |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
118 root, |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
119 "/mxd/map", |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
120 XPathConstants.NODE); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
121 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
122 //Set the name. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
123 map.setName(mapNode.getAttribute("name")); |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
124 map.setMetaData("wms_title", mapNode.getAttribute("name")); |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
125 //Set the extent. |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
126 map.setExtent( |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
127 Double.parseDouble(mapNode.getAttribute("extent_min_x")), |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
128 Double.parseDouble(mapNode.getAttribute("extent_min_y")), |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
129 Double.parseDouble(mapNode.getAttribute("extent_max_x")), |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
130 Double.parseDouble(mapNode.getAttribute("extent_max_y"))); |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
131 |
172
929e09649b08
Handle unknown projections.
vc11884admin@VC11884.win.bsh.de
parents:
170
diff
changeset
|
132 //Set the units and projection. |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
133 int proj = Integer.parseInt(mapNode.getAttribute("projection")); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
134 if(proj != 0) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
135 map.setProjection("epsg:" + mapNode.getAttribute("projection")); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
136 } |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
137 String u = mapNode.getAttribute("units"); |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
138 if(u.equals("feet")) { |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
139 units = MS_UNITS.MS_FEET; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
140 } |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
141 else if(u.equals("inches")) { |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
142 units = MS_UNITS.MS_INCHES; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
143 } |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
144 else if(u.equals("kilometers")) { |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
145 units = MS_UNITS.MS_KILOMETERS; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
146 } |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
147 else if(u.equals("meters")) { |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
148 units = MS_UNITS.MS_METERS; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
149 } |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
150 else if(u.equals("miles")) { |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
151 units = MS_UNITS.MS_MILES; |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
152 } |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
153 else if(u.equals("nauticalmiles")) { |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
154 units = MS_UNITS.MS_NAUTICALMILES; |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
155 } |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
156 else if(u.equals("points")) { |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
157 units = MS_UNITS.MS_PIXELS; |
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
158 } |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
159 else if(u.equals("degree")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
160 units = MS_UNITS.MS_DD; |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
161 } |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
162 else { |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
163 units = MS_UNITS.MS_METERS; |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
164 } |
170
b9ee44070056
Manage projections and units.
vc11884admin@VC11884.win.bsh.de
parents:
169
diff
changeset
|
165 map.setUnits(units); |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
166 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
167 |
43
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
168 /** |
ef7ca23c4233
Added comments, done some code styling and removed typos.
Raimund Renkert <rrenkert@intevation.de>
parents:
42
diff
changeset
|
169 * 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
|
170 */ |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
102
diff
changeset
|
171 private void writeLayer() { |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
172 logger.debug("writeLayer()"); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
173 Element mapNode = (Element)XMLUtils.xpath( |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
174 root, |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
175 "/mxd/map", |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
176 XPathConstants.NODE); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
177 NodeList list = mapNode.getElementsByTagName("layer"); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
178 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
|
179 Element layerElement = (Element)list.item(i); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
180 layerObj layer = new layerObj(map); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
181 |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
182 //The layer name. |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
183 String lname = layerElement.getAttribute("name"); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
184 lname = lname.replaceAll(" ", ""); |
132
02df1dbc2166
Remove all whitespaces in layer name.
vc11884admin@VC11884.win.bsh.de
parents:
130
diff
changeset
|
185 layer.setName(lname); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
186 layer.setUnits(units.swigValue()); |
128
1616622a8c8d
Insert metadata for layer title for getCapabilities request.
Raimund Renkert <rrenkert@intevation.de>
parents:
127
diff
changeset
|
187 layer.setMetaData("wms_title", layerElement.getAttribute("name")); |
148
2bf35f0babd0
Implemented new group layer functionality.
vc11884admin@VC11884.win.bsh.de
parents:
145
diff
changeset
|
188 if(layerElement.hasAttribute("group")) { |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
189 layer.setGroup(layerElement.getAttribute("group")); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
190 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
191 |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
192 //The layer status. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
193 String stat = layerElement.getAttribute("status"); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
194 if (stat.equals("on")) { |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
195 layer.setStatus(1); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
196 } |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
197 else { |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
198 layer.setStatus(0); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
199 } |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
200 |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
201 //The scale. |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
202 double maxScale = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
203 double minScale = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
204 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
205 maxScale = |
153
7ed49420ee5a
Changed min scale and max scale in writer.
vc11884admin@VC11884.win.bsh.de
parents:
152
diff
changeset
|
206 Double.parseDouble(layerElement.getAttribute("min_scale")); |
7ed49420ee5a
Changed min scale and max scale in writer.
vc11884admin@VC11884.win.bsh.de
parents:
152
diff
changeset
|
207 minScale = |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
208 Double.parseDouble(layerElement.getAttribute("max_scale")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
209 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
210 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
211 logger.warn("Error setting scale."); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
212 maxScale = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
213 minScale = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
214 } |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
215 layer.setMaxscaledenom(maxScale); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
216 layer.setMinscaledenom(minScale); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
217 |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
218 //The layer type. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
219 String type = layerElement.getAttribute("type"); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
220 if(type.equals("point")) { |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
221 layer.setType(MS_LAYER_TYPE.MS_LAYER_POINT); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
222 } |
62
e468cf8701ea
Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
59
diff
changeset
|
223 else if (type.equals("line")) { |
e468cf8701ea
Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
59
diff
changeset
|
224 layer.setType(MS_LAYER_TYPE.MS_LAYER_LINE); |
e468cf8701ea
Prepared the converter to handle and write line symbols.
Raimund Renkert <rrenkert@intevation.de>
parents:
59
diff
changeset
|
225 } |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
226 else if (type.equals("polygon")) { |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
227 layer.setType(MS_LAYER_TYPE.MS_LAYER_POLYGON); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
228 } |
102
3ca2ec55fb3b
Set TILEITEM to an empty string.
Raimund Renkert <rrenkert@intevation.de>
parents:
99
diff
changeset
|
229 layer.setTileitem(""); |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
230 |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
231 //The layer datasource. |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
232 String con_type = layerElement.getAttribute("connection_type"); |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
233 if(con_type.equals("local")) { |
130
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
234 String datasource = ""; |
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
235 if(layerElement.hasAttribute("workspace")) { |
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
236 datasource = layerElement.getAttribute("workspace"); |
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
237 datasource += File.separator; |
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
238 } |
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
239 datasource += layerElement.getAttribute("data_source"); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
240 datasource = datasource.replaceAll("\\\\", "/"); |
130
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
241 layer.setData(datasource); |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
242 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
243 else if(con_type.equals("SDE")) { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
244 logger.info( |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
245 "SDE datasource found." + |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
246 " Please edit password in mapfile."); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
247 layer.setConnectionType( |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
248 MS_CONNECTION_TYPE.MS_PLUGIN.swigValue(), |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
249 MS_BINDIR + "/ms/plugins/msplugin_sde_93.dll"); |
130
5991c1f90f91
Added data source "SDE" to writer.
vc11884admin@VC11884.win.bsh.de
parents:
129
diff
changeset
|
250 layer.setConnection( |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
251 layerElement.getAttribute("server") + "," + |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
252 "port:" + layerElement.getAttribute("instance") + "," + |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
253 layerElement.getAttribute("database") + "," + |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
254 layerElement.getAttribute("user") + ",<PASSWORD>"); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
255 layer.setData( |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
256 layerElement.getAttribute("data_source") + |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
257 ",SHAPE," + |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
258 layerElement.getAttribute("version")); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
259 layer.setProcessing("CLOSE_CONNECTION=defer"); |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
260 layer.setProcessing("ATTRIBUTE_QUALIFIED=TRUE"); |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
261 if(layerElement.hasAttribute("join_table")) { |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
262 layer.setProcessing( |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
263 "JOINTABLE=" + |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
264 layerElement.getAttribute("join_table")); |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
265 layer.setFilter( |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
266 "where " + |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
267 layerElement.getAttribute("definition_query") + |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
268 " AND " + |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
269 layerElement.getAttribute("join_table_target") + "." + |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
270 layerElement.getAttribute("join_field_target") + "=" + |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
271 layerElement.getAttribute("join_table") + "." + |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
272 layerElement.getAttribute("join_field")); |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
273 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
274 else { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
275 prefix = layerElement.getAttribute("data_source"); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
276 if(layerElement.hasAttribute("definition_query") && |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
277 !layerElement.getAttribute("definition_query") |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
278 .equals("")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
279 layer.setFilter("where " + |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
280 layerElement.getAttribute("definition_query")); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
281 } |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
282 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
283 } |
129
0b119169618f
Insert TEMPLATE entry for GFI request.
Raimund Renkert <rrenkert@intevation.de>
parents:
128
diff
changeset
|
284 layer.setTemplate("PleaseInsertAValidTemplateForGFI"); |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
285 |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
286 NodeList labels = layerElement.getElementsByTagName("label"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
287 if(labels.getLength() > 0) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
288 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
|
289 String expr = label.getAttribute("expression"); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
290 expr = expr.replaceAll("\\[", ""); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
291 expr = expr.replaceAll("\\]", ""); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
292 if(!prefix.equals("")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
293 expr = prefix + "." + expr; |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
294 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
295 layer.setLabelitem(expr); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
296 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
297 |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
298 //Write classes. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
299 writeClass(layer, layerElement); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
300 } |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
301 |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
302 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
303 |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
304 /** |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
305 * Adds the classes to the layer. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
306 * @param layer Mapscript layer object. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
307 * @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
|
308 */ |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
102
diff
changeset
|
309 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
|
310 logger.debug("writeClass(layerObj, Element)"); |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
311 //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
|
312 //mapfile.) |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
313 NodeList list = layerElement.getElementsByTagName("renderer"); |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
314 |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
315 //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
|
316 //each class. |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
317 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
|
318 Element classElement = (Element)list.item(i); |
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
319 classObj co = new classObj(layer); |
124
0f5819732288
Set label text as class name in mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents:
120
diff
changeset
|
320 String name = classElement.getAttribute("label"); |
99
d6d2a4058ebf
Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents:
98
diff
changeset
|
321 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
|
322 name = layerElement.getAttribute("name"); |
d6d2a4058ebf
Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents:
98
diff
changeset
|
323 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
|
324 name += "-" + i; |
d6d2a4058ebf
Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents:
98
diff
changeset
|
325 } |
d6d2a4058ebf
Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents:
98
diff
changeset
|
326 } |
d6d2a4058ebf
Set the class name to the layer name if it is empty.
Raimund Renkert <rrenkert@intevation.de>
parents:
98
diff
changeset
|
327 co.setName (name); |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
328 |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
329 NodeList labels = layerElement.getElementsByTagName("label"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
330 if(labels.getLength() > 0) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
331 Element labelElement = (Element)labels.item(0); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
332 String layerType = layerElement.getAttribute("type"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
333 writeLabel(co, labelElement, layerType); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
334 } |
44
9b5fb5e5914d
Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
335 if(classElement.hasAttribute("field_count")) { |
152
8a87c796bf47
Fixed expression for the first min value.
vc11884admin@VC11884.win.bsh.de
parents:
148
diff
changeset
|
336 co.setExpression(createExpression(classElement, i)); |
44
9b5fb5e5914d
Added expressions for mapserver classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
43
diff
changeset
|
337 } |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
338 //Write symbols and styles. |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
339 NodeList l = classElement.getChildNodes(); |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
137
diff
changeset
|
340 for (int j = l.getLength() - 1; j >= 0; j--) { |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
341 Element elem = (Element)l.item(j); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
342 |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
343 String type = layerElement.getAttribute("type"); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
344 if(type.equals("point") && |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
345 elem.getTagName().equals("symbol")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
346 MarkerStyleWriter swriter = |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
347 new MarkerStyleWriter (this.map, co); |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
348 swriter.write (elem); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
62
diff
changeset
|
349 } |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
350 else if(type.equals("line") && |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
351 elem.getTagName().equals("symbol")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
352 LineStyleWriter swriter = |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
353 new LineStyleWriter (this.map, co); |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
354 swriter.write (elem); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
355 } |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
356 else if(type.equals("polygon") && |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
357 elem.getTagName().equals("symbol")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
358 FillStyleWriter swriter = |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
359 new FillStyleWriter (this.map, co); |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
360 swriter.write (elem); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
62
diff
changeset
|
361 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
62
diff
changeset
|
362 } |
42
395307e8b7ee
First MapScript Writer that generates valid mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
41
diff
changeset
|
363 } |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
364 } |
126
ff0354265a7d
Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents:
124
diff
changeset
|
365 |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
366 |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
367 private void writeLabel( |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
368 classObj co, |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
369 Element labelElement, |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
370 String layerType) { |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
371 |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
372 labelObj label = co.getLabel(); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
373 Element symbol = (Element)labelElement.getFirstChild(); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
374 if(symbol != null && symbol.getTagName().equals("symbol")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
375 String type = symbol.getAttribute("type"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
376 if(type.equals("text")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
377 label.setType(MS_FONT_TYPE.MS_TRUETYPE); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
378 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
379 label.setSize(Double.parseDouble(symbol.getAttribute("size"))); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
380 |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
381 if(symbol.hasAttribute("color")) { |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
382 String c = symbol.getAttribute("color"); |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
383 Color col = Color.decode(c); |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
384 colorObj color = new colorObj( |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
385 col.getRed(), |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
386 col.getGreen(), |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
387 col.getBlue(), |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
388 -4); |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
389 label.setColor(color); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
390 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
391 if(symbol.hasAttribute("font")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
392 String font = symbol.getAttribute("font"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
393 fontSetObj fso = this.map.getFontset(); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
394 hashTableObj fonts = fso.getFonts(); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
395 String mapFont = fonts.get(font,""); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
396 if(mapFont != null && !mapFont.equals("")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
397 label.setFont(font); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
398 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
399 else { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
400 logger.info( |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
401 "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
|
402 "Using FreeSans for labels."); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
403 label.setFont("FreeSans"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
404 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
405 } |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
406 |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
407 if(labelElement.hasAttribute("max_scale")) { |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
408 double min = |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
409 Double.parseDouble(labelElement.getAttribute("max_scale")); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
410 if(min > 0) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
411 label.setMinscaledenom(min); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
412 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
413 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
414 if(labelElement.hasAttribute("min_scale")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
415 double max = |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
416 Double.parseDouble(labelElement.getAttribute("min_scale")); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
417 if(max > 0) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
418 label.setMaxscaledenom(max); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
419 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
420 } |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
421 |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
422 if(layerType.equals("point")) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
423 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
|
424 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
425 } |
179
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
426 } |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
427 |
f3a91cd7440b
Added a first version of feature labeling.
raimund renkert <raimund.renkert@intevation.de>
parents:
175
diff
changeset
|
428 |
152
8a87c796bf47
Fixed expression for the first min value.
vc11884admin@VC11884.win.bsh.de
parents:
148
diff
changeset
|
429 private String createExpression(Element ce, int index) { |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
430 String expression = "("; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
431 int count = 0; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
432 try { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
433 count = Integer.parseInt(ce.getAttribute("field_count")); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
434 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
435 catch(NumberFormatException nfe) { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
436 return ""; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
437 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
438 if(count == 1) { |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
439 try { |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
440 Double.parseDouble(ce.getAttribute("value")); |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
441 String exp = ce.getAttribute("expression_field_0"); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
442 String pre = ""; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
443 if (!prefix.equals("") && !exp.startsWith(prefix)) { |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
444 pre = prefix + "."; |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
445 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
446 expression += "[" + pre; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
447 expression += ce.getAttribute("expression_field_0") + "]"; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
448 if(ce.hasAttribute("min_value")) { |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
449 if(index == 0) { |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
450 expression += " >= " + ce.getAttribute("min_value"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
451 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
452 else { |
152
8a87c796bf47
Fixed expression for the first min value.
vc11884admin@VC11884.win.bsh.de
parents:
148
diff
changeset
|
453 expression += " > " + ce.getAttribute("min_value"); |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
454 } |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
455 expression += " AND [" + pre; |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
456 expression += ce.getAttribute("expression_field_0"); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
457 expression += "]"; |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
458 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
459 expression += " " + ce.getAttribute("expression_operator"); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
460 expression += " " + ce.getAttribute("value") + ")"; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
461 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
462 catch(NumberFormatException nfe) { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
463 String exp = ce.getAttribute("expression_field_0"); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
464 String pre = ""; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
465 if (!prefix.equals("") && !exp.startsWith(prefix)) { |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
466 pre = prefix + "."; |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
467 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
468 expression += "\"[" + pre; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
469 expression += ce.getAttribute("expression_field_0") + "]\""; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
470 expression += " " + ce.getAttribute("expression_operator"); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
471 expression += " \"" + ce.getAttribute("value") + "\")"; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
472 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
473 catch(Exception e) { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
474 e.printStackTrace(); |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
475 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
476 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
477 else { |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
478 for (int i = 0; i < count; i++) { |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
479 try { |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
480 Double.parseDouble(ce.getAttribute("value_" + i)); |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
481 String exp = ce.getAttribute("expression_field_" + i); |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
482 String pre = ""; |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
483 if (!prefix.equals("") && !exp.startsWith(prefix)) { |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
484 pre = prefix + "."; |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
485 } |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
486 expression += "[" + pre; |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
487 expression += ce.getAttribute("expression_field_" + i); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
488 expression += "]"; |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
489 expression += " " + ce.getAttribute("expression_operator"); |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
490 expression += " " + ce.getAttribute("value_" + i); |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
491 if (i < count - 1) { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
492 expression += " AND "; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
493 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
494 else { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
495 expression += ")"; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
496 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
497 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
498 catch (NumberFormatException nfe) { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
499 String exp = ce.getAttribute("expression_field_" + i); |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
500 String pre = ""; |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
501 if (!prefix.equals("") && !exp.startsWith(prefix)) { |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
502 pre = prefix + "."; |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
503 } |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
504 expression += "\"[" + pre; |
180
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
505 expression += ce.getAttribute("expression_field_" + i); |
f4eb506499f5
Done some code styling and removed TODOs.
Raimund Renkert <rrenkert@intevation.de>
parents:
179
diff
changeset
|
506 expression += "]\""; |
134
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
507 expression += " " + ce.getAttribute("expression_operator"); |
acc9e5430177
Handle SDE connection attributes and expressions.
vc11884admin@VC11884.win.bsh.de
parents:
132
diff
changeset
|
508 expression += " " + ce.getAttribute("value_" + i); |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
509 if (i < count - 1) { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
510 expression += " AND "; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
511 } |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
512 else { |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
513 expression += ")"; |
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
514 } |
126
ff0354265a7d
Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents:
124
diff
changeset
|
515 } |
ff0354265a7d
Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents:
124
diff
changeset
|
516 } |
ff0354265a7d
Write the correct expression for double values.
Raimund Renkert <rrenkert@intevation.de>
parents:
124
diff
changeset
|
517 } |
137
cd55975ba0c4
Done some minor reformatings.
Raimund Renkert <rrenkert@intevation.de>
parents:
134
diff
changeset
|
518 return expression; |
127
5ba8bf865dc7
Write expressions for string values to the mapfile.
Raimund Renkert <rrenkert@intevation.de>
parents:
126
diff
changeset
|
519 } |
41
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
520 } |
60ed2164035a
Introduced MapScript writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
521 |