Search in sources :

Example 1 with SemanticType

use of org.opengis.style.SemanticType in project geotoolkit by Geomatys.

the class SEforSLD100Test method testFTS.

@Test
public void testFTS() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_SE_FTS);
    assertNotNull(obj);
    FeatureTypeStyle jax = (FeatureTypeStyle) obj;
    MutableFeatureTypeStyle fts = TRANSFORMER_GT.visitFTS(jax);
    assertNotNull(fts);
    assertEquals(fts.getName(), valueName);
    assertEquals(fts.getDescription().getTitle().toString(), valueTitle);
    assertEquals(fts.getDescription().getAbstract().toString(), valueAbstract);
    assertEquals(fts.featureTypeNames().iterator().next().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
    FeatureTypeStyle pvt = TRANSFORMER_OGC.visit(fts, null);
    assertNotNull(pvt);
    assertEquals(pvt.getName(), valueName);
    assertEquals(pvt.getTitle(), valueTitle);
    assertEquals(pvt.getAbstract(), valueAbstract);
    assertEquals(pvt.getFeatureTypeName(), valueFTN);
    assertEquals(pvt.getRule().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(pvt, TEST_FILE_SE_FTS);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : Marshaller(javax.xml.bind.Marshaller) SemanticType(org.opengis.style.SemanticType) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) FeatureTypeStyle(org.geotoolkit.sld.xml.v100.FeatureTypeStyle) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 2 with SemanticType

use of org.opengis.style.SemanticType 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 3 with SemanticType

use of org.opengis.style.SemanticType in project geotoolkit by Geomatys.

the class GTtoSE100Transformer method visit.

/**
 * Transform a GT FTS in Jaxb FeatureTypeStyle or CoveragaStyle or OnlineResource.
 */
@Override
public org.geotoolkit.sld.xml.v100.FeatureTypeStyle visit(final FeatureTypeStyle fts, final Object data) {
    // normally we should try to figure out if we have here a coverage FTS or not
    // no need, SLD 1.0.0 only have feature tag
    final org.geotoolkit.sld.xml.v100.FeatureTypeStyle ftst = sld_factory_v100.createFeatureTypeStyle();
    ftst.setName(fts.getName());
    if (!fts.featureTypeNames().isEmpty()) {
        final GenericName name = fts.featureTypeNames().iterator().next();
        final String local = name.toString();
        ftst.setFeatureTypeName(local);
    }
    if (fts.getDescription() != null) {
        if (fts.getDescription().getAbstract() != null)
            ftst.setAbstract(fts.getDescription().getAbstract().toString());
        if (fts.getDescription().getTitle() != null)
            ftst.setTitle(fts.getDescription().getTitle().toString());
    }
    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.getRule().add(visit(rule, null));
    }
    return ftst;
}
Also used : GenericName(org.opengis.util.GenericName) SemanticType(org.opengis.style.SemanticType) Rule(org.opengis.style.Rule)

Example 4 with SemanticType

use of org.opengis.style.SemanticType in project geotoolkit by Geomatys.

the class ListenerTest method testFTSListener.

