Search in sources :

Example 1 with Position

use of org.opengis.temporal.Position in project geowave by locationtech.

the class TimeUtils method toDuringFilter.

/**
 * @param startTimeMillis start time (inclusive)
 * @param endTimeMillis end time (exclusive)
 * @param singleTimeField
 * @return the during filter
 */
public static Filter toDuringFilter(final long startTimeMillis, final long endTimeMillis, final String singleTimeField) {
    final FilterFactory2 factory = CommonFactoryFinder.getFilterFactory2();
    final Position ip1 = new DefaultPosition(new Date(startTimeMillis - 1));
    final Position ip2 = new DefaultPosition(new Date(endTimeMillis));
    final Period period = new DefaultPeriod(new DefaultInstant(ip1), new DefaultInstant(ip2));
    return factory.during(factory.property(singleTimeField), factory.literal(period));
}
Also used : DefaultPosition(org.geotools.temporal.object.DefaultPosition) Position(org.opengis.temporal.Position) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) DefaultPosition(org.geotools.temporal.object.DefaultPosition) Period(org.opengis.temporal.Period) DefaultPeriod(org.geotools.temporal.object.DefaultPeriod) DefaultInstant(org.geotools.temporal.object.DefaultInstant) FilterFactory2(org.opengis.filter.FilterFactory2) Date(java.util.Date)

Example 2 with Position

use of org.opengis.temporal.Position in project geowave by locationtech.

the class ExtractTimeFilterVisitor method btime.

/**
 * Produce an ReferencedEnvelope from the provided data parameter.
 *
 * @param data
 * @return ReferencedEnvelope
 */
private TemporalConstraints btime(final Object data) {
    if (data == null) {
        return null;
    }
    if (data instanceof Date) {
        return toSet(new TemporalRange((Date) data, (Date) data));
    } else if (data instanceof Timestamp) {
        return toSet(new TemporalRange((Timestamp) data, (Timestamp) data));
    } else if (data instanceof Number) {
        final long val = ((Number) data).longValue();
        return toSet(new TemporalRange(new Date(val), new Date(val)));
    } else if (data instanceof TemporalRange) {
        return toSet((TemporalRange) data);
    } else if (data instanceof TemporalConstraints) {
        return (TemporalConstraints) data;
    } else if (data instanceof Period) {
        // all periods are exclusive
        final Position beginPosition = ((Period) data).getBeginning().getPosition();
        final Position endPosition = ((Period) data).getEnding().getPosition();
        Date s = TemporalRange.START_TIME, e = TemporalRange.START_TIME;
        if (beginPosition.getDate() != null) {
            // make it exclusive on start
            s = new Date(beginPosition.getDate().getTime() + 1);
        } else if (beginPosition.getTime() != null) {
            // make it exclusive on start
            s = new Date(beginPosition.getTime().getTime() + 1);
        }
        if (endPosition.getDate() != null) {
            // make it exclusive on end
            e = new Date(endPosition.getDate().getTime() - 1);
        } else if (endPosition.getTime() != null) {
            // make it exclusive on end
            e = new Date(endPosition.getTime().getTime() - 1);
        }
        if (s.getTime() > e.getTime()) {
            return new TemporalConstraints();
        }
        return toSet(new TemporalRange(s, e));
    } else if (data instanceof Instant) {
        final Position beginPosition = ((Instant) data).getPosition();
        Date s = TemporalRange.START_TIME;
        if (beginPosition.getDate() != null) {
            s = beginPosition.getDate();
        } else if (beginPosition.getTime() != null) {
            s = beginPosition.getTime();
        }
        return toSet(new TemporalRange(s, s));
    }
    final Date convertedDate = Converters.convert(data, Date.class);
    if (convertedDate != null) {
        return btime(convertedDate);
    }
    return new TemporalConstraints();
}
Also used : Position(org.opengis.temporal.Position) Instant(org.opengis.temporal.Instant) Period(org.opengis.temporal.Period) TemporalRange(org.locationtech.geowave.core.geotime.store.query.TemporalRange) TemporalConstraints(org.locationtech.geowave.core.geotime.store.query.TemporalConstraints) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Aggregations

Date (java.util.Date)2 Period (org.opengis.temporal.Period)2 Position (org.opengis.temporal.Position)2 Timestamp (java.sql.Timestamp)1 DefaultInstant (org.geotools.temporal.object.DefaultInstant)1 DefaultPeriod (org.geotools.temporal.object.DefaultPeriod)1 DefaultPosition (org.geotools.temporal.object.DefaultPosition)1 TemporalConstraints (org.locationtech.geowave.core.geotime.store.query.TemporalConstraints)1 TemporalRange (org.locationtech.geowave.core.geotime.store.query.TemporalRange)1 FilterFactory2 (org.opengis.filter.FilterFactory2)1 Instant (org.opengis.temporal.Instant)1