Search in sources :

Example 1 with SpatialContains

use of org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains in project geowave by locationtech.

the class ExpressionQueryIT method testSpatialExpressionQueries.

@Test
public void testSpatialExpressionQueries() {
    final DataStore ds = dataStore.createDataStore();
    final DataTypeAdapter<SimpleFeature> adapter = createDataAdapter();
    final Index spatialIndex = SpatialDimensionalityTypeProvider.createIndexFromOptions(new SpatialOptions());
    ds.addType(adapter, spatialIndex);
    final Index altIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, ALTERNATE_GEOMETRY_FIELD));
    final Index polyIndex = AttributeDimensionalityTypeProvider.createIndexFromOptions(ds, new AttributeIndexOptions(TYPE_NAME, POLYGON_FIELD));
    ds.addIndex(TYPE_NAME, altIndex, polyIndex);
    final PersistentAdapterStore adapterStore = dataStore.createAdapterStore();
    final InternalAdapterStore internalAdapterStore = dataStore.createInternalAdapterStore();
    final AdapterIndexMappingStore aimStore = dataStore.createAdapterIndexMappingStore();
    final IndexStore indexStore = dataStore.createIndexStore();
    final DataStatisticsStore statsStore = dataStore.createDataStatisticsStore();
    final InternalDataAdapter<?> internalAdapter = adapterStore.getAdapter(internalAdapterStore.getAdapterId(TYPE_NAME));
    final Polygon boxPoly = GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-20.5, -20.5), new Coordinate(-20.5, 20.5), new Coordinate(20.5, 20.5), new Coordinate(20.5, -20.5), new Coordinate(-20.5, -20.5) });
    final Polygon boxPoly2 = GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-20, -20), new Coordinate(-20, 20), new Coordinate(20, 20), new Coordinate(20, -20), new Coordinate(-20, -20) });
    // Large diagonal line
    final LineString line = GeometryUtils.GEOMETRY_FACTORY.createLineString(new Coordinate[] { new Coordinate(-20.5, -20.5), new Coordinate(20.5, 20.5) });
    // Ingest data
    ingestData(ds);
    // ///////////////////////////////////////////////////
    // Basic BBOX
    // ///////////////////////////////////////////////////
    Query<SimpleFeature> query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.bbox(0.5, 0.5, 64.5, 64.5)).build();
    QueryConstraints queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    ExplicitFilteredQuery constraints = (ExplicitFilteredQuery) queryConstraints;
    List<QueryFilter> filters = constraints.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    Filter filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof BBox);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2 - 1, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Loose BBOX
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.bboxLoose(0.5, 0.5, 64.5, 64.5)).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(spatialIndex);
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES / 2 - 1, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Intersects
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(ALT.intersects(boxPoly)).build();
    queryConstraints = assertBestIndex(internalAdapter, altIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(altIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Intersects);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(20, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Loose Intersects
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(ALT.intersectsLoose(boxPoly)).build();
    queryConstraints = assertBestIndex(internalAdapter, altIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(altIndex);
    assertEquals(0, filters.size());
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(20, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Disjoint
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.disjoint(boxPoly)).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof FilteredEverythingQuery);
    FilteredEverythingQuery everything = (FilteredEverythingQuery) queryConstraints;
    filters = everything.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Disjoint);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES - 41, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Loose Disjoint
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.disjointLoose(boxPoly)).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof FilteredEverythingQuery);
    everything = (FilteredEverythingQuery) queryConstraints;
    filters = everything.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Disjoint);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES - 41, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Crosses
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(POLY.crosses(line)).build();
    queryConstraints = assertBestIndex(internalAdapter, polyIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(polyIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Crosses);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(43, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Overlaps
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(POLY.overlaps(boxPoly)).build();
    queryConstraints = assertBestIndex(internalAdapter, polyIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(polyIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Overlaps);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        // it overlaps 2 polygons in each corner
        assertEquals(4, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Contains
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.contains(boxPoly)).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof SpatialContains);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertFalse(iterator.hasNext());
    }
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(SpatialLiteral.of(boxPoly).contains(GEOM)).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof SpatialContains);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(41, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Touches
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(POLY.touches(boxPoly2)).build();
    queryConstraints = assertBestIndex(internalAdapter, polyIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(polyIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Touches);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(2, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // Within
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.within(boxPoly)).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Within);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(41, Iterators.size(iterator));
    }
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(SpatialLiteral.of(boxPoly).within(GEOM)).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof Within);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertFalse(iterator.hasNext());
    }
    // ///////////////////////////////////////////////////
    // EqualTo
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.isEqualTo(GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(1, 1)))).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof ExplicitFilteredQuery);
    constraints = (ExplicitFilteredQuery) queryConstraints;
    filters = constraints.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof SpatialEqualTo);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(1, Iterators.size(iterator));
    }
    // ///////////////////////////////////////////////////
    // NotEqualTo
    // ///////////////////////////////////////////////////
    query = QueryBuilder.newBuilder(SimpleFeature.class).filter(GEOM.isNotEqualTo(GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(1, 1)))).build();
    queryConstraints = assertBestIndex(internalAdapter, spatialIndex, query, adapterStore, internalAdapterStore, aimStore, indexStore, statsStore);
    assertTrue(queryConstraints instanceof FilteredEverythingQuery);
    everything = (FilteredEverythingQuery) queryConstraints;
    filters = everything.createFilters(spatialIndex);
    assertEquals(1, filters.size());
    assertTrue(filters.get(0) instanceof ExpressionQueryFilter);
    filter = ((ExpressionQueryFilter<?>) filters.get(0)).getFilter();
    assertTrue(filter instanceof SpatialNotEqualTo);
    // Query data
    try (CloseableIterator<SimpleFeature> iterator = ds.query(query)) {
        assertTrue(iterator.hasNext());
        assertEquals(TOTAL_FEATURES - 1, Iterators.size(iterator));
    }
}
Also used : TimeOverlaps(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TimeOverlaps) Overlaps(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Overlaps) Index(org.locationtech.geowave.core.store.api.Index) CustomQueryConstraints(org.locationtech.geowave.core.store.query.constraints.CustomQueryConstraints) QueryConstraints(org.locationtech.geowave.core.store.query.constraints.QueryConstraints) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) DataStatisticsStore(org.locationtech.geowave.core.store.statistics.DataStatisticsStore) Crosses(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Crosses) DataStore(org.locationtech.geowave.core.store.api.DataStore) Intersects(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Intersects) Disjoint(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Disjoint) Touches(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Touches) FilteredEverythingQuery(org.locationtech.geowave.core.store.query.constraints.FilteredEverythingQuery) Polygon(org.locationtech.jts.geom.Polygon) ExplicitFilteredQuery(org.locationtech.geowave.core.store.query.constraints.ExplicitFilteredQuery) InternalAdapterStore(org.locationtech.geowave.core.store.adapter.InternalAdapterStore) SpatialNotEqualTo(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialNotEqualTo) SpatialOptions(org.locationtech.geowave.core.geotime.index.SpatialOptions) AdapterIndexMappingStore(org.locationtech.geowave.core.store.adapter.AdapterIndexMappingStore) SimpleFeature(org.opengis.feature.simple.SimpleFeature) PersistentAdapterStore(org.locationtech.geowave.core.store.adapter.PersistentAdapterStore) QueryFilter(org.locationtech.geowave.core.store.query.filter.QueryFilter) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) AttributeIndexOptions(org.locationtech.geowave.core.store.index.AttributeIndexOptions) SpatialEqualTo(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialEqualTo) SpatialContains(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) QueryFilter(org.locationtech.geowave.core.store.query.filter.QueryFilter) ExpressionQueryFilter(org.locationtech.geowave.core.store.query.filter.ExpressionQueryFilter) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) BBox(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.BBox) Within(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Within) IndexStore(org.locationtech.geowave.core.store.index.IndexStore) Test(org.junit.Test)