@Test
public void testFTSListener() throws URISyntaxException {
    final MutableFeatureTypeStyle fts = SF.featureTypeStyle();
    final List<PropertyChangeEvent> propEvents = new ArrayList<PropertyChangeEvent>();
    final List<CollectionChangeEvent<MutableRule>> events = new ArrayList();
    NumberRange range;
    fts.addListener(new FeatureTypeStyleListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            propEvents.add(event);
        }

        @Override
        public void ruleChange(CollectionChangeEvent<MutableRule> event) {
            events.add(event);
        }

        @Override
        public void featureTypeNameChange(CollectionChangeEvent<GenericName> event) {
        // todo add test on this event
        }

        @Override
        public void semanticTypeChange(CollectionChangeEvent<SemanticType> event) {
        // todo add test on this event
        }
    });
    final MutableRule rule = SF.rule();
    // test add
    events.clear();
    fts.rules().add(rule);
    assertEquals(1, events.size());
    assertEquals(CollectionChangeEvent.ITEM_ADDED, events.get(0).getType());
    assertEquals(1, events.get(0).getItems().size());
    assertEquals(rule, events.get(0).getItems().iterator().next());
    range = events.get(0).getRange();
    assertEquals(0d, range.getMinDouble(), DELTA);
    assertEquals(0d, range.getMaxDouble(), DELTA);
    // test remove
    events.clear();
    fts.rules().remove(rule);
    assertEquals(1, events.size());
    assertEquals(CollectionChangeEvent.ITEM_REMOVED, events.get(0).getType());
    assertEquals(1, events.get(0).getItems().size());
    assertEquals(rule, events.get(0).getItems().iterator().next());
    range = events.get(0).getRange();
    assertEquals(0d, range.getMinDouble(), DELTA);
    assertEquals(0d, range.getMaxDouble(), DELTA);
    // test rule event forwarded
    final Symbolizer symbol = SF.lineSymbolizer();
    fts.rules().add(rule);
    events.clear();
    rule.symbolizers().add(symbol);
    assertEquals(1, events.size());
    assertEquals(CollectionChangeEvent.ITEM_CHANGED, events.get(0).getType());
    assertEquals(1, events.get(0).getItems().size());
    assertEquals(rule, events.get(0).getItems().iterator().next());
    range = events.get(0).getRange();
    assertEquals(0d, range.getMinDouble(), DELTA);
    assertEquals(0d, range.getMaxDouble(), DELTA);
    EventObject subEvent = events.get(0).getChangeEvent();
    assertTrue(subEvent instanceof CollectionChangeEvent);
    CollectionChangeEvent sub = (CollectionChangeEvent) subEvent;
    assertEquals(CollectionChangeEvent.ITEM_ADDED, sub.getType());
    assertEquals(1, sub.getItems().size());
    assertEquals(symbol, sub.getItems().iterator().next());
    range = sub.getRange();
    assertEquals(0d, range.getMinDouble(), DELTA);
    assertEquals(0d, range.getMaxDouble(), DELTA);
    // test property events
    fts.setName("currentName");
    fts.setDescription(SF.description("title", "abstract"));
    fts.setOnlineResource(SF.onlineResource(new URI("http://test.com")));
    fts.setFeatureInstanceIDs(FF.resourceId("id1"));
    propEvents.clear();
    // ensure that no events are fired when the new value is the same
    fts.setName("currentName");
    assertEquals(0, propEvents.size());
    fts.setDescription(SF.description("title", "abstract"));
    assertEquals(0, propEvents.size());
    fts.setOnlineResource(SF.onlineResource(new URI("http://test.com")));
    assertEquals(0, propEvents.size());
    fts.setFeatureInstanceIDs(FF.resourceId("id1"));
    assertEquals(0, propEvents.size());
    // ensure that event are correctly send
    propEvents.clear();
    fts.setName("newName");
    assertEquals(1, propEvents.size());
    assertEquals(propEvents.get(0).getOldValue(), "currentName");
    assertEquals(propEvents.get(0).getNewValue(), "newName");
    propEvents.clear();
    fts.setDescription(SF.description("newtitle", "newabstract"));
    assertEquals(1, propEvents.size());
    assertEquals(propEvents.get(0).getOldValue(), SF.description("title", "abstract"));
    assertEquals(propEvents.get(0).getNewValue(), SF.description("newtitle", "newabstract"));
    propEvents.clear();
    fts.setOnlineResource(SF.onlineResource(new URI("http://test2.com")));
    assertEquals(1, propEvents.size());
    assertEquals(propEvents.get(0).getOldValue(), SF.onlineResource(new URI("http://test.com")));
    assertEquals(propEvents.get(0).getNewValue(), SF.onlineResource(new URI("http://test2.com")));
    propEvents.clear();
    fts.setFeatureInstanceIDs(FF.resourceId("id2"));
    assertEquals(1, propEvents.size());
    assertEquals(propEvents.get(0).getOldValue(), FF.resourceId("id1"));
    assertEquals(propEvents.get(0).getNewValue(), FF.resourceId("id2"));
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) SemanticType(org.opengis.style.SemanticType) ArrayList(java.util.ArrayList) URI(java.net.URI) Symbolizer(org.opengis.style.Symbolizer) EventObject(java.util.EventObject) NumberRange(org.apache.sis.measure.NumberRange) GenericName(org.opengis.util.GenericName) CollectionChangeEvent(org.geotoolkit.util.collection.CollectionChangeEvent) Test(org.junit.Test)

Example 5 with SemanticType

use of org.opengis.style.SemanticType 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

SemanticType (org.opengis.style.SemanticType)5 Test (org.junit.Test)3 GenericName (org.opengis.util.GenericName)3 Marshaller (javax.xml.bind.Marshaller)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 CoverageStyleType (org.geotoolkit.se.xml.v110.CoverageStyleType)2 MutableFeatureTypeStyle (org.geotoolkit.style.MutableFeatureTypeStyle)2 Rule (org.opengis.style.Rule)2 Symbolizer (org.opengis.style.Symbolizer)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 EventObject (java.util.EventObject)1 JAXBElement (javax.xml.bind.JAXBElement)1 QName (javax.xml.namespace.QName)1 NumberRange (org.apache.sis.measure.NumberRange)1 FeatureTypeStyleType (org.geotoolkit.se.xml.v110.FeatureTypeStyleType)1 ObjectFactory (org.geotoolkit.se.xml.v110.ObjectFactory)1 FeatureTypeStyle (org.geotoolkit.sld.xml.v100.FeatureTypeStyle)1 CollectionChangeEvent (org.geotoolkit.util.collection.CollectionChangeEvent)1