APISonar


org.geoserver.catalog.ResourceInfo.TIME

> org > geoserver > catalog > ResourceInfo > TIME
org APIs geoserver APIs catalog APIs ResourceInfo APIs TIME APIs

Example 1
Date getCurrentTime(CoverageInfo coverage, ReaderDimensionsAccessor dimensions)
            throws IOException {
        // check the time metadata
        DimensionInfo time = coverage.getMetadata().get(ResourceInfo.TIME, DimensionInfo.class);
        String name = coverage.getPrefixedName();
        if (time == null || !time.isEnabled()) {
            throw new ServiceException("Layer " + name + " does not have time support enabled");
        }

        // get and parse the current time
        return dimensions.getMaxTime();
    }
Example 2
public Object getDefaultTime(ResourceInfo resourceInfo) {
        // check the time metadata
        DimensionInfo time = resourceInfo.getMetadata().get(ResourceInfo.TIME, DimensionInfo.class);
        if (time == null || !time.isEnabled()) {
            throw new ServiceException(
                    "Layer " + resourceInfo.prefixedName() + " does not have time support enabled");
        }
        DimensionDefaultValueSelectionStrategy strategy =
                this.getDefaultValueStrategy(resourceInfo, ResourceInfo.TIME, time);
        return strategy.getDefaultValue(resourceInfo, ResourceInfo.TIME, time, Date.class);
    }
Example 3
private void handleTimeDimensionVector(FeatureTypeInfo typeInfo) throws IOException {
        // build the time dim representation
        TreeSet<Date> values = wms.getFeatureTypeTimes(typeInfo);
        String timeMetadata;
        if (values != null && !values.isEmpty()) {
            DimensionInfo timeInfo = typeInfo.getMetadata().get(ResourceInfo.TIME,
                DimensionInfo.class);
            timeMetadata = getTemporalDomainRepresentation(timeInfo, values);
        } else {
            timeMetadata = "";
        }
        writeTimeDimension(timeMetadata);
    }
Example 4
private List<Object> getNearestTimeMatch(
            ResourceInfo coverage, DimensionInfo dimension, List<Object> queryRanges)
            throws IOException {
        NearestMatchFinder finder = NearestMatchFinder.get(coverage, dimension, ResourceInfo.TIME);
        if (finder != null) {
            return finder.getMatches(
                    coverage.prefixedName(), dimension, queryRanges, ResourceInfo.TIME, -1);
        } else {
            return Collections.emptyList();
        }
    }
Example 5
public TreeSet<Object> queryFeatureTypeTimes(
            FeatureTypeInfo typeInfo, DateRange range, int maxItems) throws IOException {
        return queryFeatureTypeDimension(typeInfo, range, maxItems, ResourceInfo.TIME);
    }
Example 6
public void testTimeIntervalResolution() throws Exception {
        // adding a extra elevation that is simply not there, should not break
        setupVectorDimension(
                ResourceInfo.TIME, "time", DimensionPresentation.LIST, null, null, null);
        String base = baseFeatureInfo + "&time=2011-05-01/2011-05-04/P2D";

        // first and third
        assertEquals("TimeElevation.0", getFeatureAt(base, 20, 10));
        assertNull(getFeatureAt(base, 60, 10));
        assertEquals("TimeElevation.2", getFeatureAt(base, 20, 30));
        assertNull(getFeatureAt(base, 60, 30));
    }
Example 7
public WCSDimensionsHelper(final DimensionInfo timeDimension,
            final GridCoverage2DReader reader, final String coverageId) throws IOException {
        this(new HashMap<String, DimensionInfo>() {
            {
                put(ResourceInfo.TIME, timeDimension);
            }
        }, reader, coverageId);
    }
