Package org.vfny.geoserver.wcs

Examples of org.vfny.geoserver.wcs.WcsException


    @Override
    public Object parse(String value) throws Exception {
        Collection coverages = new ArrayList();
        final List<String> identifiers = KvpUtils.readFlat(value);
        if (identifiers == null || identifiers.size() == 0) {
            throw new WcsException("Required paramer, sourcecoverage, missing",
                    WcsExceptionCode.MissingParameterValue, "sourcecoverage");
        }

        for (String coverage : identifiers) {
            String coverageName = coverage.indexOf("@") > 0 ? coverage.substring(0, coverage
                    .indexOf("@")) : coverage;
            String fieldName = coverage.indexOf("@") > 0 ? coverage
                    .substring(coverage.indexOf("@") + 1) : null;

            LayerInfo layer = catalog.getLayerByName(value);
            if (layer == null || layer.getType() != LayerInfo.Type.RASTER)
                throw new WcsException("Could not find sourcecoverage '" + coverage + "'",
                        InvalidParameterValue, "sourcecoverage");
            coverages.add(coverage);
        }

        if (coverages.size() > 1) {
            throw new WcsException(
                    "Wrong parameter, sourcecoverage, more than one identifier was specified",
                    WcsExceptionCode.InvalidParameterValue, "sourcecoverage");
        }

        return ((ArrayList) coverages).get(0);
View Full Code Here


            axisSubset.getInterval().add(interval);
        } else {
            List<String> unparsed = KvpUtils.readFlat(value, KvpUtils.INNER_DELIMETER);

            if (unparsed.size() == 0) {
                throw new WcsException(
                        "Requested axis subset contains wrong number of values (should have at least 1): "
                                + unparsed.size(), WcsExceptionCode.InvalidParameterValue, "band");
            }

            for (String bandValue : unparsed) {
View Full Code Here

    public Object read(Object request, Map kvp, Map rawKvp) throws Exception {
        GetCoverageType getCoverage = (GetCoverageType) super.read(request, kvp, rawKvp);

        // grab coverage info to perform further checks
        if (getCoverage.getIdentifier() == null)
            throw new WcsException("identifier parameter is mandatory", MissingParameterValue,
                    "identifier");

        // build the domain subset
        getCoverage.setDomainSubset(parseDomainSubset(kvp));
View Full Code Here

        // either bbox or timesequence must be there
        BoundingBoxType bbox = (BoundingBoxType) kvp.get("BoundingBox");
        TimeSequenceType timeSequence = (TimeSequenceType) kvp.get("TimeSequence");
        if (timeSequence == null && bbox == null)
            throw new WcsException(
                    "Bounding box cannot be null, TimeSequence has not been specified",
                    WcsExceptionCode.MissingParameterValue, "BoundingBox");

        domainSubset.setBoundingBox(bbox);
        domainSubset.setTemporalSubset(timeSequence);
View Full Code Here

            output.setStore(store.booleanValue());

        // check and set format
        String format = (String) kvp.get("format");
        if (format == null)
            throw new WcsException("format parameter is mandatory", MissingParameterValue, "format");
        output.setFormat(format);

        // set the other gridcrs properties
        final GridCrsType gridCRS = output.getGridCRS();
        gridCRS.setGridBaseCRS((String) kvp.get("gridBaseCrs"));
View Full Code Here

    public Object parse(String value) throws Exception {
        List unparsed = KvpUtils.readFlat(value, KvpUtils.INNER_DELIMETER);

        // check to make sure that the bounding box has 4 coordinates
        if (unparsed.size() < 4) {
            throw new WcsException("Requested bounding box contains wrong"
                    + "number of coordinates (should have at least 4): " + unparsed.size(),
                    WcsExceptionCode.InvalidParameterValue, "BoundingBox");
        }

        // if it does, store them in an array of doubles
        int size = unparsed.size();
        Double[] lower = new Double[(int) Math.floor(size / 2.0)];
        Double[] upper = new Double[lower.length];

        for (int i = 0; i < lower.length; i++) {
            try {
                lower[i] = Double.parseDouble((String) unparsed.get(i));
            } catch (NumberFormatException e) {
                throw new WcsException("Bounding box coordinate is not parsable:"
                        + unparsed.get(i * 2), WcsExceptionCode.InvalidParameterValue,
                        "BoundingBox");
            }

            try {
                upper[i] = Double.parseDouble((String) unparsed.get(lower.length + i));
            } catch (NumberFormatException e) {
                throw new WcsException("Bounding box coordinate is not parsable:"
                        + unparsed.get(i * 2 + 1), WcsExceptionCode.InvalidParameterValue,
                        "BoundingBox");
            }
        }

        // check for crs
        String crsName = null;
        CoordinateReferenceSystem crs = null;
        if (unparsed.size() % 2 == 1) {
            crsName = (String) unparsed.get(unparsed.size() - 1);
            try {
                if("urn:ogc:def:crs:OGC:1.3:CRS84".equals(crsName)) {
                    crsName = "EPSG:4326";
                } else {
                    crs = CRS.decode(crsName);
                    if (crs.getCoordinateSystem().getDimension() != lower.length)
                        throw new WcsException("CRS specified has dimension "
                            + crs.getCoordinateSystem().getDimension() + " but bbox specified has "
                            + lower.length, InvalidParameterValue, "BoundingBox");
                }
            } catch (Exception e) {
                throw new WcsException("Could not recognize crs " + crsName, InvalidParameterValue,
                        "BoundingBox");
            }
        }
       
        // we do not check that lower <= higher because in the case of geographic
View Full Code Here

        // parse
        Object parsed;
        try {
            parsed = parser.parse(reader);
        } catch (Exception e) {
            throw new WcsException(
                    "Parsing failed, the xml request is most probably not compliant to the wcs 2.0.1 schema",
                    e);
        }

        return parsed;
View Full Code Here

        try {

            // acquire coverage info
            meta = catalog.getCoverageByName(request.getSourceCoverage());
            if (meta == null)
                throw new WcsException("Cannot find sourceCoverage " + request.getSourceCoverage() + " in the catalog!");

            // first let's run some sanity checks on the inputs
            checkRangeSubset(meta, request.getRangeSubset());
            checkInterpolationMethod(meta, request.getInterpolationMethod());
            checkOutput(meta, request.getOutput());

            //
            // PREPARE DOMAIN SUBSET ELEMENT
            //
            final DomainSubsetType domainSubset = request.getDomainSubset();
            // time
            final TimeSequenceType temporalSubset = domainSubset.getTemporalSubset();
            // spatial
            final SpatialSubsetType spatialSubset = domainSubset.getSpatialSubset();
            final EList grids = spatialSubset.getGrid();
            if (grids.size() == 0)
                throw new IllegalArgumentException(
                        "Invalid number of Grid for spatial subsetting was set:" + grids.size());
            final RectifiedGridType grid = (RectifiedGridType) grids.get(0);
            final List envelopes = spatialSubset.getEnvelope();
            if (envelopes.size() == 0)
                throw new IllegalArgumentException(
                        "Invalid number of Envelope for spatial subsetting was set:"
                                + envelopes.size());
            final GeneralEnvelope requestedEnvelope = (GeneralEnvelope) envelopes.get(0);
           
            final OutputType output = request.getOutput();
            if (output == null)
                throw new IllegalArgumentException("Output type was null");
            final CodeType outputCRS = output.getCrs();

            final int dimension = grid.getDimension().intValue();
            // WE SUPPORT 3D DIMENSION ONLY VIA A BAND
            if (dimension == 3)
                throw new WcsException(
                        "We support a third dimension only via a specifica Axis in Range",
                        InvalidParameterValue, null);

            //
            // GRAB A READER
            //
            // grab the reader using the default params
            final GridCoverage2DReader reader = (GridCoverage2DReader) meta
                    .getGridCoverageReader(null, WCSUtils.getReaderHints(wcs));
            if (reader == null) {
                // cannot instantiate a reader, we should return an empty array
                return coverageResults.toArray(new GridCoverage2D[] {});
            }

            // get native elements and then play with the the requested ones
            final GeneralEnvelope nativeEnvelope = reader.getOriginalEnvelope();
            final CoordinateReferenceSystem nativeCRS = nativeEnvelope
                    .getCoordinateReferenceSystem();

            // get requested crs
            String requestedCRS = null;
            if (outputCRS != null) {
                requestedCRS = outputCRS.getValue();
            }

            // Compute the target crs, the crs that the final coverage will be served into
            final CoordinateReferenceSystem targetCRS;
            if (requestedCRS == null) {
                targetCRS = reader.getOriginalEnvelope().getCoordinateReferenceSystem();
                requestedCRS = CRS.lookupIdentifier(targetCRS, true);
            } else {
                // FORCE LON,LAT!!!!
                targetCRS = CRS.decode(requestedCRS, true);
            }
           
            //
            // PREPARE DESTINATION DIMENSIONS
            //
            final Rectangle destinationSize;
            final AffineTransform2D destinationG2W;
            final GridEnvelope limits = grid.getLimits();
            if (limits != null) {
                //
                // we have imposed limits from the request, we just use them as they are
                //
                final int[] lowers = limits.getLow().getCoordinateValues();
                destinationG2W = null;
                destinationSize = new Rectangle(lowers[0], lowers[1], limits.getSpan(0), limits
                        .getSpan(1));
            } else if (grid.getOffsetVector() != null && grid.getOffsetVector().size() > 0) {
                //
                // we have NO imposed limits from the request, we need to create a proper G2W with
                // the RESOLUTION we where given.
                // Notice that this is specific to WCS 1.0.0 since the request just allow us to
                // specify ResX and ResY
                //
                final VectorType offsetVector = (VectorType) grid.getOffsetVector().get(0);
                final List offsetValues = offsetVector.getValue();
                final double resX = (Double) offsetValues.get(0);
                final double resY = (Double) offsetValues.get(1);

                final DirectPositionType origin_ = grid.getOrigin().getPos();
                destinationSize = null;
                destinationG2W = new AffineTransform2D(resX, 0d, 0d, resY, (Double) origin_
                        .getValue().get(0), (Double) origin_.getValue().get(1));

            } else {
                throw new WcsException("Invalid Grid value:" + grid.toString(),
                        InvalidParameterValue, null);
            }

            //
            // SETTING COVERAGE READING PARAMS
            //
            // get the group of parameters tha this reader supports
            final ParameterValueGroup readParametersDescriptor = reader.getFormat()
                    .getReadParameters();
            GeneralParameterValue[] readParameters = CoverageUtils.getParameters(
                    readParametersDescriptor, meta.getParameters());
            readParameters = (readParameters != null ? readParameters
                    : new GeneralParameterValue[0]);

            // read grid geometry
            final GridGeometry2D requestedGridGeometry;
            if (destinationSize != null)
                // we have been asked to support a specific raster size, we will set the grid2world
                // accordingly
                requestedGridGeometry = new GridGeometry2D(new GridEnvelope2D(destinationSize),
                        getHorizontalEnvelope(requestedEnvelope));
            else
                // we have been asked to support a specific g2w, we will set the raster size
                // accordingly
                requestedGridGeometry = new GridGeometry2D(PixelInCell.CELL_CENTER, destinationG2W,
                        getHorizontalEnvelope(requestedEnvelope), null);
            // NOTICE that we always have to respect the provided envelope
            final ParameterValue<GeneralGridGeometry> requestedGridGeometryParam = new DefaultParameterDescriptor<GeneralGridGeometry>(
                    AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(),
                    GeneralGridGeometry.class, null, requestedGridGeometry).createValue();
            GeneralParameterValue[] tmpArray = new GeneralParameterValue[readParameters.length+1];
            System.arraycopy(readParameters, 0, tmpArray, 0, readParameters.length);
            tmpArray[tmpArray.length-1]=requestedGridGeometryParam;
            readParameters=tmpArray;
           
           
            /*
             * Test if the parameter "TIME" is present in the WMS request, and by the way in the
             * reading parameters. If it is the case, one can adds it to the request. If an
             * exception is thrown, we have nothing to do.
             */
            final List<GeneralParameterDescriptor> parameterDescriptors = new ArrayList<GeneralParameterDescriptor>(
                    readParametersDescriptor.getDescriptor().descriptors());
            Set<ParameterDescriptor<List>> dynamicParameters = reader.getDynamicParameters();
            parameterDescriptors.addAll(dynamicParameters);

            //
            // TIME
            //
            ReaderDimensionsAccessor dimensions = new ReaderDimensionsAccessor(reader);
            DimensionInfo timeDimension = meta.getMetadata().get(ResourceInfo.TIME, DimensionInfo.class);
            if(timeDimension != null && timeDimension.isEnabled() && dimensions.hasTime()) {
                final List<Object> timeValues = new ArrayList<Object>();
                if (temporalSubset != null && temporalSubset.getTimePosition() != null) {
                    // grab the time positions
                    final EList timePosition = temporalSubset.getTimePosition();
                    for (Iterator it = timePosition.iterator(); it.hasNext();) {
                        TimePositionType tp = (TimePositionType) it.next();
                        Date date = (Date) tp.getValue();
                        if(date == null) {
                            date = dimensions.getMaxTime();
                        }
                        timeValues.add(date);
                    }
                    // grab the time intervals
                    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();
                    timeValues.add(date);
                }
               
                readParameters = CoverageUtils.mergeParameter(parameterDescriptors,
                        readParameters, timeValues, "TIME", "Time");
            }
           
            //
            // ELEVATION SUPPORT VIA A SPECIFIC AXIS ELEVATION
            //
            DimensionInfo elevationDimension = meta.getMetadata().get(ResourceInfo.ELEVATION, DimensionInfo.class);
            if(elevationDimension != null && elevationDimension.isEnabled() && dimensions.hasElevation()) {
                List<Double> elevations = new ArrayList<Double>();
                // extract elevation values
                List axisSubset = null;
                if (request.getRangeSubset() != null) {
                    axisSubset = request.getRangeSubset().getAxisSubset();
                    if (axisSubset.size() > 0) {
                        for (int a = 0; a < axisSubset.size(); a++) {
                            AxisSubsetType axis = (AxisSubsetType) axisSubset.get(a);

                            String axisName = axis.getName();
                            if (axisName.equalsIgnoreCase(WCSUtils.ELEVATION)) {
                                if (axis.getSingleValue().size() > 0) {
                                    for (int s = 0; s < axis.getSingleValue().size(); s++) {
                                        elevations.add(Double.parseDouble(((TypedLiteralType) axis
                                                .getSingleValue().get(s)).getValue()));
                                    }
                                } else if (axis.getInterval().size() > 0) {
                                    IntervalType interval = (IntervalType) axis.getInterval().get(0);
                                    int min = Integer.parseInt(interval.getMin().getValue());
                                    int max = Integer.parseInt(interval.getMax().getValue());
                                    int res = (interval.getRes() != null ? Integer.parseInt(interval
                                            .getRes().getValue()) : 1);

                                    int count = (int) (Math.floor(max - min) / res + 1);
                                    for (int b = 0; b < count; b++) {
                                        elevations.add(new Double(min + b * res));
                                    }
                                }
                            }
                        }
                    }
                }
               
                if(elevations.isEmpty()) {
                    elevations.add(dimensions.getMinElevation());
                }
               
                readParameters = CoverageUtils.mergeParameter(parameterDescriptors,
                        readParameters, elevations, "ELEVATION", "Elevation");
            }
           
            //
            // CUSTOM DIMENSION SUPPORT
            //
            if (request.getRangeSubset() != null) {
                EList<?> axisSubset = request.getRangeSubset().getAxisSubset();
                final int asCount = axisSubset == null ? 0 : axisSubset.size();
                for (int i = 0; i < asCount; i++) {
                    AxisSubsetType axis = (AxisSubsetType)axisSubset.get(i);
                    String axisName = axis.getName();
                    if (!axisName.equalsIgnoreCase(WCSUtils.ELEVATION)) {
                        Object dimInfo = meta.getMetadata().get(ResourceInfo.CUSTOM_DIMENSION_PREFIX + axisName);
                        axisName = axisName.toUpperCase(); // using uppercase with imagemosaic
                        if (dimInfo instanceof DimensionInfo && dimensions.hasDomain(axisName)) {
                            int valueCount = axis.getSingleValue().size();
                            if (valueCount > 0) {
                                List<String> dimValues = new ArrayList<String>(valueCount);
                                for (int s = 0; s < valueCount; s++) {
                                    dimValues.add(((TypedLiteralType) axis
                                            .getSingleValue().get(s)).getValue());
                                }
                                readParameters = CoverageUtils.mergeParameter(parameterDescriptors,
                                        readParameters, dimValues, axisName);
                            }
                        }
                    }
                }   
            }
           
            //
            // Check if we have a filter among the params
            //
            Filter filter = WCSUtils.getRequestFilter();
            if(filter != null) {
                readParameters = CoverageUtils.mergeParameter(parameterDescriptors,
                        readParameters, filter, "FILTER", "Filter");
            }
           
            // Check we're not going to read too much data
            WCSUtils.checkInputLimits(wcs, meta, reader, requestedGridGeometry);


            //
            // Checking for supported Interpolation Methods
            //
            Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST);

            String interpolationType = null;
            if(request.getInterpolationMethod()!=null){
                interpolationType = request.getInterpolationMethod().getLiteral();           
                if (interpolationType != null) {
                  
                    if (interpolationType.equalsIgnoreCase("bilinear")) {
                        interpolation = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);
                    } else if (interpolationType.equalsIgnoreCase("bicubic")) {
                        interpolation = Interpolation.getInstance(Interpolation.INTERP_BICUBIC);
                    } else if (interpolationType.equalsIgnoreCase("nearest neighbor")) {
                        interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST);
                    }
                    readParameters = CoverageUtils.mergeParameter(parameterDescriptors,readParameters, interpolation, "interpolation");
                    if(meta.getStore().getFormat() instanceof ImageMosaicFormat){
                        GeneralParameterValue[] temp = new GeneralParameterValue[readParameters.length+1];
                        System.arraycopy(readParameters, 0, temp, 0, readParameters.length);
                        temp[temp.length-1]=ImageMosaicFormat.INTERPOLATION.createValue();
                        ((ParameterValue)temp[temp.length-1]).setValue(interpolation);
                        readParameters=temp;
                    }
                }
            }
            //
            // make sure we work in streaming mode
            //
            // work in streaming fashion when JAI is involved
            readParameters = WCSUtils.replaceParameter(readParameters, Boolean.FALSE,
                    AbstractGridFormat.USE_JAI_IMAGEREAD);
           
            //
            // perform read
            //
            coverage = (GridCoverage2D) reader.read(readParameters);
            if ((coverage == null) || !(coverage instanceof GridCoverage2D)) {
                throw new IOException("No raster data found in the request (it may be that " +
                    "the request bbox is outside of the coverage area, or that the filters used " +
                    "match no portions of it.");
            }

            // double check what we have loaded
            WCSUtils.checkInputLimits(wcs, coverage);

            //
            // Band Select (works on just one field)
            //
            GridCoverage2D bandSelectedCoverage = coverage;
            // ImageIOUtilities.visualize(coverage.getRenderedImage());
            if (request.getRangeSubset() != null) {
                // if (request.getRangeSubset().getAxisSubset().size() > 1) {
                // throw new WcsException("Multi field coverages are not supported yet");
                // }

                // extract the band indexes
                EList axisSubset = request.getRangeSubset().getAxisSubset();
                if (axisSubset.size() > 0) {
                    for (int a = 0; a < axisSubset.size(); a++) {
                        AxisSubsetType axis = (AxisSubsetType) axisSubset.get(a);

                        try {
                            String axisName = axis.getName();
                            if (axisName.equalsIgnoreCase("Band")) {
                                int[] bands = null;
                                if (axis.getSingleValue().size() > 0) {
                                    bands = new int[axis.getSingleValue().size()];
                                    for (int s = 0; s < axis.getSingleValue().size(); s++) {
                                        bands[s] = Integer.parseInt(((TypedLiteralType) axis
                                                .getSingleValue().get(s)).getValue()) - 1;
                                    }
                                } else if (axis.getInterval().size() > 0) {
                                    IntervalType interval = (IntervalType) axis.getInterval()
                                            .get(0);
                                    int min = Integer.parseInt(interval.getMin().getValue());
                                    int max = Integer.parseInt(interval.getMax().getValue());
                                    int res = (interval.getRes() != null ? Integer
                                            .parseInt(interval.getRes().getValue()) : 1);

                                    bands = new int[(int) (Math.floor(max - min) / res + 1)];
                                    for (int b = 0; b < bands.length; b++)
                                        bands[b] = (min + b * res) - 1;
                                }

                                // finally execute the band select
                                bandSelectedCoverage = (GridCoverage2D) WCSUtils.bandSelect(
                                        coverage, bands);
                            }
                        } catch (Exception e) {
                            // Warning: Axis not found!!!
                            throw new WcsException("Band Select Operation: "
                                    + e.getLocalizedMessage());
                        }
                    }
                }
            }

            //
            // final step for the requested coverage
            //
            // compute intersection envelope to be used
            GeneralEnvelope destinationEnvelope = (GeneralEnvelope) getHorizontalEnvelope(computeIntersectionEnvelope(
                    requestedEnvelope, nativeEnvelope));
            if(targetCRS != null) {
                destinationEnvelope = CRS.transform(destinationEnvelope, targetCRS);
                destinationEnvelope.setCoordinateReferenceSystem(targetCRS);
            }

            final GridGeometry2D destinationGridGeometry;
            if (destinationSize != null) {
                destinationGridGeometry = new GridGeometry2D(new GridEnvelope2D(destinationSize),
                        destinationEnvelope);
            } else {
                destinationGridGeometry = new GridGeometry2D(PixelInCell.CELL_CENTER,
                        destinationG2W, destinationEnvelope, null);
            }

            // verify we're not going to build a raster exceeding the output limits
            WCSUtils.checkOutputLimits(wcs, destinationGridGeometry.getGridRange2D(),
                    bandSelectedCoverage.getRenderedImage().getSampleModel());

            final GridCoverage2D finalCoverage = WCSUtils.resample(bandSelectedCoverage, nativeCRS,
                    targetCRS, destinationGridGeometry, interpolation);
            coverageResults.add(finalCoverage);

            return coverageResults.toArray(new GridCoverage2D[] {});
        } catch (Exception e) {
          CoverageCleanerCallback.addCoverages(coverage);
            if (e instanceof WcsException) {
                throw (WcsException) e;
            } else {
                throw new WcsException(e);
            }
        }

    }
View Full Code Here

                    interpolationSupported = true;
                }
            }

            if (!interpolationSupported)
                throw new WcsException(
                        "The requested Interpolation method is not supported by this Coverage.",
                        InvalidParameterValue, "RangeSubset");
        }
    }
View Full Code Here

        // check output format
        String format = output.getFormat().getValue();
        String declaredFormat = getDeclaredFormat(meta.getSupportedFormats(), format);
        if (declaredFormat == null)
            throw new WcsException("format " + format + " is not supported for this coverage",
                    InvalidParameterValue, "format");

        // check requested CRS
        // if (output.getCrs() != null) {
        // String requestedCRS = output.getCrs().getValue();
View Full Code Here

TOP

Related Classes of org.vfny.geoserver.wcs.WcsException

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.