Example 2 with SpatialContains

use of org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains in project geowave by locationtech.

the class CQLToGeoWaveFilterTest method testCQLtoGeoWaveFilter.

@Test
public void testCQLtoGeoWaveFilter() throws CQLException, ParseException {
    Filter f = fromCQL("EMPLOYED < 15000000");
    assertTrue(f instanceof NumericComparisonOperator);
    assertEquals(CompareOp.LESS_THAN, ((NumericComparisonOperator) f).getCompareOp());
    assertTrue(((NumericComparisonOperator) f).getExpression1() instanceof NumericFieldValue);
    assertEquals("EMPLOYED", ((NumericFieldValue) ((NumericComparisonOperator) f).getExpression1()).getFieldName());
    assertTrue(((NumericComparisonOperator) f).getExpression2() instanceof NumericLiteral);
    assertEquals(15000000L, ((NumericLiteral) ((NumericComparisonOperator) f).getExpression2()).getValue().longValue());
    f = fromCQL("EMPLOYED BETWEEN 1000000 AND 3000000");
    assertTrue(f instanceof NumericBetween);
    assertTrue(((NumericBetween) f).getValue() instanceof NumericFieldValue);
    assertEquals("EMPLOYED", ((NumericFieldValue) ((NumericBetween) f).getValue()).getFieldName());
    assertTrue(((NumericBetween) f).getLowerBound() instanceof NumericLiteral);
    assertEquals(1000000L, ((NumericLiteral) ((NumericBetween) f).getLowerBound()).getValue().longValue());
    assertTrue(((NumericBetween) f).getUpperBound() instanceof NumericLiteral);
    assertEquals(3000000L, ((NumericLiteral) ((NumericBetween) f).getUpperBound()).getValue().longValue());
    f = fromCQL("name = 'California'");
    assertTrue(f instanceof TextComparisonOperator);
    assertEquals(CompareOp.EQUAL_TO, ((TextComparisonOperator) f).getCompareOp());
    assertTrue(((TextComparisonOperator) f).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((TextComparisonOperator) f).getExpression1()).getFieldName());
    assertTrue(((TextComparisonOperator) f).getExpression2() instanceof TextLiteral);
    assertEquals("California", ((TextLiteral) ((TextComparisonOperator) f).getExpression2()).getValue());
    f = fromCQL("UNEMPLOY / (EMPLOYED + UNEMPLOY) > 0.07");
    assertTrue(f instanceof NumericComparisonOperator);
    assertEquals(CompareOp.GREATER_THAN, ((NumericComparisonOperator) f).getCompareOp());
    assertTrue(((NumericComparisonOperator) f).getExpression1() instanceof Divide);
    Divide divide = (Divide) ((NumericComparisonOperator) f).getExpression1();
    assertTrue(divide.getExpression1() instanceof NumericFieldValue);
    assertEquals("UNEMPLOY", ((NumericFieldValue) divide.getExpression1()).getFieldName());
    assertTrue(divide.getExpression2() instanceof Add);
    Add add = (Add) divide.getExpression2();
    assertTrue(add.getExpression1() instanceof NumericFieldValue);
    assertEquals("EMPLOYED", ((NumericFieldValue) add.getExpression1()).getFieldName());
    assertTrue(add.getExpression2() instanceof NumericFieldValue);
    assertEquals("UNEMPLOY", ((NumericFieldValue) add.getExpression2()).getFieldName());
    assertTrue(((NumericComparisonOperator) f).getExpression2() instanceof NumericLiteral);
    assertEquals(0.07, ((NumericLiteral) ((NumericComparisonOperator) f).getExpression2()).getValue(), EPSILON);
    f = fromCQL("A <> B AND B <= 8.1");
    assertTrue(f instanceof And);
    assertTrue(((And) f).getChildren().length == 2);
    assertTrue(((And) f).getChildren()[0] instanceof Not);
    assertTrue(((Not) ((And) f).getChildren()[0]).getFilter() instanceof NumericComparisonOperator);
    NumericComparisonOperator equalTo = (NumericComparisonOperator) ((Not) ((And) f).getChildren()[0]).getFilter();
    assertEquals(CompareOp.EQUAL_TO, equalTo.getCompareOp());
    assertTrue(equalTo.getExpression1() instanceof NumericFieldValue);
    assertEquals("A", ((NumericFieldValue) equalTo.getExpression1()).getFieldName());
    assertTrue(equalTo.getExpression2() instanceof NumericFieldValue);
    assertEquals("B", ((NumericFieldValue) equalTo.getExpression2()).getFieldName());
    assertTrue(((And) f).getChildren()[1] instanceof NumericComparisonOperator);
    NumericComparisonOperator lessThan = (NumericComparisonOperator) ((And) f).getChildren()[1];
    assertEquals(CompareOp.LESS_THAN_OR_EQUAL, lessThan.getCompareOp());
    assertTrue(lessThan.getExpression1() instanceof NumericFieldValue);
    assertEquals("B", ((NumericFieldValue) lessThan.getExpression1()).getFieldName());
    assertTrue(lessThan.getExpression2() instanceof NumericLiteral);
    assertEquals(8.1, ((NumericLiteral) lessThan.getExpression2()).getValue(), EPSILON);
    // Order of operations should be preserved
    f = fromCQL("A + B - (C * D) / 8.5 >= E");
    assertTrue(f instanceof NumericComparisonOperator);
    assertEquals(CompareOp.GREATER_THAN_OR_EQUAL, ((NumericComparisonOperator) f).getCompareOp());
    assertTrue(((NumericComparisonOperator) f).getExpression1() instanceof Subtract);
    Subtract subtract = (Subtract) ((NumericComparisonOperator) f).getExpression1();
    assertTrue(subtract.getExpression1() instanceof Add);
    add = (Add) subtract.getExpression1();
    assertTrue(add.getExpression1() instanceof NumericFieldValue);
    assertEquals("A", ((NumericFieldValue) add.getExpression1()).getFieldName());
    assertTrue(add.getExpression2() instanceof NumericFieldValue);
    assertEquals("B", ((NumericFieldValue) add.getExpression2()).getFieldName());
    assertTrue(subtract.getExpression2() instanceof Divide);
    divide = (Divide) subtract.getExpression2();
    assertTrue(divide.getExpression1() instanceof Multiply);
    Multiply multiply = (Multiply) divide.getExpression1();
    assertTrue(multiply.getExpression1() instanceof NumericFieldValue);
    assertEquals("C", ((NumericFieldValue) multiply.getExpression1()).getFieldName());
    assertTrue(multiply.getExpression2() instanceof NumericFieldValue);
    assertEquals("D", ((NumericFieldValue) multiply.getExpression2()).getFieldName());
    assertTrue(divide.getExpression2() instanceof NumericLiteral);
    assertEquals(8.5, ((NumericLiteral) divide.getExpression2()).getValue(), EPSILON);
    assertTrue(((NumericComparisonOperator) f).getExpression2() instanceof NumericFieldValue);
    assertEquals("E", ((NumericFieldValue) ((NumericComparisonOperator) f).getExpression2()).getFieldName());
    f = fromCQL("BBOX(geom, -90, 40, -60, 45)");
    assertTrue(f instanceof BBox);
    assertTrue(((BBox) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((BBox) f).getExpression1()).getFieldName());
    assertTrue(((BBox) f).getExpression2() instanceof SpatialLiteral);
    SpatialLiteral spatialLit = (SpatialLiteral) ((BBox) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    Geometry geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(-90, -60, 40, 45))));
    f = fromCQL("DISJOINT(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Disjoint);
    assertTrue(((Disjoint) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Disjoint) f).getExpression1()).getFieldName());
    assertTrue(((Disjoint) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Disjoint) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("EQUALS(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof SpatialEqualTo);
    assertTrue(((SpatialEqualTo) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((SpatialEqualTo) f).getExpression1()).getFieldName());
    assertTrue(((SpatialEqualTo) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((SpatialEqualTo) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("CONTAINS(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof SpatialContains);
    assertTrue(((SpatialContains) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((SpatialContains) f).getExpression1()).getFieldName());
    assertTrue(((SpatialContains) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((SpatialContains) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("CROSSES(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Crosses);
    assertTrue(((Crosses) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Crosses) f).getExpression1()).getFieldName());
    assertTrue(((Crosses) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Crosses) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("INTERSECTS(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Intersects);
    assertTrue(((Intersects) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Intersects) f).getExpression1()).getFieldName());
    assertTrue(((Intersects) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Intersects) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("OVERLAPS(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Overlaps);
    assertTrue(((Overlaps) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Overlaps) f).getExpression1()).getFieldName());
    assertTrue(((Overlaps) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Overlaps) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("TOUCHES(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Touches);
    assertTrue(((Touches) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Touches) f).getExpression1()).getFieldName());
    assertTrue(((Touches) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Touches) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    f = fromCQL("WITHIN(geom, POLYGON((-90 40, -90 45, -60 45, -60 40, -90 40)))");
    assertTrue(f instanceof Within);
    assertTrue(((Within) f).getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) ((Within) f).getExpression1()).getFieldName());
    assertTrue(((Within) f).getExpression2() instanceof SpatialLiteral);
    spatialLit = (SpatialLiteral) ((Within) f).getExpression2();
    assertTrue(spatialLit.getValue() instanceof UnpreparedFilterGeometry);
    geom = ((UnpreparedFilterGeometry) spatialLit.getValue()).getGeometry();
    assertTrue(geom.equalsTopo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(-90, 40), new Coordinate(-90, 45), new Coordinate(-60, 45), new Coordinate(-60, 40), new Coordinate(-90, 40) })));
    final Instant date1 = Instant.parse("2020-01-25T00:28:32Z");
    final Instant date2 = Instant.parse("2021-03-02T13:08:45Z");
    f = fromCQL("date AFTER 2020-01-25T00:28:32Z");
    assertTrue(f instanceof After);
    assertTrue(((After) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((After) f).getExpression1()).getFieldName());
    assertTrue(((After) f).getExpression2() instanceof TemporalLiteral);
    Interval interval = ((TemporalLiteral) ((After) f).getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date > 2020-01-25T00:28:32Z");
    assertTrue(f instanceof After);
    assertTrue(((After) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((After) f).getExpression1()).getFieldName());
    assertTrue(((After) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((After) f).getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date BEFORE 2021-03-02T13:08:45Z");
    assertTrue(f instanceof Before);
    assertTrue(((Before) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((Before) f).getExpression1()).getFieldName());
    assertTrue(((Before) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((Before) f).getExpression2()).getValue();
    assertEquals(date2.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date < 2021-03-02T13:08:45Z");
    assertTrue(f instanceof Before);
    assertTrue(((Before) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((Before) f).getExpression1()).getFieldName());
    assertTrue(((Before) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((Before) f).getExpression2()).getValue();
    assertEquals(date2.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date DURING 2020-01-25T00:28:32Z/2021-03-02T13:08:45Z");
    assertTrue(f instanceof During);
    assertTrue(((During) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((During) f).getExpression1()).getFieldName());
    assertTrue(((During) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((During) f).getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    // GeoWave has a BeforeOrDuring class, but the CQL filter translates it using OR
    f = fromCQL("date BEFORE OR DURING 2020-01-25T00:28:32Z/2021-03-02T13:08:45Z");
    assertTrue(f instanceof Or);
    assertTrue(((Or) f).getChildren().length == 2);
    assertTrue(((Or) f).getChildren()[0] instanceof Before);
    Before before = (Before) ((Or) f).getChildren()[0];
    assertTrue(before.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) before.getExpression1()).getFieldName());
    assertTrue(before.getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) before.getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    assertTrue(((Or) f).getChildren()[1] instanceof During);
    During during = (During) ((Or) f).getChildren()[1];
    assertTrue(during.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) during.getExpression1()).getFieldName());
    assertTrue(during.getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) during.getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date DURING OR AFTER 2020-01-25T00:28:32Z/2021-03-02T13:08:45Z");
    assertTrue(f instanceof Or);
    assertTrue(((Or) f).getChildren().length == 2);
    assertTrue(((Or) f).getChildren()[0] instanceof During);
    during = (During) ((Or) f).getChildren()[0];
    assertTrue(during.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) during.getExpression1()).getFieldName());
    assertTrue(during.getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) during.getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    assertTrue(((Or) f).getChildren()[1] instanceof After);
    After after = (After) ((Or) f).getChildren()[1];
    assertTrue(after.getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) after.getExpression1()).getFieldName());
    assertTrue(after.getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) after.getExpression2()).getValue();
    assertEquals(date2.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date <= 2020-01-25T00:28:32Z");
    assertTrue(f instanceof BeforeOrDuring);
    assertTrue(((BeforeOrDuring) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((BeforeOrDuring) f).getExpression1()).getFieldName());
    assertTrue(((BeforeOrDuring) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((BeforeOrDuring) f).getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date >= 2020-01-25T00:28:32Z");
    assertTrue(f instanceof DuringOrAfter);
    assertTrue(((DuringOrAfter) f).getExpression1() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((DuringOrAfter) f).getExpression1()).getFieldName());
    assertTrue(((DuringOrAfter) f).getExpression2() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) ((DuringOrAfter) f).getExpression2()).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date BETWEEN 2020-01-25T00:28:32Z AND 2021-03-02T13:08:45Z");
    assertTrue(f instanceof TemporalBetween);
    assertTrue(((TemporalBetween) f).getValue() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((TemporalBetween) f).getValue()).getFieldName());
    assertTrue(((TemporalBetween) f).getLowerBound() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) (((TemporalBetween) f).getLowerBound())).getValue();
    assertEquals(date1.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date1.getEpochSecond(), interval.getEnd().getEpochSecond());
    assertTrue(((TemporalBetween) f).getUpperBound() instanceof TemporalLiteral);
    interval = ((TemporalLiteral) (((TemporalBetween) f).getUpperBound())).getValue();
    assertEquals(date2.getEpochSecond(), interval.getStart().getEpochSecond());
    assertEquals(date2.getEpochSecond(), interval.getEnd().getEpochSecond());
    f = fromCQL("date IS NULL");
    assertTrue(f instanceof IsNull);
    assertTrue(((IsNull) f).getExpression() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((IsNull) f).getExpression()).getFieldName());
    f = fromCQL("date IS NOT NULL");
    assertTrue(f instanceof Not);
    assertTrue(((Not) f).getFilter() instanceof IsNull);
    assertTrue(((IsNull) ((Not) f).getFilter()).getExpression() instanceof TemporalFieldValue);
    assertEquals("date", ((TemporalFieldValue) ((IsNull) ((Not) f).getFilter()).getExpression()).getFieldName());
    f = fromCQL("INCLUDE");
    assertTrue(f instanceof Include);
    f = fromCQL("EXCLUDE");
    assertTrue(f instanceof Exclude);
    f = fromCQL("bool = TRUE");
    assertTrue(f instanceof GenericEqualTo);
    assertTrue(((GenericEqualTo) f).getExpression1() instanceof BooleanFieldValue);
    assertEquals("bool", ((BooleanFieldValue) ((GenericEqualTo) f).getExpression1()).getFieldName());
    assertTrue(((GenericEqualTo) f).getExpression2() instanceof BooleanLiteral);
    assertTrue((boolean) ((BooleanLiteral) ((GenericEqualTo) f).getExpression2()).getValue());
    f = fromCQL("name LIKE '%value'");
    assertTrue(f instanceof EndsWith);
    assertTrue(((EndsWith) f).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((EndsWith) f).getExpression1()).getFieldName());
    assertTrue(((EndsWith) f).getExpression2() instanceof TextLiteral);
    assertEquals("value", ((TextLiteral) ((EndsWith) f).getExpression2()).getValue());
    f = fromCQL("name LIKE 'value%'");
    assertTrue(f instanceof StartsWith);
    assertTrue(((StartsWith) f).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((StartsWith) f).getExpression1()).getFieldName());
    assertTrue(((StartsWith) f).getExpression2() instanceof TextLiteral);
    assertEquals("value", ((TextLiteral) ((StartsWith) f).getExpression2()).getValue());
    f = fromCQL("name LIKE '%value%'");
    assertTrue(f instanceof Contains);
    assertTrue(((Contains) f).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((Contains) f).getExpression1()).getFieldName());
    assertTrue(((Contains) f).getExpression2() instanceof TextLiteral);
    assertEquals("value", ((TextLiteral) ((Contains) f).getExpression2()).getValue());
    f = fromCQL("name LIKE 'a\\_value'");
    assertTrue(f instanceof TextComparisonOperator);
    assertEquals(CompareOp.EQUAL_TO, ((TextComparisonOperator) f).getCompareOp());
    assertTrue(((TextComparisonOperator) f).getExpression1() instanceof TextFieldValue);
    assertEquals("name", ((TextFieldValue) ((TextComparisonOperator) f).getExpression1()).getFieldName());
    assertTrue(((TextComparisonOperator) f).getExpression2() instanceof TextLiteral);
    assertEquals("a_value", ((TextLiteral) ((TextComparisonOperator) f).getExpression2()).getValue());
    try {
        // _ is a single character wild card, so this is not supported
        f = fromCQL("name LIKE 'a_value'");
        fail();
    } catch (CQLToGeoWaveConversionException e) {
    // expected
    }
}
Also used : Add(org.locationtech.geowave.core.store.query.filter.expression.numeric.Add) TextComparisonOperator(org.locationtech.geowave.core.store.query.filter.expression.text.TextComparisonOperator) Or(org.locationtech.geowave.core.store.query.filter.expression.Or) GenericEqualTo(org.locationtech.geowave.core.store.query.filter.expression.GenericEqualTo) Include(org.locationtech.geowave.core.store.query.filter.expression.Include) TemporalFieldValue(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalFieldValue) BooleanFieldValue(org.locationtech.geowave.core.store.query.filter.expression.BooleanFieldValue) Divide(org.locationtech.geowave.core.store.query.filter.expression.numeric.Divide) Multiply(org.locationtech.geowave.core.store.query.filter.expression.numeric.Multiply) Intersects(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Intersects) Touches(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Touches) TextLiteral(org.locationtech.geowave.core.store.query.filter.expression.text.TextLiteral) SpatialFieldValue(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialFieldValue) NumericBetween(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericBetween) Instant(java.time.Instant) Not(org.locationtech.geowave.core.store.query.filter.expression.Not) Coordinate(org.locationtech.jts.geom.Coordinate) And(org.locationtech.geowave.core.store.query.filter.expression.And) BBox(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.BBox) SpatialContains(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains) Contains(org.locationtech.geowave.core.store.query.filter.expression.text.Contains) Subtract(org.locationtech.geowave.core.store.query.filter.expression.numeric.Subtract) EndsWith(org.locationtech.geowave.core.store.query.filter.expression.text.EndsWith) Interval(org.threeten.extra.Interval) Before(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.Before) Overlaps(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Overlaps) Exclude(org.locationtech.geowave.core.store.query.filter.expression.Exclude) NumericLiteral(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericLiteral) NumericComparisonOperator(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericComparisonOperator) BooleanLiteral(org.locationtech.geowave.core.store.query.filter.expression.BooleanLiteral) NumericFieldValue(org.locationtech.geowave.core.store.query.filter.expression.numeric.NumericFieldValue) Envelope(org.locationtech.jts.geom.Envelope) StartsWith(org.locationtech.geowave.core.store.query.filter.expression.text.StartsWith) TextFieldValue(org.locationtech.geowave.core.store.query.filter.expression.text.TextFieldValue) BeforeOrDuring(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BeforeOrDuring) During(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.During) Crosses(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Crosses) DuringOrAfter(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter) Disjoint(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Disjoint) TemporalLiteral(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalLiteral) UnpreparedFilterGeometry(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.UnpreparedFilterGeometry) Geometry(org.locationtech.jts.geom.Geometry) UnpreparedFilterGeometry(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.UnpreparedFilterGeometry) SpatialEqualTo(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialEqualTo) SpatialContains(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) Within(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Within) After(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.After) DuringOrAfter(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.DuringOrAfter) IsNull(org.locationtech.geowave.core.store.query.filter.expression.IsNull) SpatialLiteral(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialLiteral) BeforeOrDuring(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.BeforeOrDuring) TemporalBetween(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TemporalBetween) Test(org.junit.Test)