Example 8
private static Class getDataTypeFromDimension(ResourceInfo info, String dimensionName) {
        if (dimensionName.equalsIgnoreCase(ResourceInfo.TIME)) {
            return Date.class;
        } else if (dimensionName.equalsIgnoreCase(ResourceInfo.ELEVATION)) {
            return Double.class;
        }

        // if it's a custome dimension do custom logic based on the resourceinfo, e.g. pick the
        // attributes
        // from featuretype/structured readers and use strings for anything else
        throw new IllegalArgumentException(
                "Dimension " + dimensionName + " not supported for nearest match yet");
    }
Example 9
public boolean isValidDataset(CoverageInfo ci) {
        Boolean dataset = ci.getMetadata().get(WCSEOMetadata.DATASET.key, Boolean.class);
        DimensionInfo time = ci.getMetadata().get(ResourceInfo.TIME, DimensionInfo.class);
        try {
            GridCoverageReader reader = ci.getGridCoverageReader(null, GeoTools.getDefaultHints());
            boolean structured = reader instanceof StructuredGridCoverage2DReader;
            return dataset != null && dataset && time != null && time.isEnabled() && structured;
        } catch (IOException e) {
            throw new ServiceException(
                    "Failed to locate the grid coverage reader for coverage " + ci.prefixedName());
        }
    }
Example 10
public void testExplicitMinTimeCoverageSelector() throws Exception {
        // Use explicit default value strategy:
        DimensionDefaultValueSetting defaultValueSetting = new DimensionDefaultValueSetting();
        defaultValueSetting.setStrategyType(Strategy.MINIMUM);
        setupResourceDimensionDefaultValue(WATTEMP_FUTURE, ResourceInfo.TIME, defaultValueSetting);

        // From src/test/resources/org/geoserver/wms/watertemp.zip:
        Date expected = Date.valueOf("2008-10-31");

        CoverageInfo coverage = getCatalog().getCoverageByName(WATTEMP_FUTURE.getLocalPart());

        java.util.Date d = (java.util.Date) wms.getDefaultTime(coverage);
        assertTrue("Returns a valid Default time", d != null);
        assertTrue("Default time should be the smallest one", d.getTime() == expected.getTime());
    }
Example 11
public void testDefaultTimeRangeFixed() throws Exception {
        DimensionDefaultValueSetting defaultValueSetting = new DimensionDefaultValueSetting();
        defaultValueSetting.setStrategyType(Strategy.FIXED);
        defaultValueSetting.setReferenceValue("P1M/PRESENT");
        setupResourceDimensionDefaultValue(V_TIME_ELEVATION, ResourceInfo.TIME, defaultValueSetting);

        Document dom = dom(get("wms?request=getCapabilities&version=1.1.1"), false);
        // print(dom);
        
        assertXpathEvaluatesTo("1", "count(//Layer/Dimension)", dom);
        assertXpathEvaluatesTo("time", "//Layer/Dimension/@name", dom);
        assertXpathEvaluatesTo("P1M/PRESENT", "//Layer/Extent/@default", dom);
    }
Example 12
public void testTimeListMulti() throws Exception {
        setupVectorDimension(ResourceInfo.TIME, "time", DimensionPresentation.LIST, null, null, null);
        BufferedImage image = getAsImage("wms?service=WMS&version=1.1.1&request=GetMap"
                + "&bbox=-180,-90,180,90&styles=&Format=image/png&width=80&height=40&srs=EPSG:4326"
                + "&layers=" + getLayerId(V_TIME_ELEVATION) + "&time=2011-05-02,2011-05-04",
                "image/png");

        // we should get only second and fourth
        assertPixel(image, 20, 10, Color.WHITE);
        assertPixel(image, 60, 10, Color.BLACK);
        assertPixel(image, 20, 30, Color.WHITE);
        assertPixel(image, 60, 30, Color.BLACK);
    }
Example 13
private void handleTimeDimensionRaster(CoverageInfo cvInfo, DimensionInfo timeInfo, ReaderDimensionsAccessor dimension) throws IOException {
        TreeSet<Object> temporalDomain = dimension.getTimeDomain();
        String timeMetadata = getTemporalDomainRepresentation(timeInfo, temporalDomain);
        String defaultValue = getDefaultValueRepresentation(cvInfo, ResourceInfo.TIME, DimensionDefaultValueSetting.TIME_CURRENT);
        writeTimeDimension(timeMetadata, defaultValue);
    }
