Revision 438
org.gvsig.sld/tags/org.gvsig.sld-2.0.79/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<artifactId>org.gvsig.sldconverter.lib.impl</artifactId> |
|
5 |
<packaging>jar</packaging> |
|
6 |
<name>${project.artifactId}</name> |
|
7 |
<parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.sldconverter.lib</artifactId> |
|
10 |
<version>2.0.79</version> |
|
11 |
</parent> |
|
12 |
|
|
13 |
<dependencies> |
|
14 |
|
|
15 |
<dependency> |
|
16 |
<groupId>org.gvsig</groupId> |
|
17 |
<artifactId>org.gvsig.sldconverter.lib.api</artifactId> |
|
18 |
<scope>compile</scope> |
|
19 |
</dependency> |
|
20 |
|
|
21 |
<dependency> |
|
22 |
<groupId>org.gvsig</groupId> |
|
23 |
<artifactId>org.gvsig.sldsupport.lib.api</artifactId> |
|
24 |
<scope>compile</scope> |
|
25 |
</dependency> |
|
26 |
<dependency> |
|
27 |
<groupId>org.gvsig</groupId> |
|
28 |
<artifactId>org.gvsig.symbology.lib.api</artifactId> |
|
29 |
<scope>compile</scope> |
|
30 |
</dependency> |
|
31 |
<dependency> |
|
32 |
<groupId>org.gvsig</groupId> |
|
33 |
<artifactId>org.gvsig.fmap.mapcontext.api</artifactId> |
|
34 |
<scope>compile</scope> |
|
35 |
</dependency> |
|
36 |
|
|
37 |
</dependencies> |
|
38 |
|
|
39 |
|
|
40 |
<build> |
|
41 |
|
|
42 |
<resources> |
|
43 |
<resource> |
|
44 |
<!-- |
|
45 |
<targetPath>org/gvsig/gui/beans/resources/translations</targetPath> |
|
46 |
<filtering>false</filtering> |
|
47 |
--> |
|
48 |
<directory>src/main/resources</directory> |
|
49 |
<!-- |
|
50 |
<includes> |
|
51 |
<include>**/*.png</include> |
|
52 |
<include>**/*.png</include> |
|
53 |
</includes> |
|
54 |
--> |
|
55 |
</resource> |
|
56 |
</resources> |
|
57 |
|
|
58 |
|
|
59 |
<plugins> |
|
60 |
|
|
61 |
<!-- Skip compilation tests |
|
62 |
<plugin> |
|
63 |
<groupId>org.apache.maven.plugins</groupId> |
|
64 |
<artifactId>maven-compiler-plugin</artifactId> |
|
65 |
<executions> |
|
66 |
<execution> |
|
67 |
<id>default-testCompile</id> |
|
68 |
<phase>process-test-sources</phase> |
|
69 |
<goals> |
|
70 |
<goal>testCompile</goal> |
|
71 |
</goals> |
|
72 |
<configuration> |
|
73 |
<skip>true</skip> |
|
74 |
</configuration> |
|
75 |
</execution> |
|
76 |
</executions> |
|
77 |
</plugin> |
|
78 |
--> |
|
79 |
|
|
80 |
<!-- TODO: MAKE TESTS WORK AND REMOVE THIS OPTION --> |
|
81 |
|
|
82 |
<!-- |
|
83 |
<plugin> |
|
84 |
<groupId>org.apache.maven.plugins</groupId> |
|
85 |
<artifactId>maven-surefire-plugin</artifactId> |
|
86 |
<configuration> |
|
87 |
<skipTests>true</skipTests> |
|
88 |
</configuration> |
|
89 |
</plugin> |
|
90 |
--> |
|
91 |
|
|
92 |
</plugins> |
|
93 |
|
|
94 |
</build> |
|
95 |
</project> |
|
96 |
|
|
97 |
|
org.gvsig.sld/tags/org.gvsig.sld-2.0.79/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.sldconverter.impl.SLDConverterDefaultLibrary |
org.gvsig.sld/tags/org.gvsig.sld-2.0.79/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/SLDConverterDefaultLibrary.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
2 |
* |
|
3 |
* gvSIG. Desktop Geographic Information System. |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
6 |
* |
|
7 |
* This program is free software; you can redistribute it and/or |
|
8 |
* modify it under the terms of the GNU General Public License |
|
9 |
* as published by the Free Software Foundation; either version 3 |
|
10 |
* of the License, or (at your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, |
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
* GNU General Public License for more details. |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License |
|
18 |
* along with this program; if not, write to the Free Software |
|
19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
20 |
* MA 02110-1301, USA. |
|
21 |
* |
|
22 |
* For any additional information, do not hesitate to contact us |
|
23 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
24 |
* |
|
25 |
*******************************************************************************/ |
|
26 |
package org.gvsig.sldconverter.impl; |
|
27 |
|
|
28 |
import org.gvsig.sldconverter.SLDConverterLibrary; |
|
29 |
import org.gvsig.sldconverter.SLDConverterLocator; |
|
30 |
import org.gvsig.sldconverter.SLDConverterManager; |
|
31 |
import org.gvsig.sldconverter.impl.legend.BasicLegendConverterFactory; |
|
32 |
import org.gvsig.sldconverter.impl.symbol.BasicSymbolConverterFactory; |
|
33 |
import org.gvsig.tools.library.AbstractLibrary; |
|
34 |
import org.gvsig.tools.library.LibraryException; |
|
35 |
|
|
36 |
public class SLDConverterDefaultLibrary extends AbstractLibrary { |
|
37 |
|
|
38 |
public void doRegistration() { |
|
39 |
registerAsImplementationOf(SLDConverterLibrary.class); |
|
40 |
} |
|
41 |
|
|
42 |
protected void doInitialize() throws LibraryException { |
|
43 |
|
|
44 |
SLDConverterLocator.getInstance().registerSLDConverterManager( |
|
45 |
DefaultSLDConverterManager.class); |
|
46 |
|
|
47 |
} |
|
48 |
|
|
49 |
|
|
50 |
protected void doPostInitialize() throws LibraryException { |
|
51 |
|
|
52 |
SLDConverterManager mana = |
|
53 |
SLDConverterLocator.getInstance().getSLDConverterManager(); |
|
54 |
|
|
55 |
/* |
|
56 |
* Register conversors... |
|
57 |
*/ |
|
58 |
BasicLegendConverterFactory basicLegConvFact = new BasicLegendConverterFactory(); |
|
59 |
mana.registerSLDToLegendConverter(basicLegConvFact); |
|
60 |
mana.registerLegendToSLDConverter(basicLegConvFact); |
|
61 |
|
|
62 |
BasicSymbolConverterFactory basicSymConvFact = new BasicSymbolConverterFactory(); |
|
63 |
mana.registerSLDToSymbolConverter(basicSymConvFact); |
|
64 |
mana.registerSymbolToSLDConverter(basicSymConvFact); |
|
65 |
|
|
66 |
} |
|
67 |
|
|
68 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.79/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/symbol/LineSymbolUtils.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
2 |
* |
|
3 |
* gvSIG. Desktop Geographic Information System. |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
6 |
* |
|
7 |
* This program is free software; you can redistribute it and/or |
|
8 |
* modify it under the terms of the GNU General Public License |
|
9 |
* as published by the Free Software Foundation; either version 3 |
|
10 |
* of the License, or (at your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, |
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
* GNU General Public License for more details. |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License |
|
18 |
* along with this program; if not, write to the Free Software |
|
19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
20 |
* MA 02110-1301, USA. |
|
21 |
* |
|
22 |
* For any additional information, do not hesitate to contact us |
|
23 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
24 |
* |
|
25 |
*******************************************************************************/ |
|
26 |
package org.gvsig.sldconverter.impl.symbol; |
|
27 |
|
|
28 |
import java.awt.Color; |
|
29 |
|
|
30 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
31 |
import org.gvsig.sldconverter.exception.UnsupportedSymbolException; |
|
32 |
import org.gvsig.sldconverter.impl.util.BasicUtils; |
|
33 |
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException; |
|
34 |
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDLiteral; |
|
35 |
import org.gvsig.sldsupport.sld.symbol.SLDLineSymbol; |
|
36 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDStroke; |
|
37 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
38 |
|
|
39 |
public class LineSymbolUtils { |
|
40 |
|
|
41 |
public static ISymbol toLineSymbol(SLDLineSymbol sym) |
|
42 |
throws UnsupportedSLDObjectException { |
|
43 |
|
|
44 |
ILineSymbol resp = BasicUtils.symMan().createSimpleLineSymbol(); |
|
45 |
SLDStroke stro = sym.getStroke(); |
|
46 |
|
|
47 |
Color col = BasicUtils.toColor(stro.getColor()); |
|
48 |
if (col != null) { |
|
49 |
resp.setColor(col); |
|
50 |
} |
|
51 |
Double wi = BasicUtils.toDouble(stro.getWidth()); |
|
52 |
if (wi != null) { |
|
53 |
resp.setLineWidth(wi); |
|
54 |
} |
|
55 |
return resp; |
|
56 |
} |
|
57 |
|
|
58 |
|
|
59 |
public static SLDLineSymbol toSLDLineSymbol(ILineSymbol sym) |
|
60 |
throws UnsupportedSymbolException { |
|
61 |
|
|
62 |
Color bcolor = sym.getColor(); |
|
63 |
double bw = sym.getLineWidth(); |
|
64 |
|
|
65 |
SLDStroke stro = new SLDStroke(); |
|
66 |
stro.setColor(bcolor); |
|
67 |
stro.setWidth(new SLDLiteral(BasicUtils.df.format(bw))); |
|
68 |
|
|
69 |
SLDLineSymbol resp = new SLDLineSymbol(); |
|
70 |
resp.setStroke(stro); |
|
71 |
return resp; |
|
72 |
} |
|
73 |
|
|
74 |
|
|
75 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.79/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/symbol/PolygonSymbolUtils.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
2 |
* |
|
3 |
* gvSIG. Desktop Geographic Information System. |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
6 |
* |
|
7 |
* This program is free software; you can redistribute it and/or |
|
8 |
* modify it under the terms of the GNU General Public License |
|
9 |
* as published by the Free Software Foundation; either version 3 |
|
10 |
* of the License, or (at your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, |
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
* GNU General Public License for more details. |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License |
|
18 |
* along with this program; if not, write to the Free Software |
|
19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
20 |
* MA 02110-1301, USA. |
|
21 |
* |
|
22 |
* For any additional information, do not hesitate to contact us |
|
23 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
24 |
* |
|
25 |
*******************************************************************************/ |
|
26 |
package org.gvsig.sldconverter.impl.symbol; |
|
27 |
|
|
28 |
import java.awt.Color; |
|
29 |
|
|
30 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
31 |
import org.gvsig.sldconverter.exception.UnsupportedSymbolException; |
|
32 |
import org.gvsig.sldconverter.impl.util.BasicUtils; |
|
33 |
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException; |
|
34 |
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDLiteral; |
|
35 |
import org.gvsig.sldsupport.sld.graphic.SLDGraphic; |
|
36 |
import org.gvsig.sldsupport.sld.symbol.SLDPolygonSymbol; |
|
37 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDFill; |
|
38 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDStroke; |
|
39 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
|
40 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IPictureFillSymbol; |
|
41 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.ISimpleFillSymbol; |
|
42 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IPictureMarkerSymbol; |
|
43 |
|
|
44 |
public class PolygonSymbolUtils { |
|
45 |
|
|
46 |
public static ISymbol toFillSymbol(SLDPolygonSymbol sym) |
|
47 |
throws UnsupportedSLDObjectException { |
|
48 |
|
|
49 |
ISimpleFillSymbol resp = BasicUtils.symMan().createSimpleFillSymbol(); |
|
50 |
SLDFill fill = sym.getFill(); |
|
51 |
SLDGraphic gra = fill.getFillGraphic(); |
|
52 |
SLDStroke stro = sym.getStroke(); |
|
53 |
|
|
54 |
Color borderColor = null; |
|
55 |
Double borderWidth = null; |
|
56 |
|
|
57 |
if (gra == null) { |
|
58 |
// Solid fill |
|
59 |
Color aux_co = BasicUtils.toColor(fill.getFillColor()); |
|
60 |
if (aux_co != null) { |
|
61 |
resp.setFillColor(aux_co); |
|
62 |
} |
|
63 |
borderColor = BasicUtils.toColor(stro.getColor()); |
|
64 |
if (borderColor != null) { |
|
65 |
resp.getOutline().setColor(borderColor); |
|
66 |
} |
|
67 |
borderWidth = BasicUtils.toDouble(stro.getWidth()); |
|
68 |
if (borderWidth != null) { |
|
69 |
resp.getOutline().setLineWidth(borderWidth.doubleValue()); |
|
70 |
} |
|
71 |
return resp; |
|
72 |
|
|
73 |
} else { |
|
74 |
|
|
75 |
ISymbol aux = PointSymbolUtils.toMarkerSymbol(gra); |
|
76 |
if (aux instanceof IPictureMarkerSymbol) { |
|
77 |
IPictureMarkerSymbol pms = (IPictureMarkerSymbol) aux; |
|
78 |
IPictureFillSymbol pfs = null; |
|
79 |
try { |
|
80 |
pfs = BasicUtils.symMan().createPictureFillSymbol( |
|
81 |
pms.getSource(), pms.getSelectedSource()); |
|
82 |
} catch (Exception exc) { |
|
83 |
throw new UnsupportedSLDObjectException( |
|
84 |
exc, |
|
85 |
"SLDPolygonSymbol", |
|
86 |
"This type of grachic not supported as fill graphic: " |
|
87 |
+ aux.getClass().getName()); |
|
88 |
} |
|
89 |
return pfs; |
|
90 |
} else { |
|
91 |
throw new UnsupportedSLDObjectException( |
|
92 |
"SLDPolygonSymbol", |
|
93 |
"This type of grachic not supported as fill graphic: " |
|
94 |
+ aux.getClass().getName()); |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
public static SLDPolygonSymbol toSLDPolygonSymbol(IFillSymbol sym) |
|
102 |
throws UnsupportedSymbolException { |
|
103 |
|
|
104 |
Color color = sym.getOutline().getColor(); |
|
105 |
double w = sym.getOutline().getLineWidth(); |
|
106 |
SLDStroke stro = new SLDStroke(); |
|
107 |
if (color != null) { |
|
108 |
stro.setColor(color); |
|
109 |
} |
|
110 |
stro.setWidth(new SLDLiteral(BasicUtils.df.format(w))); |
|
111 |
// ================= |
|
112 |
color = sym.getColor(); |
|
113 |
SLDFill fill = new SLDFill(); |
|
114 |
if (color != null) { |
|
115 |
fill.setFillColor(color); |
|
116 |
} |
|
117 |
// ================= |
|
118 |
SLDPolygonSymbol resp = new SLDPolygonSymbol(); |
|
119 |
resp.setFill(fill); |
|
120 |
resp.setStroke(stro); |
|
121 |
return resp; |
|
122 |
} |
|
123 |
|
|
124 |
|
|
125 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.79/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/symbol/BasicSymbolConverter.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
2 |
* |
|
3 |
* gvSIG. Desktop Geographic Information System. |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
6 |
* |
|
7 |
* This program is free software; you can redistribute it and/or |
|
8 |
* modify it under the terms of the GNU General Public License |
|
9 |
* as published by the Free Software Foundation; either version 3 |
|
10 |
* of the License, or (at your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, |
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
* GNU General Public License for more details. |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License |
|
18 |
* along with this program; if not, write to the Free Software |
|
19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
20 |
* MA 02110-1301, USA. |
|
21 |
* |
|
22 |
* For any additional information, do not hesitate to contact us |
|
23 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
24 |
* |
|
25 |
*******************************************************************************/ |
|
26 |
package org.gvsig.sldconverter.impl.symbol; |
|
27 |
|
|
28 |
import java.util.ArrayList; |
|
29 |
import java.util.List; |
|
30 |
|
|
31 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
32 |
import org.gvsig.sldconverter.exception.UnsupportedSymbolException; |
|
33 |
import org.gvsig.sldconverter.symbol.SLDToSymbolConverter; |
|
34 |
import org.gvsig.sldconverter.symbol.SymbolToSLDConverter; |
|
35 |
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException; |
|
36 |
import org.gvsig.sldsupport.sld.symbol.SLDLineSymbol; |
|
37 |
import org.gvsig.sldsupport.sld.symbol.SLDPointSymbol; |
|
38 |
import org.gvsig.sldsupport.sld.symbol.SLDPolygonSymbol; |
|
39 |
import org.gvsig.sldsupport.sld.symbol.SLDSymbol; |
|
40 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
|
41 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IMultiLayerFillSymbol; |
|
42 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
43 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.IMultiLayerLineSymbol; |
|
44 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
|
45 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMultiLayerMarkerSymbol; |
|
46 |
|
|
47 |
public class BasicSymbolConverter |
|
48 |
implements SymbolToSLDConverter, SLDToSymbolConverter { |
|
49 |
|
|
50 |
public ISymbol convert(SLDSymbol sldSym) throws UnsupportedSLDObjectException { |
|
51 |
|
|
52 |
if (sldSym == null) { |
|
53 |
throw new UnsupportedSLDObjectException("SLDSymbol", "Null"); |
|
54 |
} |
|
55 |
|
|
56 |
if (sldSym instanceof SLDPointSymbol) { |
|
57 |
return PointSymbolUtils.toMarkerSymbol((SLDPointSymbol) sldSym); |
|
58 |
} else { |
|
59 |
if (sldSym instanceof SLDLineSymbol) { |
|
60 |
return LineSymbolUtils.toLineSymbol((SLDLineSymbol) sldSym); |
|
61 |
} else { |
|
62 |
if (sldSym instanceof SLDPolygonSymbol) { |
|
63 |
return PolygonSymbolUtils.toFillSymbol((SLDPolygonSymbol) sldSym); |
|
64 |
} else { |
|
65 |
throw new UnsupportedSLDObjectException("SLDSymbol", |
|
66 |
"Unexpected class: " + sldSym.getClass().getName()); |
|
67 |
} |
|
68 |
} |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
public SLDSymbol convert(ISymbol sym) throws UnsupportedSymbolException { |
|
73 |
|
|
74 |
List<SLDSymbol> list = toSLDSymbol(sym); |
|
75 |
if (list == null || list.size() < 1) { |
|
76 |
throw new UnsupportedSymbolException( |
|
77 |
sym == null ? "Null" : sym.getClass().getName(), |
|
78 |
"Unsupported symbol"); |
|
79 |
} else { |
|
80 |
/* |
|
81 |
* TODO think how to improve this |
|
82 |
*/ |
|
83 |
return list.get(0); |
|
84 |
} |
|
85 |
} |
|
86 |
|
|
87 |
|
|
88 |
private List<SLDSymbol> toSLDSymbol(ISymbol sym) |
|
89 |
throws UnsupportedSymbolException { |
|
90 |
|
|
91 |
List<SLDSymbol> resp = new ArrayList<SLDSymbol>(); |
|
92 |
if (sym instanceof IMultiLayerFillSymbol) { |
|
93 |
IMultiLayerFillSymbol aux = (IMultiLayerFillSymbol) sym; |
|
94 |
for (int i=0; i<aux.getLayerCount(); i++) { |
|
95 |
resp.addAll(toSLDSymbol(aux.getLayer(i))); |
|
96 |
} |
|
97 |
return resp; |
|
98 |
} |
|
99 |
if (sym instanceof IMultiLayerLineSymbol) { |
|
100 |
IMultiLayerLineSymbol aux = (IMultiLayerLineSymbol) sym; |
|
101 |
for (int i=0; i<aux.getLayerCount(); i++) { |
|
102 |
resp.addAll(toSLDSymbol(aux.getLayer(i))); |
|
103 |
} |
|
104 |
return resp; |
|
105 |
} |
|
106 |
if (sym instanceof IMultiLayerMarkerSymbol) { |
|
107 |
IMultiLayerMarkerSymbol aux = (IMultiLayerMarkerSymbol) sym; |
|
108 |
for (int i=0; i<aux.getLayerCount(); i++) { |
|
109 |
resp.addAll(toSLDSymbol(aux.getLayer(i))); |
|
110 |
} |
|
111 |
return resp; |
|
112 |
} |
|
113 |
// ==================================================== |
|
114 |
if (sym instanceof IFillSymbol) { |
|
115 |
resp.add(PolygonSymbolUtils.toSLDPolygonSymbol((IFillSymbol) sym)); |
|
116 |
return resp; |
|
117 |
} |
|
118 |
if (sym instanceof ILineSymbol) { |
|
119 |
resp.add(LineSymbolUtils.toSLDLineSymbol((ILineSymbol) sym)); |
|
120 |
return resp; |
|
121 |
} |
|
122 |
if (sym instanceof IMarkerSymbol) { |
|
123 |
resp.add(PointSymbolUtils.toSLDPointSymbol((IMarkerSymbol) sym)); |
|
124 |
return resp; |
|
125 |
} |
|
126 |
// ==================== |
|
127 |
throw new UnsupportedSymbolException( |
|
128 |
sym == null ? "Null" : sym.getClass().getName(), |
|
129 |
"Unsupported symbol"); |
|
130 |
} |
|
131 |
|
|
132 |
|
|
133 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.79/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/symbol/PointSymbolUtils.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
2 |
* |
|
3 |
* gvSIG. Desktop Geographic Information System. |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
6 |
* |
|
7 |
* This program is free software; you can redistribute it and/or |
|
8 |
* modify it under the terms of the GNU General Public License |
|
9 |
* as published by the Free Software Foundation; either version 3 |
|
10 |
* of the License, or (at your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, |
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
* GNU General Public License for more details. |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License |
|
18 |
* along with this program; if not, write to the Free Software |
|
19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
20 |
* MA 02110-1301, USA. |
|
21 |
* |
|
22 |
* For any additional information, do not hesitate to contact us |
|
23 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
24 |
* |
|
25 |
*******************************************************************************/ |
|
26 |
package org.gvsig.sldconverter.impl.symbol; |
|
27 |
|
|
28 |
import java.awt.Color; |
|
29 |
import java.net.URL; |
|
30 |
import java.util.List; |
|
31 |
|
|
32 |
import org.gvsig.fmap.geom.Geometry; |
|
33 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
|
34 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
35 |
import org.gvsig.sldconverter.exception.UnsupportedSymbolException; |
|
36 |
import org.gvsig.sldconverter.impl.util.BasicUtils; |
|
37 |
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException; |
|
38 |
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDLiteral; |
|
39 |
import org.gvsig.sldsupport.sld.graphic.SLDExternalGraphic; |
|
40 |
import org.gvsig.sldsupport.sld.graphic.SLDGraphic; |
|
41 |
import org.gvsig.sldsupport.sld.graphic.SLDGraphicStackElement; |
|
42 |
import org.gvsig.sldsupport.sld.graphic.SLDMark; |
|
43 |
import org.gvsig.sldsupport.sld.symbol.SLDPointSymbol; |
|
44 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDFill; |
|
45 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDParameterValue; |
|
46 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDStroke; |
|
47 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
|
48 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IPictureMarkerSymbol; |
|
49 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.ISimpleMarkerSymbol; |
|
50 |
|
|
51 |
public class PointSymbolUtils { |
|
52 |
|
|
53 |
public static ISymbol toMarkerSymbol(SLDPointSymbol sym) |
|
54 |
throws UnsupportedSLDObjectException { |
|
55 |
|
|
56 |
SLDGraphic gra = sym.getGraphic(); |
|
57 |
List<SLDGraphicStackElement> list = gra.getElementStack(); |
|
58 |
if (list.size() == 1) { |
|
59 |
|
|
60 |
Integer alpha = BasicUtils.getAlphaValue(gra.getOpacity()); |
|
61 |
Double sz = BasicUtils.getDouble(gra.getSize()); |
|
62 |
IMarkerSymbol msym = toMarkerSymbol(list.get(0)); |
|
63 |
if (alpha != null) { |
|
64 |
msym.setAlpha(alpha.intValue()); |
|
65 |
} |
|
66 |
if (sz != null) { |
|
67 |
msym.setSize(sz.doubleValue()); |
|
68 |
} |
|
69 |
return msym; |
|
70 |
} else { |
|
71 |
|
|
72 |
IMultiLayerSymbol resp = BasicUtils.syMan().createMultiLayerSymbol( |
|
73 |
Geometry.TYPES.POINT); |
|
74 |
for (int i=0; i<list.size(); i++) { |
|
75 |
resp.addLayer(toMarkerSymbol(list.get(i))); |
|
76 |
} |
|
77 |
return resp; |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
|
|
82 |
private static IMarkerSymbol toMarkerSymbol(SLDExternalGraphic extgra) |
|
83 |
throws UnsupportedSLDObjectException { |
|
84 |
|
|
85 |
if (extgra.isOnlineResource()) { |
|
86 |
URL u = null; |
|
87 |
IPictureMarkerSymbol pms = null; |
|
88 |
try { |
|
89 |
u = new URL(extgra.getOnlineResource()); |
|
90 |
pms = BasicUtils.symMan().createPictureMarkerSymbol(u,u); |
|
91 |
} catch (Exception exc) { |
|
92 |
throw new UnsupportedSLDObjectException(exc, |
|
93 |
"SLDExternalGraphic", "Creating picture marker symbol from URL"); |
|
94 |
} |
|
95 |
return pms; |
|
96 |
} else { |
|
97 |
// TODO Not supported yet |
|
98 |
throw new UnsupportedSLDObjectException( |
|
99 |
"SLDExternalGraphic", |
|
100 |
"Inline content not supported."); |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
private static IMarkerSymbol toMarkerSymbol(SLDGraphicStackElement elem) |
|
105 |
throws UnsupportedSLDObjectException { |
|
106 |
|
|
107 |
if (elem == null) { |
|
108 |
throw new UnsupportedSLDObjectException("SLDGraphicStackElement", "Null"); |
|
109 |
} |
|
110 |
|
|
111 |
if (elem instanceof SLDExternalGraphic) { |
|
112 |
return toMarkerSymbol((SLDExternalGraphic) elem); |
|
113 |
} else { |
|
114 |
if (elem instanceof SLDMark) { |
|
115 |
return toMarkerSymbol((SLDMark) elem); |
|
116 |
} else { |
|
117 |
throw new UnsupportedSLDObjectException( |
|
118 |
"SLDGraphicStackElement", |
|
119 |
"Unexpected class: " + elem.getClass().getName()); |
|
120 |
} |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
|
|
125 |
private static IMarkerSymbol toMarkerSymbol(SLDMark mk) |
|
126 |
throws UnsupportedSLDObjectException { |
|
127 |
|
|
128 |
switch (mk.getMarkType()) { |
|
129 |
case SLDMark.MARK_TYPE_INLINE_CONTENT: |
|
130 |
throw new UnsupportedSLDObjectException( |
|
131 |
"SLDMark", |
|
132 |
"Inline content not supported."); |
|
133 |
// ============================================ |
|
134 |
case SLDMark.MARK_TYPE_ONLINE_RESOURCE: |
|
135 |
URL u = null; |
|
136 |
IPictureMarkerSymbol pms = null; |
|
137 |
try { |
|
138 |
u = new URL(mk.getOnlineResource()); |
|
139 |
pms = BasicUtils.symMan().createPictureMarkerSymbol(u,u); |
|
140 |
} catch (Exception exc) { |
|
141 |
throw new UnsupportedSLDObjectException(exc, "SLDMark", |
|
142 |
"Creating picture marker symbol from URL"); |
|
143 |
} |
|
144 |
return pms; |
|
145 |
// ============================================ |
|
146 |
case SLDMark.MARK_TYPE_WELL_KNOWN_NAME: |
|
147 |
String wkn = mk.getWellKnownName(); |
|
148 |
int t = getMarkerSymbolType(wkn); |
|
149 |
ISimpleMarkerSymbol resp = BasicUtils.symMan().createSimpleMarkerSymbol(); |
|
150 |
resp.setStyle(t); |
|
151 |
|
|
152 |
SLDFill fill = mk.getFill(); |
|
153 |
Color co = null; |
|
154 |
Double dob = null; |
|
155 |
if (fill != null) { |
|
156 |
co = BasicUtils.toColor(fill.getFillColor()); |
|
157 |
if (co != null) { |
|
158 |
resp.setColor(co); |
|
159 |
} |
|
160 |
} |
|
161 |
SLDStroke stro = mk.getStroke(); |
|
162 |
if (stro != null) { |
|
163 |
co = BasicUtils.toColor(stro.getColor()); |
|
164 |
if (co != null) { |
|
165 |
resp.setOutlineColor(co); |
|
166 |
} |
|
167 |
dob = BasicUtils.toDouble(stro.getWidth()); |
|
168 |
if (dob != null) { |
|
169 |
resp.setOutlineSize(dob.doubleValue()); |
|
170 |
} |
|
171 |
} |
|
172 |
return resp; |
|
173 |
// ============================================ |
|
174 |
default: |
|
175 |
IMarkerSymbol ms = BasicUtils.symMan().createSimpleMarkerSymbol(); |
|
176 |
SLDStroke str = mk.getStroke(); |
|
177 |
Color col = BasicUtils.getColor(str.getColor()); |
|
178 |
if (col != null) { |
|
179 |
ms.setColor(col); |
|
180 |
} |
|
181 |
Double sz = BasicUtils.toDouble(str.getWidth()); |
|
182 |
if (sz != null) { |
|
183 |
ms.setSize(sz.doubleValue()); |
|
184 |
} |
|
185 |
return ms; |
|
186 |
} |
|
187 |
|
|
188 |
} |
|
189 |
|
|
190 |
private static int getMarkerSymbolType(String wkn) { |
|
191 |
|
|
192 |
if (wkn.compareToIgnoreCase("circle") == 0) |
|
193 |
return IMarkerSymbol.CIRCLE_STYLE; |
|
194 |
else if (wkn.compareToIgnoreCase("x") == 0) |
|
195 |
return IMarkerSymbol.X_STYLE; |
|
196 |
else if (wkn.compareToIgnoreCase("cross") == 0) |
|
197 |
return IMarkerSymbol.CROSS_STYLE; |
|
198 |
else if (wkn.compareToIgnoreCase("triangle") == 0) |
|
199 |
return IMarkerSymbol.TRIANGLE_STYLE; |
|
200 |
else if (wkn.compareToIgnoreCase("star") == 0) |
|
201 |
return IMarkerSymbol.STAR_STYLE; |
|
202 |
return IMarkerSymbol.SQUARE_STYLE; |
|
203 |
} |
|
204 |
|
|
205 |
public static ISymbol toMarkerSymbol(SLDGraphic gra) |
|
206 |
throws UnsupportedSLDObjectException { |
|
207 |
|
|
208 |
IMarkerSymbol resp = null; |
|
209 |
List<SLDGraphicStackElement> list = gra.getElementStack(); |
|
210 |
|
|
211 |
Integer alpha = BasicUtils.getAlphaValue(gra.getOpacity()); |
|
212 |
Double sz = BasicUtils.getDouble(gra.getSize()); |
|
213 |
|
|
214 |
if (list.size() == 0) { |
|
215 |
// Get data from css/svg params |
|
216 |
ISimpleMarkerSymbol sms = BasicUtils.symMan().createSimpleMarkerSymbol(); |
|
217 |
if (alpha != null) { |
|
218 |
sms.setAlpha(alpha.intValue()); |
|
219 |
} |
|
220 |
if (sz != null) { |
|
221 |
sms.setSize(sz.doubleValue()); |
|
222 |
} |
|
223 |
// color? default? |
|
224 |
return sms; |
|
225 |
|
|
226 |
} else { |
|
227 |
|
|
228 |
if (list.size() == 1) { |
|
229 |
IMarkerSymbol msym = toMarkerSymbol(list.get(0)); |
|
230 |
if (alpha != null) { |
|
231 |
msym.setAlpha(alpha.intValue()); |
|
232 |
} |
|
233 |
if (sz != null) { |
|
234 |
msym.setSize(sz.doubleValue()); |
|
235 |
} |
|
236 |
return msym; |
|
237 |
} else { |
|
238 |
|
|
239 |
IMultiLayerSymbol mls = BasicUtils.syMan().createMultiLayerSymbol(Geometry.TYPES.POINT); |
|
240 |
for (int i=0; i<list.size(); i++) { |
|
241 |
mls.addLayer(toMarkerSymbol(list.get(i))); |
|
242 |
} |
|
243 |
return mls; |
|
244 |
} |
|
245 |
} |
|
246 |
} |
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
private static String getMarkWellKnownName(int style) { |
|
251 |
|
|
252 |
if (style == IMarkerSymbol.CIRCLE_STYLE) |
|
253 |
return "circle"; |
|
254 |
else if (style == IMarkerSymbol.CROSS_STYLE) |
|
255 |
return "cross"; |
|
256 |
else if (style == IMarkerSymbol.SQUARE_STYLE) |
|
257 |
return "square"; |
|
258 |
else if (style == IMarkerSymbol.TRIANGLE_STYLE) |
|
259 |
return "triangle"; |
|
260 |
else if (style == IMarkerSymbol.STAR_STYLE) |
|
261 |
return "star"; |
|
262 |
else if (style == IMarkerSymbol.X_STYLE) |
|
263 |
return "x"; |
|
264 |
|
|
265 |
return "square"; |
|
266 |
} |
|
267 |
|
|
268 |
public static SLDPointSymbol toSLDPointSymbol(IMarkerSymbol sym) |
|
269 |
throws UnsupportedSymbolException { |
|
270 |
|
|
271 |
if (sym instanceof IPictureMarkerSymbol) { |
|
272 |
|
|
273 |
IPictureMarkerSymbol aux = (IPictureMarkerSymbol) sym; |
|
274 |
SLDExternalGraphic egra = new SLDExternalGraphic(); |
|
275 |
egra.setIsOnline(true); |
|
276 |
egra.setOnlineResource(aux.getSource().toString()); |
|
277 |
egra.setFormat(BasicUtils.getFormat(aux.getSource())); |
|
278 |
SLDGraphic gra = new SLDGraphic(); |
|
279 |
gra.getElementStack().add(egra); |
|
280 |
SLDPointSymbol resp = new SLDPointSymbol(); |
|
281 |
resp.setGraphic(gra); |
|
282 |
return resp; |
|
283 |
|
|
284 |
} else { |
|
285 |
if (sym instanceof ISimpleMarkerSymbol) { |
|
286 |
|
|
287 |
ISimpleMarkerSymbol aux = (ISimpleMarkerSymbol) sym; |
|
288 |
|
|
289 |
SLDMark mark = new SLDMark(); |
|
290 |
mark.setMarkType(SLDMark.MARK_TYPE_WELL_KNOWN_NAME); |
|
291 |
String wkn = getMarkWellKnownName(aux.getStyle()); |
|
292 |
mark.setWellKnownName(wkn); |
|
293 |
|
|
294 |
Color fillColor = aux.getColor(); |
|
295 |
Color borderColor = aux.getOutlineColor(); |
|
296 |
double size = aux.getSize(); |
|
297 |
double borderw = aux.getOutlineSize(); |
|
298 |
double rot = aux.getRotation(); |
|
299 |
// from (radians,anticlockwise) to (degrees,clockwise) |
|
300 |
rot = -rot * 180.0 / Math.PI; |
|
301 |
// =============== |
|
302 |
SLDFill fill = new SLDFill(); |
|
303 |
if (fillColor == null) { |
|
304 |
fillColor = SLDFill.DEFAULT_FILL_COLOR; |
|
305 |
} |
|
306 |
|
|
307 |
fill.setFillColor(fillColor); |
|
308 |
mark.setFill(fill); |
|
309 |
// === |
|
310 |
SLDStroke stro = new SLDStroke(); |
|
311 |
stro.setColor(borderColor); |
|
312 |
|
|
313 |
stro.setWidth(new SLDLiteral(BasicUtils.df.format(borderw))); |
|
314 |
mark.setStroke(stro); |
|
315 |
// =============== |
|
316 |
SLDGraphic gra = new SLDGraphic(); |
|
317 |
// =============== |
|
318 |
SLDParameterValue pv = new SLDParameterValue(); |
|
319 |
pv.getExpressionList().add(new SLDLiteral(BasicUtils.df.format(size))); |
|
320 |
gra.setSize(pv); |
|
321 |
// === |
|
322 |
pv = new SLDParameterValue(); |
|
323 |
pv.getExpressionList().add(new SLDLiteral(BasicUtils.df.format(rot))); |
|
324 |
gra.setRotation(pv); |
|
325 |
// =============== |
|
326 |
gra.getElementStack().add(mark); |
|
327 |
SLDPointSymbol resp = new SLDPointSymbol(); |
|
328 |
resp.setGraphic(gra); |
|
329 |
return resp; |
|
330 |
|
|
331 |
} else { |
|
332 |
throw new UnsupportedSymbolException( |
|
333 |
sym.getClass().getName(), |
|
334 |
"Unsupported class for conversion to SLD"); |
|
335 |
} |
|
336 |
} |
|
337 |
} |
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.79/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/symbol/BasicSymbolConverterFactory.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
2 |
* |
|
3 |
* gvSIG. Desktop Geographic Information System. |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
6 |
* |
|
7 |
* This program is free software; you can redistribute it and/or |
|
8 |
* modify it under the terms of the GNU General Public License |
|
9 |
* as published by the Free Software Foundation; either version 3 |
|
10 |
* of the License, or (at your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, |
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
* GNU General Public License for more details. |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License |
|
18 |
* along with this program; if not, write to the Free Software |
|
19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
20 |
* MA 02110-1301, USA. |
|
21 |
* |
|
22 |
* For any additional information, do not hesitate to contact us |
|
23 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
24 |
* |
|
25 |
*******************************************************************************/ |
|
26 |
package org.gvsig.sldconverter.impl.symbol; |
|
27 |
|
|
28 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
29 |
import org.gvsig.sldconverter.SLDConverterManager; |
|
30 |
import org.gvsig.sldconverter.symbol.SLDToSymbolConverter; |
|
31 |
import org.gvsig.sldconverter.symbol.SLDToSymbolConverterFactory; |
|
32 |
import org.gvsig.sldconverter.symbol.SymbolToSLDConverter; |
|
33 |
import org.gvsig.sldconverter.symbol.SymbolToSLDConverterFactory; |
|
34 |
import org.gvsig.sldsupport.sld.symbol.SLDLineSymbol; |
|
35 |
import org.gvsig.sldsupport.sld.symbol.SLDPointSymbol; |
|
36 |
import org.gvsig.sldsupport.sld.symbol.SLDPolygonSymbol; |
|
37 |
import org.gvsig.sldsupport.sld.symbol.SLDSymbol; |
|
38 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
|
39 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IMultiLayerFillSymbol; |
|
40 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
41 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.IMultiLayerLineSymbol; |
|
42 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
|
43 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMultiLayerMarkerSymbol; |
|
44 |
|
|
45 |
public class BasicSymbolConverterFactory |
|
46 |
implements SymbolToSLDConverterFactory, SLDToSymbolConverterFactory { |
|
47 |
|
|
48 |
public int canConvert(SLDSymbol sldSym) { |
|
49 |
|
|
50 |
if (sldSym instanceof SLDPointSymbol |
|
51 |
|| sldSym instanceof SLDLineSymbol |
|
52 |
|| sldSym instanceof SLDPolygonSymbol) { |
|
53 |
|
|
54 |
/* |
|
55 |
* This allows precedence of specific conversors |
|
56 |
*/ |
|
57 |
return SLDConverterManager.CAN_CONVERT_PARTIALLY; |
|
58 |
} else { |
|
59 |
/* |
|
60 |
* SLDRasterSymbol |
|
61 |
* SLDTextSymbol |
|
62 |
* SLDMappedColorSymbol |
|
63 |
*/ |
|
64 |
return SLDConverterManager.CAN_NOT_CONVERT; |
|
65 |
} |
|
66 |
|
|
67 |
} |
|
68 |
|
|
69 |
public SLDToSymbolConverter createSLDToSymbolConverter() { |
|
70 |
return new BasicSymbolConverter(); |
|
71 |
} |
|
72 |
|
|
73 |
// ====================================== |
|
74 |
|
|
75 |
public int canConvert(ISymbol sym) { |
|
76 |
|
|
77 |
if (sym instanceof IMultiLayerMarkerSymbol |
|
78 |
|| sym instanceof IMultiLayerLineSymbol |
|
79 |
|| sym instanceof IMultiLayerFillSymbol |
|
80 |
|| sym instanceof IMarkerSymbol |
|
81 |
|| sym instanceof ILineSymbol |
|
82 |
|| sym instanceof IFillSymbol) { |
|
83 |
|
|
84 |
|
|
85 |
return SLDConverterManager.CAN_CONVERT_PARTIALLY; |
|
86 |
} else { |
|
87 |
return SLDConverterManager.CAN_NOT_CONVERT; |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
public SymbolToSLDConverter createSymbolToSLDConverter() { |
|
92 |
return new BasicSymbolConverter(); |
|
93 |
} |
|
94 |
|
|
95 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.79/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/DefaultSLDConverterManager.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
2 |
* |
|
3 |
* gvSIG. Desktop Geographic Information System. |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
6 |
* |
|
7 |
* This program is free software; you can redistribute it and/or |
|
8 |
* modify it under the terms of the GNU General Public License |
|
9 |
* as published by the Free Software Foundation; either version 3 |
|
10 |
* of the License, or (at your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, |
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
* GNU General Public License for more details. |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License |
|
18 |
* along with this program; if not, write to the Free Software |
|
19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
20 |
* MA 02110-1301, USA. |
|
21 |
* |
|
22 |
* For any additional information, do not hesitate to contact us |
|
23 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
24 |
* |
|
25 |
*******************************************************************************/ |
|
26 |
package org.gvsig.sldconverter.impl; |
|
27 |
|
|
28 |
import java.util.HashSet; |
|
29 |
import java.util.Iterator; |
|
30 |
import java.util.Set; |
|
31 |
|
|
32 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
33 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
34 |
import org.gvsig.sldconverter.SLDConverterManager; |
|
35 |
import org.gvsig.sldconverter.exception.UnsupportedLegendException; |
|
36 |
import org.gvsig.sldconverter.exception.UnsupportedSymbolException; |
|
37 |
import org.gvsig.sldconverter.legend.LegendToSLDConverter; |
|
38 |
import org.gvsig.sldconverter.legend.LegendToSLDConverterFactory; |
|
39 |
import org.gvsig.sldconverter.legend.SLDToLegendConverter; |
|
40 |
import org.gvsig.sldconverter.legend.SLDToLegendConverterFactory; |
|
41 |
import org.gvsig.sldconverter.symbol.SLDToSymbolConverter; |
|
42 |
import org.gvsig.sldconverter.symbol.SLDToSymbolConverterFactory; |
|
43 |
import org.gvsig.sldconverter.symbol.SymbolToSLDConverter; |
|
44 |
import org.gvsig.sldconverter.symbol.SymbolToSLDConverterFactory; |
|
45 |
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException; |
|
46 |
import org.gvsig.sldsupport.sld.layer.SLDLayer; |
|
47 |
import org.gvsig.sldsupport.sld.symbol.SLDSymbol; |
|
48 |
|
|
49 |
public class DefaultSLDConverterManager implements SLDConverterManager { |
|
50 |
|
|
51 |
private Set<SLDToLegendConverterFactory> legendFromSLD = |
|
52 |
new HashSet<SLDToLegendConverterFactory>(); |
|
53 |
private Set<LegendToSLDConverterFactory> legendToSLD = |
|
54 |
new HashSet<LegendToSLDConverterFactory>(); |
|
55 |
// ========================================================= |
|
56 |
private Set<SLDToSymbolConverterFactory> symbolFromSLD = |
|
57 |
new HashSet<SLDToSymbolConverterFactory>(); |
|
58 |
private Set<SymbolToSLDConverterFactory> symbolToSLD = |
|
59 |
new HashSet<SymbolToSLDConverterFactory>(); |
|
60 |
// ========================================================= |
|
61 |
|
|
62 |
|
|
63 |
public SLDSymbol toSLDSymbol(ISymbol sym) throws UnsupportedSymbolException { |
|
64 |
|
|
65 |
if (sym == null) { |
|
66 |
throw new UnsupportedSymbolException("ISymbol", "Null"); |
|
67 |
} |
|
68 |
|
|
69 |
int max = 0; |
|
70 |
SymbolToSLDConverterFactory factToUse = null; |
|
71 |
Iterator<SymbolToSLDConverterFactory> iter = symbolToSLD.iterator(); |
|
72 |
SymbolToSLDConverterFactory fact = null; |
|
73 |
int aux = 0; |
|
74 |
while (iter.hasNext()) { |
|
75 |
fact = iter.next(); |
|
76 |
aux = fact.canConvert(sym); |
|
77 |
if (aux > max) { |
|
78 |
max = aux; |
|
79 |
factToUse = fact; |
|
80 |
} |
|
81 |
} |
|
82 |
|
|
83 |
if (max == 0) { |
|
84 |
throw new UnsupportedSymbolException( |
|
85 |
sym.getClass().getName(), "No converter found."); |
|
86 |
} |
|
87 |
|
|
88 |
SymbolToSLDConverter conv = factToUse.createSymbolToSLDConverter(); |
|
89 |
return conv.convert(sym); |
|
90 |
} |
|
91 |
|
|
92 |
|
|
93 |
public ISymbol toSymbol(SLDSymbol sldsym) throws UnsupportedSLDObjectException { |
|
94 |
|
|
95 |
if (sldsym == null) { |
|
96 |
throw new UnsupportedSLDObjectException("SLDSymbol", "Null"); |
|
97 |
} |
|
98 |
int max = 0; |
|
99 |
SLDToSymbolConverterFactory factToUse = null; |
|
100 |
Iterator<SLDToSymbolConverterFactory> iter = symbolFromSLD.iterator(); |
|
101 |
SLDToSymbolConverterFactory fact = null; |
|
102 |
int aux = 0; |
|
103 |
while (iter.hasNext()) { |
|
104 |
fact = iter.next(); |
|
105 |
aux = fact.canConvert(sldsym); |
|
106 |
if (aux > max) { |
|
107 |
max = aux; |
|
108 |
factToUse = fact; |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
if (max == 0) { |
|
113 |
throw new UnsupportedSLDObjectException( |
|
114 |
sldsym.getClass().getSimpleName(), "No converter found."); |
|
115 |
} |
|
116 |
|
|
117 |
SLDToSymbolConverter conv = factToUse.createSLDToSymbolConverter(); |
|
118 |
return conv.convert(sldsym); |
|
119 |
} |
|
120 |
|
|
121 |
public SLDLayer toSLDLayer(ILegend legend) |
|
122 |
throws UnsupportedLegendException, UnsupportedSymbolException { |
|
123 |
|
|
124 |
if (legend == null) { |
|
125 |
throw new UnsupportedLegendException("ILegend", "Null"); |
|
126 |
} |
|
127 |
|
|
128 |
int max = 0; |
|
129 |
LegendToSLDConverterFactory factToUse = null; |
|
130 |
Iterator<LegendToSLDConverterFactory> iter = legendToSLD.iterator(); |
|
131 |
LegendToSLDConverterFactory fact = null; |
|
132 |
int aux = 0; |
|
133 |
while (iter.hasNext()) { |
|
134 |
fact = iter.next(); |
|
135 |
aux = fact.canConvert(legend); |
|
136 |
if (aux > max) { |
|
137 |
max = aux; |
|
138 |
factToUse = fact; |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
142 |
if (max == 0) { |
|
143 |
throw new UnsupportedLegendException( |
|
144 |
legend.getClass().getName(), "No converter found."); |
|
145 |
} |
|
146 |
|
|
147 |
LegendToSLDConverter conv = factToUse.createLegendToSLDConverter(); |
|
148 |
return conv.convert(legend); |
|
149 |
} |
|
150 |
|
|
151 |
public ILegend toLegend(SLDLayer sldlayer) throws UnsupportedSLDObjectException { |
|
152 |
|
|
153 |
if (sldlayer == null) { |
|
154 |
throw new UnsupportedSLDObjectException("SLDLayer", "Null"); |
|
155 |
} |
|
156 |
int max = 0; |
|
157 |
SLDToLegendConverterFactory factToUse = null; |
|
158 |
Iterator<SLDToLegendConverterFactory> iter = legendFromSLD.iterator(); |
|
159 |
SLDToLegendConverterFactory fact = null; |
|
160 |
int aux = 0; |
|
161 |
while (iter.hasNext()) { |
|
162 |
fact = iter.next(); |
|
163 |
aux = fact.canConvert(sldlayer); |
|
164 |
if (aux > max) { |
|
165 |
max = aux; |
|
166 |
factToUse = fact; |
|
167 |
} |
|
168 |
} |
|
169 |
|
|
170 |
if (max == 0) { |
|
171 |
throw new UnsupportedSLDObjectException( |
|
172 |
sldlayer.getClass().getSimpleName(), "No converter found."); |
|
173 |
} |
|
174 |
|
|
175 |
SLDToLegendConverter conv = factToUse.createSLDToLegendConverter(); |
|
176 |
return conv.convert(sldlayer); |
|
177 |
} |
|
178 |
|
|
179 |
// ============================================================= |
|
180 |
// ============================================================= |
|
181 |
|
|
182 |
public void registerSLDToSymbolConverter(SLDToSymbolConverterFactory fact) { |
|
183 |
if (fact != null) { |
|
184 |
this.symbolFromSLD.add(fact); |
|
185 |
} |
|
186 |
} |
|
187 |
|
|
188 |
public void registerSymbolToSLDConverter(SymbolToSLDConverterFactory fact) { |
|
189 |
if (fact != null) { |
|
190 |
this.symbolToSLD.add(fact); |
|
191 |
} |
|
192 |
} |
|
193 |
|
|
194 |
public void registerSLDToLegendConverter(SLDToLegendConverterFactory fact) { |
|
195 |
if (fact != null) { |
|
196 |
this.legendFromSLD.add(fact); |
|
197 |
} |
|
198 |
} |
|
199 |
|
|
200 |
public void registerLegendToSLDConverter(LegendToSLDConverterFactory fact) { |
|
201 |
if (fact != null) { |
|
202 |
this.legendToSLD.add(fact); |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
206 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.79/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/util/BasicUtils.java | ||
---|---|---|
1 |
/******************************************************************************* |
|
2 |
* |
|
3 |
* gvSIG. Desktop Geographic Information System. |
|
4 |
* |
|
5 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
6 |
* |
|
7 |
* This program is free software; you can redistribute it and/or |
|
8 |
* modify it under the terms of the GNU General Public License |
|
9 |
* as published by the Free Software Foundation; either version 3 |
|
10 |
* of the License, or (at your option) any later version. |
|
11 |
* |
|
12 |
* This program is distributed in the hope that it will be useful, |
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 |
* GNU General Public License for more details. |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License |
|
18 |
* along with this program; if not, write to the Free Software |
|
19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
20 |
* MA 02110-1301, USA. |
|
21 |
* |
|
22 |
* For any additional information, do not hesitate to contact us |
|
23 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
24 |
* |
|
25 |
*******************************************************************************/ |
|
26 |
package org.gvsig.sldconverter.impl.util; |
|
27 |
|
|
28 |
import java.awt.Color; |
|
29 |
import java.net.URL; |
|
30 |
import java.text.DecimalFormat; |
|
31 |
import java.text.DecimalFormatSymbols; |
|
32 |
import java.util.ArrayList; |
|
33 |
import java.util.HashMap; |
|
34 |
import java.util.Iterator; |
|
35 |
import java.util.List; |
|
36 |
import java.util.Map; |
|
37 |
|
|
38 |
import org.slf4j.Logger; |
|
39 |
import org.slf4j.LoggerFactory; |
|
40 |
|
|
41 |
import org.gvsig.fmap.dal.DataTypes; |
|
42 |
import org.gvsig.fmap.geom.Geometry; |
|
43 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
44 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
45 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
|
46 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
47 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
|
48 |
import org.gvsig.sldconverter.SLDConverterLocator; |
|
49 |
import org.gvsig.sldconverter.SLDConverterManager; |
|
50 |
import org.gvsig.sldsupport.SLDSupportLocator; |
|
51 |
import org.gvsig.sldsupport.SLDSupportManager; |
|
52 |
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException; |
|
53 |
import org.gvsig.sldsupport.sld.filter.FilterTags; |
|
54 |
import org.gvsig.sldsupport.sld.filter.SLDFilter; |
|
55 |
import org.gvsig.sldsupport.sld.filter.SLDFilterOperator; |
|
56 |
import org.gvsig.sldsupport.sld.filter.expression.SLDExpression; |
|
57 |
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDLiteral; |
|
58 |
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDPropertyName; |
|
59 |
import org.gvsig.sldsupport.sld.filter.operator.SLDComparisonOperator; |
|
60 |
import org.gvsig.sldsupport.sld.filter.operator.comparison.SLDBinaryComparisonOperator; |
|
61 |
import org.gvsig.sldsupport.sld.layer.SLDLayer; |
|
62 |
import org.gvsig.sldsupport.sld.layer.SLDNamedLayer; |
|
63 |
import org.gvsig.sldsupport.sld.layer.SLDUserLayer; |
|
64 |
import org.gvsig.sldsupport.sld.rule.SLDRule; |
|
65 |
import org.gvsig.sldsupport.sld.style.layer.SLDUserStyle; |
|
66 |
import org.gvsig.sldsupport.sld.symbol.SLDLineSymbol; |
|
67 |
import org.gvsig.sldsupport.sld.symbol.SLDPointSymbol; |
|
68 |
import org.gvsig.sldsupport.sld.symbol.SLDPolygonSymbol; |
|
69 |
import org.gvsig.sldsupport.sld.symbol.SLDSymbol; |
|
70 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDParameterValue; |
|
71 |
import org.gvsig.symbology.SymbologyLocator; |
|
72 |
import org.gvsig.symbology.SymbologyManager; |
|
73 |
import org.gvsig.tools.ToolsLocator; |
|
74 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
75 |
import org.gvsig.tools.dataTypes.DataType; |
|
76 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
77 |
|
|
78 |
public class BasicUtils { |
|
79 |
|
|
80 |
private static Logger logger = LoggerFactory.getLogger(BasicUtils.class); |
|
81 |
|
|
82 |
public static DecimalFormat df = null; |
|
83 |
static { |
|
84 |
DecimalFormatSymbols dformater_rules = new DecimalFormatSymbols(); |
|
85 |
dformater_rules.setDecimalSeparator ('.'); |
|
86 |
df = new DecimalFormat("##########.0##########", dformater_rules); |
|
87 |
} |
|
88 |
|
|
89 |
public static SLDConverterManager sldMan() { |
|
90 |
return SLDConverterLocator.getInstance().getSLDConverterManager(); |
|
91 |
} |
|
92 |
|
|
93 |
public static SLDSupportManager supMan() { |
|
94 |
return SLDSupportLocator.getInstance().getSLDSupportManager(); |
|
95 |
} |
|
96 |
|
|
97 |
public static SymbologyManager symMan() { |
|
98 |
return SymbologyLocator.getSymbologyManager(); |
|
99 |
} |
|
100 |
|
|
101 |
public static SymbolManager syMan() { |
|
102 |
return MapContextLocator.getSymbolManager(); |
|
103 |
} |
|
104 |
|
|
105 |
public static MapContextManager mapMan() { |
|
106 |
return MapContextLocator.getMapContextManager(); |
|
107 |
} |
|
108 |
|
|
109 |
public static DataTypesManager datMan() { |
|
110 |
return ToolsLocator.getDataTypesManager(); |
|
111 |
} |
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
public static String getFirstPropertyName(List<SLDRule> rules) { |
|
128 |
if (rules == null || rules.size() == 0) { |
|
129 |
return null; |
|
130 |
} |
|
131 |
|
|
132 |
SLDRule rule = null; |
|
133 |
String fieldName = null; |
|
134 |
for (int i=0; i<rules.size(); i++) { |
|
135 |
rule = rules.get(i); |
|
136 |
fieldName = getFirstPropertyName(rule); |
|
137 |
if (fieldName != null) { |
|
138 |
return fieldName; |
|
139 |
} |
|
140 |
} |
|
141 |
return null; |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* Gets data type from literals. |
|
146 |
* Possible responses: |
|
147 |
* |
|
148 |
* - DataTypes.DOUBLE |
|
149 |
* - DataTypes.INTEGER |
|
150 |
* - DataTypes.STRING |
|
151 |
* |
|
152 |
* @param lits |
|
153 |
* @return |
|
154 |
*/ |
|
155 |
public static DataType guessDataType(List<SLDLiteral> lits) { |
|
156 |
|
|
157 |
boolean isDouble = true; |
|
158 |
boolean isInt = true; |
|
159 |
Iterator<SLDLiteral> iter = lits.iterator(); |
|
160 |
SLDLiteral lit = null; |
|
161 |
|
|
162 |
while (iter.hasNext()) { |
|
163 |
lit = iter.next(); |
|
164 |
try { Double.parseDouble(lit.getValue()); } catch (Exception exc) { |
|
165 |
isDouble = false; |
|
166 |
break; |
|
167 |
} |
|
168 |
} |
|
169 |
if (isDouble) { |
|
170 |
return datMan().get(DataTypes.DOUBLE); |
|
171 |
} |
|
172 |
// ======================================= |
|
173 |
iter = lits.iterator(); |
|
174 |
isInt = true; |
|
175 |
while (iter.hasNext()) { |
|
176 |
lit = iter.next(); |
|
177 |
try { Integer.parseInt(lit.getValue()); } catch (Exception exc) { |
|
178 |
isInt = false; |
|
179 |
break; |
|
180 |
} |
|
181 |
} |
|
182 |
if (isInt) { |
|
183 |
return datMan().get(DataTypes.INT); |
|
184 |
} else { |
|
185 |
return datMan().get(DataTypes.STRING); |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
/** |
|
190 |
* Coerces literal value using the dataType |
|
191 |
* Returns null if coercion was not possible |
|
192 |
* @param lit |
|
193 |
* @param dt |
|
194 |
* @return |
|
195 |
*/ |
|
196 |
public static Object getValue(SLDLiteral lit, DataType dt) { |
|
197 |
|
|
198 |
if (lit == null) { |
|
199 |
return null; |
|
200 |
} |
|
201 |
try { |
|
202 |
return dt.coerce(lit.getValue()); |
|
203 |
} catch (CoercionException e) { |
|
204 |
logger.info("While coercing literal: " + lit.getValue(), e); |
|
205 |
return null; |
|
206 |
} |
|
207 |
} |
|
208 |
|
|
209 |
public static List<SLDLiteral> getComparisonLiterals(List<SLDRule> rules) { |
|
210 |
List<SLDLiteral> resp = new ArrayList<SLDLiteral>(); |
|
211 |
SLDRule rule = null; |
|
212 |
SLDComparisonOperator item = null; |
|
213 |
for (int i=0; i<rules.size(); i++) { |
|
214 |
rule = rules.get(i); |
|
215 |
SLDFilter filt = rule.getFilter(); |
|
216 |
if (filt != null && !filt.isElse()) { |
|
217 |
SLDFilterOperator oper = filt.getFilterOperator(); |
|
218 |
if (oper instanceof SLDComparisonOperator) { |
|
219 |
item = (SLDComparisonOperator) oper; |
|
220 |
List<SLDExpression> list = item.getExpressions(); |
|
221 |
for (int j=0; j<list.size(); j++) { |
|
222 |
if (list.get(j) instanceof SLDLiteral) { |
|
223 |
resp.add((SLDLiteral) list.get(j)); |
|
224 |
} |
|
225 |
} |
|
226 |
} |
|
227 |
} |
|
228 |
} |
|
229 |
return resp; |
|
230 |
} |
|
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
public static boolean isElse(SLDRule rule) { |
|
236 |
SLDFilter filt = rule.getFilter(); |
|
237 |
return filt != null && filt.isElse(); |
|
238 |
} |
|
239 |
|
|
240 |
|
|
241 |
private static String getFirstPropertyName(SLDRule rule) { |
|
242 |
SLDFilter filt = rule.getFilter(); |
|
243 |
if (filt == null) { |
|
244 |
return null; |
|
245 |
} |
|
246 |
SLDFilterOperator oper = filt.getFilterOperator(); |
|
247 |
if (oper instanceof SLDComparisonOperator) { |
|
248 |
|
|
249 |
SLDComparisonOperator cop = (SLDComparisonOperator) oper; |
Also available in: Unified diff