Mercurial > mxd2map
annotate src/java/de/intevation/mxd/writer/SymbolWriter.java @ 353:0b0ed5e98361
Fix repository urls on development page
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Thu, 06 Feb 2014 17:20:54 +0100 |
parents | 2cb2f26d0d54 |
children |
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.symbolObj; |
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.symbolSetObj; |
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.lineObj; |
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.pointObj; |
192
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
32 import edu.umn.gis.mapscript.fontSetObj; |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
33 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
|
34 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
|
35 |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
36 import java.io.File; |
251
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
37 import java.awt.Image; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
38 import java.awt.image.BufferedImage; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
39 import java.awt.image.FilteredImageSource; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
40 import java.awt.image.ImageFilter; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
41 import java.awt.image.ImageProducer; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
42 import java.awt.image.RGBImageFilter; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
43 import java.awt.Toolkit; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
44 import java.awt.Color; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
45 import java.awt.Graphics2D; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
46 import javax.imageio.ImageIO; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
47 import java.io.ByteArrayInputStream; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
48 |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
49 import org.apache.commons.codec.binary.Base64; |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
50 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
51 /** |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
52 * 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
|
53 * |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
54 * @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
|
55 */ |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
56 public class SymbolWriter { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
57 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
58 /** |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
59 * The Logger. |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
60 */ |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
61 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
|
62 |
181 | 63 /** |
64 * Private member. | |
65 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
66 private mapObj map; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
67 private classObj cl; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
68 |
181 | 69 /** |
70 * Contructor with map object and class object. | |
71 * | |
72 * @param map The map object. | |
73 * @param cl The class object containing the style. | |
74 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
75 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
|
76 this.map = map; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
77 this.cl = cl; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
78 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
79 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
80 /** |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
81 * Write the content. |
181 | 82 * |
83 * @param symbolElement DOM element containg the style and symbol | |
84 * attributes. | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
85 */ |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
86 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
|
87 logger.debug("write(Element)"); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
88 symbolSetObj symbolSet = map.getSymbolset(); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
89 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
90 String symType = symbolElement.getAttribute("style"); |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
91 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
|
92 if(symType.equals("point")) { |
251
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
93 String name = symbolElement.getAttribute("name"); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
94 symbolObj sym = symbolSet.getSymbolByName(name); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
95 writeSimple(sym); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
96 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
97 else if (symType.equals("arrow")) { |
251
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
98 String name = symbolElement.getAttribute("name"); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
99 symbolObj sym = symbolSet.getSymbolByName(name); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
100 writeArrow(sym, symbolElement); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
101 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
102 else if (symType.equals("char")) { |
251
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
103 String name = symbolElement.getAttribute("name"); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
104 symbolObj sym = symbolSet.getSymbolByName(name); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
105 |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
106 int exists = symbolExists(symbolElement); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
107 if(exists == -1) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
108 String old = symbolElement.getAttribute("name"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
109 symbolElement.setAttribute( |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
110 "name", |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
111 old + symbolSet.getNumsymbols() + 1); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
112 writeCharacter(sym, symbolElement); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
113 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
114 else { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
115 symbolElement.setAttribute( |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
116 "name", |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
117 symbolSet.getSymbol(exists).getName()); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
118 } |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
119 } |
251
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
120 else if (type.equals("line") && !symType.equals("picture")) { |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
121 String name = symbolElement.getAttribute("name"); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
122 symbolObj sym = symbolSet.getSymbolByName(name); |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
123 writeHatch(sym); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
124 } |
251
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
125 else if(symType.equals("picture")) { |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
126 // Create the path to the picture. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
127 int exists = symbolExists(symbolElement); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
128 String n = symbolElement.getAttribute("name"); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
129 symbolElement.setAttribute( |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
130 "name", |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
131 n + symbolSet.getNumsymbols() + 1); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
132 String path = this.map.getMappath(); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
133 if (path.endsWith(".map")) { |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
134 path = path.substring(0, path.lastIndexOf(File.separator) + 1); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
135 path += symbolElement.getAttribute("name") + ".png"; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
136 } |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
137 else { |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
138 path += symbolElement.getAttribute("name") + ".png"; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
139 } |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
140 // Create a new symbol using the path as symbol name. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
141 // This is a workarround to set the IMAGE attribute to the path |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
142 // since this attribute is immutable via mapscript. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
143 symbolObj sym = symbolSet.getSymbolByName(path); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
144 writePicture(sym, symbolElement, path); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
145 } |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
146 else { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
147 return false; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
148 } |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
149 |
120
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
150 try { |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
151 saveSymbolSet(symbolSet); |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
152 } |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
153 catch(Exception e) { |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
154 logger.error("Error saving symbol set."); |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
155 return false; |
11d63bf00326
Changed exception handling and logging in writer classes.
Raimund Renkert <rrenkert@intevation.de>
parents:
97
diff
changeset
|
156 } |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
157 |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
158 return true; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
159 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
160 |
181 | 161 /** |
162 * Create a simple point symbol. | |
163 * | |
164 * @param symbol The symbol object. | |
165 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
166 private void writeSimple(symbolObj symbol) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
167 logger.debug("writeSimple(symbolObj)"); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
168 lineObj points = new lineObj(); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
169 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
|
170 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
|
171 symbol.setPoints(points); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
172 symbol.setFilled(1); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
173 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
174 |
181 | 175 /** |
176 * Create an arrow symbol. | |
177 * | |
178 * @param symbol The symbol object. | |
179 * @param symbolElement DOM element containing symbol attributes. | |
180 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
181 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
|
182 logger.debug("writeArrow(symbolObj, Element)"); |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
183 double len = 0; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
184 double width = 1; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
185 try { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
186 len = |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
187 Double.parseDouble(symbolElement.getAttribute("length")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
188 width = |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
189 Double.parseDouble(symbolElement.getAttribute("width")); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
190 } |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
191 catch(NumberFormatException nfe) { |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
192 logger.warn ("Error setting arrow symbol."); |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
193 return; |
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
194 } |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
195 double ratio = len/width; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
196 lineObj points = new lineObj(); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
197 |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
198 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
|
199 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
|
200 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
|
201 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
|
202 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
|
203 symbol.setPoints(points); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
204 symbol.setFilled(1); |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
205 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
206 |
181 | 207 /** |
208 * Create a character marker symbol. | |
209 * | |
210 * @param symbol The symbol object. | |
211 * @param symbolElement DOM element containing symbol attributes. | |
212 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 //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
|
217 font = font.replaceAll(" ", ""); |
192
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
218 fontSetObj fso = this.map.getFontset(); |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
219 hashTableObj fonts = fso.getFonts(); |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
220 String mapFont = fonts.get(font,""); |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
221 if (mapFont == null || mapFont.equals("")) { |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
222 logger.warn( |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
223 "Could not find font " + font + " in font set. " + |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
224 "Setting FreeSans as symbol font." + |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
225 "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
|
226 "in symbol \"" + symbolElement.getAttribute("name") + "\"."); |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
227 font = "FreeSans"; |
0dc34dcdaedc
Lookup symbol font in fontset.
raimund renkert <raimund.renkert@intevation.de>
parents:
184
diff
changeset
|
228 } |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
229 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
|
230 symbol.setFont(font); |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
231 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
|
232 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
|
233 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
|
234 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
235 |
251
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
236 |
181 | 237 /** |
251
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
238 * Create the image and a pixmap symbol. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
239 * |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
240 * @param sym The symbol object. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
241 * @param symElem The DOM element containing symbol informations. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
242 */ |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
243 private void writePicture(symbolObj sym, Element symElem, String path) { |
254
8e5d67c45b64
Changed logging from info to debug in writePicture.
raimund renkert <raimund.renkert@intevation.de>
parents:
251
diff
changeset
|
244 logger.debug("writePicture(symbolObj, Element)"); |
251
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
245 try { |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
246 // Create the image as png. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
247 if(symElem.hasAttribute("picture")) { |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
248 Base64 decoder = new Base64(); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
249 // Decode the base64 string. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
250 byte[] ba = decoder.decode(symElem.getAttribute("picture")); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
251 ByteArrayInputStream ins = new ByteArrayInputStream(ba); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
252 // Create temporary image from byte array. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
253 BufferedImage bi = ImageIO.read(ins); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
254 Color c = Color.decode( |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
255 symElem.getAttribute("transparent_color")); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
256 // Make a color transparent. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
257 Image im = colorToTransparent(bi, c); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
258 |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
259 // Save image as png. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
260 BufferedImage dest = new BufferedImage( |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
261 bi.getWidth(), |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
262 bi.getHeight(), |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
263 BufferedImage.TYPE_INT_ARGB); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
264 Graphics2D g2 = dest.createGraphics(); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
265 g2.drawImage(im, 0, 0, null); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
266 g2.dispose(); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
267 File f = new File(path); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
268 ImageIO.write(dest, "PNG", f); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
269 } |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
270 // Set symbol attributes. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
271 // Overwrite the symbol name conating the path to the image |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
272 // with the real name. This is part of the workarround(line 137). |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
273 sym.setName(symElem.getAttribute("name")); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
274 sym.setType(MS_SYMBOL_TYPE.MS_SYMBOL_PIXMAP.swigValue()); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
275 } |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
276 catch(Exception e) { |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
277 logger.warn("Could not save image for pixmap symbol."); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
278 } |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
279 } |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
280 |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
281 |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
282 /** |
181 | 283 * Create a hatch symbol for polygon fill. |
284 * | |
285 * @param symbol The symbol object. | |
286 */ | |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
287 private void writeHatch(symbolObj symbol) { |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
288 logger.debug("writeHatch(symbolObj)"); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
289 symbol.setType(MS_SYMBOL_TYPE.MS_SYMBOL_HATCH.swigValue()); |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
290 } |
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
291 |
181 | 292 /** |
293 * Determine whether this writer can create the symbol. | |
294 * | |
295 * @param type The symbol type. | |
296 */ | |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
297 public boolean canWrite(String type) { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
298 if (type.equals("point") || |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
299 type.equals("arrow") || |
97
18e4f143896b
Added polygon writer.
Raimund Renkert <rrenkert@intevation.de>
parents:
96
diff
changeset
|
300 type.equals("char") || |
251
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
301 type.equals("line") || |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
302 type.equals("picture")) { |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
303 return true; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
304 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
305 else { |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
306 return false; |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
307 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
308 } |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
309 |
181 | 310 /** |
311 * Save the symbol set. | |
312 * | |
313 * @param symbols The symbol set object. | |
314 */ | |
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
|
315 public void saveSymbolSet(symbolSetObj symbols) |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
316 throws Exception { |
93
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 String symbolPath = filename + "-symbols.sym"; |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
321 if(path.equals("")) { |
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
322 return; |
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
323 } |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
324 |
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
325 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
|
326 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
|
327 path += symbolPath; |
174
707f13cfba74
Improved the commandline arguments and save the mapfile in the correct directory.
raimund.renkert@intevation.de
parents:
145
diff
changeset
|
328 } |
93
3993b5adf67c
Write the character symbol correctly to the mapfile and the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
90
diff
changeset
|
329 else { |
175
f11d13940626
Handle symbol set and font set paths.
raimund renkert <raimund.renkert@intevation.de>
parents:
174
diff
changeset
|
330 path += symbolPath; |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
331 } |
175
f11d13940626
Handle symbol set and font set paths.
raimund renkert <raimund.renkert@intevation.de>
parents:
174
diff
changeset
|
332 path = path.replaceAll("\\\\", "/"); |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
333 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
|
334 this.map.setSymbolSet(path); |
90
82a1f39214fd
Added method to save the symbolset.
Raimund Renkert <rrenkert@intevation.de>
parents:
87
diff
changeset
|
335 } |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
336 |
181 | 337 /** |
338 * Determine whether the symbol exists. | |
339 * | |
340 * @param elem DOM element containing the symbol attributes. | |
341 * | |
342 * @return Returns the symbol index if the symbol exists, else returns -1. | |
343 */ | |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
344 private int symbolExists (Element elem) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
345 symbolSetObj symbolSet = map.getSymbolset(); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
346 for (int i = 0; i < symbolSet.getNumsymbols(); i++) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
347 symbolObj sym = symbolSet.getSymbol(i); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
348 int stype = sym.getType(); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
349 String etype = elem.getAttribute("style"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
350 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
|
351 etype.equals("point")) { |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
352 return i; |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
353 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
354 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
|
355 etype.equals("arrow")) { |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
356 return i; |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
357 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
358 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
|
359 etype.equals("char")) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
360 String font = elem.getAttribute("font"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
361 font = font.replaceAll(" ", ""); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
362 String c = elem.getAttribute("char"); |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
363 c = "&#" + c + ";"; |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
364 if (font.equals(sym.getFont()) && |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
365 c.equals(sym.getCharacter())) { |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
366 return i; |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
367 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
368 |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
369 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
370 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
|
371 etype.equals("hatch")) { |
145
b2c5a66022f1
Exception handling for number conversions in writer modules.
Raimund Renkert <rrenkert@intevation.de>
parents:
141
diff
changeset
|
372 return i; |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
373 } |
251
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
374 else if(stype == MS_SYMBOL_TYPE.MS_SYMBOL_PIXMAP.swigValue() && |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
375 etype.equals("picture")) { |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
376 return i; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
377 } |
141
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
378 } |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
379 return -1; |
8f30f7e802d6
Manage symbol names and symbol comparison.
vc11884admin@VC11884.win.bsh.de
parents:
120
diff
changeset
|
380 } |
251
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
381 |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
382 |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
383 /** |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
384 * Transform a color to transparency. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
385 * |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
386 * @param bi The image. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
387 * @param col the color. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
388 * |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
389 * @return The image with transparent color. |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
390 */ |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
391 private Image colorToTransparent(BufferedImage bi, Color col) { |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
392 final int markerRGB = col.getRGB() | 0xFF000000; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
393 ImageFilter filter = new RGBImageFilter() { |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
394 public final int filterRGB(int x, int y, int rgb) { |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
395 if ((rgb | 0xFF000000) == markerRGB) { |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
396 // Mark the alpha bits as zero - transparent |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
397 return 0x00FFFFFF & rgb; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
398 } |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
399 else { |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
400 // nothing to do |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
401 return rgb; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
402 } |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
403 } |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
404 }; |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
405 ImageProducer ip = new FilteredImageSource(bi.getSource(), filter); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
406 return Toolkit.getDefaultToolkit().createImage(ip); |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
407 } |
6b80e46b8f38
Added picture symbol support to the converter.
raimund renkert <raimund.renkert@intevation.de>
parents:
243
diff
changeset
|
408 |
87
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
409 } |
7d4cf2db43f1
Added new writer classes to be flexible in creating mapfiles.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff
changeset
|
410 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |