Search in sources :

Example 11 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class CachedTextSymbolizer method evaluate.

@Override
protected void evaluate() {
    if (!isNotEvaluated)
        return;
    final Expression expLabel = styleElement.getLabel();
    // we can not know so always visible
    isStaticVisible = VisibilityState.VISIBLE;
    if (GO2Utilities.isStatic(expLabel)) {
        label = GO2Utilities.evaluate(expLabel, null, String.class, "No Label");
    } else {
        label = null;
        GO2Utilities.getRequieredAttributsName(expLabel, requieredAttributs);
        isStatic = false;
    }
    cachedFont.getRequieredAttributsName(requieredAttributs);
    cachedFill.getRequieredAttributsName(requieredAttributs);
    cachedHalo.getRequieredAttributsName(requieredAttributs);
    cachedPlacement.getRequieredAttributsName(requieredAttributs);
    // no attributs needed replace with static empty list.
    if (requieredAttributs.isEmpty()) {
        requieredAttributs = EMPTY_ATTRIBUTS;
    }
    isNotEvaluated = false;
}
Also used : Expression(org.opengis.filter.Expression)

Example 12 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class JAXPStreamValueCollectionWriter method writeFeature.

/**
 * Write the feature into the stream.
 *
 * @param feature The feature
 * @throws XMLStreamException
 */
private void writeFeature(final Feature feature) throws XMLStreamException {
    final FeatureType type = feature.getType();
    // write properties in the type order
    Expression exp = FilterUtilities.FF.property(valueReference);
    Object valueA = exp.apply(feature);
    if (valueA instanceof Collection) {
        for (Object value : (Collection) valueA) {
            writer.writeStartElement("wfs", "member", WFS_NAMESPACE);
            writeValue(value);
            writer.writeEndElement();
        }
    } else if (valueA instanceof Map) {
        final Map<?, ?> map = (Map) valueA;
        for (Map.Entry<?, ?> entry : map.entrySet()) {
            writer.writeStartElement("wfs", "member", WFS_NAMESPACE);
            final Object key = entry.getKey();
            if (key != null) {
                writer.writeAttribute("name", (String) key);
            }
            writeValue(entry.getValue());
            writer.writeEndElement();
        }
    } else if (valueA != null && valueA.getClass().isArray()) {
        final int length = Array.getLength(valueA);
        for (int i = 0; i < length; i++) {
            writer.writeStartElement("wfs", "member", WFS_NAMESPACE);
            final Object value = Array.get(valueA, i);
            final String textValue;
            if (value != null && value.getClass().isArray()) {
                // matrix
                final StringBuilder sb = new StringBuilder();
                final int length2 = Array.getLength(value);
                for (int j = 0; j < length2; j++) {
                    final Object subValue = Array.get(value, j);
                    sb.append(Utils.getStringValue(subValue)).append(" ");
                }
                textValue = sb.toString();
            } else {
                textValue = Utils.getStringValue(value);
            }
            writer.writeCharacters(textValue);
            writer.writeEndElement();
        }
    } else if (valueA instanceof org.locationtech.jts.geom.Geometry) {
        writer.writeStartElement("wfs", "member", WFS_NAMESPACE);
        AbstractGeometry gmlGeometry = null;
        try {
            gmlGeometry = JTStoGeometry.toGML("3.2.1", (org.locationtech.jts.geom.Geometry) valueA, FeatureExt.getCRS(type));
        } catch (FactoryException ex) {
            LOGGER.log(Level.WARNING, "Factory exception when transforming JTS geometry to GML binding", ex);
        }
        final JAXBElement element = GML32_FACTORY.buildAnyGeometry(gmlGeometry);
        try {
            final Marshaller marshaller;
            marshaller = GML_32_POOL.acquireMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
            marshal(marshaller, element);
            GML_32_POOL.recycle(marshaller);
        } catch (JAXBException ex) {
            LOGGER.log(Level.WARNING, "JAXB Exception while marshalling the iso geometry: " + ex.getMessage(), ex);
        }
        writer.writeEndElement();
    } else {
        String value = Utils.getStringValue(valueA);
        if (value != null) {
            writer.writeStartElement("wfs", "member", WFS_NAMESPACE);
            writeValue(value);
            writer.writeEndElement();
        }
    }
}
Also used : FeatureType(org.opengis.feature.FeatureType) Marshaller(javax.xml.bind.Marshaller) AbstractGeometry(org.geotoolkit.gml.xml.AbstractGeometry) FactoryException(org.opengis.util.FactoryException) JAXBException(javax.xml.bind.JAXBException) JAXBElement(javax.xml.bind.JAXBElement) Expression(org.opengis.filter.Expression) Collection(java.util.Collection) Map(java.util.Map)

