Search in sources :

Example 1 with FeatureTypeStyleType

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

the class ProvidersXmlTest method testUnmarshallingWithSLD.

/**
 * Test for the unmarshalling process of a string-representation of a {@link MapContext}.
 *
 * @throws JAXBException
 */
@Test
public void testUnmarshallingWithSLD() throws JAXBException {
    final StringReader sr = new StringReader(RESULT_MARSHALLING_WITH_SLD);
    final Object result = unmarshaller.unmarshal(new StringReader(RESULT_MARSHALLING_WITH_SLD));
    sr.close();
    assertNotNull(result);
    assertTrue(result instanceof MapContext);
    final MapContext mc = (MapContext) result;
    final List<MapItem> mapItems = mc.getMapItem().getMapItems();
    assertNotNull(mapItems);
    assertFalse(mapItems.isEmpty());
    assertEquals(3, mapItems.size());
    final MapLayer ml0 = (MapLayer) mapItems.get(0).getMapItems().get(0);
    assertEquals("postgis_test:my_otherlayer", ml0.getDataReference().getValue());
    assertTrue(ml0.getStyle().getNamedLayerOrUserLayer().get(0) instanceof UserLayer);
    final UserLayer ul = (UserLayer) ml0.getStyle().getNamedLayerOrUserLayer().get(0);
    assertTrue(ul.getUserStyle().get(0).getFeatureTypeStyleOrCoverageStyleOrOnlineResource().get(0) instanceof FeatureTypeStyleType);
    final FeatureTypeStyleType fts = (FeatureTypeStyleType) ul.getUserStyle().get(0).getFeatureTypeStyleOrCoverageStyleOrOnlineResource().get(0);
    assertEquals("ft_test", fts.getName());
    final MapLayer ml1 = (MapLayer) mapItems.get(0).getMapItems().get(1);
    assertEquals("coverage:my_thirdlayer", ml1.getDataReference().getValue());
    assertEquals("my_newstyle", ml1.getStyleReference().getValue());
    assertEquals("postgis_test:my_layer", ((MapLayer) mapItems.get(2)).getDataReference().getValue());
    assertEquals("my_style", ((MapLayer) mapItems.get(2)).getStyleReference().getValue());
}
Also used : StringReader(java.io.StringReader) FeatureTypeStyleType(org.geotoolkit.se.xml.v110.FeatureTypeStyleType) UserLayer(org.geotoolkit.sld.xml.v110.UserLayer)

Example 2 with FeatureTypeStyleType

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

the class ProvidersXmlTest method testMarshallingWithSLD.

/**
 * Test for the marshalling process of a {@link MapContext}.
 *
 * @throws JAXBException
 */
@Test
public void testMarshallingWithSLD() throws JAXBException, Exception {
    final List<MapItem> mapLayers2 = new ArrayList<>();
    final StyledLayerDescriptor sld = new StyledLayerDescriptor();
    final UserStyle us = new UserStyle();
    final DescriptionType title = new DescriptionType();
    title.setTitle("test_sld");
    us.setDescription(title);
    final FeatureTypeStyleType fts = new FeatureTypeStyleType();
    fts.setName("ft_test");
    us.getFeatureTypeStyleOrCoverageStyleOrOnlineResource().add(fts);
    final UserLayer ul = new UserLayer();
    ul.getUserStyle().add(us);
    sld.getNamedLayerOrUserLayer().add(ul);
    mapLayers2.add(new MapLayer(new DataReference("postgis_test:my_otherlayer"), sld));
    mapLayers2.add(new MapLayer(new DataReference("coverage:my_thirdlayer"), new StyleReference("my_newstyle")));
    final List<MapItem> mapItems = new ArrayList<>();
    mapItems.add(new MapItem(mapLayers2));
    final MapLayer ml = new MapLayer(new DataReference("postgis_test:my_layer"), new StyleReference("my_style"));
    mapItems.add(new MapItem());
    mapItems.add(ml);
    final MapItem mapItem = new MapItem(mapItems);
    final MapContext mapContext = new MapContext(mapItem);
    final StringWriter sw = new StringWriter();
    marshaller.marshal(mapContext, sw);
    final String result = sw.toString();
    try {
        sw.close();
    } catch (IOException e) {
        fail("Unable to close the writer");
    }
    assertNotNull(result);
    assertFalse(result.isEmpty());
    DocumentComparator comparator = new DocumentComparator(RESULT_MARSHALLING_WITH_SLD, result.trim());
    comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
    comparator.compare();
}
Also used : UserStyle(org.geotoolkit.sld.xml.v110.UserStyle) DescriptionType(org.geotoolkit.se.xml.v110.DescriptionType) ArrayList(java.util.ArrayList) IOException(java.io.IOException) StyledLayerDescriptor(org.geotoolkit.sld.xml.v110.StyledLayerDescriptor) StringWriter(java.io.StringWriter) DocumentComparator(org.apache.sis.test.xml.DocumentComparator) FeatureTypeStyleType(org.geotoolkit.se.xml.v110.FeatureTypeStyleType) UserLayer(org.geotoolkit.sld.xml.v110.UserLayer)

Example 3 with FeatureTypeStyleType

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

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

FeatureTypeStyleType (org.geotoolkit.se.xml.v110.FeatureTypeStyleType)4 CoverageStyleType (org.geotoolkit.se.xml.v110.CoverageStyleType)2 UserLayer (org.geotoolkit.sld.xml.v110.UserLayer)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 JAXBException (javax.xml.bind.JAXBException)1 QName (javax.xml.namespace.QName)1 DocumentComparator (org.apache.sis.test.xml.DocumentComparator)1 DescriptionType (org.geotoolkit.se.xml.v110.DescriptionType)1 OnlineResourceType (org.geotoolkit.se.xml.v110.OnlineResourceType)1 StyledLayerDescriptor (org.geotoolkit.sld.xml.v110.StyledLayerDescriptor)1 UserStyle (org.geotoolkit.sld.xml.v110.UserStyle)1 MutableFeatureTypeStyle (org.geotoolkit.style.MutableFeatureTypeStyle)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