Package org.geoserver.wcs2_0.response

Examples of org.geoserver.wcs2_0.response.FileReference


            // extract dimensions subsetting
            dimensionsSubset = extractDimensionsSubset();
        }

        // Prepare subsetting request
        GridCoverageRequest subsettingRequest = new GridCoverageRequest();
        subsettingRequest.setSpatialSubset(spatialSubset);
        subsettingRequest.setElevationSubset(elevationSubset);
        subsettingRequest.setTemporalSubset(temporalSubset);
        subsettingRequest.setDimensionsSubset(dimensionsSubset);
        subsettingRequest.setFilter(request.getFilter());

        // Handle default values and update subsetting values if needed
        String coverageName =  getCoverageName();
        //TODO consider dealing with the Format instance instead of a String parsing or check against WCSUtils.isSupportedMDOutputFormat(String).
        if (!GetCoverage.formatSupportMDOutput(request.getFormat())) {
View Full Code Here


        try {
            while (iterator.hasNext()) {
                final SimpleFeature feature = iterator.next();

                // Prepare subRequest setting up dimensions matching the values of the current granule
                final GridCoverageRequest subRequest = new GridCoverageRequest();

                // Setting up constant elements (outputCRS, spatial subset, interpolation
                subRequest.setOutputCRS(gridCoverageRequest.getOutputCRS());
                subRequest.setSpatialInterpolation(gridCoverageRequest.getSpatialInterpolation());
                subRequest.setSpatialSubset(gridCoverageRequest.getSpatialSubset());
                subRequest.setTemporalInterpolation(gridCoverageRequest.getTemporalInterpolation());

                //Setting up specific dimensions subset
                updateDimensions(subRequest, feature, structuredReader, coverageName);
                requests.add(subRequest);
            }
View Full Code Here

     */
    private WCSEnvelope extractSubsettingEnvelope() {

        //default envelope in subsettingCRS
        final CoordinateReferenceSystem sourceCRS = reader.getCoordinateReferenceSystem();
        WCSEnvelope sourceEnvelopeInSubsettingCRS = new WCSEnvelope(reader.getOriginalEnvelope());
        if (!(subsettingCRS == null || CRS.equalsIgnoreMetadata(subsettingCRS, sourceCRS))) {
            // reproject source envelope to subsetting crs for initialization
            try {
                sourceEnvelopeInSubsettingCRS = new WCSEnvelope(CRS.transform(
                        reader.getOriginalEnvelope(), subsettingCRS));
            } catch (Exception e) {
                try {
                    // see if we can get a valid restricted area using the projection handlers
                    ProjectionHandler handler = ProjectionHandlerFinder.getHandler(
                            new ReferencedEnvelope(0, 1, 0, 1, subsettingCRS), sourceCRS, false);
                    if (handler != null) {
                        ReferencedEnvelope validArea = handler.getValidAreaBounds();
                        Envelope intersection = validArea.intersection(ReferencedEnvelope
                                .reference(reader.getOriginalEnvelope()));
                        ReferencedEnvelope re = new ReferencedEnvelope(intersection, sourceCRS);
                        sourceEnvelopeInSubsettingCRS = new WCSEnvelope(re.transform(subsettingCRS,
                                true));
                    } else {
                        throw new WCS20Exception("Unable to initialize subsetting envelope",
                                WCS20Exception.WCS20ExceptionCode.SubsettingCrsNotSupported,
                                subsettingCRS.toWKT(), e); // TODO extract code
                    }
                } catch (Exception e2) {
                    throw new WCS20Exception("Unable to initialize subsetting envelope",
                            WCS20Exception.WCS20ExceptionCode.SubsettingCrsNotSupported,
                            subsettingCRS.toWKT(), e2); // TODO extract code
                }
            }
        }

        // check if we have to subset, if not let's send back the basic coverage
        final EList<DimensionSubsetType> requestedDimensions = request.getDimensionSubset();
        if(requestedDimensions==null||requestedDimensions.size()<=0){
            return sourceEnvelopeInSubsettingCRS;
        }

        int maxDimensions = 2 + enabledDimensions.size();
        if(requestedDimensions.size() > maxDimensions){
            throw new WCS20Exception(
                    "Invalid number of dimensions",
                    WCS20Exception.WCS20ExceptionCode.InvalidSubsetting,Integer.toString(requestedDimensions.size()));
        }

        // put aside the dimensions that we have for double checking
        final List<String> axesNames = envelopeDimensionsMapper.getAxesNames(sourceEnvelopeInSubsettingCRS, true);
        final List<String> foundDimensions= new ArrayList<String>();
       
        // === parse dimensions
        // the subsetting envelope is initialized with the source envelope in subsetting CRS
        WCSEnvelope subsettingEnvelope = new WCSEnvelope(sourceEnvelopeInSubsettingCRS);

        Set<String> dimensionKeys = enabledDimensions.keySet();
        for (DimensionSubsetType dim : requestedDimensions){
            String dimension = WCSDimensionsSubsetHelper.getDimensionName(dim);
            // skip time support
            if (WCSDimensionsSubsetHelper.TIME_NAMES.contains(dimension.toLowerCase())) {
                if (dimensionKeys.contains(ResourceInfo.TIME)) {
                    // fine, we'll parse it later
                    continue;
                } else {
                    throw new WCS20Exception("Invalid axis label provided: " + dimension,
                            WCS20Exception.WCS20ExceptionCode.InvalidAxisLabel, null);
                }
            }
            if (WCSDimensionsSubsetHelper.ELEVATION_NAMES.contains(dimension.toLowerCase())) {
                if (dimensionKeys.contains(ResourceInfo.ELEVATION)) {
                    // fine, we'll parse it later
                    continue;
                } else {
                    throw new WCS20Exception("Invalid axis label provided: " + dimension,
                            WCS20Exception.WCS20ExceptionCode.InvalidAxisLabel, null);
                }
            }

            boolean isCustomDimension = false;
            for (String dimensionKey : dimensionKeys){
                if (dimensionKey.equalsIgnoreCase(dimension)) {
                    isCustomDimension = true;
                    break;
                }
            }
            if (isCustomDimension) {
                continue;
            }
           
            if(!axesNames.contains(dimension)) {
                throw new WCS20Exception("Invalid axis label provided: " + dimension,
                        WCS20Exception.WCS20ExceptionCode.InvalidAxisLabel,
                        dimension == null ? "Null" : dimension);
            }

            // did we already do something with this dimension?
            if(foundDimensions.contains(dimension)){
                throw new WCS20Exception("Axis label already used during subsetting",WCS20Exception.WCS20ExceptionCode.InvalidAxisLabel,dimension);
            }
            foundDimensions.add(dimension);

            // now decide what to do
//            final String CRS= dim.getCRS();// TODO HOW DO WE USE THIS???
            if(dim instanceof DimensionTrimType){

                // TRIMMING
                final DimensionTrimType trim = (DimensionTrimType) dim;
                final double low = Double.parseDouble(trim.getTrimLow());
                final double high = Double.parseDouble(trim.getTrimHigh());

                final int axisIndex = envelopeDimensionsMapper.getAxisIndex(sourceEnvelopeInSubsettingCRS, dimension);
                if (axisIndex < 0) {
                    throw new WCS20Exception("Invalid axis provided",WCS20Exception.WCS20ExceptionCode.InvalidAxisLabel,dimension);
                }
               
                // low > high && not dateline wrapping?
                if (low > high && !subsettingEnvelope.isLongitude(axisIndex)) {
                    throw new WCS20Exception("Low greater than High",
                            WCS20Exception.WCS20ExceptionCode.InvalidSubsetting, trim.getTrimLow());
                }

                // notice how we choose the order of the axes
                subsettingEnvelope.setRange(axisIndex, low, high);
            } else if (dim instanceof DimensionSliceType) {

                // SLICING
                final DimensionSliceType slicing= (DimensionSliceType) dim;
                final String slicePointS = slicing.getSlicePoint();
                final double slicePoint=Double.parseDouble(slicePointS);           

                final int axisIndex=envelopeDimensionsMapper.getAxisIndex(sourceEnvelopeInSubsettingCRS, dimension);
                if (axisIndex < 0) {
                    throw new WCS20Exception("Invalid axis provided",WCS20Exception.WCS20ExceptionCode.InvalidAxisLabel,dimension);
                }
                // notice how we choose the order of the axes
                AffineTransform affineTransform = RequestUtils.getAffineTransform(reader.getOriginalGridToWorld(PixelInCell.CELL_CENTER));
                final double scale = axisIndex == 0 ? affineTransform.getScaleX() : -affineTransform.getScaleY();
                subsettingEnvelope.setRange(axisIndex, slicePoint, slicePoint + scale);
               
                // slice point outside coverage
                if (sourceEnvelopeInSubsettingCRS.getMinimum(axisIndex) > slicePoint || slicePoint > sourceEnvelopeInSubsettingCRS.getMaximum(axisIndex)){
                    throw new WCS20Exception(
                            "SlicePoint outside coverage envelope",
                            WCS20Exception.WCS20ExceptionCode.InvalidSubsetting,
                            slicePointS);
                }
            } else {
                throw new WCS20Exception(
                        "Invalid element found while attempting to parse dimension subsetting request",
                        WCS20Exception.WCS20ExceptionCode.InvalidSubsetting,
                        dim.getClass().toString());
            }
        }

        // make sure we have not been requested to subset outside of the source CRS
        requestedEnvelope = new WCSEnvelope(subsettingEnvelope);
        subsettingEnvelope.intersect(new GeneralEnvelope(sourceEnvelopeInSubsettingCRS));

        if (subsettingEnvelope.isEmpty()) {
            throw new WCS20Exception("Empty intersection after subsetting",
                    WCS20Exception.WCS20ExceptionCode.InvalidSubsetting, "");// TODO spit our
                                                                             // envelope trimmed
        }

View Full Code Here

     *
     * @return
     * @throws IOException
     */
    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;

View Full Code Here

        return query;
    }

    private Filter filterSpatial(GridCoverageRequest gcr,
            StructuredGridCoverage2DReader reader, GranuleSource source) throws IOException, MismatchedDimensionException, TransformException, FactoryException {
        WCSEnvelope envelope = gcr.getSpatialSubset();
        Polygon llPolygon = JTS.toGeometry(new ReferencedEnvelope(envelope));
        GeometryDescriptor geom = source.getSchema().getGeometryDescriptor();
        PropertyName geometryProperty = ff.property(geom.getLocalName());
        Geometry nativeCRSPolygon = JTS.transform(llPolygon, CRS.findMathTransform(envelope.getCoordinateReferenceSystem(), reader.getCoordinateReferenceSystem()));
        Literal polygonLiteral = ff.literal(nativeCRSPolygon);
//                    if(overlaps) {
        return ff.intersects(geometryProperty, polygonLiteral);
//                    } else {
//                        filter = ff.within(geometryProperty, polygonLiteral);
View Full Code Here

                    new OWSExceptionCode("noSuchEODataset", 404), "eoid");
        }

        WCS20DescribeCoverageTransformer tx = new WCS20DescribeCoverageTransformer(
                getServiceInfo(), catalog, responseFactory, envelopeAxesMapper, mimemapper);
        return new DescribeEOCoverageSetTransformer(getServiceInfo(), resourceCodec, envelopeAxesMapper, tx);
    }
