Search in sources :

Example 1 with Literal

use of org.opengis.filter.expression.Literal in project ddf by codice.

the class GeotoolsFilterAdapterImpl method visit.

public Object visit(PropertyIsGreaterThanOrEqualTo filter, Object delegate) {
    ExpressionValues filterValues = getExpressions(filter, delegate);
    String propertyName = filterValues.propertyName;
    Object literal = filterValues.literal;
    // Are property name and literal reversed?
    if (filter.getExpression1() instanceof Literal) {
        // convert literal >= property to property <= literal
        Filter lessThanOrEqual = FF.lessOrEqual(FF.property(propertyName), FF.literal(literal));
        return lessThanOrEqual.accept(this, delegate);
    }
    if (literal instanceof String) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, (String) literal);
    } else if (literal instanceof Date) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, (Date) literal);
    } else if (literal instanceof Integer) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, ((Integer) literal).intValue());
    } else if (literal instanceof Short) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, ((Short) literal).shortValue());
    } else if (literal instanceof Long) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, ((Long) literal).longValue());
    } else if (literal instanceof Float) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, ((Float) literal).floatValue());
    } else if (literal instanceof Double) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, ((Double) literal).doubleValue());
    } else if (literal instanceof Boolean) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, literal);
    } else if (literal instanceof byte[]) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, literal);
    } else {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThanOrEqualTo(propertyName, literal);
    }
}
Also used : FilterDelegate(ddf.catalog.filter.FilterDelegate) Date(java.util.Date) IncludeFilter(org.opengis.filter.IncludeFilter) ExcludeFilter(org.opengis.filter.ExcludeFilter) Filter(org.opengis.filter.Filter) Literal(org.opengis.filter.expression.Literal)

Example 2 with Literal

use of org.opengis.filter.expression.Literal in project ddf by codice.

the class GeotoolsFilterAdapterImpl method visit.

public Object visit(PropertyIsGreaterThan filter, Object delegate) {
    ExpressionValues filterValues = getExpressions(filter, delegate);
    String propertyName = filterValues.propertyName;
    Object literal = filterValues.literal;
    // Are property name and literal reversed?
    if (filter.getExpression1() instanceof Literal) {
        // convert literal > property to property < literal
        Filter lessThan = FF.less(FF.property(propertyName), FF.literal(literal));
        return lessThan.accept(this, delegate);
    }
    if (literal instanceof String) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, (String) literal);
    } else if (literal instanceof Date) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, (Date) literal);
    } else if (literal instanceof Integer) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, ((Integer) literal).intValue());
    } else if (literal instanceof Short) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, ((Short) literal).shortValue());
    } else if (literal instanceof Long) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, ((Long) literal).longValue());
    } else if (literal instanceof Float) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, ((Float) literal).floatValue());
    } else if (literal instanceof Double) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, ((Double) literal).doubleValue());
    } else if (literal instanceof Boolean) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, literal);
    } else if (literal instanceof byte[]) {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, literal);
    } else {
        return ((FilterDelegate<?>) delegate).propertyIsGreaterThan(propertyName, literal);
    }
}
Also used : FilterDelegate(ddf.catalog.filter.FilterDelegate) Date(java.util.Date) IncludeFilter(org.opengis.filter.IncludeFilter) ExcludeFilter(org.opengis.filter.ExcludeFilter) Filter(org.opengis.filter.Filter) Literal(org.opengis.filter.expression.Literal)

Example 3 with Literal

use of org.opengis.filter.expression.Literal in project ddf by codice.

the class GeotoolsFilterAdapterImpl method visit.

public Object visit(PropertyIsLessThan filter, Object delegate) {
    ExpressionValues filterValues = getExpressions(filter, delegate);
    String propertyName = filterValues.propertyName;
    Object literal = filterValues.literal;
    // Are property name and literal reversed?
    if (filter.getExpression1() instanceof Literal) {
        // convert literal < property to property > literal
        Filter greaterThan = FF.greater(FF.property(propertyName), FF.literal(literal));
        return greaterThan.accept(this, delegate);
    }
    if (literal instanceof String) {
        return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, (String) literal);
    } else if (literal instanceof Date) {
        return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, (Date) literal);
    } else if (literal instanceof Integer) {
        return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, ((Integer) literal).intValue());
    } else if (literal instanceof Short) {
        return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, ((Short) literal).shortValue());
    } else if (literal instanceof Long) {
        return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, ((Long) literal).longValue());
    } else if (literal instanceof Float) {
        return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, ((Float) literal).floatValue());
    } else if (literal instanceof Double) {
        return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, ((Double) literal).doubleValue());
    } else if (literal instanceof Boolean) {
        return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, literal);
    } else if (literal instanceof byte[]) {
        return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, literal);
    } else {
        return ((FilterDelegate<?>) delegate).propertyIsLessThan(propertyName, literal);
    }
}
Also used : FilterDelegate(ddf.catalog.filter.FilterDelegate) Date(java.util.Date) IncludeFilter(org.opengis.filter.IncludeFilter) ExcludeFilter(org.opengis.filter.ExcludeFilter) Filter(org.opengis.filter.Filter) Literal(org.opengis.filter.expression.Literal)

