/** * Returns the min value for the time * * @throws IOException */ public Date getMinTime() throws IOException { if (!hasTime()) { return null; } final String currentTime = reader.getMetadataValue(AbstractGridCoverage2DReader.TIME_DOMAIN_MINIMUM); if (currentTime == null) { return null; } try { return getTimeFormat().parse(currentTime); } catch (ParseException e) { throw new RuntimeException("Failed to get minimum time from coverage reader", e); } }
/** * Returns the max value for the time, either as a single {@link Date} or {@link DateRange} * according to what the underlying reader provides * * @throws IOException */ public Date getMaxTime() throws IOException { if (!hasTime()) { return null; } final String currentTime = reader.getMetadataValue(AbstractGridCoverage2DReader.TIME_DOMAIN_MAXIMUM); if (currentTime == null) { return null; } try { return getTimeFormat().parse(currentTime); } catch (ParseException e) { throw new RuntimeException("Failed to get CURRENT time from coverage reader", e); } }
/** * Returns the full set of time values supported by the raster, sorted by time. They are either * {@link Date} objects, or {@link DateRange} objects, according to what the underlying reader * provides. * * @throws IOException */ public TreeSet<Object> getTimeDomain() throws IOException { if (!hasTime()) { Collections.emptySet(); } final SimpleDateFormat df = getTimeFormat(); String domain = reader.getMetadataValue(TIME_DOMAIN); String[] timeInstants = domain.split("\\s*,\\s*"); TreeSet<Object> values = new TreeSet<Object>(TEMPORAL_COMPARATOR); for (String tp : timeInstants) { try { values.add(parseTimeOrRange(df, tp)); } catch (ParseException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); } } return values; }
@Test public void testMixedTimeExtraction() throws IOException, ParseException { MockDimensionReader reader = new MockDimensionReader(); reader.metadata.put(GridCoverage2DReader.HAS_TIME_DOMAIN, "true"); reader.metadata.put( GridCoverage2DReader.TIME_DOMAIN, "2016-02-23T03:00:00.000Z/2016-02-23T03:00:00.000Z/PT1S,2016-02-23T06:00:00.000Z,2016-02-23T09:00:00.000Z/2016-02-23T12:00:00.000Z/PT1S"); ReaderDimensionsAccessor accessor = new ReaderDimensionsAccessor(reader); TreeSet<Object> domain = accessor.getTimeDomain(); assertEquals(3, domain.size()); Iterator<Object> it = domain.iterator(); Date firstEntry = (Date) it.next(); assertEquals(accessor.getTimeFormat().parse("2016-02-23T03:00:00.000Z"), firstEntry); Date secondEntry = (Date) it.next(); assertEquals(accessor.getTimeFormat().parse("2016-02-23T06:00:00.000Z"), secondEntry); DateRange thirdEntry = (DateRange) it.next(); assertEquals( accessor.getTimeFormat().parse("2016-02-23T09:00:00.000Z"), thirdEntry.getMinValue()); assertEquals( accessor.getTimeFormat().parse("2016-02-23T12:00:00.000Z"), thirdEntry.getMaxValue()); }
SimpleDateFormat timeFormat = dimensions.getTimeFormat(); element("gml:timePosition", timeFormat.format(dimensions.getMinTime())); element("gml:timePosition", timeFormat.format(dimensions.getMaxTime()));
CoverageInfo ci, DimensionInfo timeInfo, ReaderDimensionsAccessor dimensions) throws IOException { SimpleDateFormat timeFormat = dimensions.getTimeFormat(); start("wcs:temporalDomain"); if (timeInfo.getPresentation() == DimensionPresentation.LIST) {
String maxTime = null; if (timeInfo != null && timeInfo.isEnabled()) { SimpleDateFormat timeFormat = dimensions.getTimeFormat(); minTime = timeFormat.format(dimensions.getMinTime()); maxTime = timeFormat.format(dimensions.getMaxTime());
if (timeInfo != null && timeInfo.isEnabled()) { ReaderDimensionsAccessor dimensions = new ReaderDimensionsAccessor(reader); SimpleDateFormat format = dimensions.getTimeFormat(); element("gml:timePosition", format.format(dimensions.getMinTime())); element("gml:timePosition", format.format(dimensions.getMaxTime()));