Example 3 with SpatialContains

use of org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains in project geowave by locationtech.

the class SpatialTemporalFilterExpressionTest method testSpatialExpressions.

@Test
public void testSpatialExpressions() {
    final DataTypeAdapter<TestType> adapter = new TestTypeBasicDataAdapter();
    final TestType entry = new TestType(GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(20, 20)), new Date(), "test");
    final TestType entryNulls = new TestType(null, null, null);
    final SpatialLiteral bboxLit = SpatialLiteral.of(new Envelope(0, 5, 0, 5));
    final SpatialLiteral preparedBboxLit = SpatialLiteral.of(new Envelope(0, 5, 0, 5));
    preparedBboxLit.prepare(GeometryUtils.getDefaultCRS());
    final SpatialLiteral polygonLit = SpatialLiteral.of(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(0, 5), new Coordinate(0, 10), new Coordinate(5, 10), new Coordinate(5, 5), new Coordinate(0, 5) }));
    final SpatialLiteral preparedPolygonLit = SpatialLiteral.of(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(0, 5), new Coordinate(0, 10), new Coordinate(5, 10), new Coordinate(5, 5), new Coordinate(0, 5) }));
    preparedPolygonLit.prepare(GeometryUtils.getDefaultCRS());
    final SpatialLiteral referencedBboxLit = SpatialLiteral.of(new ReferencedEnvelope(0, 25, 0, 25, GeometryUtils.getDefaultCRS()));
    final SpatialLiteral referencedBboxLit2 = SpatialLiteral.of(new ReferencedEnvelope(4, 25, 4, 25, GeometryUtils.getDefaultCRS()));
    final SpatialFieldValue spatialField = SpatialFieldValue.of("geom");
    // Test comparisons
    assertTrue(bboxLit.isEqualTo(GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(0, 0), new Coordinate(0, 5), new Coordinate(5, 5), new Coordinate(5, 0), new Coordinate(0, 0) })).evaluate(adapter, entry));
    assertTrue(bboxLit.isEqualTo(preparedBboxLit).evaluate(adapter, entry));
    assertTrue(preparedBboxLit.isEqualTo(bboxLit).evaluate(adapter, entry));
    assertTrue(bboxLit.isEqualTo(new Envelope(0, 5, 0, 5)).evaluate(adapter, entry));
    assertFalse(spatialField.isEqualTo(referencedBboxLit).evaluate(adapter, entry));
    assertFalse(spatialField.isEqualTo(null).evaluate(adapter, entry));
    assertTrue(spatialField.isEqualTo(null).evaluate(adapter, entryNulls));
    assertFalse(spatialField.isEqualTo(bboxLit).evaluate(adapter, entryNulls));
    assertFalse(spatialField.isNull().evaluate(adapter, entry));
    assertTrue(spatialField.isNull().evaluate(adapter, entryNulls));
    assertFalse(bboxLit.isNotEqualTo(new ReferencedEnvelope(0, 5, 0, 5, GeometryUtils.getDefaultCRS())).evaluate(adapter, entry));
    assertFalse(bboxLit.isNotEqualTo(preparedBboxLit).evaluate(adapter, entry));
    assertTrue(bboxLit.isNotEqualTo(polygonLit).evaluate(adapter, entry));
    assertFalse(polygonLit.isNotEqualTo(polygonLit).evaluate(adapter, entry));
    assertTrue(spatialField.isNotEqualTo(bboxLit).evaluate(adapter, entryNulls));
    assertFalse(spatialField.isNotEqualTo(null).evaluate(adapter, entryNulls));
    assertTrue(spatialField.isNotEqualTo(null).evaluate(adapter, entry));
    assertTrue(SpatialLiteral.of(null).isNull().evaluate(adapter, entry));
    // Preparing null or already prepared geometries should not fail
    preparedBboxLit.prepare(GeometryUtils.getDefaultCRS());
    SpatialLiteral.of(null).prepare(GeometryUtils.getDefaultCRS());
    try {
        SpatialLiteral.of("invalid");
        fail();
    } catch (RuntimeException e) {
    // expected
    }
    // Test functions
    assertTrue(spatialField.bbox(19, 19, 21, 21).evaluate(adapter, entry));
    assertFalse(spatialField.bbox(0, 0, 5, 5).evaluate(adapter, entry));
    assertTrue(bboxLit.touches(polygonLit).evaluate(adapter, entry));
    assertTrue(preparedBboxLit.touches(polygonLit).evaluate(adapter, entry));
    assertTrue(preparedBboxLit.touches(preparedPolygonLit).evaluate(adapter, entry));
    assertTrue(bboxLit.touches(preparedPolygonLit).evaluate(adapter, entry));
    assertFalse(spatialField.touches(polygonLit).evaluate(adapter, entry));
    assertFalse(spatialField.touches(polygonLit).evaluate(adapter, entryNulls));
    assertFalse(polygonLit.touches(spatialField).evaluate(adapter, entryNulls));
    assertFalse(spatialField.touches(preparedPolygonLit).evaluate(adapter, entry));
    assertTrue(bboxLit.intersects(referencedBboxLit).evaluate(adapter, entry));
    assertTrue(preparedBboxLit.intersects(polygonLit).evaluate(adapter, entry));
    assertTrue(preparedBboxLit.intersects(preparedPolygonLit).evaluate(adapter, entry));
    assertTrue(bboxLit.intersects(preparedPolygonLit).evaluate(adapter, entry));
    assertTrue(spatialField.intersects(referencedBboxLit).evaluate(adapter, entry));
    assertFalse(spatialField.intersects(referencedBboxLit).evaluate(adapter, entryNulls));
    assertFalse(polygonLit.intersects(spatialField).evaluate(adapter, entryNulls));
    assertFalse(spatialField.intersects(preparedPolygonLit).evaluate(adapter, entry));
    assertFalse(bboxLit.disjoint(referencedBboxLit).evaluate(adapter, entry));
    assertFalse(preparedBboxLit.disjoint(polygonLit).evaluate(adapter, entry));
    assertFalse(preparedBboxLit.disjoint(preparedPolygonLit).evaluate(adapter, entry));
    assertFalse(bboxLit.disjoint(preparedPolygonLit).evaluate(adapter, entry));
    assertFalse(spatialField.disjoint(referencedBboxLit).evaluate(adapter, entry));
    assertFalse(spatialField.disjoint(referencedBboxLit).evaluate(adapter, entryNulls));
    assertFalse(polygonLit.disjoint(spatialField).evaluate(adapter, entryNulls));
    assertTrue(spatialField.disjoint(preparedPolygonLit).evaluate(adapter, entry));
    assertTrue(bboxLit.disjoint(spatialField).evaluate(adapter, entry));
    assertFalse(bboxLit.contains(referencedBboxLit).evaluate(adapter, entry));
    assertTrue(referencedBboxLit.contains(bboxLit).evaluate(adapter, entry));
    assertFalse(preparedBboxLit.contains(preparedPolygonLit).evaluate(adapter, entry));
    assertFalse(bboxLit.contains(preparedPolygonLit).evaluate(adapter, entry));
    assertFalse(spatialField.contains(referencedBboxLit).evaluate(adapter, entry));
    assertFalse(spatialField.contains(referencedBboxLit).evaluate(adapter, entryNulls));
    assertFalse(polygonLit.contains(spatialField).evaluate(adapter, entryNulls));
    assertFalse(spatialField.contains(preparedPolygonLit).evaluate(adapter, entry));
    assertTrue(referencedBboxLit.contains(spatialField).evaluate(adapter, entry));
    assertFalse(bboxLit.crosses(referencedBboxLit).evaluate(adapter, entry));
    assertFalse(referencedBboxLit.crosses(bboxLit).evaluate(adapter, entry));
    assertFalse(preparedBboxLit.crosses(preparedPolygonLit).evaluate(adapter, entry));
    assertFalse(bboxLit.crosses(preparedPolygonLit).evaluate(adapter, entry));
    assertFalse(spatialField.crosses(referencedBboxLit).evaluate(adapter, entry));
    assertFalse(spatialField.crosses(referencedBboxLit).evaluate(adapter, entryNulls));
    assertFalse(polygonLit.crosses(spatialField).evaluate(adapter, entryNulls));
    assertFalse(spatialField.crosses(preparedPolygonLit).evaluate(adapter, entry));
    assertFalse(referencedBboxLit.crosses(spatialField).evaluate(adapter, entry));
    assertTrue(SpatialLiteral.of(GeometryUtils.GEOMETRY_FACTORY.createLineString(new Coordinate[] { new Coordinate(0, 0), new Coordinate(5, 5) })).crosses(SpatialLiteral.of(GeometryUtils.GEOMETRY_FACTORY.createLineString(new Coordinate[] { new Coordinate(5, 0), new Coordinate(0, 5) }))).evaluate(adapter, entry));
    assertTrue(bboxLit.overlaps(referencedBboxLit2).evaluate(adapter, entry));
    assertTrue(referencedBboxLit2.overlaps(bboxLit).evaluate(adapter, entry));
    assertFalse(preparedBboxLit.overlaps(preparedPolygonLit).evaluate(adapter, entry));
    assertFalse(bboxLit.overlaps(preparedPolygonLit).evaluate(adapter, entry));
    assertFalse(spatialField.overlaps(referencedBboxLit).evaluate(adapter, entry));
    assertFalse(spatialField.overlaps(referencedBboxLit).evaluate(adapter, entryNulls));
    assertFalse(polygonLit.overlaps(spatialField).evaluate(adapter, entryNulls));
    assertFalse(spatialField.overlaps(preparedPolygonLit).evaluate(adapter, entry));
    assertFalse(referencedBboxLit.overlaps(spatialField).evaluate(adapter, entry));
    assertTrue(bboxLit.within(referencedBboxLit).evaluate(adapter, entry));
    assertFalse(referencedBboxLit.within(bboxLit).evaluate(adapter, entry));
    assertFalse(preparedBboxLit.within(preparedPolygonLit).evaluate(adapter, entry));
    assertFalse(bboxLit.within(preparedPolygonLit).evaluate(adapter, entry));
    assertTrue(spatialField.within(referencedBboxLit).evaluate(adapter, entry));
    assertFalse(spatialField.within(referencedBboxLit).evaluate(adapter, entryNulls));
    assertFalse(polygonLit.within(spatialField).evaluate(adapter, entryNulls));
    assertFalse(spatialField.within(preparedPolygonLit).evaluate(adapter, entry));
    assertFalse(referencedBboxLit.within(spatialField).evaluate(adapter, entry));
    // Test CRS transforms
    // This looks like it should be true, but spatial expressions need to be prepared for the query,
    // the spatial field could be any CRS because it would be determined by the index and not the
    // field descriptor
    assertFalse(spatialField.bbox(2115070, 2154935, 2337709, 2391878, GeometryUtils.decodeCRS("EPSG:3857")).evaluate(adapter, entry));
    // This looks like it should be false, but the expression hasn't been prepared for the query.
    assertTrue(spatialField.bbox(0, 0, 556597, 557305, GeometryUtils.decodeCRS("EPSG:3857")).evaluate(adapter, entry));
    try {
        bboxLit.isEqualTo(5).evaluate(adapter, entry);
        fail();
    } catch (RuntimeException e) {
    // expected
    }
    try {
        bboxLit.isNotEqualTo(5).evaluate(adapter, entry);
        fail();
    } catch (RuntimeException e) {
    // expected
    }
    // Test serialization
    byte[] bytes = PersistenceUtils.toBinary(spatialField.bbox(-5, -8, 5, 8));
    final BBox bbox = (BBox) PersistenceUtils.fromBinary(bytes);
    assertTrue(bbox.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) bbox.getExpression1()).getFieldName());
    assertTrue(bbox.getExpression2() instanceof SpatialLiteral);
    assertTrue(((SpatialLiteral) bbox.getExpression2()).getValue() instanceof UnpreparedFilterGeometry);
    assertTrue(((UnpreparedFilterGeometry) ((SpatialLiteral) bbox.getExpression2()).getValue()).getGeometry().equalsTopo(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(-5, 5, -8, 8))));
    bytes = PersistenceUtils.toBinary(spatialField.crosses(bboxLit));
    final Crosses crosses = (Crosses) PersistenceUtils.fromBinary(bytes);
    assertTrue(crosses.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) crosses.getExpression1()).getFieldName());
    assertTrue(crosses.getExpression2() instanceof SpatialLiteral);
    assertTrue(((SpatialLiteral) crosses.getExpression2()).getValue() instanceof UnpreparedFilterGeometry);
    assertTrue(((UnpreparedFilterGeometry) ((SpatialLiteral) crosses.getExpression2()).getValue()).getGeometry().equalsTopo(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(0, 5, 0, 5))));
    bytes = PersistenceUtils.toBinary(spatialField.disjoint(preparedBboxLit));
    final Disjoint disjoint = (Disjoint) PersistenceUtils.fromBinary(bytes);
    assertTrue(disjoint.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) disjoint.getExpression1()).getFieldName());
    assertTrue(disjoint.getExpression2() instanceof SpatialLiteral);
    assertTrue(((SpatialLiteral) disjoint.getExpression2()).getValue() instanceof PreparedFilterGeometry);
    assertTrue(((PreparedFilterGeometry) ((SpatialLiteral) disjoint.getExpression2()).getValue()).getGeometry().equalsTopo(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(0, 5, 0, 5))));
    bytes = PersistenceUtils.toBinary(spatialField.intersects(preparedBboxLit));
    final Intersects intersects = (Intersects) PersistenceUtils.fromBinary(bytes);
    assertTrue(intersects.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) intersects.getExpression1()).getFieldName());
    assertTrue(intersects.getExpression2() instanceof SpatialLiteral);
    assertTrue(((SpatialLiteral) intersects.getExpression2()).getValue() instanceof PreparedFilterGeometry);
    assertTrue(((PreparedFilterGeometry) ((SpatialLiteral) intersects.getExpression2()).getValue()).getGeometry().equalsTopo(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(0, 5, 0, 5))));
    bytes = PersistenceUtils.toBinary(spatialField.overlaps(preparedBboxLit));
    final Overlaps overlaps = (Overlaps) PersistenceUtils.fromBinary(bytes);
    assertTrue(overlaps.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) overlaps.getExpression1()).getFieldName());
    assertTrue(overlaps.getExpression2() instanceof SpatialLiteral);
    assertTrue(((SpatialLiteral) overlaps.getExpression2()).getValue() instanceof PreparedFilterGeometry);
    assertTrue(((PreparedFilterGeometry) ((SpatialLiteral) overlaps.getExpression2()).getValue()).getGeometry().equalsTopo(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(0, 5, 0, 5))));
    bytes = PersistenceUtils.toBinary(spatialField.contains(SpatialLiteral.of(null)));
    final SpatialContains contains = (SpatialContains) PersistenceUtils.fromBinary(bytes);
    assertTrue(contains.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) contains.getExpression1()).getFieldName());
    assertTrue(contains.getExpression2() instanceof SpatialLiteral);
    assertNull(((SpatialLiteral) contains.getExpression2()).getValue());
    bytes = PersistenceUtils.toBinary(spatialField.touches(preparedBboxLit));
    final Touches touches = (Touches) PersistenceUtils.fromBinary(bytes);
    assertTrue(touches.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) touches.getExpression1()).getFieldName());
    assertTrue(touches.getExpression2() instanceof SpatialLiteral);
    assertTrue(((SpatialLiteral) touches.getExpression2()).getValue() instanceof PreparedFilterGeometry);
    assertTrue(((PreparedFilterGeometry) ((SpatialLiteral) touches.getExpression2()).getValue()).getGeometry().equalsTopo(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(0, 5, 0, 5))));
    bytes = PersistenceUtils.toBinary(spatialField.within(preparedBboxLit));
    final Within within = (Within) PersistenceUtils.fromBinary(bytes);
    assertTrue(within.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) within.getExpression1()).getFieldName());
    assertTrue(within.getExpression2() instanceof SpatialLiteral);
    assertTrue(((SpatialLiteral) within.getExpression2()).getValue() instanceof PreparedFilterGeometry);
    assertTrue(((PreparedFilterGeometry) ((SpatialLiteral) within.getExpression2()).getValue()).getGeometry().equalsTopo(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(0, 5, 0, 5))));
    bytes = PersistenceUtils.toBinary(spatialField.isEqualTo(preparedBboxLit));
    final SpatialEqualTo equalTo = (SpatialEqualTo) PersistenceUtils.fromBinary(bytes);
    assertTrue(equalTo.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) equalTo.getExpression1()).getFieldName());
    assertTrue(equalTo.getExpression2() instanceof SpatialLiteral);
    assertTrue(((SpatialLiteral) equalTo.getExpression2()).getValue() instanceof PreparedFilterGeometry);
    assertTrue(((PreparedFilterGeometry) ((SpatialLiteral) equalTo.getExpression2()).getValue()).getGeometry().equalsTopo(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(0, 5, 0, 5))));
    bytes = PersistenceUtils.toBinary(spatialField.isNotEqualTo(preparedBboxLit));
    final SpatialNotEqualTo notEqualTo = (SpatialNotEqualTo) PersistenceUtils.fromBinary(bytes);
    assertTrue(notEqualTo.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geom", ((SpatialFieldValue) notEqualTo.getExpression1()).getFieldName());
    assertTrue(notEqualTo.getExpression2() instanceof SpatialLiteral);
    assertTrue(((SpatialLiteral) notEqualTo.getExpression2()).getValue() instanceof PreparedFilterGeometry);
    assertTrue(((PreparedFilterGeometry) ((SpatialLiteral) notEqualTo.getExpression2()).getValue()).getGeometry().equalsTopo(GeometryUtils.GEOMETRY_FACTORY.toGeometry(new Envelope(0, 5, 0, 5))));
}
Also used : SpatialFieldValue(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialFieldValue) TimeOverlaps(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TimeOverlaps) Overlaps(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Overlaps) PreparedFilterGeometry(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.PreparedFilterGeometry) SpatialNotEqualTo(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialNotEqualTo) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(org.locationtech.jts.geom.Envelope) Date(java.util.Date) UnpreparedFilterGeometry(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.UnpreparedFilterGeometry) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Crosses(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Crosses) SpatialEqualTo(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialEqualTo) SpatialContains(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains) Coordinate(org.locationtech.jts.geom.Coordinate) BBox(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.BBox) Intersects(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Intersects) Within(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Within) Disjoint(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Disjoint) Touches(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Touches) SpatialLiteral(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialLiteral) Test(org.junit.Test)

