Search in sources :

Example 6 with LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl in project ddf by codice.

the class CswRecordMapperFilterVisitor method visit.

@Override
public Object visit(PropertyIsEqualTo filter, Object extraData) {
    if (StringUtils.equals(Core.SOURCE_ID, ((PropertyName) filter.getExpression1()).getPropertyName())) {
        sourceIds.add((String) ((Literal) filter.getExpression2()).getValue());
        return null;
    }
    AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression1()).getPropertyName());
    LiteralExpressionImpl typedExpression = (LiteralExpressionImpl) filter.getExpression2();
    setExpressionType(type, typedExpression);
    Expression expr1 = visit(filter.getExpression1(), extraData);
    Expression expr2 = visit((Expression) typedExpression, expr1);
    return getFactory(extraData).equal(expr1, expr2, filter.isMatchingCase());
}
Also used : Expression(org.opengis.filter.expression.Expression) AttributeType(ddf.catalog.data.AttributeType) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) Literal(org.opengis.filter.expression.Literal)

Example 7 with LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl in project ddf by codice.

the class CswRecordMapperFilterVisitor method visit.

@Override
public Object visit(PropertyIsLessThan filter, Object extraData) {
    Expression expr1 = visit(filter.getExpression1(), extraData);
    Expression expr2 = visit(filter.getExpression2(), expr1);
    // work around since solr provider doesn't support lessthan on temporal (DDF-311)
    if (isTemporalQuery(expr1, expr2)) {
        return getFactory(extraData).before(expr1, expr2);
    } else {
        AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression1()).getPropertyName());
        LiteralExpressionImpl typedExpression = (LiteralExpressionImpl) filter.getExpression2();
        setExpressionType(type, typedExpression);
        expr2 = visit((Expression) typedExpression, expr1);
    }
    return getFactory(extraData).less(expr1, expr2);
}
Also used : Expression(org.opengis.filter.expression.Expression) AttributeType(ddf.catalog.data.AttributeType) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl)

Example 8 with LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl in project ddf by codice.

the class CswRecordMapperFilterVisitor method convertGeometryExpressionToEpsg4326.

private static void convertGeometryExpressionToEpsg4326(Expression expression) {
    if (expression instanceof LiteralExpressionImpl) {
        LiteralExpressionImpl literalExpression = (LiteralExpressionImpl) expression;
        Object valueObj = literalExpression.getValue();
        if (valueObj instanceof Geometry) {
            Geometry geometry = (Geometry) valueObj;
            Object userDataObj = geometry.getUserData();
            if (userDataObj instanceof CoordinateReferenceSystem) {
                CoordinateReferenceSystem sourceCRS = (CoordinateReferenceSystem) userDataObj;
                Geometry convertedGeometry = null;
                try {
                    convertedGeometry = GeospatialUtil.transformToEPSG4326LonLatFormat(geometry, sourceCRS);
                    literalExpression.setValue(convertedGeometry);
                } catch (GeoFormatException e) {
                    LOGGER.trace("Unable to convert geometry to EPSG:4326 format", e);
                }
            }
        }
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) GeoFormatException(org.codice.ddf.libs.geo.GeoFormatException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 9 with LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl in project ddf by codice.

the class CswRecordMapperFilterVisitor method visit.

@Override
public Object visit(PropertyIsLessThanOrEqualTo filter, Object extraData) {
    Expression expr1 = visit(filter.getExpression1(), extraData);
    Expression expr2 = visit(filter.getExpression2(), expr1);
    // work around since solr provider doesn't support lessOrEqual on temporal (DDF-311)
    if (isTemporalQuery(expr1, expr2)) {
        // work around #1 fails, solr provider doesn't support tEquals either (DDF-311)
        //TEquals tEquals = getFactory(extraData).tequals(expr1, expr2);
        //Before before = getFactory(extraData).before(expr1, expr2);
        //return getFactory(extraData).or(tEquals, before);
        Object val = null;
        Expression other = null;
        if (expr2 instanceof Literal) {
            val = ((Literal) expr2).getValue();
            other = expr1;
        } else if (expr1 instanceof Literal) {
            val = ((Literal) expr1).getValue();
            other = expr2;
        }
        if (val != null) {
            Date orig = (Date) val;
            orig.setTime(orig.getTime() + 1);
            Literal literal = getFactory(extraData).literal(orig);
            return getFactory(extraData).before(other, literal);
        }
    } else {
        AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression1()).getPropertyName());
        LiteralExpressionImpl typedExpression = (LiteralExpressionImpl) filter.getExpression2();
        setExpressionType(type, typedExpression);
        expr2 = visit((Expression) typedExpression, expr1);
    }
    return getFactory(extraData).lessOrEqual(expr1, expr2);
}
Also used : Expression(org.opengis.filter.expression.Expression) AttributeType(ddf.catalog.data.AttributeType) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl) Literal(org.opengis.filter.expression.Literal) Date(java.util.Date)

Example 10 with LiteralExpressionImpl

use of org.geotools.filter.LiteralExpressionImpl in project ddf by codice.

the class CswRecordMapperFilterVisitor method visit.

@Override
public Object visit(PropertyIsNotEqualTo filter, Object extraData) {
    AttributeType type = attributeTypes.get(((PropertyName) filter.getExpression1()).getPropertyName());
    LiteralExpressionImpl typedExpression = (LiteralExpressionImpl) filter.getExpression2();
    setExpressionType(type, typedExpression);
    Expression expr1 = visit(filter.getExpression1(), extraData);
    Expression expr2 = visit((Expression) typedExpression, expr1);
    return getFactory(extraData).notEqual(expr1, expr2, filter.isMatchingCase());
}
Also used : Expression(org.opengis.filter.expression.Expression) AttributeType(ddf.catalog.data.AttributeType) LiteralExpressionImpl(org.geotools.filter.LiteralExpressionImpl)

Aggregations

LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)11 AttributeType (ddf.catalog.data.AttributeType)7 Expression (org.opengis.filter.expression.Expression)7 Date (java.util.Date)4 Literal (org.opengis.filter.expression.Literal)4 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)3 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)2 ContextualPredicate (ddf.catalog.pubsub.predicate.ContextualPredicate)2 EntryPredicate (ddf.catalog.pubsub.predicate.EntryPredicate)2 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)2 Predicate (ddf.catalog.pubsub.predicate.Predicate)2 TemporalPredicate (ddf.catalog.pubsub.predicate.TemporalPredicate)2 DefaultInstant (org.geotools.temporal.object.DefaultInstant)2 DefaultPeriod (org.geotools.temporal.object.DefaultPeriod)2 DefaultPosition (org.geotools.temporal.object.DefaultPosition)2 Instant (org.opengis.temporal.Instant)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 GeoFormatException (org.codice.ddf.libs.geo.GeoFormatException)1