Package org.geotools.util

Examples of org.geotools.util.DateRange


                        return false;
                    } else if(result == 0) {
                        return true;
                    }
                } else if(curr instanceof DateRange) {
                    DateRange range = (DateRange) curr;
                    if(range.contains(sliceDate)) {
                        return true;
                    } else if(range.getMaxValue().compareTo(sliceDate) < 0) {
                        return false;
                    }
                }
            }
        } else if (slicePoint instanceof Number) {
            //TODO: Should we check for other data types?
            Number sliceNumber = (Number) slicePoint;
            for (Object curr : domain) {
                if(curr instanceof Number) {
                    Double num = (Double) curr;
                    int result = num.compareTo((Double)sliceNumber);
                    if( result > 0) {
                        return false;
                    } else if(result == 0) {
                        return true;
                    }
                } else if(curr instanceof NumberRange) {
                    NumberRange range = (NumberRange) curr;
                    if(range.contains(sliceNumber)) {
                        return true;
                    } else if(range.getMaxValue().compareTo(sliceNumber) < 0) {
                        return false;
                    }
                }
            }
        }
View Full Code Here


    public GridCoverageRequest createGridCoverageRequestSubset() throws IOException {
        final WCSEnvelope spatialSubset = extractSubsettingEnvelope();
        assert spatialSubset != null && !spatialSubset.isEmpty();
       
        Map<String, List<Object>> dimensionsSubset = null;
        DateRange temporalSubset = null;
        NumberRange elevationSubset = null;

        // Parse specified subset values (if any)
        if (enabledDimensions != null && !enabledDimensions.isEmpty()) {
            // extract temporal subsetting
View Full Code Here

        if (timeDescriptor != null) {
            startTimeAttribute = timeDescriptor.getStartAttribute();
            endTimeAttribute = timeDescriptor.getEndAttribute();
            Date startDate = (Date) feature.getAttribute(startTimeAttribute);
            Date endDate = (endTimeAttribute != null) ? (Date) feature.getAttribute(endTimeAttribute) : startDate;
            DateRange range = new DateRange(startDate, endDate);
            subRequest.setTemporalSubset(range);
        }

        // ----------------------------------
        // Updating vertical dimension subset
        // ----------------------------------
        String startElevationAttribute = null;
        String endElevationAttribute = null;
        DimensionDescriptor elevationDescriptor = WCSDimensionsHelper.getDimensionDescriptor(reader, coverageName, "ELEVATION");
        if (elevationDescriptor != null) {
            startElevationAttribute = elevationDescriptor.getStartAttribute();
            endElevationAttribute = elevationDescriptor.getEndAttribute();
            Number startValue = (Number) feature.getAttribute(startElevationAttribute);
            Number endValue = (endElevationAttribute != null) ? (Number) feature.getAttribute(endElevationAttribute) : startValue;
            NumberRange range = new NumberRange(startValue.getClass(), startValue, endValue);
            subRequest.setElevationSubset(range);
        }

        // ---------------------------------
        // Updating custom dimensions subset
        // ---------------------------------
        List<String> customDomains = (List<String>) (accessor != null ? accessor.getCustomDomains() : Collections.emptyList());
        Map<String, List<Object>> dimensionsSubset = new HashMap<String, List<Object>>();
        for (String customDomain: customDomains) {
            String startAttribute = null;
            String endAttribute = null;
            DimensionDescriptor descriptor = WCSDimensionsHelper.getDimensionDescriptor(reader, coverageName, customDomain);
            if (descriptor != null) {
                startAttribute = descriptor.getStartAttribute();
                endAttribute = descriptor.getEndAttribute();

                Object value = feature.getAttribute(startAttribute);
                if (endAttribute != null) {
                    Object endValue = feature.getAttribute(endAttribute);
                    Class objectClass = endValue.getClass();
                    String classDataType = objectClass.toString();
                    if (classDataType.endsWith("Timestamp")) {
                        value = new DateRange(new Date(((Timestamp) value).getTime()), new Date(
                                ((Timestamp) endValue).getTime()));
                    } else if (classDataType.endsWith("Date")) {
                        value = new DateRange((Date) value, (Date) endValue);
                    } else {
                        value = new NumberRange(objectClass, (Number) value, (Number) endValue);
                    }
                }
                List<Object> dimensionValues = new ArrayList<Object>();
View Full Code Here

     * @param coverageName
     * @param reader
     * @return
     */
    private Filter filterTime(Filter filter, GridCoverageRequest gcr, String coverageName, StructuredGridCoverage2DReader reader) {
        DateRange timeRange = gcr.getTemporalSubset();
        DimensionDescriptor timeDescriptor = null;
        String startTime = null;
        String endTime = null;
        Filter timeFilter = filter;
        if (timeRange != null && filter != Filter.EXCLUDE) {
            timeDescriptor = WCSDimensionsHelper.getDimensionDescriptor(reader, coverageName, "TIME");
            startTime = timeDescriptor.getStartAttribute();
            endTime = timeDescriptor.getEndAttribute();
            timeFilter = filter(startTime, endTime, timeRange.getMinValue(), timeRange.getMaxValue(), filter);
        }
        return timeFilter;
    }
View Full Code Here

            // Note that currently, dimensionValues only contain one element (slicing specifies a single value for a dimension)
            Object element = dimensionValues.get(0);
            Object min = null;
            Object max = null;
            if (element instanceof DateRange) {
                DateRange dateRange = (DateRange) element;
                min = dateRange.getMinValue();
                max = dateRange.getMaxValue();
            } else if (element instanceof NumberRange) {
                NumberRange numberRange = (NumberRange) element;
                min = numberRange.getMinValue();
                max = numberRange.getMaxValue();
            } else if (element instanceof Date || element instanceof Number || element instanceof String) {
View Full Code Here

        final Date h = parseAsDate(high);
        if (l != null && h != null) {
            if (l.compareTo(h) > 0) {
                throwInvalidRangeException(low, high);
            }
            selectedValues.add(new DateRange(l, h));
            return true;
        }
        return false;
    }
View Full Code Here

        doTimeElevationFilter( Date.valueOf("2012-02-13"), null, 1, 2);
        doTimeElevationFilter( Date.valueOf("2012-02-15"), null);
      
        //Test start and end before all ranges.
        doTimeElevationFilter(
                new DateRange(Date.valueOf("2012-02-09"), Date.valueOf("2012-02-10")), null
        );
        //Test start before and end during a range.
        doTimeElevationFilter(
                new DateRange(Date.valueOf("2012-02-09"), Date.valueOf("2012-02-11")), null,
                0, 2
        );
        //Test start on and end after or during a range.
        doTimeElevationFilter(
                new DateRange(Date.valueOf("2012-02-11"), Date.valueOf("2012-02-13")), null,
                0, 1, 2
        );
        //Test start before and end after all ranges.
        doTimeElevationFilter(
                new DateRange(Date.valueOf("2012-02-09"), Date.valueOf("2012-02-14")), null,
                0, 1, 2
        );
         //Test start during and end after a range.
        doTimeElevationFilter(
                new DateRange(Date.valueOf("2012-02-13"), Date.valueOf("2012-02-14")), null,
                1,2
        );
        //Test start during and end during a range.
        doTimeElevationFilter(
                new DateRange(Date.valueOf("2012-02-12"), Date.valueOf("2012-02-13")), null,
                0,1,2
        );
        //Test start and end after all ranges.
        doTimeElevationFilter(
                new DateRange(Date.valueOf("2012-02-15"), Date.valueOf("2012-02-16")), null
        );
       
        doTimeElevationFilter( null, 0);
        doTimeElevationFilter( null, 1, 0 , 2);
        doTimeElevationFilter( null, 2, 0 , 1, 2);
View Full Code Here

                } else if (d.equals(toMatch)) {
                    candidate = d;
                    break;
                }
            } else if (dateOrRange instanceof DateRange) {
                DateRange d = (DateRange) dateOrRange;
                if (d.getMaxValue().before(toMatch)) {
                    currentDistance = toMatch.getTime() - d.getMaxValue().getTime();
                    if (currentDistance < shortestDistance) {
                        shortestDistance = currentDistance;
                        candidate = d.getMaxValue();
                    }
                } else if (d.getMinValue().after(toMatch)) {
                    currentDistance = d.getMinValue().getTime() - toMatch.getTime();
                    if (currentDistance < shortestDistance) {
                        candidate = d.getMinValue();
                    }
                    // the distance can only grow after this
                    // assuming the times are in ascending order,
                    // so stop iterating at this point for efficiency:
                    break;
View Full Code Here

                    final EList timePeriods = temporalSubset.getTimePeriod();
                    for (Iterator it = timePeriods.iterator(); it.hasNext();) {
                        TimePeriodType tp = (TimePeriodType) it.next();
                        Date begin = (Date) tp.getBeginPosition().getValue();
                        Date end = (Date) tp.getEndPosition().getValue();
                        timeValues.add(new DateRange(begin, end));
                    }
                }
               
                if(timeValues.isEmpty()) {
                    Date date = dimensions.getMaxTime();
View Full Code Here

            if(timeInfo.getPresentation() == DimensionPresentation.LIST) {
                for(Object item : dimensions.getTimeDomain()) {
                    if(item instanceof Date) {
                        element("gml:timePosition", timeFormat.format((Date) item));
                    } else {
                        DateRange range = (DateRange) item;
                        start("wcs:timePeriod");
                        String minTime = timeFormat.format(range.getMinValue());
                        String maxTime = timeFormat.format(range.getMaxValue());
                        element("wcs:beginPosition", minTime);
                        element("wcs:endPosition", maxTime);
                        end("wcs:timePeriod");
                    }
                }
View Full Code Here

TOP

Related Classes of org.geotools.util.DateRange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.