Revision 40804
branches/v02_desarrollo/libraries/sld/temp/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.api/src/main/java/org/gvsig/sldconverter/exception/UnsupportedSLDObjectException.java | ||
---|---|---|
1 |
package org.gvsig.sldconverter.exception; |
|
2 |
|
|
3 |
import org.gvsig.sldsupport.exception.SLDException; |
|
4 |
|
|
5 |
public class UnsupportedSLDObjectException extends SLDException { |
|
6 |
|
|
7 |
|
|
8 |
private static final long serialVersionUID = -2048913423487606767L; |
|
9 |
|
|
10 |
public UnsupportedSLDObjectException( |
|
11 |
String element_name, |
|
12 |
String detail) { |
|
13 |
super("Unsupported SLD Object: " + element_name + "; Detail: " + detail, |
|
14 |
"_Unsupported_SLD_object", |
|
15 |
serialVersionUID); |
|
16 |
} |
|
17 |
|
|
18 |
|
|
19 |
} |
branches/v02_desarrollo/libraries/sld/temp/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.api/src/main/java/org/gvsig/sldconverter/legend/SLDToLegendConverter.java | ||
---|---|---|
1 | 1 |
package org.gvsig.sldconverter.legend; |
2 | 2 |
|
3 | 3 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
4 |
import org.gvsig.sldconverter.exception.UnsupportedSLDObjectException; |
|
4 | 5 |
import org.gvsig.sldsupport.sld.layer.SLDLayer; |
5 | 6 |
|
6 | 7 |
public interface SLDToLegendConverter { |
7 | 8 |
|
8 |
public ILegend convert(SLDLayer sldLay); |
|
9 |
public ILegend convert(SLDLayer sldLay) throws UnsupportedSLDObjectException;
|
|
9 | 10 |
|
10 | 11 |
} |
branches/v02_desarrollo/libraries/sld/temp/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.api/src/main/java/org/gvsig/sldconverter/SLDConverterManager.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
4 | 4 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
5 |
import org.gvsig.sldconverter.exception.UnsupportedSLDObjectException; |
|
5 | 6 |
import org.gvsig.sldconverter.legend.LegendToSLDConverterFactory; |
6 | 7 |
import org.gvsig.sldconverter.legend.SLDToLegendConverterFactory; |
7 | 8 |
import org.gvsig.sldconverter.symbol.SLDToSymbolConverterFactory; |
... | ... | |
15 | 16 |
public static final int CAN_CONVERT_FULLY = 100; |
16 | 17 |
|
17 | 18 |
public SLDSymbol toSLDSymbol(ISymbol sym); |
18 |
public ISymbol toSymbol(SLDSymbol sldSym); |
|
19 |
public ISymbol toSymbol(SLDSymbol sldSym) throws UnsupportedSLDObjectException;
|
|
19 | 20 |
|
20 | 21 |
public SLDLayer toSLDLayer(ILegend legend); |
21 |
public ILegend toLegend(SLDLayer sldLayer); |
|
22 |
public ILegend toLegend(SLDLayer sldLayer) throws UnsupportedSLDObjectException;
|
|
22 | 23 |
|
23 | 24 |
public void registerSLDToSymbolConverter(SLDToSymbolConverterFactory fact); |
24 | 25 |
public void registerSymbolToSLDConverter(SymbolToSLDConverterFactory fact); |
branches/v02_desarrollo/libraries/sld/temp/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.api/src/main/java/org/gvsig/sldconverter/symbol/SLDToSymbolConverter.java | ||
---|---|---|
1 | 1 |
package org.gvsig.sldconverter.symbol; |
2 | 2 |
|
3 | 3 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
4 |
import org.gvsig.sldconverter.exception.UnsupportedSLDObjectException; |
|
4 | 5 |
import org.gvsig.sldsupport.sld.symbol.SLDSymbol; |
5 | 6 |
|
6 | 7 |
public interface SLDToSymbolConverter { |
7 | 8 |
|
8 |
public ISymbol convert(SLDSymbol sldSym); |
|
9 |
public ISymbol convert(SLDSymbol sldSym) throws UnsupportedSLDObjectException;
|
|
9 | 10 |
} |
branches/v02_desarrollo/libraries/sld/temp/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/symbol/BasicSymbolConverter.java | ||
---|---|---|
1 | 1 |
package org.gvsig.sldconverter.impl.symbol; |
2 | 2 |
|
3 | 3 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
4 |
import org.gvsig.sldconverter.exception.UnsupportedSLDObjectException; |
|
5 |
import org.gvsig.sldconverter.impl.legend.BasicUtils; |
|
4 | 6 |
import org.gvsig.sldconverter.symbol.SLDToSymbolConverter; |
5 | 7 |
import org.gvsig.sldconverter.symbol.SymbolToSLDConverter; |
8 |
import org.gvsig.sldsupport.sld.symbol.SLDLineSymbol; |
|
9 |
import org.gvsig.sldsupport.sld.symbol.SLDPointSymbol; |
|
10 |
import org.gvsig.sldsupport.sld.symbol.SLDPolygonSymbol; |
|
6 | 11 |
import org.gvsig.sldsupport.sld.symbol.SLDSymbol; |
7 | 12 |
|
8 | 13 |
public class BasicSymbolConverter |
9 | 14 |
implements SymbolToSLDConverter, SLDToSymbolConverter { |
10 | 15 |
|
11 |
public ISymbol convert(SLDSymbol sldSym) { |
|
12 |
// TODO Auto-generated method stub |
|
13 |
return null; |
|
16 |
public ISymbol convert(SLDSymbol sldSym) throws UnsupportedSLDObjectException { |
|
17 |
|
|
18 |
if (sldSym == null) { |
|
19 |
throw new UnsupportedSLDObjectException("SLDSymbol", "Null"); |
|
20 |
} |
|
21 |
|
|
22 |
if (sldSym instanceof SLDPointSymbol) { |
|
23 |
return BasicUtils.toMarkerSymbol((SLDPointSymbol) sldSym); |
|
24 |
} else { |
|
25 |
if (sldSym instanceof SLDLineSymbol) { |
|
26 |
return BasicUtils.toLineSymbol((SLDLineSymbol) sldSym); |
|
27 |
} else { |
|
28 |
if (sldSym instanceof SLDPolygonSymbol) { |
|
29 |
return BasicUtils.toFillSymbol((SLDPolygonSymbol) sldSym); |
|
30 |
} else { |
|
31 |
throw new UnsupportedSLDObjectException("SLDSymbol", |
|
32 |
"Unexpected class: " + sldSym.getClass().getName()); |
|
33 |
} |
|
34 |
} |
|
35 |
} |
|
14 | 36 |
} |
15 | 37 |
|
16 | 38 |
public SLDSymbol convert(ISymbol sym) { |
branches/v02_desarrollo/libraries/sld/temp/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/DefaultSLDConverterManager.java | ||
---|---|---|
3 | 3 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
4 | 4 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
5 | 5 |
import org.gvsig.sldconverter.SLDConverterManager; |
6 |
import org.gvsig.sldconverter.exception.UnsupportedSLDObjectException; |
|
6 | 7 |
import org.gvsig.sldconverter.legend.LegendToSLDConverterFactory; |
7 | 8 |
import org.gvsig.sldconverter.legend.SLDToLegendConverterFactory; |
8 | 9 |
import org.gvsig.sldconverter.symbol.SLDToSymbolConverterFactory; |
... | ... | |
17 | 18 |
return null; |
18 | 19 |
} |
19 | 20 |
|
20 |
public ISymbol toSymbol(SLDSymbol sldSym) { |
|
21 |
public ISymbol toSymbol(SLDSymbol sldSym) throws UnsupportedSLDObjectException {
|
|
21 | 22 |
// TODO Auto-generated method stub |
22 | 23 |
return null; |
23 | 24 |
} |
... | ... | |
27 | 28 |
return null; |
28 | 29 |
} |
29 | 30 |
|
30 |
public ILegend toLegend(SLDLayer sldLayer) { |
|
31 |
public ILegend toLegend(SLDLayer sldLayer) throws UnsupportedSLDObjectException {
|
|
31 | 32 |
// TODO Auto-generated method stub |
32 | 33 |
return null; |
33 | 34 |
} |
branches/v02_desarrollo/libraries/sld/temp/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/legend/BasicLegendConverter.java | ||
---|---|---|
1 | 1 |
package org.gvsig.sldconverter.impl.legend; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import org.gvsig.fmap.geom.Geometry; |
|
7 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
3 | 8 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
9 |
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend; |
|
10 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
11 |
import org.gvsig.sldconverter.SLDConverterManager; |
|
12 |
import org.gvsig.sldconverter.exception.UnsupportedSLDObjectException; |
|
4 | 13 |
import org.gvsig.sldconverter.legend.LegendToSLDConverter; |
5 | 14 |
import org.gvsig.sldconverter.legend.SLDToLegendConverter; |
6 | 15 |
import org.gvsig.sldsupport.sld.layer.SLDLayer; |
16 |
import org.gvsig.sldsupport.sld.layer.SLDNamedLayer; |
|
17 |
import org.gvsig.sldsupport.sld.layer.SLDUserLayer; |
|
18 |
import org.gvsig.sldsupport.sld.rule.SLDRule; |
|
19 |
import org.gvsig.sldsupport.sld.style.SLDFeatureStyle; |
|
20 |
import org.gvsig.sldsupport.sld.style.layer.SLDUserStyle; |
|
21 |
import org.gvsig.sldsupport.sld.symbol.SLDSymbol; |
|
7 | 22 |
|
8 | 23 |
public class BasicLegendConverter |
9 | 24 |
implements LegendToSLDConverter, SLDToLegendConverter { |
10 | 25 |
|
11 |
public ILegend convert(SLDLayer sldLay) { |
|
12 |
// TODO Auto-generated method stub |
|
13 |
return null; |
|
26 |
public ILegend convert(SLDLayer layer) throws UnsupportedSLDObjectException { |
|
27 |
|
|
28 |
if (layer == null ) { |
|
29 |
throw new UnsupportedSLDObjectException("SLDLayer", "Null"); |
|
30 |
} |
|
31 |
|
|
32 |
SLDUserStyle sty = BasicUtils.getFirstUserStyle(layer); |
|
33 |
if (sty == null) { |
|
34 |
throw new UnsupportedSLDObjectException("SLDLayer", "Bad structure"); |
|
35 |
} |
|
36 |
|
|
37 |
List<SLDFeatureStyle> fstys = sty.getFeatureStyles(); |
|
38 |
if (fstys == null || fstys.size() == 0) { |
|
39 |
throw new UnsupportedSLDObjectException("SLDFeatureStyle", "Bad structure"); |
|
40 |
} |
|
41 |
|
|
42 |
List<SLDRule> rules = fstys.get(0).getRules(); |
|
43 |
SLDRule rule = null; |
|
44 |
SLDConverterManager man = BasicUtils.sldMan(); |
|
45 |
|
|
46 |
ISymbol singleSym = null; |
|
47 |
|
|
48 |
if (BasicUtils.areRulesOfSingleSymbol(rules)) { |
|
49 |
|
|
50 |
rule = rules.get(0); |
|
51 |
List<SLDSymbol> sld_syms = rule.getSymbols(); |
|
52 |
/* |
|
53 |
for (int i=0; i<sld_syms.size(); i++) { |
|
54 |
sym = man.toSymbol(sld_syms.get(i)); |
|
55 |
gsyms.add(sym); |
|
56 |
} |
|
57 |
*/ |
|
58 |
if (sld_syms.size() == 1) { |
|
59 |
SLDSymbol aux = sld_syms.get(0); |
|
60 |
singleSym = man.toSymbol(aux); |
|
61 |
} else { |
|
62 |
int geo_type = BasicUtils.getGeometryTypeForSymbols(sld_syms); |
|
63 |
if (geo_type == Geometry.TYPES.NULL) { |
|
64 |
/* |
|
65 |
* We use only first symbol |
|
66 |
*/ |
|
67 |
SLDSymbol aux = sld_syms.get(0); |
|
68 |
singleSym = man.toSymbol(aux); |
|
69 |
} else { |
|
70 |
List<ISymbol> gsyms = new ArrayList<ISymbol>(); |
|
71 |
singleSym = BasicUtils.combineSymbols(gsyms, geo_type); |
|
72 |
} |
|
73 |
|
|
74 |
} |
|
75 |
|
|
76 |
ISingleSymbolLegend resp = (ISingleSymbolLegend) |
|
77 |
MapContextLocator.getMapContextManager().createLegend( |
|
78 |
ISingleSymbolLegend.LEGEND_NAME); |
|
79 |
resp.setDefaultSymbol(singleSym); |
|
80 |
return resp; |
|
81 |
|
|
82 |
} else { |
|
83 |
if (BasicUtils.areRulesOfUniqueSymbol(rules)) { |
|
84 |
return null; |
|
85 |
|
|
86 |
} else { |
|
87 |
if (BasicUtils.areRulesOfIntervals(rules)) { |
|
88 |
return null; |
|
89 |
|
|
90 |
} else { |
|
91 |
throw new UnsupportedSLDObjectException( |
|
92 |
"SLDFeatureStyle", "Rules do not follow recognizable pattern"); |
|
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
97 |
|
|
98 |
|
|
14 | 99 |
} |
15 | 100 |
|
16 | 101 |
public SLDLayer convert(ILegend legend) { |
branches/v02_desarrollo/libraries/sld/temp/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/legend/BasicLegendConverterFactory.java | ||
---|---|---|
1 | 1 |
package org.gvsig.sldconverter.impl.legend; |
2 | 2 |
|
3 |
import java.util.List; |
|
4 |
|
|
3 | 5 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
6 |
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend; |
|
7 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialIntervalLegend; |
|
8 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend; |
|
9 |
import org.gvsig.sldconverter.SLDConverterManager; |
|
4 | 10 |
import org.gvsig.sldconverter.legend.LegendToSLDConverter; |
5 | 11 |
import org.gvsig.sldconverter.legend.LegendToSLDConverterFactory; |
6 | 12 |
import org.gvsig.sldconverter.legend.SLDToLegendConverter; |
7 | 13 |
import org.gvsig.sldconverter.legend.SLDToLegendConverterFactory; |
8 | 14 |
import org.gvsig.sldsupport.sld.layer.SLDLayer; |
15 |
import org.gvsig.sldsupport.sld.layer.SLDNamedLayer; |
|
16 |
import org.gvsig.sldsupport.sld.layer.SLDUserLayer; |
|
17 |
import org.gvsig.sldsupport.sld.rule.SLDRule; |
|
18 |
import org.gvsig.sldsupport.sld.style.SLDFeatureStyle; |
|
19 |
import org.gvsig.sldsupport.sld.style.layer.SLDLayerStyle; |
|
20 |
import org.gvsig.sldsupport.sld.style.layer.SLDUserStyle; |
|
21 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDStroke; |
|
9 | 22 |
|
10 | 23 |
public class BasicLegendConverterFactory |
11 | 24 |
implements LegendToSLDConverterFactory, SLDToLegendConverterFactory { |
25 |
|
|
26 |
public static int LEGEND_PARTIALLY_CONVERTED = 50; |
|
12 | 27 |
|
13 |
public int canConvert(SLDLayer sldLay) { |
|
14 |
// TODO Auto-generated method stub |
|
15 |
return 0; |
|
28 |
public int canConvert(ILegend legend) { |
|
29 |
if (legend instanceof ISingleSymbolLegend |
|
30 |
|| legend instanceof IVectorialUniqueValueLegend |
|
31 |
|| legend instanceof IVectorialIntervalLegend) { |
|
32 |
|
|
33 |
return SLDConverterManager.CAN_CONVERT_FULLY; |
|
34 |
} else { |
|
35 |
return SLDConverterManager.CANNOT_CONVERT; |
|
36 |
} |
|
16 | 37 |
} |
17 | 38 |
|
18 |
public SLDToLegendConverter createSLDToLegendConverter() {
|
|
39 |
public LegendToSLDConverter createLegendToSLDConverter() {
|
|
19 | 40 |
return new BasicLegendConverter(); |
20 | 41 |
} |
21 | 42 |
|
22 | 43 |
// ======================================= |
23 |
|
|
24 |
public int canConvert(ILegend legend) { |
|
25 |
// TODO Auto-generated method stub |
|
26 |
return 0; |
|
27 |
} |
|
28 |
|
|
29 |
public LegendToSLDConverter createLegendToSLDConverter() { |
|
44 |
|
|
45 |
public SLDToLegendConverter createSLDToLegendConverter() { |
|
30 | 46 |
return new BasicLegendConverter(); |
31 | 47 |
} |
48 |
|
|
49 |
public int canConvert(SLDLayer layer) { |
|
50 |
|
|
51 |
if (layer == null ) { |
|
52 |
return SLDConverterManager.CANNOT_CONVERT; |
|
53 |
} |
|
54 |
|
|
55 |
if (layer instanceof SLDNamedLayer) { |
|
56 |
return BasicUtils.canConvertNamedLayer((SLDNamedLayer) layer); |
|
57 |
} else { |
|
58 |
if (layer instanceof SLDUserLayer) { |
|
59 |
return BasicUtils.canConvertUserLayer((SLDUserLayer) layer); |
|
60 |
} else { |
|
61 |
// Unknown layer |
|
62 |
return SLDConverterManager.CANNOT_CONVERT; |
|
63 |
} |
|
64 |
} |
|
65 |
} |
|
32 | 66 |
|
67 |
|
|
68 |
|
|
69 |
|
|
33 | 70 |
} |
branches/v02_desarrollo/libraries/sld/temp/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/legend/BasicUtils.java | ||
---|---|---|
1 |
package org.gvsig.sldconverter.impl.legend; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import org.gvsig.fmap.geom.Geometry; |
|
8 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
9 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
|
10 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
11 |
import org.gvsig.sldconverter.SLDConverterLocator; |
|
12 |
import org.gvsig.sldconverter.SLDConverterManager; |
|
13 |
import org.gvsig.sldconverter.exception.UnsupportedSLDObjectException; |
|
14 |
import org.gvsig.sldsupport.sld.filter.expression.SLDExpression; |
|
15 |
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDLiteral; |
|
16 |
import org.gvsig.sldsupport.sld.graphic.SLDExternalGraphic; |
|
17 |
import org.gvsig.sldsupport.sld.graphic.SLDGraphic; |
|
18 |
import org.gvsig.sldsupport.sld.graphic.SLDGraphicStackElement; |
|
19 |
import org.gvsig.sldsupport.sld.graphic.SLDMark; |
|
20 |
import org.gvsig.sldsupport.sld.layer.SLDLayer; |
|
21 |
import org.gvsig.sldsupport.sld.layer.SLDNamedLayer; |
|
22 |
import org.gvsig.sldsupport.sld.layer.SLDUserLayer; |
|
23 |
import org.gvsig.sldsupport.sld.rule.SLDRule; |
|
24 |
import org.gvsig.sldsupport.sld.style.SLDFeatureStyle; |
|
25 |
import org.gvsig.sldsupport.sld.style.layer.SLDLayerStyle; |
|
26 |
import org.gvsig.sldsupport.sld.style.layer.SLDUserStyle; |
|
27 |
import org.gvsig.sldsupport.sld.symbol.SLDLineSymbol; |
|
28 |
import org.gvsig.sldsupport.sld.symbol.SLDPointSymbol; |
|
29 |
import org.gvsig.sldsupport.sld.symbol.SLDPolygonSymbol; |
|
30 |
import org.gvsig.sldsupport.sld.symbol.SLDSymbol; |
|
31 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDFill; |
|
32 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDStroke; |
|
33 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
|
34 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
35 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
|
36 |
|
|
37 |
public class BasicUtils { |
|
38 |
|
|
39 |
public static SLDConverterManager sldMan() { |
|
40 |
return SLDConverterLocator.getInstance().getSLDSupportManager(); |
|
41 |
} |
|
42 |
|
|
43 |
public static int canConvertUserLayer(SLDUserLayer layer) { |
|
44 |
List<SLDUserStyle> stys = layer.getStyles(); |
|
45 |
if (stys.size() == 0) { |
|
46 |
return SLDConverterManager.CANNOT_CONVERT; |
|
47 |
} else { |
|
48 |
if (stys.size() == 1) { |
|
49 |
return canConvertUserStyle( |
|
50 |
stys.get(0), |
|
51 |
SLDConverterManager.CAN_CONVERT_FULLY); |
|
52 |
} else { |
|
53 |
return canConvertUserStyle( |
|
54 |
stys.get(0), |
|
55 |
/*result devaluated*/ |
|
56 |
SLDConverterManager.CAN_CONVERT_FULLY / 2); |
|
57 |
} |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
|
|
62 |
public static int canConvertNamedLayer(SLDNamedLayer layer) { |
|
63 |
|
|
64 |
List<SLDLayerStyle> stys = layer.getStyles(); |
|
65 |
if (stys.size() == 0) { |
|
66 |
return SLDConverterManager.CANNOT_CONVERT; |
|
67 |
} else { |
|
68 |
if (stys.size() == 1 && stys.get(0) instanceof SLDUserStyle) { |
|
69 |
return canConvertUserStyle( |
|
70 |
(SLDUserStyle) stys.get(0), |
|
71 |
SLDConverterManager.CAN_CONVERT_FULLY); |
|
72 |
} else { |
|
73 |
for (int i=0; i<stys.size(); i++) { |
|
74 |
if (stys.get(i) instanceof SLDUserStyle) { |
|
75 |
/* |
|
76 |
* Get first USerStyle and devaluate result |
|
77 |
*/ |
|
78 |
return canConvertUserStyle( |
|
79 |
(SLDUserStyle) stys.get(0), |
|
80 |
/*result devaluated*/ |
|
81 |
SLDConverterManager.CAN_CONVERT_FULLY / 2); |
|
82 |
} |
|
83 |
} |
|
84 |
// No user style found: |
|
85 |
return SLDConverterManager.CANNOT_CONVERT; |
|
86 |
} |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
public static int canConvertUserStyle(SLDUserStyle style, int max) { |
|
91 |
|
|
92 |
List<SLDFeatureStyle> fstys = style.getFeatureStyles(); |
|
93 |
if (fstys.size() == 0) { |
|
94 |
return SLDConverterManager.CANNOT_CONVERT; |
|
95 |
} else { |
|
96 |
if (fstys.size() == 1) { |
|
97 |
return canConvertFeatureStyle(fstys.get(0), max); |
|
98 |
} else { |
|
99 |
return canConvertFeatureStyle(fstys.get(0), max / 2); |
|
100 |
} |
|
101 |
} |
|
102 |
} |
|
103 |
|
|
104 |
public static int canConvertFeatureStyle(SLDFeatureStyle sldFeatureStyle, int max) { |
|
105 |
|
|
106 |
List<SLDRule> rules = sldFeatureStyle.getRules(); |
|
107 |
if (rules == null || rules.size() == 0) { |
|
108 |
return SLDConverterManager.CANNOT_CONVERT; |
|
109 |
} |
|
110 |
|
|
111 |
if (areRulesOfSingleSymbol(rules)) { |
|
112 |
return max; |
|
113 |
} else { |
|
114 |
if (areRulesOfUniqueSymbol(rules)) { |
|
115 |
return max; |
|
116 |
} else { |
|
117 |
if (areRulesOfIntervals(rules)) { |
|
118 |
return max; |
|
119 |
} else { |
|
120 |
return SLDConverterManager.CANNOT_CONVERT; |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
public static boolean areRulesOfIntervals(List<SLDRule> rules) { |
|
127 |
|
|
128 |
// TODO Auto-generated method stub |
|
129 |
return false; |
|
130 |
} |
|
131 |
|
|
132 |
public static boolean areRulesOfUniqueSymbol(List<SLDRule> rules) { |
|
133 |
|
|
134 |
// TODO Auto-generated method stub |
|
135 |
return false; |
|
136 |
} |
|
137 |
|
|
138 |
public static boolean areRulesOfSingleSymbol(List<SLDRule> rules) { |
|
139 |
|
|
140 |
if (rules.size() != 1) { |
|
141 |
return false; |
|
142 |
} |
|
143 |
|
|
144 |
SLDRule rule = rules.get(0); |
|
145 |
/* |
|
146 |
* Check there is NOT a filter |
|
147 |
*/ |
|
148 |
return rule.getFilter() == null; |
|
149 |
} |
|
150 |
|
|
151 |
|
|
152 |
public static SLDUserStyle getFirstUserStyle(SLDLayer layer) { |
|
153 |
|
|
154 |
if (layer instanceof SLDNamedLayer) { |
|
155 |
SLDNamedLayer nl = (SLDNamedLayer) layer; |
|
156 |
for (int i=0; i<nl.getStyles().size(); i++) { |
|
157 |
if (nl.getStyles().get(i) instanceof SLDUserStyle) { |
|
158 |
// return first found |
|
159 |
return (SLDUserStyle) nl.getStyles().get(i); |
|
160 |
} |
|
161 |
} |
|
162 |
return null; |
|
163 |
} else { |
|
164 |
if (layer instanceof SLDUserLayer) { |
|
165 |
SLDUserLayer ul = (SLDUserLayer) layer; |
|
166 |
if (ul.getStyles().size() == 1) { |
|
167 |
return ul.getStyles().get(0); |
|
168 |
} else { |
|
169 |
return null; |
|
170 |
} |
|
171 |
} else { |
|
172 |
return null; |
|
173 |
} |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 |
/** |
|
178 |
* |
|
179 |
* Geometry.TYPES.POINT |
|
180 |
* Geometry.TYPES.CURVE |
|
181 |
* Geometry.TYPES.SURFACE |
|
182 |
* or |
|
183 |
* Geometry.TYPES.NULL if there is not consistency in the list |
|
184 |
* |
|
185 |
* @return |
|
186 |
*/ |
|
187 |
public static int getGeometryTypeForSymbols(List<SLDSymbol> list) { |
|
188 |
|
|
189 |
if (list == null || list.size() == 0) { |
|
190 |
return Geometry.TYPES.NULL; |
|
191 |
} |
|
192 |
|
|
193 |
SLDSymbol ss = list.get(0); |
|
194 |
if (ss instanceof SLDPointSymbol) { |
|
195 |
if (allItemsOfClass(list, SLDPointSymbol.class)) { |
|
196 |
return Geometry.TYPES.POINT; |
|
197 |
} |
|
198 |
} else { |
|
199 |
if (ss instanceof SLDLineSymbol) { |
|
200 |
if (allItemsOfClass(list, SLDLineSymbol.class)) { |
|
201 |
return Geometry.TYPES.CURVE; |
|
202 |
} |
|
203 |
} else { |
|
204 |
if (ss instanceof SLDPolygonSymbol) { |
|
205 |
if (allItemsOfClass(list, SLDPolygonSymbol.class)) { |
|
206 |
return Geometry.TYPES.SURFACE; |
|
207 |
} |
|
208 |
} else { |
|
209 |
// Unknown |
|
210 |
return Geometry.TYPES.NULL; |
|
211 |
} |
|
212 |
} |
|
213 |
} |
|
214 |
// Inconsistent list |
|
215 |
return Geometry.TYPES.NULL; |
|
216 |
} |
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
private static boolean allItemsOfClass(List<SLDSymbol> list, Class clazz) { |
|
221 |
for (int i=0; i<list.size(); i++) { |
|
222 |
if (list.get(i).getClass() != clazz) { |
|
223 |
return false; |
|
224 |
} |
|
225 |
} |
|
226 |
return true; |
|
227 |
} |
|
228 |
|
|
229 |
public static ISymbol combineSymbols(List<ISymbol> gsyms, int geotype) { |
|
230 |
|
|
231 |
if (gsyms.size() == 1) { |
|
232 |
return gsyms.get(0); |
|
233 |
} |
|
234 |
|
|
235 |
IMultiLayerSymbol resp = |
|
236 |
MapContextLocator.getSymbolManager().createMultiLayerSymbol(geotype); |
|
237 |
for (int i=0; i<gsyms.size(); i++) { |
|
238 |
resp.addLayer(gsyms.get(i)); |
|
239 |
} |
|
240 |
return resp; |
|
241 |
} |
|
242 |
|
|
243 |
// ========================================================== |
|
244 |
// ========================================================== |
|
245 |
// ========================================================== |
|
246 |
/* |
|
247 |
* Symbol utilities... |
|
248 |
*/ |
|
249 |
|
|
250 |
public static ISymbol toMarkerSymbol(SLDPointSymbol sym) |
|
251 |
throws UnsupportedSLDObjectException { |
|
252 |
|
|
253 |
SLDGraphic gra = sym.getGraphic(); |
|
254 |
List<SLDGraphicStackElement> list = gra.getElementStack(); |
|
255 |
if (list.size() == 1) { |
|
256 |
return toMarkerSymbol(list.get(0)); |
|
257 |
} else { |
|
258 |
List<ISymbol> listsym = new ArrayList<ISymbol>(); |
|
259 |
IMultiLayerSymbol resp = |
|
260 |
MapContextLocator.getSymbolManager().createMultiLayerSymbol( |
|
261 |
Geometry.TYPES.POINT); |
|
262 |
for (int i=0; i<list.size(); i++) { |
|
263 |
resp.addLayer(toMarkerSymbol(list.get(i))); |
|
264 |
} |
|
265 |
return resp; |
|
266 |
} |
|
267 |
} |
|
268 |
|
|
269 |
|
|
270 |
private static ISymbol toMarkerSymbol(SLDGraphicStackElement graelem) |
|
271 |
throws UnsupportedSLDObjectException { |
|
272 |
|
|
273 |
if (graelem instanceof SLDExternalGraphic) { |
|
274 |
|
|
275 |
SLDExternalGraphic ext = (SLDExternalGraphic) graelem; |
|
276 |
IMarkerSymbol resp = (IMarkerSymbol) |
|
277 |
MapContextLocator.getSymbolManager().createSymbol( |
|
278 |
IMarkerSymbol.SYMBOL_NAME, Color.RED); |
|
279 |
return resp; |
|
280 |
|
|
281 |
} else { |
|
282 |
if (graelem instanceof SLDMark) { |
|
283 |
IMarkerSymbol resp = (IMarkerSymbol) |
|
284 |
MapContextLocator.getSymbolManager().createSymbol( |
|
285 |
IMarkerSymbol.SYMBOL_NAME, Color.BLUE); |
|
286 |
return resp; |
|
287 |
} else { |
|
288 |
throw new UnsupportedSLDObjectException( |
|
289 |
"SLDGraphicStackElement", |
|
290 |
"Unexpected class: " + graelem.getClass().getName()); |
|
291 |
} |
|
292 |
} |
|
293 |
} |
|
294 |
|
|
295 |
// ========================================================== |
|
296 |
// ========================================================== |
|
297 |
|
|
298 |
public static ISymbol toLineSymbol(SLDLineSymbol sym) |
|
299 |
throws UnsupportedSLDObjectException { |
|
300 |
|
|
301 |
ILineSymbol resp = (ILineSymbol) MapContextLocator.getSymbolManager().createSymbol( |
|
302 |
Geometry.TYPES.CURVE); |
|
303 |
SLDStroke stro = sym.getStroke(); |
|
304 |
|
|
305 |
Color col = BasicUtils.toColor(stro.getColor()); |
|
306 |
double wi = BasicUtils.toDouble(stro.getWidth()); |
|
307 |
|
|
308 |
resp.setColor(col); |
|
309 |
resp.setLineWidth(wi); |
|
310 |
|
|
311 |
return resp; |
|
312 |
} |
|
313 |
|
|
314 |
private static double toDouble(SLDExpression width) |
|
315 |
throws UnsupportedSLDObjectException { |
|
316 |
|
|
317 |
if (width instanceof SLDLiteral) { |
|
318 |
|
|
319 |
SLDLiteral lit = (SLDLiteral) width; |
|
320 |
double resp = 1; |
|
321 |
try { |
|
322 |
resp = Double.parseDouble(lit.getValue()); |
|
323 |
return resp; |
|
324 |
} catch (Exception exc) { |
|
325 |
throw new UnsupportedSLDObjectException( |
|
326 |
"SLDExpression as Double", exc.getMessage()); |
|
327 |
} |
|
328 |
|
|
329 |
} else { |
|
330 |
throw new UnsupportedSLDObjectException( |
|
331 |
"SLDExpression", |
|
332 |
"Not supported as Double: " + width.getClass().getName()); |
|
333 |
} |
|
334 |
} |
|
335 |
|
|
336 |
/** |
|
337 |
* |
|
338 |
* Input must be like "#fa5e02" |
|
339 |
* |
|
340 |
* @param hex |
|
341 |
* @return |
|
342 |
*/ |
|
343 |
public static Color parseHexadecimalColor(String hex) { |
|
344 |
|
|
345 |
return Color.decode(hex.trim()); |
|
346 |
} |
|
347 |
|
|
348 |
private static Color toColor(SLDExpression color) |
|
349 |
throws UnsupportedSLDObjectException { |
|
350 |
|
|
351 |
if (color instanceof SLDLiteral) { |
|
352 |
|
|
353 |
SLDLiteral lit = (SLDLiteral) color; |
|
354 |
Color resp = null; |
|
355 |
try { |
|
356 |
resp = parseHexadecimalColor(lit.getValue()); |
|
357 |
return resp; |
|
358 |
} catch (Exception exc) { |
|
359 |
throw new UnsupportedSLDObjectException( |
|
360 |
"SLDExpression as Color", exc.getMessage()); |
|
361 |
} |
|
362 |
|
|
363 |
} else { |
|
364 |
throw new UnsupportedSLDObjectException( |
|
365 |
"SLDExpression", |
|
366 |
"Not supported as Color: " + color.getClass().getName()); |
|
367 |
} |
|
368 |
|
|
369 |
|
|
370 |
} |
|
371 |
|
|
372 |
// ========================================================== |
|
373 |
// ========================================================== |
|
374 |
|
|
375 |
public static ISymbol toFillSymbol(SLDPolygonSymbol sym) |
|
376 |
throws UnsupportedSLDObjectException { |
|
377 |
|
|
378 |
IFillSymbol resp = (IFillSymbol) |
|
379 |
MapContextLocator.getSymbolManager().createSymbol( |
|
380 |
IFillSymbol.SYMBOL_NAME); |
|
381 |
|
|
382 |
SLDFill fill = sym.getFill(); |
|
383 |
SLDStroke stro = sym.getStroke(); |
|
384 |
|
|
385 |
Color col = BasicUtils.toColor(fill.getFillColor()); |
|
386 |
resp.setFillColor(col); |
|
387 |
|
|
388 |
return resp; |
|
389 |
} |
|
390 |
|
|
391 |
} |
Also available in: Unified diff