* @param timeDimension
* @return
* @throws IOException
*/
private DateRange extractTemporalSubset() throws IOException {
DateRange timeSubset = null;
if (timeDimension != null) {
for (DimensionSubsetType dim : request.getDimensionSubset()) {
String dimension = WCSDimensionsSubsetHelper.getDimensionName(dim);
// only care for time dimensions
if (!TIME_NAMES.contains(dimension.toLowerCase())) {
continue;
}
// did we parse the range already?
if(timeSubset != null) {
throw new WCS20Exception("Time dimension trimming/slicing specified twice in the request",
WCS20Exception.WCS20ExceptionCode.InvalidSubsetting, "subset");
}
// now decide what to do
if (dim instanceof DimensionTrimType) {
// TRIMMING
final DimensionTrimType trim = (DimensionTrimType) dim;
final Date low = PARSER.parseDateTime(trim.getTrimLow());
final Date high = PARSER.parseDateTime(trim.getTrimHigh());
// low > high???
if (low.compareTo(high) > 0) {
throw new WCS20Exception("Low greater than High: " + trim.getTrimLow()
+ ", " + trim.getTrimHigh(),
WCS20Exception.WCS20ExceptionCode.InvalidSubsetting, "subset");
}
timeSubset = new DateRange(low, high);
} else if (dim instanceof DimensionSliceType) {
// SLICING
final DimensionSliceType slicing = (DimensionSliceType) dim;
final String slicePointS = slicing.getSlicePoint();
final Date slicePoint = PARSER.parseDateTime(slicePointS);
timeSubset = new DateRange(slicePoint, slicePoint);
} else {
throw new WCS20Exception(
"Invalid element found while attempting to parse dimension subsetting request: " + dim.getClass()
.toString(), WCS20Exception.WCS20ExceptionCode.InvalidSubsetting, "subset");
}
}
// right now we don't support trimming
// TODO: revisit when we have some multidimensional output support
if(!(reader instanceof StructuredGridCoverage2DReader) && timeSubset != null && !timeSubset.getMinValue().equals(timeSubset.getMaxValue())) {
throw new WCS20Exception("Trimming on time is not supported at the moment on not StructuredGridCoverage2DReaders, only slicing is");
}
// apply nearest neighbor matching on time
if (timeSubset != null && timeSubset.getMinValue().equals(timeSubset.getMaxValue())) {
timeSubset = interpolateTime(timeSubset, accessor);
}
}
return timeSubset;
}