View Full Code Here

                    WCSDimensionsHelper timeHelper = new WCSDimensionsHelper(time, reader, datasetId);
                    dcTranslator.encodeTimePeriod(timeHelper.getBeginTime(), timeHelper.getEndTime(), datasetId + "_timeperiod", null, null);

                    end("wcseo:DatasetSeriesDescription");
                } catch (IOException e) {
                    throw new WCS20Exception("Failed to build the description for dataset series "
                            + codec.getDatasetName(ci), e);
                }
            }
            end("wcseo:DatasetSeriesDescriptions");
        }
View Full Code Here

                        List<DimensionDescriptor> descriptors = getActiveDimensionDescriptor(ci, reader, name);
                        CoverageGranules granules = new CoverageGranules(ci, name, reader, collection, descriptors);
                        results.add(granules);
                    }
                } catch (IOException e) {
                    throw new WCS20Exception("Failed to load the coverage granules for covearge "
                            + ci.prefixedName(), e);
                } finally {
                    try {
                        if (source != null) {
                            source.dispose();
View Full Code Here

            NumberRange<Double> latRange = null;
            for (DimensionTrimType trim : dcs.getDimensionTrim()) {
                String name = trim.getDimension();
                if ("Long".equals(name)) {
                    if (lonRange != null) {
                        throw new WCS20Exception("Long trim specified more than once",
                                OWSExceptionCode.InvalidParameterValue, "subset");
                    }
                    lonRange = parseNumberRange(trim);
                } else if ("Lat".equals(name)) {
                    if (latRange != null) {
                        throw new WCS20Exception("Lat trim specified more than once",
                                OWSExceptionCode.InvalidParameterValue, "subset");
                    }
                    latRange = parseNumberRange(trim);
                } else if ("phenomenonTime".equals(name)) {
                    if (timeRange != null) {
                        throw new WCS20Exception("phenomenonTime trim specified more than once",
                                OWSExceptionCode.InvalidParameterValue, "subset");
                    }
                    timeRange = parseDateRange(trim);
                } else {
                    throw new WCS20Exception("Invalid dimension name " + name
                            + ", the only valid values "
                            + "by WCS EO spec are Long, Lat and phenomenonTime",
                            OWSExceptionCode.InvalidParameterValue, "subset");
                }
            }

            // check the desired containment
            boolean overlaps;
            String containment = dcs.getContainmentType();
            if (containment == null || "overlaps".equals(containment)) {
                overlaps = true;
            } else if ("contains".equals(containment)) {
                overlaps = false;
            } else {
                throw new WCS20Exception("Invalid containment value " + containment
                        + ", the only valid values by WCS EO spec are contains and overlaps",
                        OWSExceptionCode.InvalidParameterValue, "containment");
            }

            // spatial subset
            FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
            Filter filter = null;
            if (lonRange != null || latRange != null) {
                try {
                    // we are going to intersect the trims with the original envelope
                    // since the trims can only be expressed in wgs84 we need to reproject back and forth
                    ReferencedEnvelope original = new ReferencedEnvelope(reader.getOriginalEnvelope())
                            .transform(DefaultGeographicCRS.WGS84, true);
                    if (lonRange != null) {
                        ReferencedEnvelope lonTrim = new ReferencedEnvelope(lonRange.getMinimum(),
                                lonRange.getMaximum(), -90, 90, DefaultGeographicCRS.WGS84);
                        original = new ReferencedEnvelope(original.intersection(lonTrim), DefaultGeographicCRS.WGS84);
                    }
                    if (latRange != null) {
                        ReferencedEnvelope latTrim = new ReferencedEnvelope(-180, 180,
                                latRange.getMinimum(), latRange.getMaximum(),
                                DefaultGeographicCRS.WGS84);
                        original = new ReferencedEnvelope(original.intersection(latTrim), DefaultGeographicCRS.WGS84);
                    }
                    if (original.isEmpty()) {
                        filter = Filter.EXCLUDE;
                    } else {
                        Polygon llPolygon = JTS.toGeometry(original);
                        GeometryDescriptor geom = reader.getGranules(coverageName, true).getSchema().getGeometryDescriptor();
                        PropertyName geometryProperty = ff.property(geom.getLocalName());
                        Geometry nativeCRSPolygon = JTS.transform(llPolygon, CRS.findMathTransform(DefaultGeographicCRS.WGS84, reader.getCoordinateReferenceSystem()));
                        Literal polygonLiteral = ff.literal(nativeCRSPolygon);
                        if(overlaps) {
                            filter = ff.intersects(geometryProperty, polygonLiteral);
                        } else {
                            filter = ff.within(geometryProperty, polygonLiteral);
                        }
                    }
                } catch(Exception e) {
                    throw new WCS20Exception("Failed to translate the spatial trim into a native filter", e);
                }
            }

            // temporal subset
            if (timeRange != null && filter != Filter.EXCLUDE) {
View Full Code Here

                final Date low = xmlTimeConverter.parseDateTime(trim.getTrimLow()).getTime();
                final Date high = xmlTimeConverter.parseDateTime(trim.getTrimHigh()).getTime();

                // low > high???
                if (low.compareTo(high) > 0) {
                    throw new WCS20Exception("Low greater than High in trim for dimension: "
                            + trim.getDimension(),
                            WCS20Exception.WCS20ExceptionCode.InvalidSubsetting, "dimensionTrim");
                }

                return new DateRange(low, high);
            } catch (IllegalArgumentException e) {
                throw new WCS20Exception("Invalid date value",
                        OWSExceptionCode.InvalidParameterValue, "dimensionTrim", e);
            }

        }
View Full Code Here

TOP

Related Classes of org.geoserver.wcs2_0.response.FileReference

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.