use of org.geotoolkit.style.MutableRule in project geotoolkit by Geomatys.
the class SEforSLD110Test method testRule.
@Test
public void testRule() throws JAXBException, FactoryException {
final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
final Marshaller MARSHALLER = POOL.acquireMarshaller();
// Read test
Object obj = UNMARSHALLER.unmarshal(FILE_SE_RULE);
assertNotNull(obj);
JAXBElement<?> jax = (JAXBElement<?>) obj;
MutableRule rule = TRANSFORMER_GT.visitRule(jax.getValue());
assertNotNull(rule);
assertEquals(rule.getName(), valueName);
assertEquals(rule.getDescription().getTitle().toString(), valueTitle);
assertEquals(rule.getDescription().getAbstract().toString(), valueAbstract);
assertEquals(rule.getMinScaleDenominator(), 500d, DELTA);
assertEquals(rule.getMaxScaleDenominator(), 1000d, DELTA);
assertNull(rule.getLegend());
assertNotNull(rule.getFilter());
assertEquals(rule.symbolizers().size(), 4);
// Write test
RuleType pvt = (RuleType) TRANSFORMER_OGC.visit(rule, null);
assertNotNull(pvt);
assertEquals(pvt.getName(), valueName);
assertEquals(String.valueOf(pvt.getDescription().getTitle()), valueTitle);
assertEquals(String.valueOf(pvt.getDescription().getAbstract()), valueAbstract);
assertEquals(pvt.getMinScaleDenominator(), 500d, DELTA);
assertEquals(pvt.getMaxScaleDenominator(), 1000d, DELTA);
assertNull(pvt.getLegendGraphic());
assertEquals(pvt.getSymbolizer().size(), 4);
MARSHALLER.marshal(new ObjectFactory().createRule(pvt), TEST_FILE_SE_RULE);
POOL.recycle(MARSHALLER);
POOL.recycle(UNMARSHALLER);
}
use of org.geotoolkit.style.MutableRule in project geotoolkit by Geomatys.
the class StyleXmlIO method readRule.
/**
* Read a SE Rule source and parse it in GT Rule object.
* Source can be : File, InputSource, InputStream, Node, Reader, Source, URL,
* XMLEventReader, XMLStreamReader or OnlineResource
*/
public MutableRule readRule(final Object source, final Specification.SymbologyEncoding version) throws JAXBException, FactoryException {
ensureNonNull("source", source);
ensureNonNull("version", version);
final Object obj;
switch(version) {
case SLD_1_0_0:
obj = unmarshallV100(source);
if (obj instanceof org.geotoolkit.sld.xml.v100.Rule) {
return getTransformer100().visitRule((org.geotoolkit.sld.xml.v100.Rule) obj);
} else {
throw new JAXBException("Source is not a valid OGC SLD Rule v1.0.0");
}
case V_1_1_0:
obj = unmarshallV110(source);
if (obj instanceof org.geotoolkit.se.xml.v110.RuleType) {
return getTransformer110().visitRule(obj);
} else if (obj instanceof JAXBElement<?> && (((JAXBElement<?>) obj).getValue() instanceof org.geotoolkit.se.xml.v110.OnlineResourceType || ((JAXBElement<?>) obj).getValue() instanceof org.geotoolkit.se.xml.v110.RuleType)) {
return getTransformer110().visitRule(((JAXBElement<?>) obj).getValue());
} else {
throw new JAXBException("Source is not a valid OGC SE Rule v1.1.0");
}
default:
throw new IllegalArgumentException("Unable to read source, specified version is not supported");
}
}
use of org.geotoolkit.style.MutableRule in project geotoolkit by Geomatys.
the class CopyStyleVisitor method visit.
@Override
public MutableFeatureTypeStyle visit(FeatureTypeStyle fts, Object data) {
final MutableFeatureTypeStyle copy = SF.featureTypeStyle();
copy.semanticTypeIdentifiers().addAll(fts.semanticTypeIdentifiers());
copy.setDescription(fts.getDescription());
copy.setFeatureInstanceIDs(fts.getFeatureInstanceIDs());
copy.setName(fts.getName());
copy.setOnlineResource(fts.getOnlineResource());
for (Rule r : fts.rules()) {
copy.rules().add((MutableRule) r.accept(this, data));
}
return copy;
}
use of org.geotoolkit.style.MutableRule in project geotoolkit by Geomatys.
the class CopyStyleVisitor method visit.
@Override
public MutableRule visit(Rule rule, Object data) {
final MutableRule copy = SF.rule();
copy.setDescription(rule.getDescription());
copy.setElseFilter(rule.isElseFilter());
copy.setFilter(rule.getFilter());
copy.setLegendGraphic(rule.getLegend());
copy.setMaxScaleDenominator(rule.getMaxScaleDenominator());
copy.setMinScaleDenominator(rule.getMinScaleDenominator());
copy.setName(rule.getName());
copy.setOnlineResource(rule.getOnlineResource());
for (Symbolizer symbol : rule.symbolizers()) {
copy.symbolizers().add(symbol);
}
return copy;
}
use of org.geotoolkit.style.MutableRule in project geotoolkit by Geomatys.
the class MapfileToSLDProcess method createRule.
private MutableRule createRule(final Feature mflayer, final Double minScale, final Double maxscale, final Feature clazz) throws ProcessException {
// mapfile type is similar to se symbolizer type
final String type = (String) mflayer.getPropertyValue(LAYER_TYPE.toString());
final MutableRule rule = SF.rule();
final StringBuilder name = new StringBuilder("[");
if (minScale != null) {
rule.setMinScaleDenominator(minScale);
name.append(minScale);
} else {
name.append(0);
}
name.append(" ↔ ");
if (maxscale != null) {
rule.setMaxScaleDenominator(maxscale);
name.append(maxscale);
} else {
name.append(Double.POSITIVE_INFINITY);
}
name.append("]");
rule.setDescription(SF.description(name.toString(), name.toString()));
// Class can act as filter, the classItem is the propertyname on which the class
// Expression is evaluated
final ValueReference classItem = (ValueReference) mflayer.getPropertyValue(LAYER_CLASSITEM.toString());
final String classExpression = (String) clazz.getPropertyValue(CLASS_EXPRESSION.toString());
if (classExpression != null) {
// equivalant to OGC filter : PropertyEquals(name,value)
final Filter filter = toFilter(classItem, classExpression);
rule.setFilter(filter);
} else {
// filter
// not handle yet
rule.setElseFilter(true);
}
final Collection<Feature> styles = (Collection<Feature>) clazz.getPropertyValue(CLASS_STYLE.toString());
final Collection<Feature> labels = (Collection<Feature>) clazz.getPropertyValue(CLASS_LABEL.toString());
for (final Feature style : styles) {
if ("POLYGON".equalsIgnoreCase(type)) {
rule.symbolizers().addAll(createPolygonSymbolizer(style));
} else if ("LINE".equalsIgnoreCase(type)) {
rule.symbolizers().addAll(createLineSymbolizer(style));
} else if ("ANNOTATION".equalsIgnoreCase(type)) {
rule.symbolizers().addAll(createPointSymbolizer(style));
}
}
for (final Feature label : labels) {
// this property contain the label to place in the text symbolizer
Expression labelProp = (Expression) mflayer.getPropertyValue(LAYER_LABELITEM.toString());
Expression labelOverride = (Expression) mflayer.getPropertyValue(CLASS_TEXT.toString());
if (labelProp == null || labelOverride != null) {
// Class Text take priority over label item
labelProp = labelOverride;
}
rule.symbolizers().addAll(createTextSymbolizer(labelProp, label));
}
return rule;
}
Aggregations