Mercurial > mxd2map
annotate src/java/de/intevation/mxd/writer/SymbolWriter.java @ 250:d10fd4de02aa
Documented a bunch of new features
* Support of picture-marker symbol (issue343)
* Support for ArcGIS named groups (issue381)
* GLOBAL and Layer extents and SRS (issue 379)
author | Stephan Holl <stephan.holl@intevation.de> |
---|---|
date | Fri, 12 Aug 2011 09:15:34 +0200 |
parents | df4e0946ef02 |
children | 6b80e46b8f38 |
rev | line source |
---|---|
243
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
1 /* |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
2 * Copyright (c) 2011 by Intevation GmbH, Germany <info@intevation.de> |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
3 * |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
4 * This file is part of MXD2map. |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
5 * |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
6 * This program is free software under the LGPL (>=v2.1) |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
7 * Read the file LICENCE.txt coming with the software for details |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
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:
192
diff
changeset
|
9 * |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
10 * MXD2map has been developed on behalf of the |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
11 * Bundesamt fuer Seeschifffahrt und Hydrographie (BSH) in Hamburg |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
12 * by Intevation GmbH. |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
13 * |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
14 * Authors: |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
15 * Raimund Renkert <raimund.renkert@intevation.de> |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
16 * Bjoern Schilberg <bjoern.schilberg@intevation.de> |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
17 * Stephan Holl <stephan.holl@intevation.de> |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
18 */ |
df4e0946ef02
Added LGPL header.
Raimund Renkert <rrenkert@intevation.de>
parents:
192
diff
changeset
|
19 |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
20 package de.intevation.mxd.writer; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
21 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
22 import org.apache.log4j.Logger; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
23 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
24 import org.w3c.dom.Element; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
25 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
26 import edu.umn.gis.mapscript.mapObj; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
27 import edu.umn.gis.mapscript.classObj; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
28 import edu.umn.gis.mapscript.styleObj; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
29 import edu.umn.gis.mapscript.symbolObj; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
30 import edu.umn.gis.mapscript.symbolSetObj; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
31 import edu.umn.gis.mapscript.lineObj; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
32 import edu.umn.gis.mapscript.pointObj; |
192
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
33 import edu.umn.gis.mapscript.fontSetObj; |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
34 import edu.umn.gis.mapscript.hashTableObj; |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
35 import edu.umn.gis.mapscript.MS_SYMBOL_TYPE; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
36 |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
37 import java.io.File; |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
38 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
39 /** |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
40 * The interface to the mapfile writer. |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
41 * |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
42 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
43 */ |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
44 public class SymbolWriter { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
45 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
46 /** |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
47 * The Logger. |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
48 */ |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
49 private static final Logger logger = Logger.getLogger(SymbolWriter.class); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
50 |
181 | 51 /** |
52 * Private member. | |
53 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
54 private mapObj map; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
55 private classObj cl; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
56 |
181 | 57 /** |
58 * Contructor with map object and class object. | |
59 * | |
60 * @param map The map object. | |
61 * @param cl The class object containing the style. | |
62 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
63 public SymbolWriter (mapObj map, classObj cl) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
64 this.map = map; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
65 this.cl = cl; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
66 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
67 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
68 /** |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
69 * Write the content. |
181 | 70 * |
71 * @param symbolElement DOM element containg the style and symbol | |
72 * attributes. | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
73 */ |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
74 public boolean write(Element symbolElement) { |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
75 logger.debug("write(Element)"); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
76 symbolSetObj symbolSet = map.getSymbolset(); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
77 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
78 String name = symbolElement.getAttribute("name"); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
79 symbolObj sym = symbolSet.getSymbolByName(name); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
80 String symType = symbolElement.getAttribute("style"); |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
81 String type = symbolElement.getAttribute("type"); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
82 if(symType.equals("point")) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
83 writeSimple(sym); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
84 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
85 else if (symType.equals("arrow")) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
86 writeArrow(sym, symbolElement); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
87 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
88 else if (symType.equals("char")) { |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
89 int exists = symbolExists(symbolElement); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
90 if(exists == -1) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
91 String old = symbolElement.getAttribute("name"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
92 symbolElement.setAttribute( |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
93 "name", |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
94 old + symbolSet.getNumsymbols() + 1); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
95 writeCharacter(sym, symbolElement); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
96 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
97 else { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
98 symbolElement.setAttribute( |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
99 "name", |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
100 symbolSet.getSymbol(exists).getName()); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
101 } |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
102 } |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
103 else if (type.equals("line")) { |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
104 writeHatch(sym); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
105 } |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
106 else { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
107 return false; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
108 } |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
109 |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
110 try { |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
111 saveSymbolSet(symbolSet); |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
112 } |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
113 catch(Exception e) { |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
114 logger.error("Error saving symbol set."); |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
115 return false; |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
116 } |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
117 |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
118 return true; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
119 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
120 |
181 | 121 /** |
122 * Create a simple point symbol. | |
123 * | |
124 * @param symbol The symbol object. | |
125 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
126 private void writeSimple(symbolObj symbol) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
127 logger.debug("writeSimple(symbolObj)"); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
128 lineObj points = new lineObj(); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
129 points.add(new pointObj(1,1,0)); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
130 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue()); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
131 symbol.setPoints(points); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
132 symbol.setFilled(1); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
133 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
134 |
181 | 135 /** |
136 * Create an arrow symbol. | |
137 * | |
138 * @param symbol The symbol object. | |
139 * @param symbolElement DOM element containing symbol attributes. | |
140 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
141 private void writeArrow(symbolObj symbol, Element symbolElement) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
142 logger.debug("writeArrow(symbolObj, Element)"); |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
143 double len = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
144 double width = 1; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
145 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
146 len = |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
147 Double.parseDouble(symbolElement.getAttribute("length")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
148 width = |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
149 Double.parseDouble(symbolElement.getAttribute("width")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
150 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
151 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
152 logger.warn ("Error setting arrow symbol."); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
153 return; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
154 } |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
155 double ratio = len/width; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
156 lineObj points = new lineObj(); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
157 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
158 points.add(new pointObj(0, 0, 0)); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
159 points.add(new pointObj((1*ratio), 0.5, 0)); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
160 points.add(new pointObj(0, 1, 0)); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
161 points.add(new pointObj(0, 0, 0)); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
162 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_VECTOR.swigValue()); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
163 symbol.setPoints(points); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
164 symbol.setFilled(1); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
165 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
166 |
181 | 167 /** |
168 * Create a character marker symbol. | |
169 * | |
170 * @param symbol The symbol object. | |
171 * @param symbolElement DOM element containing symbol attributes. | |
172 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
173 private void writeCharacter(symbolObj symbol, Element symbolElement) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
174 logger.debug("writeCharacter(symbolObj, Element)"); |
93
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
175 String font = symbolElement.getAttribute("font"); |
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
176 //Remove all blank character to match the mapserver fonts.txt. |
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
177 font = font.replaceAll(" ", ""); |
192
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
178 fontSetObj fso = this.map.getFontset(); |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
179 hashTableObj fonts = fso.getFonts(); |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
180 String mapFont = fonts.get(font,""); |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
181 if (mapFont == null || mapFont.equals("")) { |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
182 logger.warn( |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
183 "Could not find font " + font + " in font set. " + |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
184 "Setting FreeSans as symbol font." + |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
185 "Please add " + font + " to fonts.txt and replace the alias " + |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
186 "in symbol \"" + symbolElement.getAttribute("name") + "\"."); |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
187 font = "FreeSans"; |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
188 } |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
189 symbol.setName(symbolElement.getAttribute("name")); |
93
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
190 symbol.setFont(font); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
191 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue()); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
192 symbol.setAntialias(1); |
93
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
193 symbol.setCharacter("&#" + symbolElement.getAttribute("char") + ";"); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
194 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
195 |
181 | 196 /** |
197 * Create a hatch symbol for polygon fill. | |
198 * | |
199 * @param symbol The symbol object. | |
200 */ | |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
201 private void writeHatch(symbolObj symbol) { |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
202 logger.debug("writeHatch(symbolObj)"); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
203 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_HATCH.swigValue()); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
204 } |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
205 |
181 | 206 /** |
207 * Determine whether this writer can create the symbol. | |
208 * | |
209 * @param type The symbol type. | |
210 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
211 public boolean canWrite(String type) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
212 if (type.equals("point") || |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
213 type.equals("arrow") || |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
214 type.equals("char") || |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
215 type.equals("line")) { |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
216 return true; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
217 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
218 else { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
219 return false; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
220 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
221 } |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
222 |
181 | 223 /** |
224 * Save the symbol set. | |
225 * | |
226 * @param symbols The symbol set object. | |
227 */ | |
184
c79c3c6fc99a
Always save a symbol set, use the mapfile name as prefix for the symbol set and
raimund renkert <raimund.renkert@intevation.de>
parents:
181
diff
changeset
|
228 public void saveSymbolSet(symbolSetObj symbols) |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
229 throws Exception { |
93
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
230 String path = this.map.getMappath(); |
184
c79c3c6fc99a
Always save a symbol set, use the mapfile name as prefix for the symbol set and
raimund renkert <raimund.renkert@intevation.de>
parents:
181
diff
changeset
|
231 String filename = path.substring(path.lastIndexOf(File.separator) + 1, |
c79c3c6fc99a
Always save a symbol set, use the mapfile name as prefix for the symbol set and
raimund renkert <raimund.renkert@intevation.de>
parents:
181
diff
changeset
|
232 path.lastIndexOf(".")); |
c79c3c6fc99a
Always save a symbol set, use the mapfile name as prefix for the symbol set and
raimund renkert <raimund.renkert@intevation.de>
parents:
181
diff
changeset
|
233 String symbolPath = filename + "-symbols.sym"; |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
234 if(path.equals("")) { |
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
235 return; |
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
236 } |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
237 |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
238 if (path.endsWith(".map")) { |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
239 path = path.substring(0, path.lastIndexOf(File.separator) + 1); |
175
f11d13940626
Handle symbol set and font set paths.
raimund renkert <raimund.renkert@intevation.de>
parents:
174
diff
changeset
|
240 path += symbolPath; |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
241 } |
93
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
242 else { |
175
f11d13940626
Handle symbol set and font set paths.
raimund renkert <raimund.renkert@intevation.de>
parents:
174
diff
changeset
|
243 path += symbolPath; |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
244 } |
175
f11d13940626
Handle symbol set and font set paths.
raimund renkert <raimund.renkert@intevation.de>
parents:
174
diff
changeset
|
245 path = path.replaceAll("\\\\", "/"); |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
246 symbols.save(path); |
184
c79c3c6fc99a
Always save a symbol set, use the mapfile name as prefix for the symbol set and
raimund renkert <raimund.renkert@intevation.de>
parents:
181
diff
changeset
|
247 this.map.setSymbolSet(path); |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
248 } |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
249 |
181 | 250 /** |
251 * Determine whether the symbol exists. | |
252 * | |
253 * @param elem DOM element containing the symbol attributes. | |
254 * | |
255 * @return Returns the symbol index if the symbol exists, else returns -1. | |
256 */ | |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
257 private int symbolExists (Element elem) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
258 symbolSetObj symbolSet = map.getSymbolset(); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
259 for (int i = 0; i < symbolSet.getNumsymbols(); i++) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
260 symbolObj sym = symbolSet.getSymbol(i); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
261 int stype = sym.getType(); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
262 String etype = elem.getAttribute("style"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
263 if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_ELLIPSE.swigValue () && |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
264 etype.equals("point")) { |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
265 return i; |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
266 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
267 else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_VECTOR.swigValue () && |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
268 etype.equals("arrow")) { |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
269 return i; |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
270 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
271 else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_TRUETYPE.swigValue () && |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
272 etype.equals("char")) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
273 String font = elem.getAttribute("font"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
274 font = font.replaceAll(" ", ""); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
275 String c = elem.getAttribute("char"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
276 c = "&#" + c + ";"; |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
277 if (font.equals(sym.getFont()) && |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
278 c.equals(sym.getCharacter())) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
279 return i; |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
280 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
281 |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
282 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
283 else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_HATCH.swigValue () && |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
284 etype.equals("hatch")) { |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
285 return i; |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
286 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
287 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
288 return -1; |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
289 } |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
290 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
291 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |