Search in sources :

Example 1 with RuleType

use of org.geotoolkit.se.xml.v110.RuleType 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 2 with RuleType

use of org.geotoolkit.se.xml.v110.RuleType in project geotoolkit by Geomatys.

the class SE110toGTTransformer method visitRule.

/**
 * Trasnform SLD v1.1 rule in GT Rule.
 */
public MutableRule visitRule(final org.geotoolkit.se.xml.v110.RuleType rt) throws FactoryException {
    final MutableRule rule = styleFactory.rule();
    rule.setName(rt.getName());
    rule.setDescription(visitDescription(rt.getDescription()));
    rule.setElseFilter(rt.getElseFilter() != null);
    rule.setFilter(visitFilter(rt.getFilter()));
    rule.setLegendGraphic(visitLegend(rt.getLegendGraphic()));
    rule.setMaxScaleDenominator((rt.getMaxScaleDenominator() == null) ? Double.MAX_VALUE : rt.getMaxScaleDenominator());
    rule.setMinScaleDenominator((rt.getMinScaleDenominator() == null) ? 0 : rt.getMinScaleDenominator());
    if (rt.getSymbolizer() == null || rt.getSymbolizer().isEmpty()) {
    } else {
        for (final JAXBElement<?> jax : rt.getSymbolizer()) {
            final Object st = jax.getValue();
            if (st == null) {
                continue;
            } else if (st instanceof SymbolizerType) {
                rule.symbolizers().add(visit((SymbolizerType) st));
            } else if (st instanceof Symbolizer) {
                rule.symbolizers().add((Symbolizer) st);
            }
        }
    }
    return rule;
}
Also used : MutableRule(org.geotoolkit.style.MutableRule) PointSymbolizerType(org.geotoolkit.se.xml.v110.PointSymbolizerType) SymbolizerType(org.geotoolkit.se.xml.v110.SymbolizerType) TextSymbolizerType(org.geotoolkit.se.xml.v110.TextSymbolizerType) LineSymbolizerType(org.geotoolkit.se.xml.v110.LineSymbolizerType) RasterSymbolizerType(org.geotoolkit.se.xml.v110.RasterSymbolizerType) PolygonSymbolizerType(org.geotoolkit.se.xml.v110.PolygonSymbolizerType) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) PointSymbolizer(org.opengis.style.PointSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) Symbolizer(org.opengis.style.Symbolizer)

Example 3 with RuleType

use of org.geotoolkit.se.xml.v110.RuleType in project geotoolkit by Geomatys.

the class GTtoSE110Transformer method visit.

/**
 * Transform a GT rule in jaxb rule or OnlineResource
 */
@Override
public Object visit(final Rule rule, final Object data) {
    if (rule.getOnlineResource() != null) {
        // we store only the online resource
        return visit(rule.getOnlineResource(), null);
    }
    final RuleType rt = se_factory.createRuleType();
    rt.setName(rule.getName());
    rt.setDescription(visit(rule.getDescription(), null));
    if (rule.isElseFilter()) {
        rt.setElseFilter(se_factory.createElseFilterType());
    } else if (rule.getFilter() != null) {
        rt.setFilter(apply(rule.getFilter()));
    }
    if (rule.getLegend() != null) {
        rt.setLegendGraphic(visit(rule.getLegend(), null));
    }
    rt.setMaxScaleDenominator(rule.getMaxScaleDenominator());
    rt.setMinScaleDenominator(rule.getMinScaleDenominator());
    for (final Symbolizer symbol : rule.symbolizers()) {
        if (symbol instanceof LineSymbolizer) {
            rt.getSymbolizer().add(visit((LineSymbolizer) symbol, null));
        } else if (symbol instanceof PolygonSymbolizer) {
            rt.getSymbolizer().add(visit((PolygonSymbolizer) symbol, null));
        } else if (symbol instanceof PointSymbolizer) {
            rt.getSymbolizer().add(visit((PointSymbolizer) symbol, null));
        } else if (symbol instanceof RasterSymbolizer) {
            rt.getSymbolizer().add(visit((RasterSymbolizer) symbol, null));
        } else if (symbol instanceof TextSymbolizer) {
            rt.getSymbolizer().add(visit((TextSymbolizer) symbol, null));
        } else if (symbol instanceof ExtensionSymbolizer) {
            ((List) rt.getSymbolizer()).add(visit((ExtensionSymbolizer) symbol, null));
        }
    }
    return rt;
}
Also used : RasterSymbolizer(org.opengis.style.RasterSymbolizer) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) RuleType(org.geotoolkit.se.xml.v110.RuleType) ExtensionSymbolizer(org.opengis.style.ExtensionSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) ExtensionSymbolizer(org.opengis.style.ExtensionSymbolizer) PointSymbolizer(org.opengis.style.PointSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) Symbolizer(org.opengis.style.Symbolizer)

Aggregations

RuleType (org.geotoolkit.se.xml.v110.RuleType)2 MutableRule (org.geotoolkit.style.MutableRule)2 LineSymbolizer (org.opengis.style.LineSymbolizer)2 PointSymbolizer (org.opengis.style.PointSymbolizer)2 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)2 RasterSymbolizer (org.opengis.style.RasterSymbolizer)2 Symbolizer (org.opengis.style.Symbolizer)2 TextSymbolizer (org.opengis.style.TextSymbolizer)2 JAXBElement (javax.xml.bind.JAXBElement)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 LineSymbolizerType (org.geotoolkit.se.xml.v110.LineSymbolizerType)1 ObjectFactory (org.geotoolkit.se.xml.v110.ObjectFactory)1 PointSymbolizerType (org.geotoolkit.se.xml.v110.PointSymbolizerType)1 PolygonSymbolizerType (org.geotoolkit.se.xml.v110.PolygonSymbolizerType)1 RasterSymbolizerType (org.geotoolkit.se.xml.v110.RasterSymbolizerType)1 SymbolizerType (org.geotoolkit.se.xml.v110.SymbolizerType)1 TextSymbolizerType (org.geotoolkit.se.xml.v110.TextSymbolizerType)1 Test (org.junit.Test)1 ExtensionSymbolizer (org.opengis.style.ExtensionSymbolizer)1