Search in sources :

Example 1 with OptimalCQLQuery

use of org.locationtech.geowave.core.geotime.store.query.OptimalCQLQuery in project geowave by locationtech.

the class TestUtils method featureToQuery.

public static QueryConstraints featureToQuery(final SimpleFeature savedFilter, final Pair<String, String> optimalCqlQueryGeometryAndTimeField, final String crsCode, final boolean useDuring) {
    final Geometry filterGeometry = (Geometry) savedFilter.getDefaultGeometry();
    final Object startObj = savedFilter.getAttribute(TEST_FILTER_START_TIME_ATTRIBUTE_NAME);
    final Object endObj = savedFilter.getAttribute(TEST_FILTER_END_TIME_ATTRIBUTE_NAME);
    if ((startObj != null) && (endObj != null)) {
        // if we can resolve start and end times, make it a spatial temporal
        // query
        Date startDate = null, endDate = null;
        if (startObj instanceof Calendar) {
            startDate = ((Calendar) startObj).getTime();
        } else if (startObj instanceof Date) {
            startDate = (Date) startObj;
        }
        if (endObj instanceof Calendar) {
            endDate = ((Calendar) endObj).getTime();
        } else if (endObj instanceof Date) {
            endDate = (Date) endObj;
        }
        if ((startDate != null) && (endDate != null)) {
            if (optimalCqlQueryGeometryAndTimeField != null) {
                final FilterFactory2 factory = CommonFactoryFinder.getFilterFactory2();
                Filter timeConstraint;
                if (useDuring) {
                    timeConstraint = TimeUtils.toDuringFilter(startDate.getTime(), endDate.getTime(), optimalCqlQueryGeometryAndTimeField.getRight());
                } else {
                    timeConstraint = TimeUtils.toFilter(startDate.getTime(), endDate.getTime(), optimalCqlQueryGeometryAndTimeField.getRight(), optimalCqlQueryGeometryAndTimeField.getRight());
                }
                final And expression = factory.and(GeometryUtils.geometryToSpatialOperator(filterGeometry, optimalCqlQueryGeometryAndTimeField.getLeft(), GeometryUtils.getDefaultCRS()), timeConstraint);
                return new OptimalCQLQuery(expression);
            }
            return new SpatialTemporalQuery(new ExplicitSpatialTemporalQuery(startDate, endDate, filterGeometry, crsCode));
        }
    }
    if (optimalCqlQueryGeometryAndTimeField != null) {
        return new OptimalCQLQuery(GeometryUtils.geometryToSpatialOperator(filterGeometry, optimalCqlQueryGeometryAndTimeField.getLeft(), GeometryUtils.getDefaultCRS()));
    }
    // otherwise just return a spatial query
    return new SpatialQuery(new ExplicitSpatialQuery(filterGeometry, crsCode));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ExplicitSpatialQuery(org.locationtech.geowave.core.geotime.store.query.ExplicitSpatialQuery) SpatialTemporalQuery(org.locationtech.geowave.core.geotime.store.query.SpatialTemporalQuery) ExplicitSpatialTemporalQuery(org.locationtech.geowave.core.geotime.store.query.ExplicitSpatialTemporalQuery) Filter(org.opengis.filter.Filter) And(org.opengis.filter.And) Calendar(java.util.Calendar) SpatialQuery(org.locationtech.geowave.core.geotime.store.query.SpatialQuery) ExplicitSpatialQuery(org.locationtech.geowave.core.geotime.store.query.ExplicitSpatialQuery) ExplicitSpatialTemporalQuery(org.locationtech.geowave.core.geotime.store.query.ExplicitSpatialTemporalQuery) OptimalCQLQuery(org.locationtech.geowave.core.geotime.store.query.OptimalCQLQuery) FilterFactory2(org.opengis.filter.FilterFactory2) Date(java.util.Date)

Aggregations

Calendar (java.util.Calendar)1 Date (java.util.Date)1 ExplicitSpatialQuery (org.locationtech.geowave.core.geotime.store.query.ExplicitSpatialQuery)1 ExplicitSpatialTemporalQuery (org.locationtech.geowave.core.geotime.store.query.ExplicitSpatialTemporalQuery)1 OptimalCQLQuery (org.locationtech.geowave.core.geotime.store.query.OptimalCQLQuery)1 SpatialQuery (org.locationtech.geowave.core.geotime.store.query.SpatialQuery)1 SpatialTemporalQuery (org.locationtech.geowave.core.geotime.store.query.SpatialTemporalQuery)1 Geometry (org.locationtech.jts.geom.Geometry)1 And (org.opengis.filter.And)1 Filter (org.opengis.filter.Filter)1 FilterFactory2 (org.opengis.filter.FilterFactory2)1