Search in sources :

Example 11 with MutableFeatureTypeStyle

use of org.geotoolkit.style.MutableFeatureTypeStyle in project geotoolkit by Geomatys.

the class SE110toGTTransformer method visitFTS.

/**
 * Transform a SLD v1.1 FeatureTypeStyle or CoverageStyle in GT FTS.
 */
public MutableFeatureTypeStyle visitFTS(final Object obj) throws FactoryException {
    if (obj == null)
        return null;
    if (obj instanceof OnlineResourceType) {
        final OnlineResourceType ort = (OnlineResourceType) obj;
        final OnlineResource or = visitOnlineResource(ort);
        if (or != null) {
            try {
                return xmlUtilities.readFeatureTypeStyle(or, Specification.SymbologyEncoding.V_1_1_0);
            } catch (JAXBException ex) {
                Logger.getLogger("org.geotoolkit.sld.xml").log(Level.WARNING, null, ex);
            }
            return null;
        }
    } else if (obj instanceof CoverageStyleType) {
        final MutableFeatureTypeStyle fts = styleFactory.featureTypeStyle();
        final CoverageStyleType cst = (CoverageStyleType) obj;
        fts.setName(cst.getName());
        fts.setDescription(visitDescription(cst.getDescription()));
        fts.semanticTypeIdentifiers().addAll(visitSemantics(cst.getSemanticTypeIdentifier()));
        if (cst.getCoverageName() != null) {
            fts.featureTypeNames().add(NamesExt.create(cst.getCoverageName()));
        }
        if (cst.getRuleOrOnlineResource() == null || cst.getRuleOrOnlineResource().isEmpty()) {
        } else {
            for (Object objRule : cst.getRuleOrOnlineResource()) {
                fts.rules().add(visitRule(objRule));
            }
        }
        return fts;
    } else if (obj instanceof FeatureTypeStyleType) {
        final MutableFeatureTypeStyle fts = styleFactory.featureTypeStyle();
        final FeatureTypeStyleType ftst = (FeatureTypeStyleType) obj;
        fts.setName(ftst.getName());
        fts.setDescription(visitDescription(ftst.getDescription()));
        fts.semanticTypeIdentifiers().addAll(visitSemantics(ftst.getSemanticTypeIdentifier()));
        if (ftst.getFeatureTypeName() != null) {
            fts.featureTypeNames().add(NamesExt.create(ftst.getFeatureTypeName()));
        }
        if (ftst.getRuleOrOnlineResource() == null || ftst.getRuleOrOnlineResource().isEmpty()) {
        } else {
            for (final Object objRule : ftst.getRuleOrOnlineResource()) {
                fts.rules().add(visitRule(objRule));
            }
        }
        return fts;
    }
    return null;
}
Also used : OnlineResource(org.opengis.metadata.citation.OnlineResource) OnlineResourceType(org.geotoolkit.se.xml.v110.OnlineResourceType) JAXBException(javax.xml.bind.JAXBException) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) CoverageStyleType(org.geotoolkit.se.xml.v110.CoverageStyleType) FeatureTypeStyleType(org.geotoolkit.se.xml.v110.FeatureTypeStyleType)

Example 12 with MutableFeatureTypeStyle

use of org.geotoolkit.style.MutableFeatureTypeStyle in project geotoolkit by Geomatys.

the class StyleXmlIO method readFeatureTypeStyle.

/**
 * Read a SE FeatureTypeStyle source and parse it in GT FTS object.
 * Source can be : File, InputSource, InputStream, Node, Reader, Source, URL,
 * XMLEventReader, XMLStreamReader or OnlineResource
 */
public MutableFeatureTypeStyle readFeatureTypeStyle(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.FeatureTypeStyle) {
                return getTransformer100().visitFTS((org.geotoolkit.sld.xml.v100.FeatureTypeStyle) obj);
            } else {
                throw new JAXBException("Source is not a valid OGC SLD FeatureTypeStyle v1.0.0");
            }
        case V_1_1_0:
            obj = unmarshallV110(source);
            if (obj instanceof org.geotoolkit.se.xml.v110.FeatureTypeStyleType) {
                return getTransformer110().visitFTS(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.FeatureTypeStyleType)) {
                return getTransformer110().visitFTS(((JAXBElement<?>) obj).getValue());
            } else {
                throw new JAXBException("Source is not a valid OGC SE FeatureTypeStyle v1.1.0");
            }
        default:
            throw new IllegalArgumentException("Unable to read source, specified version is not supported");
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) FeatureTypeStyle(org.opengis.style.FeatureTypeStyle) JAXBElement(javax.xml.bind.JAXBElement)

Example 13 with MutableFeatureTypeStyle

use of org.geotoolkit.style.MutableFeatureTypeStyle in project geotoolkit by Geomatys.

the class MapfileToSLDProcess method convert.

