Search in sources :

Example 1 with CoverageStyleType

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

the class SEforSLD110Test method testFTS.

@Test
public void testFTS() throws JAXBException, FactoryException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_SE_FTS);
    assertNotNull(obj);
    JAXBElement<?> jax = (JAXBElement<?>) obj;
    MutableFeatureTypeStyle fts = TRANSFORMER_GT.visitFTS(jax.getValue());
    assertNotNull(fts);
    assertEquals(fts.getName(), valueName);
    assertEquals(fts.getDescription().getTitle().toString(), valueTitle);
    assertEquals(fts.getDescription().getAbstract().toString(), valueAbstract);
    assertEquals(fts.featureTypeNames().iterator().next().tip().toString(), valueFTN);
    assertEquals(fts.rules().size(), 3);
    assertEquals(fts.semanticTypeIdentifiers().size(), 6);
    Iterator<SemanticType> ite = fts.semanticTypeIdentifiers().iterator();
    assertEquals(ite.next(), SemanticType.ANY);
    assertEquals(ite.next(), SemanticType.POINT);
    assertEquals(ite.next(), SemanticType.LINE);
    assertEquals(ite.next(), SemanticType.POLYGON);
    assertEquals(ite.next(), SemanticType.TEXT);
    assertEquals(ite.next(), SemanticType.RASTER);
    // Write test
    CoverageStyleType pvt = (CoverageStyleType) TRANSFORMER_OGC.visit(fts, null);
    assertNotNull(pvt);
    assertEquals(pvt.getName(), valueName);
    assertEquals(String.valueOf(pvt.getDescription().getTitle()), valueTitle);
    assertEquals(String.valueOf(pvt.getDescription().getAbstract()), valueAbstract);
    assertTrue(pvt.getCoverageName().contains(valueFTN));
    assertEquals(pvt.getRuleOrOnlineResource().size(), 3);
    assertEquals(pvt.getSemanticTypeIdentifier().size(), 6);
    assertEquals(pvt.getSemanticTypeIdentifier().get(0), "generic:any");
    assertEquals(pvt.getSemanticTypeIdentifier().get(1), "generic:point");
    assertEquals(pvt.getSemanticTypeIdentifier().get(2), "generic:line");
    assertEquals(pvt.getSemanticTypeIdentifier().get(3), "generic:polygon");
    assertEquals(pvt.getSemanticTypeIdentifier().get(4), "generic:text");
    assertEquals(pvt.getSemanticTypeIdentifier().get(5), "generic:raster");
    MARSHALLER.marshal(new ObjectFactory().createCoverageStyle(pvt), TEST_FILE_SE_FTS);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) SemanticType(org.opengis.style.SemanticType) ObjectFactory(org.geotoolkit.se.xml.v110.ObjectFactory) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) CoverageStyleType(org.geotoolkit.se.xml.v110.CoverageStyleType) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 2 with CoverageStyleType

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

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

the class GTtoSE110Transformer method visit.

/**
 * Transform a GT FTS in Jaxb FeatureTypeStyle or CoveragaStyle or
 * OnlineResource.
 */
