Search in sources :

Example 6 with Expression

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

the class TestCswRecordMapperFilterVisitor method testVisitPropertyIsEqualTo.

@Test
public void testVisitPropertyIsEqualTo() {
    Expression val = factory.literal("foo");
    PropertyIsEqualTo filter = factory.equals(attrExpr, val);
    PropertyIsEqualTo duplicate = (PropertyIsEqualTo) visitor.visit(filter, null);
    assertThat(duplicate.getExpression1(), is(attrExpr));
    assertThat(duplicate.getExpression2(), is(val));
    assertThat(duplicate.isMatchingCase(), is(true));
}
Also used : PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) Expression(org.opengis.filter.expression.Expression) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 7 with Expression

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

the class TestCswRecordMapperFilterVisitor method testVisitPropertyIsLessThanTemporal.

@Test
public void testVisitPropertyIsLessThanTemporal() {
    Expression val = factory.literal(new Date());
    PropertyIsLessThan filter = factory.less(created, val);
    Object obj = visitor.visit(filter, null);
    assertThat(obj, instanceOf(Before.class));
    Before duplicate = (Before) obj;
    assertThat(duplicate.getExpression1(), is(created));
    assertThat(duplicate.getExpression2(), is(val));
}
Also used : Before(org.opengis.filter.temporal.Before) Expression(org.opengis.filter.expression.Expression) PropertyIsLessThan(org.opengis.filter.PropertyIsLessThan) Date(java.util.Date) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 8 with Expression

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

the class TestCswRecordMapperFilterVisitor method testVisitBeyond.

@Test
public void testVisitBeyond() {
    GeometryFactory geoFactory = new GeometryFactory();
    double val = 30;
    Expression pt1 = factory.literal(geoFactory.createPoint(new Coordinate(4, 5)));
    Expression pt2 = factory.literal(geoFactory.createPoint(new Coordinate(6, 7)));
    Beyond filter = factory.beyond(pt1, pt2, val, "kilometers");
    Beyond duplicate = (Beyond) visitor.visit(filter, null);
    assertThat(duplicate.getExpression1(), is(pt1));
    assertThat(duplicate.getExpression2(), is(pt2));
    assertThat(duplicate.getDistanceUnits(), is(UomOgcMapping.METRE.name()));
    assertThat(duplicate.getDistance(), is(1000 * val));
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Expression(org.opengis.filter.expression.Expression) Coordinate(com.vividsolutions.jts.geom.Coordinate) Beyond(org.opengis.filter.spatial.Beyond) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 9 with Expression

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

the class TestCswRecordMapperFilterVisitor method testIntersectsUtm.

@Test
public void testIntersectsUtm() throws FactoryException, TransformException {
    double lon = 33.45;
    double lat = 25.22;
    double easting = 545328.48;
    double northing = 2789384.24;
    CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:32636");
    GeometryFactory geoFactory = new GeometryFactory();
    Geometry utmPoint = geoFactory.createPoint(new Coordinate(easting, northing));
    utmPoint.setUserData(sourceCRS);
    Expression pt1 = factory.literal(geoFactory.createPoint(new Coordinate(1, 2)));
    Expression pt2 = factory.literal(utmPoint);
    Intersects filter = factory.intersects(pt1, pt2);
    visitor.visit(filter, null);
    assertThat(pt2, instanceOf(Literal.class));
    Literal literalExpression = (Literal) pt2;
    assertThat(literalExpression.getValue(), instanceOf(Geometry.class));
    Geometry geometry = (Geometry) literalExpression.getValue();
    assertThat(geometry.getCoordinates()[0].x, closeTo(lon, .00001));
    assertThat(geometry.getCoordinates()[0].y, closeTo(lat, .00001));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) Expression(org.opengis.filter.expression.Expression) Intersects(org.opengis.filter.spatial.Intersects) Literal(org.opengis.filter.expression.Literal) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Example 10 with Expression

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

the class TestCswRecordMapperFilterVisitor method testVisitPropertyIsGreaterThanTemporal.

@Test
public void testVisitPropertyIsGreaterThanTemporal() {
    Expression val = factory.literal(new Date(System.currentTimeMillis() - 1000));
    Expression test = new AttributeExpressionImpl(new NameImpl(new QName(CswConstants.DUBLIN_CORE_SCHEMA, "TestDate", CswConstants.DUBLIN_CORE_NAMESPACE_PREFIX)));
    PropertyIsGreaterThan filter = factory.greater(test, val);
    Object obj = visitor.visit(filter, null);
    assertThat(obj, instanceOf(During.class));
    During duplicate = (During) obj;
    assertThat(duplicate.getExpression1(), is(test));
    assertThat(duplicate.getExpression2(), is(val));
}
Also used : NameImpl(org.geotools.feature.NameImpl) Expression(org.opengis.filter.expression.Expression) AttributeExpressionImpl(org.geotools.filter.AttributeExpressionImpl) QName(javax.xml.namespace.QName) Date(java.util.Date) During(org.opengis.filter.temporal.During) PropertyIsGreaterThan(org.opengis.filter.PropertyIsGreaterThan) CswQueryFactoryTest(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest) Test(org.junit.Test)

Aggregations

Expression (org.opengis.filter.expression.Expression)38 Test (org.junit.Test)20 CswQueryFactoryTest (org.codice.ddf.spatial.ogc.csw.catalog.endpoint.CswQueryFactoryTest)17 ArrayList (java.util.ArrayList)9 Date (java.util.Date)8 AttributeType (ddf.catalog.data.AttributeType)7 LiteralExpressionImpl (org.geotools.filter.LiteralExpressionImpl)7 Filter (org.opengis.filter.Filter)7 Literal (org.opengis.filter.expression.Literal)5 AttributeExpressionImpl (org.geotools.filter.AttributeExpressionImpl)4 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)3 FuzzyFunction (ddf.catalog.impl.filter.FuzzyFunction)3 SpatialFilter (ddf.catalog.impl.filter.SpatialFilter)3 DefaultInstant (org.geotools.temporal.object.DefaultInstant)3 DefaultPeriod (org.geotools.temporal.object.DefaultPeriod)3 DefaultPosition (org.geotools.temporal.object.DefaultPosition)3 PropertyIsEqualTo (org.opengis.filter.PropertyIsEqualTo)3 PropertyIsLike (org.opengis.filter.PropertyIsLike)3 Function (org.opengis.filter.expression.Function)3