Search in sources :

Example 6 with MutableRule

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);
}
Also used : MutableRule(org.geotoolkit.style.MutableRule) Marshaller(javax.xml.bind.Marshaller) ObjectFactory(org.geotoolkit.se.xml.v110.ObjectFactory) RuleType(org.geotoolkit.se.xml.v110.RuleType) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 7 with MutableRule

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");
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) Rule(org.opengis.style.Rule) MutableRule(org.geotoolkit.style.MutableRule) JAXBElement(javax.xml.bind.JAXBElement)

Example 8 with MutableRule

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;
}
Also used : MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) MutableRule(org.geotoolkit.style.MutableRule) Rule(org.opengis.style.Rule)

Example 9 with MutableRule

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;
}
Also used : MutableRule(org.geotoolkit.style.MutableRule) Symbolizer(org.opengis.style.Symbolizer)

Example 10 with MutableRule

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;
}
Also used : MutableRule(org.geotoolkit.style.MutableRule) Filter(org.opengis.filter.Filter) Expression(org.opengis.filter.Expression) Collection(java.util.Collection) Feature(org.opengis.feature.Feature) ValueReference(org.opengis.filter.ValueReference)

Aggregations

MutableRule (org.geotoolkit.style.MutableRule)18 MutableFeatureTypeStyle (org.geotoolkit.style.MutableFeatureTypeStyle)8 Symbolizer (org.opengis.style.Symbolizer)7 MutableStyle (org.geotoolkit.style.MutableStyle)6 Feature (org.opengis.feature.Feature)5 Expression (org.opengis.filter.Expression)5 Filter (org.opengis.filter.Filter)5 Rule (org.opengis.style.Rule)5 ArrayList (java.util.ArrayList)4 LineSymbolizer (org.opengis.style.LineSymbolizer)4 PointSymbolizer (org.opengis.style.PointSymbolizer)4 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)4 List (java.util.List)3 FeatureType (org.opengis.feature.FeatureType)3 ValueReference (org.opengis.filter.ValueReference)3 FeatureTypeStyle (org.opengis.style.FeatureTypeStyle)3 IOException (java.io.IOException)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 JAXBElement (javax.xml.bind.JAXBElement)2