@Override
public Object visit(final FeatureTypeStyle fts, final Object data) {
    if (fts.getOnlineResource() != null) {
        // we store only the online resource
        return visit(fts.getOnlineResource(), null);
    } else {
        // try to figure out if we have here a coverage FTS or not
        boolean isCoverage = false;
        if (fts.semanticTypeIdentifiers().contains(SemanticType.RASTER)) {
            isCoverage = true;
        } else if (fts.semanticTypeIdentifiers().contains(SemanticType.ANY) || fts.semanticTypeIdentifiers().isEmpty()) {
            if (fts.getFeatureInstanceIDs() == null) {
                // try to find a coverage style
                ruleLoop: for (final Rule r : fts.rules()) {
                    for (final Symbolizer s : r.symbolizers()) {
                        if (s instanceof RasterSymbolizer) {
                            isCoverage = true;
                            break ruleLoop;
                        }
                    }
                }
            } else {
                isCoverage = false;
            }
        } else {
            isCoverage = false;
        }
        final Object obj;
        // create the sld FTS
        if (isCoverage) {
            // coverage type
            final CoverageStyleType cst = se_factory.createCoverageStyleType();
            if (!fts.featureTypeNames().isEmpty()) {
                cst.setCoverageName(fts.featureTypeNames().iterator().next().toString());
            }
            cst.setDescription(visit(fts.getDescription(), null));
            cst.setName(fts.getName());
            for (final SemanticType semantic : fts.semanticTypeIdentifiers()) {
                if (SemanticType.ANY.equals(semantic)) {
                    cst.getSemanticTypeIdentifier().add(GENERIC_ANY);
                } else if (SemanticType.POINT.equals(semantic)) {
                    cst.getSemanticTypeIdentifier().add(GENERIC_POINT);
                } else if (SemanticType.LINE.equals(semantic)) {
                    cst.getSemanticTypeIdentifier().add(GENERIC_LINE);
                } else if (SemanticType.POLYGON.equals(semantic)) {
                    cst.getSemanticTypeIdentifier().add(GENERIC_POLYGON);
                } else if (SemanticType.TEXT.equals(semantic)) {
                    cst.getSemanticTypeIdentifier().add(GENERIC_TEXT);
                } else if (SemanticType.RASTER.equals(semantic)) {
                    cst.getSemanticTypeIdentifier().add(GENERIC_RASTER);
                } else {
                    cst.getSemanticTypeIdentifier().add(semantic.identifier());
                }
            }
            for (final Rule rule : fts.rules()) {
                cst.getRuleOrOnlineResource().add(visit(rule, null));
            }
            obj = cst;
        } else {
            // feature type
            final FeatureTypeStyleType ftst = se_factory.createFeatureTypeStyleType();
            if (!fts.featureTypeNames().isEmpty()) {
                final GenericName name = fts.featureTypeNames().iterator().next();
                final String pre = name.scope().isGlobal() ? null : name.scope().name().toString();
                final String local = name.toString();
                ftst.setFeatureTypeName(new QName(pre + ':', local));
            }
            ftst.setDescription(visit(fts.getDescription(), null));
            ftst.setName(fts.getName());
            for (final SemanticType semantic : fts.semanticTypeIdentifiers()) {
                if (SemanticType.ANY.equals(semantic)) {
                    ftst.getSemanticTypeIdentifier().add(GENERIC_ANY);
                } else if (SemanticType.POINT.equals(semantic)) {
                    ftst.getSemanticTypeIdentifier().add(GENERIC_POINT);
                } else if (SemanticType.LINE.equals(semantic)) {
                    ftst.getSemanticTypeIdentifier().add(GENERIC_LINE);
                } else if (SemanticType.POLYGON.equals(semantic)) {
                    ftst.getSemanticTypeIdentifier().add(GENERIC_POLYGON);
                } else if (SemanticType.TEXT.equals(semantic)) {
                    ftst.getSemanticTypeIdentifier().add(GENERIC_TEXT);
                } else if (SemanticType.RASTER.equals(semantic)) {
                    ftst.getSemanticTypeIdentifier().add(GENERIC_RASTER);
                } else {
                    ftst.getSemanticTypeIdentifier().add(semantic.identifier());
                }
            }
            for (final Rule rule : fts.rules()) {
                ftst.getRuleOrOnlineResource().add(visit(rule, null));
            }
            obj = ftst;
        }
        return obj;
    }
}
Also used : RasterSymbolizer(org.opengis.style.RasterSymbolizer) SemanticType(org.opengis.style.SemanticType) GenericName(org.opengis.util.GenericName) QName(javax.xml.namespace.QName) CoverageStyleType(org.geotoolkit.se.xml.v110.CoverageStyleType) FeatureTypeStyleType(org.geotoolkit.se.xml.v110.FeatureTypeStyleType) Rule(org.opengis.style.Rule) 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

CoverageStyleType (org.geotoolkit.se.xml.v110.CoverageStyleType)3 FeatureTypeStyleType (org.geotoolkit.se.xml.v110.FeatureTypeStyleType)2 MutableFeatureTypeStyle (org.geotoolkit.style.MutableFeatureTypeStyle)2 SemanticType (org.opengis.style.SemanticType)2 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 QName (javax.xml.namespace.QName)1 ObjectFactory (org.geotoolkit.se.xml.v110.ObjectFactory)1 OnlineResourceType (org.geotoolkit.se.xml.v110.OnlineResourceType)1 Test (org.junit.Test)1 OnlineResource (org.opengis.metadata.citation.OnlineResource)1 ExtensionSymbolizer (org.opengis.style.ExtensionSymbolizer)1 LineSymbolizer (org.opengis.style.LineSymbolizer)1 PointSymbolizer (org.opengis.style.PointSymbolizer)1 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)1 RasterSymbolizer (org.opengis.style.RasterSymbolizer)1 Rule (org.opengis.style.Rule)1 Symbolizer (org.opengis.style.Symbolizer)1