use of org.locationtech.geowave.core.geotime.store.query.SpatialTemporalQuery 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));
}
Aggregations