Revision 1275
org.gvsig.sld/tags/org.gvsig.sld-2.0.245/pom.xml | ||
---|---|---|
1 |
<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/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.desktop</artifactId> |
|
6 |
<version>2.0.450</version> |
|
7 |
</parent> |
|
8 |
|
|
9 |
<artifactId>org.gvsig.sld</artifactId> |
|
10 |
<version>2.0.245</version> |
|
11 |
<packaging>pom</packaging> |
|
12 |
<name>org.gvsig.sld</name> |
|
13 |
|
|
14 |
<url>https://redmine.gvsig.net/redmine/projects/gvsig-sldtools</url> |
|
15 |
<scm> |
|
16 |
<connection>scm:svn:https://devel.gvsig.org/svn/gvsig-sldtools/org.gvsig.sld/tags/org.gvsig.sld-2.0.245</connection> |
|
17 |
<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-sldtools/org.gvsig.sld/tags/org.gvsig.sld-2.0.245</developerConnection> |
|
18 |
<url>scm:svn:https://devel.gvsig.org/svn/gvsig-sldtools/org.gvsig.sld/tags/org.gvsig.sld-2.0.245</url> |
|
19 |
</scm> |
|
20 |
<repositories> |
|
21 |
<repository> |
|
22 |
<id>gvsig-public-http-repository</id> |
|
23 |
<name>gvSIG maven public HTTP repository</name> |
|
24 |
<url>http://devel.gvsig.org/m2repo/j2se</url> |
|
25 |
<releases> |
|
26 |
<enabled>true</enabled> |
|
27 |
<updatePolicy>daily</updatePolicy> |
|
28 |
<checksumPolicy>warn</checksumPolicy> |
|
29 |
</releases> |
|
30 |
<snapshots> |
|
31 |
<enabled>true</enabled> |
|
32 |
<updatePolicy>daily</updatePolicy> |
|
33 |
<checksumPolicy>warn</checksumPolicy> |
|
34 |
</snapshots> |
|
35 |
</repository> |
|
36 |
</repositories> |
|
37 |
|
|
38 |
<build> |
|
39 |
<plugins> |
|
40 |
<plugin> |
|
41 |
<groupId>org.apache.maven.plugins</groupId> |
|
42 |
<artifactId>maven-release-plugin</artifactId> |
|
43 |
<configuration> |
|
44 |
<tagBase>https://devel.gvsig.org/svn/gvsig-sldtools/org.gvsig.sld/tags</tagBase> |
|
45 |
</configuration> |
|
46 |
</plugin> |
|
47 |
</plugins> |
|
48 |
</build> |
|
49 |
|
|
50 |
<modules> |
|
51 |
<module>org.gvsig.sld.app</module> |
|
52 |
<module>org.gvsig.sldconverter</module> |
|
53 |
<module>org.gvsig.sldsupport</module> |
|
54 |
</modules> |
|
55 |
<dependencyManagement> |
|
56 |
<dependencies> |
|
57 |
<dependency> |
|
58 |
<groupId>org.gvsig</groupId> |
|
59 |
<artifactId>org.gvsig.sldsupport.lib.api</artifactId> |
|
60 |
<version>2.0.245</version> |
|
61 |
</dependency> |
|
62 |
<dependency> |
|
63 |
<groupId>org.gvsig</groupId> |
|
64 |
<artifactId>org.gvsig.sldconverter.lib.api</artifactId> |
|
65 |
<version>2.0.245</version> |
|
66 |
</dependency> |
|
67 |
<!-- <dependency> |
|
68 |
<groupId>org.gvsig</groupId> |
|
69 |
<artifactId>org.gvsig.xmlpull.lib.api</artifactId> |
|
70 |
<version>2.0.1</version> |
|
71 |
</dependency> --> |
|
72 |
<dependency> |
|
73 |
<groupId>org.gvsig</groupId> |
|
74 |
<artifactId>org.gvsig.sldsupport.lib.impl</artifactId> |
|
75 |
<version>2.0.245</version> |
|
76 |
</dependency> |
|
77 |
<dependency> |
|
78 |
<groupId>org.gvsig</groupId> |
|
79 |
<artifactId>org.gvsig.sldconverter.lib.impl</artifactId> |
|
80 |
<version>2.0.245</version> |
|
81 |
</dependency> |
|
82 |
</dependencies> |
|
83 |
</dependencyManagement> |
|
84 |
</project> |
org.gvsig.sld/tags/org.gvsig.sld-2.0.245/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.245</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.245/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/legend/UniqueSymbolLegendUtils.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.legend; |
|
27 |
|
|
28 |
import java.util.Iterator; |
|
29 |
import java.util.List; |
|
30 |
import java.util.Map; |
|
31 |
|
|
32 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend; |
|
33 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
34 |
import org.gvsig.sldconverter.exception.UnsupportedSymbolException; |
|
35 |
import org.gvsig.sldconverter.impl.util.BasicUtils; |
|
36 |
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException; |
|
37 |
import org.gvsig.sldsupport.sld.filter.FilterTags; |
|
38 |
import org.gvsig.sldsupport.sld.filter.SLDFilter; |
|
39 |
import org.gvsig.sldsupport.sld.filter.SLDFilterOperator; |
|
40 |
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDLiteral; |
|
41 |
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDPropertyName; |
|
42 |
import org.gvsig.sldsupport.sld.filter.operator.comparison.SLDBinaryComparisonOperator; |
|
43 |
import org.gvsig.sldsupport.sld.layer.SLDLayer; |
|
44 |
import org.gvsig.sldsupport.sld.layer.SLDNamedLayer; |
|
45 |
import org.gvsig.sldsupport.sld.rule.SLDRule; |
|
46 |
import org.gvsig.sldsupport.sld.style.SLDFeatureStyle; |
|
47 |
import org.gvsig.sldsupport.sld.style.layer.SLDUserStyle; |
|
48 |
import org.gvsig.sldsupport.sld.symbol.SLDSymbol; |
|
49 |
import org.gvsig.tools.dataTypes.DataType; |
|
50 |
|
|
51 |
public class UniqueSymbolLegendUtils { |
|
52 |
|
|
53 |
|
|
54 |
public static IVectorialUniqueValueLegend toUniqueValueLegend( |
|
55 |
List<SLDRule> rules) throws UnsupportedSLDObjectException { |
|
56 |
|
|
57 |
|
|
58 |
IVectorialUniqueValueLegend unileg = (IVectorialUniqueValueLegend) |
|
59 |
BasicUtils.mapMan().createLegend( |
|
60 |
IVectorialUniqueValueLegend.LEGEND_NAME); |
|
61 |
|
|
62 |
String pname = BasicUtils.getFirstPropertyName(rules); |
|
63 |
if (pname == null || pname.length() == 0) { |
|
64 |
throw new UnsupportedSLDObjectException( |
|
65 |
"SLDFeatureStyle", "Cannot interpret rules (no property name)"); |
|
66 |
} |
|
67 |
List<SLDLiteral> lits = BasicUtils.getComparisonLiterals(rules); |
|
68 |
/* |
|
69 |
* Here we know that rules are compatible with unique-symbol legend |
|
70 |
* so all literals are in the "equals" comparisons |
|
71 |
*/ |
|
72 |
if (lits == null || lits.size() == 0) { |
|
73 |
throw new UnsupportedSLDObjectException( |
|
74 |
"SLDFeatureStyle", "Cannot interpret rules (no literals)"); |
|
75 |
} |
|
76 |
DataType dt = BasicUtils.guessDataType(lits); |
|
77 |
ISymbol sym = BasicUtils.getElseSymbol(rules); |
|
78 |
// sym can be null |
|
79 |
Map<Object, ISymbol> map = BasicUtils.getValueToSymbol(rules, dt, pname); |
|
80 |
Iterator iter = map.keySet().iterator(); |
|
81 |
Object k = null; |
|
82 |
while (iter.hasNext()) { |
|
83 |
k = iter.next(); |
|
84 |
unileg.addSymbol(k, map.get(k)); |
|
85 |
} |
|
86 |
if (sym != null) { |
|
87 |
unileg.setDefaultSymbol(sym); |
|
88 |
unileg.useDefaultSymbol(true); |
|
89 |
} else { |
|
90 |
unileg.useDefaultSymbol(false); |
|
91 |
} |
|
92 |
String[] atts = new String[1]; |
|
93 |
atts[0] = pname; |
|
94 |
unileg.setClassifyingFieldNames(atts); |
|
95 |
int[] typs = new int[1]; |
|
96 |
typs[0] = dt.getType(); |
|
97 |
unileg.setClassifyingFieldTypes(typs); |
|
98 |
return unileg; |
|
99 |
} |
|
100 |
|
|
101 |
|
|
102 |
public static boolean areRulesOfUniqueSymbol(List<SLDRule> rules) { |
|
103 |
|
|
104 |
if (rules == null || rules.size() == 0) { |
|
105 |
return false; |
|
106 |
} |
|
107 |
|
|
108 |
SLDRule rule = null; |
|
109 |
String fieldName = null; |
|
110 |
for (int i=0; i<rules.size(); i++) { |
|
111 |
rule = rules.get(i); |
|
112 |
fieldName = getEqualsLiteralFieldName(rule); |
|
113 |
if (fieldName != null) { |
|
114 |
break; |
|
115 |
} |
|
116 |
} |
|
117 |
|
|
118 |
if (fieldName == null) { |
|
119 |
// The filter of first rule is not of type "field name equals literal" |
|
120 |
return false; |
|
121 |
} |
|
122 |
int elsecount = 0; |
|
123 |
for (int i=1; i<rules.size(); i++) { |
|
124 |
rule = rules.get(i); |
|
125 |
if (!BasicUtils.isElse(rule)) { |
|
126 |
String fname = getEqualsLiteralFieldName(rule); |
|
127 |
if (fname == null || fname.compareTo(fieldName) != 0) { |
|
128 |
// Not a equals operation based on the same field |
|
129 |
return false; |
|
130 |
} |
|
131 |
} else { |
|
132 |
elsecount++; |
|
133 |
} |
|
134 |
|
|
135 |
} |
|
136 |
// Found no reason to deny it's a unique symbol legend |
|
137 |
// (if number of else filters is 0 or 1) |
|
138 |
return elsecount < 2; |
|
139 |
} |
|
140 |
|
|
141 |
|
|
142 |
/** |
|
143 |
* Returns the name of the field name on which the rule |
|
144 |
* is based if the rule has a equals operation and the |
|
145 |
* operand is a literal. Otherwise returns null. |
|
146 |
* |
|
147 |
* @param rule |
|
148 |
* @return |
|
149 |
*/ |
|
150 |
private static String getEqualsLiteralFieldName(SLDRule rule) { |
|
151 |
|
|
152 |
SLDFilter filt = rule.getFilter(); |
|
153 |
if (filt == null) { |
|
154 |
return null; |
|
155 |
} |
|
156 |
SLDFilterOperator oper = filt.getFilterOperator(); |
|
157 |
if (!(oper instanceof SLDBinaryComparisonOperator)) { |
|
158 |
// not binary |
|
159 |
return null; |
|
160 |
} |
|
161 |
SLDBinaryComparisonOperator bop = (SLDBinaryComparisonOperator) oper; |
|
162 |
if (bop.getComparisonOperator().compareToIgnoreCase( |
|
163 |
FilterTags.PROPERTYISEQUALTO) != 0) { |
|
164 |
// not "equals" operand |
|
165 |
return null; |
|
166 |
} |
|
167 |
SLDPropertyName pname = null; |
|
168 |
if (bop.getFirstExpression() instanceof SLDLiteral && |
|
169 |
bop.getSecondExpression() instanceof SLDPropertyName) { |
|
170 |
pname = (SLDPropertyName) bop.getSecondExpression(); |
|
171 |
return pname.getPropertyName(); |
|
172 |
|
|
173 |
} else { |
|
174 |
if (bop.getSecondExpression() instanceof SLDLiteral && |
|
175 |
bop.getFirstExpression() instanceof SLDPropertyName) { |
|
176 |
pname = (SLDPropertyName) bop.getFirstExpression(); |
|
177 |
return pname.getPropertyName(); |
|
178 |
} else { |
|
179 |
// not a couple "property name + literal" |
|
180 |
return null; |
|
181 |
} |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
185 |
|
|
186 |
public static SLDLayer toSLDLayer(IVectorialUniqueValueLegend legend) |
|
187 |
throws UnsupportedSymbolException { |
|
188 |
|
|
189 |
String fname = legend.getClassifyingFieldNames()[0]; |
|
190 |
SLDSymbol sldsym = null; |
|
191 |
SLDRule rule = null; |
|
192 |
SLDFeatureStyle fstyle = new SLDFeatureStyle(); |
|
193 |
|
|
194 |
Object val = null; |
|
195 |
String valstr = null; |
|
196 |
Object[] vals = legend.getValues(); |
|
197 |
ISymbol[] syms = legend.getSymbols(); |
|
198 |
int n = Math.min(vals.length, syms.length); |
|
199 |
SLDFilter filt = null; |
|
200 |
SLDBinaryComparisonOperator oper = null; |
|
201 |
for (int i=0; i<n; i++) { |
|
202 |
rule = new SLDRule(); |
|
203 |
// ===================== |
|
204 |
sldsym = BasicUtils.sldMan().toSLDSymbol(syms[i]); |
|
205 |
rule.getSymbols().add(sldsym); |
|
206 |
// ===================== |
|
207 |
filt = BasicUtils.supMan().createFilter(); |
|
208 |
filt.setIsElse(false); |
|
209 |
oper = new SLDBinaryComparisonOperator(); |
|
210 |
oper.setComparisonOperator(FilterTags.PROPERTYISEQUALTO); |
|
211 |
oper.setFirstExpression(new SLDPropertyName(fname)); |
|
212 |
// ======= Value (Object) to String |
|
213 |
val = vals[i]; |
|
214 |
valstr = BasicUtils.valueToString(val); |
|
215 |
oper.setSecondExpression(new SLDLiteral(valstr)); |
|
216 |
filt.setFilterOperator(oper); |
|
217 |
// ===================== |
|
218 |
rule.setFilter(filt); |
|
219 |
// ====================== |
|
220 |
fstyle.getRules().add(rule); |
|
221 |
} |
|
222 |
// ================ Default symbol |
|
223 |
ISymbol sym = legend.getDefaultSymbol(); |
|
224 |
if (sym != null) { |
|
225 |
rule = new SLDRule(); |
|
226 |
sldsym = BasicUtils.sldMan().toSLDSymbol(sym); |
|
227 |
rule.getSymbols().add(sldsym); |
|
228 |
filt = BasicUtils.supMan().createFilter(); |
|
229 |
filt.setIsElse(true); |
|
230 |
rule.setFilter(filt); |
|
231 |
fstyle.getRules().add(rule); |
|
232 |
} |
|
233 |
// ====================== |
|
234 |
SLDUserStyle usty = new SLDUserStyle(); |
|
235 |
usty.getFeatureStyles().add(fstyle); |
|
236 |
|
|
237 |
SLDNamedLayer nlayer = new SLDNamedLayer(); |
|
238 |
nlayer.setName("Name"); |
|
239 |
nlayer.getStyles().add(usty); |
|
240 |
return nlayer; |
|
241 |
} |
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.245/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/legend/BasicLegendConverterFactory.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.legend; |
|
27 |
|
|
28 |
import java.util.List; |
|
29 |
|
|
30 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
31 |
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend; |
|
32 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialIntervalLegend; |
|
33 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend; |
|
34 |
import org.gvsig.sldconverter.SLDConverterManager; |
|
35 |
import org.gvsig.sldconverter.legend.LegendToSLDConverter; |
|
36 |
import org.gvsig.sldconverter.legend.LegendToSLDConverterFactory; |
|
37 |
import org.gvsig.sldconverter.legend.SLDToLegendConverter; |
|
38 |
import org.gvsig.sldconverter.legend.SLDToLegendConverterFactory; |
|
39 |
import org.gvsig.sldsupport.sld.layer.SLDLayer; |
|
40 |
import org.gvsig.sldsupport.sld.layer.SLDNamedLayer; |
|
41 |
import org.gvsig.sldsupport.sld.layer.SLDUserLayer; |
|
42 |
import org.gvsig.sldsupport.sld.rule.SLDRule; |
|
43 |
import org.gvsig.sldsupport.sld.style.SLDFeatureStyle; |
|
44 |
import org.gvsig.sldsupport.sld.style.layer.SLDLayerStyle; |
|
45 |
import org.gvsig.sldsupport.sld.style.layer.SLDUserStyle; |
|
46 |
|
|
47 |
public class BasicLegendConverterFactory |
|
48 |
implements LegendToSLDConverterFactory, SLDToLegendConverterFactory { |
|
49 |
|
|
50 |
public static int LEGEND_PARTIALLY_CONVERTED = 50; |
|
51 |
|
|
52 |
public int canConvert(ILegend legend) { |
|
53 |
if (legend instanceof ISingleSymbolLegend |
|
54 |
|| legend instanceof IVectorialUniqueValueLegend |
|
55 |
|| legend instanceof IVectorialIntervalLegend) { |
|
56 |
|
|
57 |
/* |
|
58 |
* This allows precedence of converters for specific classes |
|
59 |
*/ |
|
60 |
return SLDConverterManager.CAN_CONVERT_PARTIALLY; |
|
61 |
} else { |
|
62 |
return SLDConverterManager.CAN_NOT_CONVERT; |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
public LegendToSLDConverter createLegendToSLDConverter() { |
|
67 |
return new BasicLegendConverter(); |
|
68 |
} |
|
69 |
|
|
70 |
// ======================================= |
|
71 |
|
|
72 |
public SLDToLegendConverter createSLDToLegendConverter() { |
|
73 |
return new BasicLegendConverter(); |
|
74 |
} |
|
75 |
|
|
76 |
|
|
77 |
public int canConvert(SLDLayer layer) { |
|
78 |
|
|
79 |
if (layer == null ) { |
|
80 |
return SLDConverterManager.CAN_NOT_CONVERT; |
|
81 |
} |
|
82 |
|
|
83 |
if (layer instanceof SLDNamedLayer) { |
|
84 |
return canConvertNamedLayer((SLDNamedLayer) layer); |
|
85 |
} else { |
|
86 |
if (layer instanceof SLDUserLayer) { |
|
87 |
return canConvertUserLayer((SLDUserLayer) layer); |
|
88 |
} else { |
|
89 |
// Unknown layer |
|
90 |
return SLDConverterManager.CAN_NOT_CONVERT; |
|
91 |
} |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
|
|
96 |
private int canConvertNamedLayer(SLDNamedLayer layer) { |
|
97 |
|
|
98 |
List<SLDLayerStyle> stys = layer.getStyles(); |
|
99 |
if (stys.size() == 0) { |
|
100 |
return SLDConverterManager.CAN_NOT_CONVERT; |
|
101 |
} else { |
|
102 |
if (stys.size() == 1 && stys.get(0) instanceof SLDUserStyle) { |
|
103 |
return canConvertUserStyle( |
|
104 |
(SLDUserStyle) stys.get(0), |
|
105 |
SLDConverterManager.CAN_CONVERT_PARTIALLY); |
|
106 |
} else { |
|
107 |
for (int i=0; i<stys.size(); i++) { |
|
108 |
if (stys.get(i) instanceof SLDUserStyle) { |
|
109 |
/* |
|
110 |
* Get first USerStyle and devaluate result |
|
111 |
*/ |
|
112 |
return canConvertUserStyle( |
|
113 |
(SLDUserStyle) stys.get(0), |
|
114 |
/*result devaluated*/ |
|
115 |
SLDConverterManager.CAN_CONVERT_PARTIALLY); |
|
116 |
} |
|
117 |
} |
|
118 |
// No user style found: |
|
119 |
return SLDConverterManager.CAN_NOT_CONVERT; |
|
120 |
} |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
|
|
125 |
private int canConvertUserStyle(SLDUserStyle style, int max) { |
|
126 |
|
|
127 |
List<SLDFeatureStyle> fstys = style.getFeatureStyles(); |
|
128 |
if (fstys.size() == 0) { |
|
129 |
return SLDConverterManager.CAN_NOT_CONVERT; |
|
130 |
} else { |
|
131 |
if (fstys.size() == 1) { |
|
132 |
return canConvertFeatureStyle(fstys.get(0), max); |
|
133 |
} else { |
|
134 |
return canConvertFeatureStyle(fstys.get(0), max / 2); |
|
135 |
} |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
|
|
140 |
private int canConvertUserLayer(SLDUserLayer layer) { |
|
141 |
List<SLDUserStyle> stys = layer.getStyles(); |
|
142 |
if (stys.size() == 0) { |
|
143 |
return SLDConverterManager.CAN_NOT_CONVERT; |
|
144 |
} else { |
|
145 |
if (stys.size() == 1) { |
|
146 |
return canConvertUserStyle( |
|
147 |
stys.get(0), |
|
148 |
SLDConverterManager.CAN_CONVERT_PARTIALLY); |
|
149 |
} else { |
|
150 |
return canConvertUserStyle( |
|
151 |
stys.get(0), |
|
152 |
/*result devaluated*/ |
|
153 |
SLDConverterManager.CAN_CONVERT_PARTIALLY); |
|
154 |
} |
|
155 |
} |
|
156 |
} |
|
157 |
|
|
158 |
|
|
159 |
private int canConvertFeatureStyle(SLDFeatureStyle sldFeatureStyle, int max) { |
|
160 |
|
|
161 |
List<SLDRule> rules = sldFeatureStyle.getRules(); |
|
162 |
if (rules == null || rules.size() == 0) { |
|
163 |
return SLDConverterManager.CAN_NOT_CONVERT; |
|
164 |
} |
|
165 |
|
|
166 |
if (SingleSymbolLegendUtils.areRulesOfSingleSymbol(rules)) { |
|
167 |
return max; |
|
168 |
} else { |
|
169 |
if (UniqueSymbolLegendUtils.areRulesOfUniqueSymbol(rules)) { |
|
170 |
return max; |
|
171 |
} else { |
|
172 |
if (IntervalsLegendUtils.areRulesOfIntervals(rules)) { |
|
173 |
return max; |
|
174 |
} else { |
|
175 |
return SLDConverterManager.CAN_NOT_CONVERT; |
|
176 |
} |
|
177 |
} |
|
178 |
} |
|
179 |
} |
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.245/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/legend/IntervalsLegendUtils.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.legend; |
|
27 |
|
|
28 |
import java.util.HashMap; |
|
29 |
import java.util.Iterator; |
|
30 |
import java.util.List; |
|
31 |
import java.util.Map; |
|
32 |
|
|
33 |
import org.gvsig.fmap.mapcontext.rendering.legend.IInterval; |
|
34 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialIntervalLegend; |
|
35 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
36 |
import org.gvsig.sldconverter.exception.UnsupportedSymbolException; |
|
37 |
import org.gvsig.sldconverter.impl.util.BasicUtils; |
|
38 |
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException; |
|
39 |
import org.gvsig.sldsupport.sld.filter.FilterTags; |
|
40 |
import org.gvsig.sldsupport.sld.filter.SLDFilter; |
|
41 |
import org.gvsig.sldsupport.sld.filter.SLDFilterOperator; |
|
42 |
import org.gvsig.sldsupport.sld.filter.expression.SLDExpression; |
|
43 |
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDLiteral; |
|
44 |
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDPropertyName; |
|
45 |
import org.gvsig.sldsupport.sld.filter.operator.SLDComparisonOperator; |
|
46 |
import org.gvsig.sldsupport.sld.filter.operator.comparison.SLDBinaryComparisonOperator; |
|
47 |
import org.gvsig.sldsupport.sld.filter.operator.comparison.SLDIsBetweenOperator; |
|
48 |
import org.gvsig.sldsupport.sld.layer.SLDLayer; |
|
49 |
import org.gvsig.sldsupport.sld.layer.SLDNamedLayer; |
|
50 |
import org.gvsig.sldsupport.sld.rule.SLDRule; |
|
51 |
import org.gvsig.sldsupport.sld.style.SLDFeatureStyle; |
|
52 |
import org.gvsig.sldsupport.sld.style.layer.SLDUserStyle; |
|
53 |
import org.gvsig.sldsupport.sld.symbol.SLDSymbol; |
|
54 |
import org.gvsig.tools.dataTypes.CoercionException; |
|
55 |
import org.gvsig.tools.dataTypes.DataType; |
|
56 |
|
|
57 |
public class IntervalsLegendUtils { |
|
58 |
|
|
59 |
|
|
60 |
public static IVectorialIntervalLegend toIntervalsLegend(List<SLDRule> rules) |
|
61 |
throws UnsupportedSLDObjectException { |
|
62 |
|
|
63 |
IVectorialIntervalLegend intleg = (IVectorialIntervalLegend) |
|
64 |
BasicUtils.mapMan().createLegend( |
|
65 |
IVectorialIntervalLegend.LEGEND_NAME); |
|
66 |
|
|
67 |
String pname = BasicUtils.getFirstPropertyName(rules); |
|
68 |
if (pname == null || pname.length() == 0) { |
|
69 |
throw new UnsupportedSLDObjectException( |
|
70 |
"SLDFeatureStyle", "Cannot interpret rules (no property name)"); |
|
71 |
} |
|
72 |
List<SLDLiteral> lits = BasicUtils.getComparisonLiterals(rules); |
|
73 |
if (lits == null || lits.size() == 0) { |
|
74 |
throw new UnsupportedSLDObjectException( |
|
75 |
"SLDFeatureStyle", "Cannot interpret rules (no literals)"); |
|
76 |
} |
|
77 |
DataType dt = BasicUtils.guessDataType(lits); |
|
78 |
ISymbol sym = BasicUtils.getElseSymbol(rules); |
|
79 |
// sym can be null |
|
80 |
Map<IInterval, ISymbol> map = |
|
81 |
IntervalsLegendUtils.getIntervalToSymbol(rules, dt, pname); |
|
82 |
Iterator iter = map.keySet().iterator(); |
|
83 |
Object k = null; |
|
84 |
while (iter.hasNext()) { |
|
85 |
k = iter.next(); |
|
86 |
intleg.addSymbol(k, map.get(k)); |
|
87 |
} |
|
88 |
// Setting Default symbol |
|
89 |
if (sym != null) { |
|
90 |
sym.setDescription("Default"); |
|
91 |
intleg.setDefaultSymbol(sym); |
|
92 |
intleg.useDefaultSymbol(true); |
|
93 |
// String among the intervals |
|
94 |
intleg.addSymbol(sym.getDescription(), sym); |
|
95 |
} else { |
|
96 |
intleg.useDefaultSymbol(false); |
|
97 |
} |
|
98 |
|
|
99 |
String[] atts = new String[1]; |
|
100 |
atts[0] = pname; |
|
101 |
intleg.setClassifyingFieldNames(atts); |
|
102 |
int[] typs = new int[1]; |
|
103 |
typs[0] = dt.getType(); |
|
104 |
intleg.setClassifyingFieldTypes(typs); |
|
105 |
return intleg; |
|
106 |
|
|
107 |
} |
|
108 |
|
|
109 |
|
|
110 |
public static boolean areRulesOfIntervals(List<SLDRule> rules) { |
|
111 |
|
|
112 |
if (rules == null || rules.size() == 0) { |
|
113 |
return false; |
|
114 |
} |
|
115 |
|
|
116 |
SLDRule rule = null; |
|
117 |
String fieldName = null; |
|
118 |
for (int i=0; i<rules.size(); i++) { |
|
119 |
rule = rules.get(i); |
|
120 |
fieldName = getComparisonToNumericLiteralFieldName(rule); |
|
121 |
if (fieldName != null) { |
|
122 |
break; |
|
123 |
} |
|
124 |
} |
|
125 |
|
|
126 |
if (fieldName == null) { |
|
127 |
// The filter of first rule is not of type "field name equals literal" |
|
128 |
return false; |
|
129 |
} |
|
130 |
int elsecount = 0; |
|
131 |
for (int i=1; i<rules.size(); i++) { |
|
132 |
rule = rules.get(i); |
|
133 |
if (!BasicUtils.isElse(rule)) { |
|
134 |
String fname = getComparisonToNumericLiteralFieldName(rule); |
|
135 |
if (fname == null || fname.compareTo(fieldName) != 0) { |
|
136 |
// Not a equals operation based on the same field |
|
137 |
return false; |
|
138 |
} |
|
139 |
} else { |
|
140 |
elsecount++; |
|
141 |
} |
|
142 |
|
|
143 |
} |
|
144 |
// Found no reason to deny it's a interval legend |
|
145 |
// (if number of else filters is 0 or 1) |
|
146 |
return elsecount < 2; |
|
147 |
} |
|
148 |
|
|
149 |
|
|
150 |
/** |
|
151 |
* Returns the name of the field name on which the rule |
|
152 |
* is based if the rule is a interval comparison and the |
|
153 |
* operand is a literal. Otherwise returns null. |
|
154 |
* |
|
155 |
* @param rule |
|
156 |
* @return |
|
157 |
*/ |
|
158 |
private static String getComparisonToNumericLiteralFieldName(SLDRule rule) { |
|
159 |
|
|
160 |
SLDFilter filt = rule.getFilter(); |
|
161 |
if (filt == null) { |
|
162 |
return null; |
|
163 |
} |
|
164 |
SLDFilterOperator oper = filt.getFilterOperator(); |
|
165 |
if (!(oper instanceof SLDComparisonOperator)) { |
|
166 |
// interval has to be SLDComparisonOperator |
|
167 |
return null; |
|
168 |
} |
|
169 |
SLDComparisonOperator cop = (SLDComparisonOperator) oper; |
|
170 |
SLDPropertyName pname = null; |
|
171 |
if (cop instanceof SLDBinaryComparisonOperator) { |
|
172 |
SLDBinaryComparisonOperator bco = (SLDBinaryComparisonOperator) cop; |
|
173 |
String opname = bco.getComparisonOperator(); |
|
174 |
if (opname.compareTo(FilterTags.PROPERTYISGREATEROREQUALTHAN) == 0 |
|
175 |
|| opname.compareTo(FilterTags.PROPERTYISGREATERTHAN) == 0 |
|
176 |
|| opname.compareTo(FilterTags.PROPERTYISLESSOREQUALTHAN) == 0 |
|
177 |
|| opname.compareTo(FilterTags.PROPERTYISLESSTHAN) == 0) { |
|
178 |
|
|
179 |
if (bco.getFirstExpression() instanceof SLDLiteral && |
|
180 |
bco.getSecondExpression() instanceof SLDPropertyName) { |
|
181 |
|
|
182 |
pname = (SLDPropertyName) bco.getSecondExpression(); |
|
183 |
if (BasicUtils.isNumeric((SLDLiteral) bco.getFirstExpression())) { |
|
184 |
return pname.getPropertyName(); |
|
185 |
} else { |
|
186 |
return null; |
|
187 |
} |
|
188 |
|
|
189 |
} |
|
190 |
if (bco.getFirstExpression() instanceof SLDPropertyName && |
|
191 |
bco.getSecondExpression() instanceof SLDLiteral) { |
|
192 |
|
|
193 |
pname = (SLDPropertyName) bco.getFirstExpression(); |
|
194 |
if (BasicUtils.isNumeric((SLDLiteral) bco.getSecondExpression())) { |
|
195 |
return pname.getPropertyName(); |
|
196 |
} else { |
|
197 |
return null; |
|
198 |
} |
|
199 |
} |
|
200 |
} |
|
201 |
} else { |
|
202 |
if (cop instanceof SLDIsBetweenOperator) { |
|
203 |
|
|
204 |
SLDIsBetweenOperator beop = (SLDIsBetweenOperator) cop; |
|
205 |
if (beop.getExpression() instanceof SLDPropertyName |
|
206 |
// Limits must be literals |
|
207 |
&& beop.getLowerBoundary() instanceof SLDLiteral |
|
208 |
&& beop.getUpperBoundary() instanceof SLDLiteral) { |
|
209 |
|
|
210 |
pname = (SLDPropertyName) beop.getExpression(); |
|
211 |
if (BasicUtils.isNumeric((SLDLiteral) beop.getLowerBoundary()) |
|
212 |
&& BasicUtils.isNumeric((SLDLiteral) beop.getUpperBoundary())) { |
|
213 |
return pname.getPropertyName(); |
|
214 |
} else { |
|
215 |
return null; |
|
216 |
} |
|
217 |
} |
|
218 |
} |
|
219 |
} |
|
220 |
// Not the type we are looking for |
|
221 |
return null; |
|
222 |
} |
|
223 |
|
|
224 |
|
|
225 |
public static SLDLayer toSLDLayer(IVectorialIntervalLegend legend) |
|
226 |
throws UnsupportedSymbolException { |
|
227 |
|
|
228 |
String fname = legend.getClassifyingFieldNames()[0]; |
|
229 |
SLDSymbol sldsym = null; |
|
230 |
SLDRule rule = null; |
|
231 |
SLDFeatureStyle fstyle = new SLDFeatureStyle(); |
|
232 |
|
|
233 |
IInterval iival = null; |
|
234 |
String valstr = null; |
|
235 |
Object[] vals = legend.getValues(); |
|
236 |
ISymbol[] syms = legend.getSymbols(); |
|
237 |
int n = Math.min(vals.length, syms.length); |
|
238 |
SLDFilter filt = null; |
|
239 |
SLDComparisonOperator oper = null; |
|
240 |
ISymbol elsesym = null; |
|
241 |
|
|
242 |
for (int i=0; i<n; i++) { |
|
243 |
rule = new SLDRule(); |
|
244 |
// ===================== |
|
245 |
sldsym = BasicUtils.sldMan().toSLDSymbol(syms[i]); |
|
246 |
rule.getSymbols().add(sldsym); |
|
247 |
// ===================== |
|
248 |
if (vals[i] instanceof IInterval) { |
|
249 |
filt = BasicUtils.supMan().createFilter(); |
|
250 |
filt.setIsElse(false); |
|
251 |
iival = (IInterval) vals[i]; |
|
252 |
oper = intervalToComparisonOperator(iival, fname); |
|
253 |
filt.setFilterOperator(oper); |
|
254 |
// ===================== |
|
255 |
rule.setFilter(filt); |
|
256 |
// ====================== |
|
257 |
fstyle.getRules().add(rule); |
|
258 |
} else { |
|
259 |
// assuming "Default" |
|
260 |
elsesym = syms[i]; |
|
261 |
} |
|
262 |
} |
|
263 |
// ================ Default symbol |
|
264 |
|
|
265 |
// No "Default" value was found in intervals |
|
266 |
// but default sym is enabled |
|
267 |
if (elsesym == null && legend.isUseDefaultSymbol()) { |
|
268 |
elsesym = legend.getDefaultSymbol(); |
|
269 |
} |
|
270 |
|
|
271 |
if (elsesym != null) { |
|
272 |
rule = new SLDRule(); |
|
273 |
sldsym = BasicUtils.sldMan().toSLDSymbol(elsesym); |
|
274 |
rule.getSymbols().add(sldsym); |
|
275 |
filt = BasicUtils.supMan().createFilter(); |
|
276 |
filt.setIsElse(true); |
|
277 |
rule.setFilter(filt); |
|
278 |
fstyle.getRules().add(rule); |
|
279 |
} |
|
280 |
// ====================== |
|
281 |
SLDUserStyle usty = new SLDUserStyle(); |
|
282 |
usty.getFeatureStyles().add(fstyle); |
|
283 |
|
|
284 |
SLDNamedLayer nlayer = new SLDNamedLayer(); |
|
285 |
nlayer.setName("Name"); |
|
286 |
nlayer.getStyles().add(usty); |
|
287 |
return nlayer; |
|
288 |
|
|
289 |
} |
|
290 |
|
|
291 |
|
|
292 |
private static SLDComparisonOperator intervalToComparisonOperator( |
|
293 |
IInterval iival, String fieldName) { |
|
294 |
|
|
295 |
double max = iival.getMax(); |
|
296 |
double min = iival.getMin(); |
|
297 |
if (max == Double.MAX_VALUE && min != -Double.MAX_VALUE) { |
|
298 |
// greater than min |
|
299 |
SLDBinaryComparisonOperator resp = new SLDBinaryComparisonOperator(); |
|
300 |
resp.setComparisonOperator(FilterTags.PROPERTYISGREATEROREQUALTHAN); |
|
301 |
resp.setFirstExpression(new SLDPropertyName(fieldName)); |
|
302 |
|
|
303 |
resp.setSecondExpression(new SLDLiteral(BasicUtils.df.format(min))); |
|
304 |
return resp; |
|
305 |
|
|
306 |
} else { |
|
307 |
if (min == -Double.MAX_VALUE && max != Double.MAX_VALUE) { |
|
308 |
// less than max |
|
309 |
SLDBinaryComparisonOperator resp = new SLDBinaryComparisonOperator(); |
|
310 |
resp.setComparisonOperator(FilterTags.PROPERTYISLESSOREQUALTHAN); |
|
311 |
resp.setFirstExpression(new SLDPropertyName(fieldName)); |
|
312 |
resp.setSecondExpression(new SLDLiteral(BasicUtils.df.format(max))); |
|
313 |
return resp; |
|
314 |
|
|
315 |
} else { |
|
316 |
// normal (between) |
|
317 |
SLDIsBetweenOperator resp = new SLDIsBetweenOperator(); |
|
318 |
resp.setExpression(new SLDPropertyName(fieldName)); |
|
319 |
resp.setLowerBoundary(new SLDLiteral(BasicUtils.df.format(min))); |
|
320 |
resp.setUpperBoundary(new SLDLiteral(BasicUtils.df.format(max))); |
|
321 |
return resp; |
|
322 |
} |
|
323 |
} |
|
324 |
} |
|
325 |
|
|
326 |
|
|
327 |
|
|
328 |
/** |
|
329 |
* Translates rules to a interval-symbol correspondence. |
|
330 |
* |
|
331 |
* @param rules |
|
332 |
* @param dt |
|
333 |
* @return |
|
334 |
* @throws UnsupportedSLDObjectException |
|
335 |
* @throws CoercionException |
|
336 |
*/ |
|
337 |
public static Map<IInterval, ISymbol> getIntervalToSymbol( |
|
338 |
List<SLDRule> rules, DataType dt, String pname) |
|
339 |
throws UnsupportedSLDObjectException { |
|
340 |
|
|
341 |
Map<IInterval, ISymbol> resp = new HashMap<IInterval, ISymbol>(); |
|
342 |
if (rules == null || rules.size() == 0) { |
|
343 |
return resp; |
|
344 |
} |
|
345 |
SLDFilter filt = null; |
|
346 |
List<SLDSymbol> symList = null; |
|
347 |
SLDFilterOperator oper = null; |
|
348 |
SLDBinaryComparisonOperator binoper = null; |
|
349 |
ISymbol sym = null; |
|
350 |
SLDPropertyName sldpname = null; |
|
351 |
SLDLiteral sldlit = null; |
|
352 |
Object val = null; |
|
353 |
for (int i=0; i<rules.size(); i++) { |
|
354 |
symList = rules.get(i).getSymbols(); |
|
355 |
if (symList == null || symList.size() == 0) { |
|
356 |
/* |
|
357 |
* No symbols found |
|
358 |
*/ |
|
359 |
continue; |
|
360 |
} |
|
361 |
filt = rules.get(i).getFilter(); |
|
362 |
if (filt == null) { |
|
363 |
continue; |
|
364 |
} |
|
365 |
if (!filt.isElse()) { |
|
366 |
oper = filt.getFilterOperator(); |
|
367 |
if (oper instanceof SLDComparisonOperator) { |
|
368 |
sym = BasicUtils.sldMan().toSymbol(symList.get(0)); |
|
369 |
if (sym != null) { |
|
370 |
IInterval ival = getIntervalForSymbol( |
|
371 |
(SLDComparisonOperator) oper, pname, sym); |
|
372 |
if (ival != null) { |
|
373 |
resp.put(ival, sym); |
|
374 |
} |
|
375 |
} |
|
376 |
} |
|
377 |
} else { |
|
378 |
// filter is else |
|
379 |
} |
|
380 |
} |
|
381 |
return resp; |
|
382 |
} |
|
383 |
|
|
384 |
private static IInterval getIntervalForSymbol( |
|
385 |
SLDComparisonOperator oper, String pname, ISymbol sym) { |
|
386 |
|
|
387 |
double min = 0; |
|
388 |
double max = 0; |
|
389 |
SLDBinaryComparisonOperator bc = null; |
|
390 |
SLDIsBetweenOperator bw = null; |
|
391 |
SLDLiteral lit = null; |
|
392 |
if (oper instanceof SLDBinaryComparisonOperator) { |
|
393 |
bc = (SLDBinaryComparisonOperator) oper; |
|
394 |
if (isGreaterComparison(bc)) { |
|
395 |
lit = BasicUtils.getLiteral(bc.getExpressions()); |
|
396 |
try { |
|
397 |
min = Double.parseDouble(lit.getValue()); |
|
398 |
max = Double.MAX_VALUE; |
|
399 |
sym.setDescription("> " + lit.getValue()); |
|
400 |
} catch (Exception exc) { |
|
401 |
return null; |
|
402 |
} |
|
403 |
|
|
404 |
} else { |
|
405 |
if (isLessThanComparison(bc)) { |
|
406 |
lit = BasicUtils.getLiteral(bc.getExpressions()); |
|
407 |
try { |
|
408 |
max = Double.parseDouble(lit.getValue()); |
|
409 |
min = -Double.MAX_VALUE; |
|
410 |
sym.setDescription("< " + lit.getValue()); |
|
411 |
} catch (Exception exc) { |
|
412 |
return null; |
|
413 |
} |
|
414 |
} else { |
|
415 |
return null; |
|
416 |
} |
|
417 |
} |
|
418 |
} else { |
|
419 |
if (oper instanceof SLDIsBetweenOperator) { |
|
420 |
bw = (SLDIsBetweenOperator) oper; |
|
421 |
SLDExpression lower = bw.getLowerBoundary(); |
|
422 |
SLDExpression upper = bw.getUpperBoundary(); |
|
423 |
if (lower instanceof SLDLiteral && upper instanceof SLDLiteral) { |
|
424 |
String lowerstr = ((SLDLiteral) lower).getValue(); |
|
425 |
String upperstr = ((SLDLiteral) upper).getValue(); |
|
426 |
try { |
|
427 |
min = Double.parseDouble(lowerstr); |
|
428 |
max = Double.parseDouble(upperstr); |
|
429 |
sym.setDescription(lowerstr + " - " + upperstr); |
|
430 |
} catch (Exception exc) { |
|
431 |
return null; |
|
432 |
} |
|
433 |
} else { |
|
434 |
return null; |
|
435 |
} |
|
436 |
|
|
437 |
} else { |
|
438 |
return null; |
|
439 |
} |
|
440 |
} |
|
441 |
return BasicUtils.symMan().createInterval(min, max); |
|
442 |
} |
|
443 |
|
|
444 |
|
|
445 |
private static boolean isLessThanComparison(SLDBinaryComparisonOperator bc) { |
|
446 |
if (bc == null) { |
|
447 |
return false; |
|
448 |
} else { |
|
449 |
String comp = bc.getComparisonOperator(); |
|
450 |
return comp != null && |
|
451 |
(comp.compareTo(FilterTags.PROPERTYISLESSOREQUALTHAN) == 0 |
|
452 |
|| comp.compareTo(FilterTags.PROPERTYISLESSTHAN) == 0); |
|
453 |
} |
|
454 |
} |
|
455 |
|
|
456 |
private static boolean isGreaterComparison(SLDBinaryComparisonOperator bc) { |
|
457 |
if (bc == null) { |
|
458 |
return false; |
|
459 |
} else { |
|
460 |
String comp = bc.getComparisonOperator(); |
|
461 |
return comp != null && |
|
462 |
(comp.compareTo(FilterTags.PROPERTYISGREATEROREQUALTHAN) == 0 |
|
463 |
|| comp.compareTo(FilterTags.PROPERTYISGREATERTHAN) == 0); |
|
464 |
} |
|
465 |
} |
|
466 |
|
|
467 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.245/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/legend/SingleSymbolLegendUtils.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.legend; |
|
27 |
|
|
28 |
import java.util.ArrayList; |
|
29 |
import java.util.List; |
|
30 |
|
|
31 |
import org.gvsig.fmap.geom.Geometry; |
|
32 |
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend; |
|
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.impl.util.BasicUtils; |
|
38 |
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException; |
|
39 |
import org.gvsig.sldsupport.sld.layer.SLDLayer; |
|
40 |
import org.gvsig.sldsupport.sld.layer.SLDNamedLayer; |
|
41 |
import org.gvsig.sldsupport.sld.rule.SLDRule; |
|
42 |
import org.gvsig.sldsupport.sld.style.SLDFeatureStyle; |
|
43 |
import org.gvsig.sldsupport.sld.style.layer.SLDUserStyle; |
|
44 |
import org.gvsig.sldsupport.sld.symbol.SLDSymbol; |
|
45 |
|
|
46 |
public class SingleSymbolLegendUtils { |
|
47 |
|
|
48 |
public static boolean areRulesOfSingleSymbol(List<SLDRule> rules) { |
|
49 |
|
|
50 |
if (rules.size() != 1) { |
|
51 |
return false; |
|
52 |
} |
|
53 |
|
|
54 |
SLDRule rule = rules.get(0); |
|
55 |
/* |
|
56 |
* Check there is NOT a filter |
|
57 |
*/ |
|
58 |
return rule.getFilter() == null; |
|
59 |
} |
|
60 |
|
|
61 |
public static ISingleSymbolLegend toSingleSymbolLegend(List<SLDRule> rules) |
|
62 |
throws UnsupportedSLDObjectException { |
|
63 |
|
|
64 |
SLDRule rule = null; |
|
65 |
SLDConverterManager man = BasicUtils.sldMan(); |
|
66 |
|
|
67 |
ISymbol singleSym = null; |
|
68 |
|
|
69 |
|
|
70 |
rule = rules.get(0); |
|
71 |
List<SLDSymbol> sld_syms = rule.getSymbols(); |
|
72 |
|
|
73 |
if (sld_syms.size() == 1) { |
|
74 |
SLDSymbol aux = sld_syms.get(0); |
|
75 |
singleSym = man.toSymbol(aux); |
|
76 |
} else { |
|
77 |
int geo_type = BasicUtils.getGeometryTypeForSymbols(sld_syms); |
|
78 |
if (geo_type == Geometry.TYPES.NULL) { |
|
79 |
/* |
|
80 |
* We use only first symbol |
|
81 |
*/ |
|
82 |
SLDSymbol aux = sld_syms.get(0); |
|
83 |
singleSym = man.toSymbol(aux); |
|
84 |
} else { |
|
85 |
List<ISymbol> gsyms = new ArrayList<ISymbol>(); |
|
86 |
singleSym = BasicUtils.combineSymbols(gsyms, geo_type); |
|
87 |
} |
|
88 |
} |
|
89 |
ISingleSymbolLegend resp = (ISingleSymbolLegend) |
|
90 |
BasicUtils.mapMan().createLegend( |
|
91 |
ISingleSymbolLegend.LEGEND_NAME); |
|
92 |
resp.setDefaultSymbol(singleSym); |
|
93 |
return resp; |
|
94 |
} |
|
95 |
|
|
96 |
public static SLDLayer toSLDLayer(ISingleSymbolLegend legend) |
|
97 |
throws UnsupportedLegendException, UnsupportedSymbolException { |
|
98 |
|
|
99 |
ISymbol sym = legend.getDefaultSymbol(); |
|
100 |
SLDSymbol sldsym = BasicUtils.sldMan().toSLDSymbol(sym); |
|
101 |
|
|
102 |
SLDRule rule = new SLDRule(); |
|
103 |
rule.getSymbols().add(sldsym); |
|
104 |
SLDFeatureStyle fstyle = new SLDFeatureStyle(); |
|
105 |
fstyle.getRules().add(rule); |
|
106 |
|
|
107 |
SLDUserStyle usty = new SLDUserStyle(); |
|
108 |
usty.getFeatureStyles().add(fstyle); |
|
109 |
|
|
110 |
SLDNamedLayer nlayer = new SLDNamedLayer(); |
|
111 |
nlayer.setName("Name"); |
|
112 |
nlayer.getStyles().add(usty); |
|
113 |
return nlayer; |
|
114 |
} |
|
115 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.245/org.gvsig.sldconverter/org.gvsig.sldconverter.lib/org.gvsig.sldconverter.lib.impl/src/main/java/org/gvsig/sldconverter/impl/legend/BasicLegendConverter.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.legend; |
|
27 |
|
|
28 |
import java.util.List; |
|
29 |
|
|
30 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
|
31 |
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend; |
|
32 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialIntervalLegend; |
|
33 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend; |
|
34 |
import org.gvsig.sldconverter.exception.UnsupportedLegendException; |
|
35 |
import org.gvsig.sldconverter.exception.UnsupportedSymbolException; |
|
36 |
import org.gvsig.sldconverter.impl.util.BasicUtils; |
|
37 |
import org.gvsig.sldconverter.legend.LegendToSLDConverter; |
|
38 |
import org.gvsig.sldconverter.legend.SLDToLegendConverter; |
|
39 |
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException; |
|
40 |
import org.gvsig.sldsupport.sld.layer.SLDLayer; |
|
41 |
import org.gvsig.sldsupport.sld.rule.SLDRule; |
|
42 |
import org.gvsig.sldsupport.sld.style.SLDFeatureStyle; |
|
43 |
import org.gvsig.sldsupport.sld.style.layer.SLDUserStyle; |
|
44 |
|
|
45 |
public class BasicLegendConverter |
|
46 |
implements LegendToSLDConverter, SLDToLegendConverter { |
|
47 |
|
|
48 |
public ILegend convert(SLDLayer layer) throws UnsupportedSLDObjectException { |
|
49 |
|
|
50 |
if (layer == null ) { |
|
51 |
throw new UnsupportedSLDObjectException("SLDLayer", "Null"); |
|
52 |
} |
|
53 |
|
|
54 |
SLDUserStyle sty = BasicUtils.getFirstUserStyle(layer); |
|
55 |
if (sty == null) { |
|
56 |
throw new UnsupportedSLDObjectException("SLDLayer", "Bad structure"); |
|
57 |
} |
|
58 |
|
|
59 |
List<SLDFeatureStyle> fstys = sty.getFeatureStyles(); |
|
60 |
if (fstys == null || fstys.size() == 0) { |
|
61 |
throw new UnsupportedSLDObjectException("SLDFeatureStyle", "Bad structure"); |
|
62 |
} |
|
63 |
|
|
64 |
List<SLDRule> rules = fstys.get(0).getRules(); |
|
65 |
|
|
66 |
/* |
|
67 |
* Checking if rules follow a pattern |
|
68 |
*/ |
|
69 |
|
|
70 |
if (SingleSymbolLegendUtils.areRulesOfSingleSymbol(rules)) { |
|
71 |
// * Single symbol legend |
|
72 |
return SingleSymbolLegendUtils.toSingleSymbolLegend(rules); |
|
73 |
|
|
74 |
} else { |
|
75 |
if (UniqueSymbolLegendUtils.areRulesOfUniqueSymbol(rules)) { |
|
76 |
// * Unique symbol legend |
|
77 |
return UniqueSymbolLegendUtils.toUniqueValueLegend(rules); |
|
78 |
|
|
79 |
} else { |
|
80 |
if (IntervalsLegendUtils.areRulesOfIntervals(rules)) { |
|
81 |
// * Intervals legend |
|
82 |
|
|
83 |
return IntervalsLegendUtils.toIntervalsLegend(rules); |
|
84 |
|
|
85 |
} else { |
|
86 |
/* |
|
87 |
* Rules not recognized as those of a basic legend |
|
88 |
*/ |
|
89 |
throw new UnsupportedSLDObjectException( |
|
90 |
"SLDFeatureStyle", "Rules do not follow recognizable pattern"); |
|
91 |
} |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
} |
|
98 |
|
|
99 |
public SLDLayer convert(ILegend legend) throws |
|
100 |
UnsupportedLegendException, UnsupportedSymbolException { |
|
101 |
|
|
102 |
if (legend instanceof ISingleSymbolLegend) { |
|
103 |
return SingleSymbolLegendUtils.toSLDLayer((ISingleSymbolLegend) legend); |
|
104 |
} else { |
|
105 |
if (legend instanceof IVectorialUniqueValueLegend) { |
|
106 |
return UniqueSymbolLegendUtils.toSLDLayer((IVectorialUniqueValueLegend) legend); |
|
107 |
} else { |
|
108 |
if (legend instanceof IVectorialIntervalLegend) { |
|
109 |
return IntervalsLegendUtils.toSLDLayer((IVectorialIntervalLegend) legend); |
|
110 |
} else { |
|
111 |
throw new UnsupportedLegendException( |
|
112 |
legend == null ? "Null" : legend.getClass().getName(), |
|
113 |
"Unsupported legend type"); |
|
114 |
} |
|
115 |
} |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
} |
org.gvsig.sld/tags/org.gvsig.sld-2.0.245/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.245/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 |
Also available in: Unified diff