private void convert(final MutableStyledLayerDescriptor sld, final Feature feature) throws ProcessException {
    final Collection<Feature> layers = (Collection<Feature>) feature.getPropertyValue(MAP_LAYER.toString());
    for (final Feature mflayer : layers) {
        // create an sld layer
        final MutableNamedLayer sldLayer = SLDF.createNamedLayer();
        sld.layers().add(sldLayer);
        final String name = String.valueOf(mflayer.getPropertyValue(LAYER_NAME.toString()));
        sldLayer.setName(name);
        sldLayer.setDescription(SF.description(name, name));
        // create the style
        final MutableStyle sldStyle = SF.style();
        sldLayer.styles().add(sldStyle);
        final MutableFeatureTypeStyle fts = SF.featureTypeStyle();
        sldStyle.featureTypeStyles().add(fts);
        final Double minscale = (Double) mflayer.getPropertyValue(LAYER_MINSCALEDENOM.toString());
        final Double maxscale = (Double) mflayer.getPropertyValue(LAYER_MAXSCALEDENOM.toString());
        final Collection<Feature> classes = (Collection<Feature>) mflayer.getPropertyValue(LAYER_CLASS.toString());
        for (final Feature clazz : classes) {
            final MutableRule rule = createRule(mflayer, minscale, maxscale, clazz);
            fts.rules().add(rule);
        }
    }
}
Also used : MutableRule(org.geotoolkit.style.MutableRule) MutableStyle(org.geotoolkit.style.MutableStyle) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) Collection(java.util.Collection) MutableNamedLayer(org.geotoolkit.sld.MutableNamedLayer) Feature(org.opengis.feature.Feature)

Example 14 with MutableFeatureTypeStyle

use of org.geotoolkit.style.MutableFeatureTypeStyle in project geotoolkit by Geomatys.

the class Styles method scaleRule.

// ////////////////////////////////////////////////////////////////////
// RULES /////////////////////////////////////////////////////////////
// ////////////////////////////////////////////////////////////////////
public static MutableStyle scaleRule() {
    final MutableRule over = SF.rule();
    over.setMinScaleDenominator(1000000);
    over.symbolizers().add(SF.polygonSymbolizer(DEFAULT_STROKE, SF.fill(Color.RED), null));
    final MutableRule under = SF.rule();
    under.setMaxScaleDenominator(1000000);
    under.symbolizers().add(SF.polygonSymbolizer(DEFAULT_STROKE, SF.fill(Color.GREEN), null));
    final MutableStyle style = SF.style();
    final MutableFeatureTypeStyle fts = SF.featureTypeStyle();
    fts.rules().add(over);
    fts.rules().add(under);
    style.featureTypeStyles().add(fts);
    return style;
}
Also used : MutableRule(org.geotoolkit.style.MutableRule) MutableStyle(org.geotoolkit.style.MutableStyle) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle)

Example 15 with MutableFeatureTypeStyle

use of org.geotoolkit.style.MutableFeatureTypeStyle in project geotoolkit by Geomatys.

the class Styles method filterRule.

public static MutableStyle filterRule() {
    final MutableRule over = SF.rule();
    over.setFilter(FF.greaterOrEqual(FF.property("POP_CNTRY"), FF.literal(5000000)));
    over.symbolizers().add(SF.polygonSymbolizer(DEFAULT_STROKE, SF.fill(Color.RED), null));
    final MutableRule under = SF.rule();
    under.setFilter(FF.less(FF.property("POP_CNTRY"), FF.literal(5000000)));
    under.symbolizers().add(SF.polygonSymbolizer(DEFAULT_STROKE, SF.fill(Color.GREEN), null));
    final MutableStyle style = SF.style();
    final MutableFeatureTypeStyle fts = SF.featureTypeStyle();
    fts.rules().add(over);
    fts.rules().add(under);
    style.featureTypeStyles().add(fts);
    return style;
}
Also used : MutableRule(org.geotoolkit.style.MutableRule) MutableStyle(org.geotoolkit.style.MutableStyle) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle)

Aggregations

MutableFeatureTypeStyle (org.geotoolkit.style.MutableFeatureTypeStyle)15 MutableStyle (org.geotoolkit.style.MutableStyle)9 MutableRule (org.geotoolkit.style.MutableRule)6 FeatureTypeStyle (org.opengis.style.FeatureTypeStyle)3 JAXBElement (javax.xml.bind.JAXBElement)2 JAXBException (javax.xml.bind.JAXBException)2 Marshaller (javax.xml.bind.Marshaller)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 SimpleInternationalString (org.apache.sis.util.SimpleInternationalString)2 CoverageStyleType (org.geotoolkit.se.xml.v110.CoverageStyleType)2 Test (org.junit.Test)2 Feature (org.opengis.feature.Feature)2 Rule (org.opengis.style.Rule)2 SemanticType (org.opengis.style.SemanticType)2 Symbolizer (org.opengis.style.Symbolizer)2 InternationalString (org.opengis.util.InternationalString)2 Color (java.awt.Color)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1