Example 13 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class XmlFeatureTest method testWriteSimpleFeaturePrimitiveWithAtts.

@Test
public void testWriteSimpleFeaturePrimitiveWithAtts() throws JAXBException, IOException, XMLStreamException, DataStoreException, ParserConfigurationException, SAXException {
    final File temp = File.createTempFile("gml", ".xml");
    temp.deleteOnExit();
    final XmlFeatureWriter writer = new JAXPStreamFeatureWriter("3.2.1", "1.1.0", null);
    writer.write(featureEmpty, temp);
    writer.dispose();
    String result = IOUtilities.toString(new FileInputStream(temp));
    String expResult = IOUtilities.toString(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureEmpty.xml"));
    expResult = expResult.replace("EPSG_VERSION", EPSG_VERSION);
    expResult = expResult.replaceAll("(?i)epsg\\:\\d+\\.\\d+\\.?\\d*\\:", "epsg::");
    result = result.replaceAll("(?i)epsg\\:\\d+\\.\\d+\\.?\\d*\\:", "epsg::");
    final Expression exp = new DefaultPropertyName("/identifier/_value");
    Object v = exp.apply(featureEmpty);
    DomCompare.compare(expResult, result);
}
Also used : Expression(org.opengis.filter.Expression) JAXPStreamFeatureWriter(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureWriter) File(java.io.File) DefaultPropertyName(org.geotoolkit.filter.DefaultPropertyName) FileInputStream(java.io.FileInputStream)

Example 14 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class PojoDemo method main.

public static void main(String[] args) {
    Demos.init();
    final Pojo myPojo = new Pojo("squid", 1200, new Date());
    Expression exp = FF.property("family");
    System.out.println(exp.apply(myPojo));
    exp = FF.property("depth");
    System.out.println(exp.apply(myPojo));
    exp = FF.property("birth");
    System.out.println(exp.apply(myPojo));
}
Also used : Expression(org.opengis.filter.Expression) Date(java.util.Date)

Example 15 with Expression

use of org.opengis.filter.Expression in project geotoolkit by Geomatys.

the class ExpressionDemo method functionExpression.

private static Expression functionExpression() {
    // display all available functions
    System.out.println("\n==============================================================\n");
    final Collection<FunctionRegister> factories = Functions.getFactories();
    for (FunctionRegister ff : factories) {
        System.out.println(Classes.getShortClassName(ff));
        System.out.println(StringUtilities.toStringTree(ff.getNames()));
    }
    final Expression function = Functions.function(MathFunctionFactory.COS, null, FF.property("age"));
    return function;
}
Also used : Expression(org.opengis.filter.Expression) FunctionRegister(org.apache.sis.internal.filter.FunctionRegister)

Aggregations

Expression (org.opengis.filter.Expression)325 Test (org.junit.Test)112 LineString (org.locationtech.jts.geom.LineString)73 Literal (org.opengis.filter.Literal)65 ArrayList (java.util.ArrayList)47 MultiLineString (org.locationtech.jts.geom.MultiLineString)46 Unit (javax.measure.Unit)45 Description (org.opengis.style.Description)40 Fill (org.opengis.style.Fill)38 GraphicFill (org.opengis.style.GraphicFill)38 Stroke (org.opengis.style.Stroke)35 Geometry (org.locationtech.jts.geom.Geometry)31 Displacement (org.opengis.style.Displacement)29 GraphicStroke (org.opengis.style.GraphicStroke)29 ValueReference (org.opengis.filter.ValueReference)27 JAXBElement (javax.xml.bind.JAXBElement)22 LineSymbolizer (org.opengis.style.LineSymbolizer)22 PointSymbolizer (org.opengis.style.PointSymbolizer)22 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)22 MutableStyle (org.geotoolkit.style.MutableStyle)21