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));
}
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();
}
Aggregations