Example 4 with SpatialContains

use of org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains in project geowave by locationtech.

the class GWQLParserTest method testSpatialPredicateFunctions.

@Test
public void testSpatialPredicateFunctions() throws NoSuchAuthorityCodeException, FactoryException {
    final Geometry point = GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(1, 1));
    final Geometry bbox = GeometryUtils.GEOMETRY_FACTORY.createPolygon(new Coordinate[] { new Coordinate(0, 0), new Coordinate(0, 1), new Coordinate(1, 1), new Coordinate(1, 0), new Coordinate(0, 0) });
    final CoordinateReferenceSystem altCRS = CRS.decode("EPSG:3857");
    final DataStore dataStore = createDataStore();
    String statement = "SELECT * FROM type WHERE intersects(geometry, 'POINT(1 1)')";
    Statement gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    SelectStatement<?> selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    Filter filter = selectStatement.getFilter();
    assertTrue(filter instanceof Intersects);
    assertFalse(((Intersects) filter).isLoose());
    BinarySpatialPredicate predicate = (BinarySpatialPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geometry", ((SpatialFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof SpatialLiteral);
    assertTrue(point.equalsExact(((SpatialLiteral) predicate.getExpression2()).getValue().getGeometry()));
    assertEquals(GeometryUtils.getDefaultCRS(), predicate.getExpression2().getCRS(null));
    statement = "SELECT * FROM type WHERE intersectsLoose(geometry, 'POINT(1 1)')";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof Intersects);
    assertTrue(((Intersects) filter).isLoose());
    predicate = (BinarySpatialPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geometry", ((SpatialFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof SpatialLiteral);
    assertTrue(point.equalsExact(((SpatialLiteral) predicate.getExpression2()).getValue().getGeometry()));
    assertEquals(GeometryUtils.getDefaultCRS(), predicate.getExpression2().getCRS(null));
    statement = "SELECT * FROM type WHERE bbox(geometry, 0, 0, 1, 1)";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof BBox);
    assertFalse(((BBox) filter).isLoose());
    predicate = (BinarySpatialPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geometry", ((SpatialFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof SpatialLiteral);
    assertTrue(bbox.equalsExact(((SpatialLiteral) predicate.getExpression2()).getValue().getGeometry()));
    assertEquals(GeometryUtils.getDefaultCRS(), predicate.getExpression2().getCRS(null));
    statement = "SELECT * FROM type WHERE bboxLoose(geometry, 0, 0, 1, 1)";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof BBox);
    assertTrue(((BBox) filter).isLoose());
    predicate = (BinarySpatialPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geometry", ((SpatialFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof SpatialLiteral);
    assertTrue(bbox.equalsExact(((SpatialLiteral) predicate.getExpression2()).getValue().getGeometry()));
    assertEquals(GeometryUtils.getDefaultCRS(), predicate.getExpression2().getCRS(null));
    statement = "SELECT * FROM type WHERE bbox(geometry, 0, 0, 1, 1, 'EPSG:3857')";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof BBox);
    assertFalse(((BBox) filter).isLoose());
    predicate = (BinarySpatialPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geometry", ((SpatialFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof SpatialLiteral);
    assertTrue(bbox.equalsExact(((SpatialLiteral) predicate.getExpression2()).getValue().getGeometry()));
    assertEquals(altCRS, predicate.getExpression2().getCRS(null));
    statement = "SELECT * FROM type WHERE bboxLoose(geometry, 0, 0, 1, 1, 'EPSG:3857')";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof BBox);
    assertTrue(((BBox) filter).isLoose());
    predicate = (BinarySpatialPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geometry", ((SpatialFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof SpatialLiteral);
    assertTrue(bbox.equalsExact(((SpatialLiteral) predicate.getExpression2()).getValue().getGeometry()));
    assertEquals(altCRS, predicate.getExpression2().getCRS(null));
    statement = "SELECT * FROM type WHERE disjoint(geometry, 'POINT(1 1)')";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof Disjoint);
    assertFalse(((Disjoint) filter).isLoose());
    predicate = (BinarySpatialPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geometry", ((SpatialFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof SpatialLiteral);
    assertTrue(point.equalsExact(((SpatialLiteral) predicate.getExpression2()).getValue().getGeometry()));
    assertEquals(GeometryUtils.getDefaultCRS(), predicate.getExpression2().getCRS(null));
    statement = "SELECT * FROM type WHERE disjointLoose(geometry, 'POINT(1 1)')";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof Disjoint);
    assertTrue(((Disjoint) filter).isLoose());
    predicate = (BinarySpatialPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geometry", ((SpatialFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof SpatialLiteral);
    assertTrue(point.equalsExact(((SpatialLiteral) predicate.getExpression2()).getValue().getGeometry()));
    assertEquals(GeometryUtils.getDefaultCRS(), predicate.getExpression2().getCRS(null));
    statement = "SELECT * FROM type WHERE crosses(geometry, 'POINT(1 1)')";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof Crosses);
    predicate = (BinarySpatialPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geometry", ((SpatialFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof SpatialLiteral);
    assertTrue(point.equalsExact(((SpatialLiteral) predicate.getExpression2()).getValue().getGeometry()));
    assertEquals(GeometryUtils.getDefaultCRS(), predicate.getExpression2().getCRS(null));
    statement = "SELECT * FROM type WHERE touches(geometry, 'POINT(1 1)')";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof Touches);
    predicate = (BinarySpatialPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geometry", ((SpatialFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof SpatialLiteral);
    assertTrue(point.equalsExact(((SpatialLiteral) predicate.getExpression2()).getValue().getGeometry()));
    assertEquals(GeometryUtils.getDefaultCRS(), predicate.getExpression2().getCRS(null));
    statement = "SELECT * FROM type WHERE overlaps(geometry, 'POINT(1 1)')";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof Overlaps);
    predicate = (BinarySpatialPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geometry", ((SpatialFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof SpatialLiteral);
    assertTrue(point.equalsExact(((SpatialLiteral) predicate.getExpression2()).getValue().getGeometry()));
    assertEquals(GeometryUtils.getDefaultCRS(), predicate.getExpression2().getCRS(null));
    statement = "SELECT * FROM type WHERE contains(geometry, 'POINT(1 1)')";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof SpatialContains);
    predicate = (BinarySpatialPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geometry", ((SpatialFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof SpatialLiteral);
    assertTrue(point.equalsExact(((SpatialLiteral) predicate.getExpression2()).getValue().getGeometry()));
    assertEquals(GeometryUtils.getDefaultCRS(), predicate.getExpression2().getCRS(null));
    statement = "SELECT * FROM type WHERE within(geometry, 'POINT(1 1)')";
    gwStatement = GWQLParser.parseStatement(dataStore, statement);
    assertTrue(gwStatement instanceof SelectStatement);
    selectStatement = (SelectStatement<?>) gwStatement;
    assertNotNull(selectStatement.getFilter());
    filter = selectStatement.getFilter();
    assertTrue(filter instanceof Within);
    predicate = (BinarySpatialPredicate) filter;
    assertTrue(predicate.getExpression1() instanceof SpatialFieldValue);
    assertEquals("geometry", ((SpatialFieldValue) predicate.getExpression1()).getFieldName());
    assertTrue(predicate.getExpression2() instanceof SpatialLiteral);
    assertTrue(point.equalsExact(((SpatialLiteral) predicate.getExpression2()).getValue().getGeometry()));
    assertEquals(GeometryUtils.getDefaultCRS(), predicate.getExpression2().getCRS(null));
}
Also used : SpatialFieldValue(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialFieldValue) TimeOverlaps(org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TimeOverlaps) Overlaps(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Overlaps) Statement(org.locationtech.geowave.core.store.query.gwql.statement.Statement) SelectStatement(org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement) BinarySpatialPredicate(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.BinarySpatialPredicate) Geometry(org.locationtech.jts.geom.Geometry) SelectStatement(org.locationtech.geowave.core.store.query.gwql.statement.SelectStatement) Crosses(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Crosses) SpatialContains(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains) Coordinate(org.locationtech.jts.geom.Coordinate) Filter(org.locationtech.geowave.core.store.query.filter.expression.Filter) BBox(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.BBox) DataStore(org.locationtech.geowave.core.store.api.DataStore) Intersects(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Intersects) Within(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Within) Disjoint(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Disjoint) Touches(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Touches) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) SpatialLiteral(org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialLiteral) AbstractGWQLTest(org.locationtech.geowave.core.store.query.gwql.AbstractGWQLTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 BBox (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.BBox)4 Crosses (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Crosses)4 Disjoint (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Disjoint)4 Intersects (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Intersects)4 Overlaps (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Overlaps)4 SpatialContains (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialContains)4 Touches (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Touches)4 Within (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.Within)4 Coordinate (org.locationtech.jts.geom.Coordinate)4 SpatialEqualTo (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialEqualTo)3 SpatialFieldValue (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialFieldValue)3 SpatialLiteral (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialLiteral)3 TimeOverlaps (org.locationtech.geowave.core.geotime.store.query.filter.expression.temporal.TimeOverlaps)3 Filter (org.locationtech.geowave.core.store.query.filter.expression.Filter)3 SpatialNotEqualTo (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.SpatialNotEqualTo)2 UnpreparedFilterGeometry (org.locationtech.geowave.core.geotime.store.query.filter.expression.spatial.UnpreparedFilterGeometry)2 DataStore (org.locationtech.geowave.core.store.api.DataStore)2 Envelope (org.locationtech.jts.geom.Envelope)2 Geometry (org.locationtech.jts.geom.Geometry)2