Example 14
public RasterTimeDimension(WMS wms, LayerInfo layerInfo, DimensionInfo dimensionInfo) {
        super(
                wms,
                ResourceInfo.TIME,
                layerInfo,
                dimensionInfo,
                CoverageDimensionsReader.DataType.TEMPORAL);
    }
Example 15
public void testTimeTwice() throws Exception {
        setupRasterDimension(WATTEMP, ResourceInfo.ELEVATION, DimensionPresentation.LIST, null, UNITS, UNIT_SYMBOL);
        setupRasterDimension(WATTEMP, ResourceInfo.TIME, DimensionPresentation.LIST, null, null, null);
        
        BufferedImage image = getAsImage(BASE_PNG_URL + "&time=2008-10-31T00:00:00.000Z", "image/png");

        // should be similar to the default, but with different shades of color
        assertPixel(image, 36, 31, new Color(246, 246, 255));
        assertPixel(image, 68, 72, new Color(255, 181, 181));

    }
Example 16
private static final boolean isADimension(final String key) {
        return key != null
                && (key.equals(ResourceInfo.TIME)
                        || key.equals(ResourceInfo.ELEVATION)
                        || key.startsWith(ResourceInfo.CUSTOM_DIMENSION_PREFIX));
    }
Example 17
protected void clearDimensions(String coverageName) {
        CoverageInfo info = getCatalog().getCoverageByName(coverageName);
        info.getMetadata().remove(ResourceInfo.TIME);
        info.getMetadata().remove(ResourceInfo.ELEVATION);
        getCatalog().save(info);
    }
Example 18
public void testTimeCoverage() throws Exception {
        setupRasterDimension(ResourceInfo.TIME, DimensionPresentation.LIST, null);
        
        Document dom = getAsDOM(BASEPATH + "?request=GetCapabilities&service=WCS&version=1.0.0");
        // print(dom);
        checkValidationErrors(dom, WCS10_GETCAPABILITIES_SCHEMA);
        
        // check the envelopes
        String base = "//wcs:CoverageOfferingBrief[wcs:name='wcs:watertemp']//wcs:lonLatEnvelope";
        assertXpathEvaluatesTo("2008-10-31T00:00:00.000Z", base + "/gml:timePosition[1]", dom);
        assertXpathEvaluatesTo("2008-11-01T00:00:00.000Z", base + "/gml:timePosition[2]", dom);
    }
Example 19
public void testTimeElevation() throws Exception {
        setupRasterDimension(ResourceInfo.ELEVATION, DimensionPresentation.LIST, null, UNITS, UNIT_SYMBOL);
        setupRasterDimension(ResourceInfo.TIME, DimensionPresentation.LIST, null, null, null);

        String url = BASE_URL + "&time=2008-10-31T00:00:00.000Z&elevation=100";
        // this one should be the no-data
        assertEquals(-30000, getFeatureAt(url, 36, 31), EPS);
        // and this one should be medium
        assertEquals(14.134, getFeatureAt(url, 68, 72), EPS);
    }
Example 20
public void testEmptyResultsWhenNodata() throws Exception {
        setupRasterDimension(
                TIMESERIES, ResourceInfo.TIME, DimensionPresentation.LIST, null, null, null);
        String url = REQUEST_ON_NODATA_PIXEL;
        String rawCsv = getAsString(url);
        String[] csvLines = rawCsv.split("\\r?\\n");

        // Make sure we aren getting an empty value on nodata
        Assert.assertEquals("CSV Number of results", CSV_HEADER_ROWS + 1, csvLines.length);
        String line = csvLines[CSV_HEADER_ROWS];
        String[] lineSplit = line.split(",");
        // Nothing get found after the comma, meaning the result is empty
        Assert.assertEquals(1, lineSplit.length);
    }