Example 4 with Literal

use of org.opengis.filter.expression.Literal in project ddf by codice.

the class FilterBuilderTest method withinGeoTest.

/**
     *
     */
@Test
public void withinGeoTest() {
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Filter filter = builder.attribute(Metacard.GEOGRAPHY).within().wkt(POINT_WKT);
    filter.accept(new DefaultFilterVisitor() {

        @Override
        public Object visit(Within filter, Object data) {
            Literal literalWrapper = (Literal) filter.getExpression2();
            Geometry geometry = (Geometry) literalWrapper.evaluate(null);
            geometry.getCentroid().getCoordinate();
            return super.visit(filter, data);
        }
    }, null);
}
Also used : Geometry(org.opengis.geometry.Geometry) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) Filter(org.opengis.filter.Filter) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) Literal(org.opengis.filter.expression.Literal) DWithin(org.opengis.filter.spatial.DWithin) Within(org.opengis.filter.spatial.Within) Matchers.anyObject(org.mockito.Matchers.anyObject) Test(org.junit.Test)

Example 5 with Literal

use of org.opengis.filter.expression.Literal in project ddf by codice.

the class FilterBuilderTest method afterDate.

@Test
public void afterDate() {
    final Date date = new Date();
    FilterVisitor visitor = spy(new DefaultFilterVisitor() {
    });
    FilterBuilder builder = new GeotoolsFilterBuilder();
    Filter filter = builder.attribute(FOO_ATTRIBUTE).is().after().date(date);
    filter.accept(visitor, null);
    ArgumentCaptor<After> expressionArgument = ArgumentCaptor.forClass(After.class);
    verify(visitor).visit(expressionArgument.capture(), anyObject());
    ExpressionVisitor expVisitor = spy(new DefaultExpressionVisitor() {
    });
    expressionArgument.getValue().getExpression1().accept(expVisitor, null);
    ArgumentCaptor<PropertyName> propertyNameArgument = ArgumentCaptor.forClass(PropertyName.class);
    verify(expVisitor).visit(propertyNameArgument.capture(), anyObject());
    assertEquals(FOO_ATTRIBUTE, propertyNameArgument.getValue().getPropertyName());
    expressionArgument.getValue().getExpression2().accept(expVisitor, null);
    ArgumentCaptor<Literal> literalArgument = ArgumentCaptor.forClass(Literal.class);
    verify(expVisitor).visit(literalArgument.capture(), anyObject());
    assertEquals(date, ((Instant) literalArgument.getValue().getValue()).getPosition().getDate());
}
Also used : PropertyName(org.opengis.filter.expression.PropertyName) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) Instant(org.opengis.temporal.Instant) DefaultExpressionVisitor(org.geotools.filter.visitor.DefaultExpressionVisitor) ExpressionVisitor(org.opengis.filter.expression.ExpressionVisitor) Date(java.util.Date) DefaultFilterVisitor(org.geotools.filter.visitor.DefaultFilterVisitor) FilterVisitor(org.opengis.filter.FilterVisitor) Filter(org.opengis.filter.Filter) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) Literal(org.opengis.filter.expression.Literal) After(org.opengis.filter.temporal.After) DefaultExpressionVisitor(org.geotools.filter.visitor.DefaultExpressionVisitor) Test(org.junit.Test)

Aggregations

Literal (org.opengis.filter.expression.Literal)26 Date (java.util.Date)14 Test (org.junit.Test)9 Filter (org.opengis.filter.Filter)9 SurfaceImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.SurfaceImpl)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)5 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)5 Expression (org.opengis.filter.expression.Expression)5 AttributeType (ddf.catalog.data.AttributeType)4 FilterDelegate (ddf.catalog.filter.FilterDelegate)4 PropertyIsEqualToLiteral (ddf.catalog.filter.impl.PropertyIsEqualToLiteral)4 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)4 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)4 ExcludeFilter (org.opengis.filter.ExcludeFilter)4 IncludeFilter (org.opengis.filter.IncludeFilter)4 Point (com.vividsolutions.jts.geom.Point)3 SimpleDateFormat (java.text.SimpleDateFormat)3 HashMap (java.util.HashMap)3 BBoxSpatialFilter (org.codice.ddf.opensearch.query.filter.BBoxSpatialFilter)3 PolygonSpatialFilter (org.codice.ddf.opensearch.query.filter.PolygonSpatialFilter)3