Search in sources :

Example 1 with StyleXmlIO

use of org.geotoolkit.sld.xml.StyleXmlIO in project geotoolkit by Geomatys.

the class PatternSymbolizerTest method testXml.

/**
 * Test Jaxb xml support.
 */
@Test
public void testXml() throws JAXBException, IOException {
    final MutableStyleFactory SF = GO2Utilities.STYLE_FACTORY;
    final FilterFactory2 FF = GO2Utilities.FILTER_FACTORY;
    final Map<Expression, List<Symbolizer>> ranges = new LinkedHashMap<>();
    ranges.put(FF.literal(-1000), Arrays.asList(SF.polygonSymbolizer(null, SF.fill(Color.BLUE), null)));
    ranges.put(FF.literal(-500), Arrays.asList(SF.polygonSymbolizer(null, SF.fill(Color.RED), null)));
    ranges.put(FF.literal(-100), Arrays.asList(SF.polygonSymbolizer(null, SF.fill(Color.GREEN), null)));
    ranges.put(FF.literal(100), Arrays.asList(SF.polygonSymbolizer(null, SF.fill(Color.YELLOW), null)));
    ranges.put(FF.literal(1000), Arrays.asList(SF.polygonSymbolizer(null, SF.fill(Color.GRAY), null)));
    final PatternSymbolizer ps = new PatternSymbolizer(FF.literal(0), ranges, ThreshholdsBelongTo.PRECEDING);
    final MutableStyle style = GO2Utilities.STYLE_FACTORY.style(ps);
    final Path path = Files.createTempFile("xml", ".xml");
    IOUtilities.deleteOnExit(path);
    new StyleXmlIO().writeStyle(path, style, Specification.StyledLayerDescriptor.V_1_1_0);
}
Also used : Path(java.nio.file.Path) MutableStyle(org.geotoolkit.style.MutableStyle) Expression(org.opengis.filter.Expression) StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO) List(java.util.List) MutableStyleFactory(org.geotoolkit.style.MutableStyleFactory) FilterFactory2(org.geotoolkit.filter.FilterFactory2) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 2 with StyleXmlIO

use of org.geotoolkit.sld.xml.StyleXmlIO in project geotoolkit by Geomatys.

the class OwcXmlIO method readStyle.

private static MutableStyle readStyle(OfferingType offering, boolean def) throws JAXBException, FactoryException {
    final List<Object> content = offering.getOperationOrContentOrStyleSet();
    for (Object co : content) {
        if (co instanceof JAXBElement)
            co = ((JAXBElement) co).getValue();
        if (!(co instanceof StyleSetType))
            continue;
        final StyleSetType sst = (StyleSetType) co;
        if (sst.isDefault() != def)
            continue;
        final List<Object> ssc = sst.getNameOrTitleOrAbstract();
        for (Object ss : ssc) {
            if (ss instanceof JAXBElement)
                ss = ((JAXBElement) ss).getValue();
            if (!(ss instanceof ContentType))
                continue;
            final ContentType ct = (ContentType) ss;
            final List<Object> subcs = ct.getContent();
            for (Object subc : subcs) {
                if (subc instanceof JAXBElement)
                    subc = ((JAXBElement) subc).getValue();
                if (!(subc instanceof UserStyle))
                    continue;
                final StyleXmlIO io = new StyleXmlIO();
                return io.readStyle(subc, Specification.SymbologyEncoding.V_1_1_0);
            }
        }
    }
    return null;
}
Also used : UserStyle(org.geotoolkit.sld.xml.v110.UserStyle) ContentType(org.geotoolkit.owc.xml.v10.ContentType) StyleSetType(org.geotoolkit.owc.xml.v10.StyleSetType) StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO) JAXBElement(javax.xml.bind.JAXBElement)

Example 3 with StyleXmlIO

use of org.geotoolkit.sld.xml.StyleXmlIO in project geotoolkit by Geomatys.

the class PatternSymbolizer method setChannel.

public void setChannel(Expression value) {
    this.channel = value;
    this.channelType = new StyleXmlIO().getTransformerXMLv110().visitExpression(value);
}
Also used : StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO)

Example 4 with StyleXmlIO

use of org.geotoolkit.sld.xml.StyleXmlIO in project geotoolkit by Geomatys.

the class PatternSymbolizer method getRanges.

public Map<Expression, List<Symbolizer>> getRanges() {
    if (thredholds == null && range != null) {
        thredholds = new TreeMap<>(new ExpComparator());
        final SLD110toGTTransformer io = new StyleXmlIO().getTransformer110();
        final Map<Expression, List<Symbolizer>> visitRanges = io.visitRanges(range);
        thredholds.putAll(visitRanges);
    }
    return thredholds;
}
Also used : Expression(org.opengis.filter.Expression) StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO) ArrayList(java.util.ArrayList) List(java.util.List) SLD110toGTTransformer(org.geotoolkit.sld.xml.SLD110toGTTransformer)

Example 5 with StyleXmlIO

use of org.geotoolkit.sld.xml.StyleXmlIO in project geotoolkit by Geomatys.

the class PatternSymbolizer method setRanges.

public void setRanges(Map<Expression, List<Symbolizer>> range) {
    this.thredholds = new TreeMap<>(new ExpComparator());
    if (range != null)
        this.thredholds.putAll(range);
    final GTtoSLD110Transformer io = new StyleXmlIO().getTransformerXMLv110();
    final List<JAXBElement<RangeType>> ranges = new ArrayList<>();
    for (Entry<Expression, List<Symbolizer>> entry : this.thredholds.entrySet()) {
        final JAXBElement<RangeType> rt = io.visitRange(entry.getKey(), entry.getValue());
        ranges.add(rt);
    }
    this.range = ranges;
}
Also used : RangeType(org.geotoolkit.se.xml.vext.RangeType) Expression(org.opengis.filter.Expression) ArrayList(java.util.ArrayList) StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO) GTtoSLD110Transformer(org.geotoolkit.sld.xml.GTtoSLD110Transformer) ArrayList(java.util.ArrayList) List(java.util.List) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

StyleXmlIO (org.geotoolkit.sld.xml.StyleXmlIO)21 Test (org.junit.Test)6 MutableStyle (org.geotoolkit.style.MutableStyle)5 Path (java.nio.file.Path)4 List (java.util.List)3 Expression (org.opengis.filter.Expression)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 JAXBElement (javax.xml.bind.JAXBElement)2 JAXBException (javax.xml.bind.JAXBException)2 ContentType (org.geotoolkit.owc.xml.v10.ContentType)2 StyleSetType (org.geotoolkit.owc.xml.v10.StyleSetType)2 UserStyle (org.geotoolkit.sld.xml.v110.UserStyle)2 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 Icon (javax.swing.Icon)1 ImageIcon (javax.swing.ImageIcon)1 Envelope2D (org.apache.sis.geometry.Envelope2D)1 MapLayer (org.apache.sis.portrayal.MapLayer)1