Example 21
public void testTimeDefaultAsRange() throws Exception {
        // setup a default 
        DimensionDefaultValueSetting defaultValueSetting = new DimensionDefaultValueSetting();
        defaultValueSetting.setStrategyType(Strategy.FIXED);
        defaultValueSetting.setReferenceValue("2011-05-02/2011-05-03");
        setupResourceDimensionDefaultValue(V_TIME_ELEVATION, ResourceInfo.TIME, defaultValueSetting, "time");
        
        // the last three show up, the first does not
        assertNull(getFeatureAt(baseFeatureInfo, 20, 10));
        assertEquals("TimeElevation.1", getFeatureAt(baseFeatureInfo, 60, 10));
        assertEquals("TimeElevation.2", getFeatureAt(baseFeatureInfo, 20, 30));
        assertNull(getFeatureAt(baseFeatureInfo, 60, 30));
    }
Example 22
public void testCsvLatLon() throws Exception {
        setupRasterDimension(WATTEMP, ResourceInfo.ELEVATION, DimensionPresentation.LIST, null,
                UNITS, UNIT_SYMBOL);
        setupRasterDimension(WATTEMP, ResourceInfo.TIME, DimensionPresentation.LIST, null, null,
                "degrees");

        String url = BASE_URL_4326 + CSV_FORMAT + TIME_RANGE_COMPLETE;
        String rawCsv = getAsString(url);
        String[] csvLines = rawCsv.split("\\r?\\n");
        Assert.assertTrue("Geographic output", csvLines[0].startsWith("# Latitude:"));
        double latitude = Double.parseDouble(csvLines[0].substring(12));
        double longitude = Double.parseDouble(csvLines[1].substring(13));
        Assert.assertEquals("latitude", 41.93481445312501, latitude, 0.000001);
        Assert.assertEquals("longitude", 4.822998046875, longitude, 0.000001);
    }
Example 23
protected Dimension buildDimension(DimensionInfo dimensionInfo) {
        dimensionInfo.setAttribute("startTime");
        FeatureTypeInfo rasterInfo = getVectorInfo();
        Dimension dimension = new VectorTimeDimension(wms, getLayerInfo(), dimensionInfo);
        rasterInfo.getMetadata().put(ResourceInfo.TIME, dimensionInfo);
        getCatalog().save(rasterInfo);
        return dimension;
    }
Example 24
protected void enableEODataset(String coverageName) {
        CoverageInfo ci = getCatalog().getCoverageByName(coverageName);
        ci.getMetadata().put(WCSEOMetadata.DATASET.key, true);
        getCatalog().save(ci);
        setupRasterDimension(coverageName, ResourceInfo.TIME, DimensionPresentation.LIST, null);
    }
Example 25
public void testTimeList() throws Exception {
        setupRasterDimension(WATTEMP, ResourceInfo.TIME, DimensionPresentation.LIST, null, null, null);
        
        Document dom = dom(get("wms?request=getCapabilities&version=1.3.0"), false);
        // print(dom);
        
        // check dimension has been declared
        assertXpathEvaluatesTo("1", "count(//wms:Layer/wms:Dimension)", dom);
        assertXpathEvaluatesTo("time", "//wms:Layer/wms:Dimension/@name", dom);
        assertXpathEvaluatesTo("ISO8601", "//wms:Layer/wms:Dimension/@units", dom);
        // check we have the wms:Dimension        
        assertXpathEvaluatesTo("time", "//wms:Layer/wms:Dimension/@name", dom);
        assertXpathEvaluatesTo(DimensionDefaultValueSetting.TIME_CURRENT, "//wms:Layer/wms:Dimension/@default", dom);
        assertXpathEvaluatesTo("2008-10-31T00:00:00.000Z,2008-11-01T00:00:00.000Z", "//wms:Layer/wms:Dimension", dom);
    }