Package net.opengis.gml

Examples of net.opengis.gml.RectifiedGridType


     *
     * @generated modifiable
     */
    public Object parse(ElementInstance instance, Node node, Object value)
            throws Exception {
        RectifiedGridType grid = Gml4wcsFactory.eINSTANCE.createRectifiedGridType();
       
        if(node.hasAttribute("srsName")) {
            grid.setSrsName(node.getAttributeValue("srsName").toString());
        }
       
        grid.setDimension((BigInteger) node.getAttribute("dimension").getValue());

        GeneralGridEnvelope limitsEnvelope = (GeneralGridEnvelope) node.getChildValue("limits");
       
//        GridLimitsType limits = Gml4wcsFactory.eINSTANCE.createGridLimitsType();
//        GridEnvelopeType gridEnelope = Gml4wcsFactory.eINSTANCE.createGridEnvelopeType();
//        List l = new ArrayList();
//             l.add(limitsEnvelope.getLow(0));
//             l.add(limitsEnvelope.getLow(1));
//        List h = new ArrayList();
//             h.add(limitsEnvelope.getHigh(0));
//             h.add(limitsEnvelope.getHigh(1));

        grid.setDimension(BigInteger.valueOf(2));
        grid.setLimits(new GridEnvelope2D(
                (int)limitsEnvelope.getLow(0), (int)limitsEnvelope.getLow(1),
                (int)limitsEnvelope.getHigh(0), (int)limitsEnvelope.getHigh(1))
        );
       
        List<Node> axisNames = node.getChildren("axisName");
        if (axisNames != null && !axisNames.isEmpty()) {
            for (Node axisName : axisNames) {
                grid.getAxisName().add(axisName.getValue());
            }
        }

        return grid;
//       return super.parse(instance, node, value);
View Full Code Here


                    WcsExceptionCode.MissingParameterValue, "BBOX");

        //
        // GRID management
        //
        final RectifiedGridType grid = Gml4wcsFactory.eINSTANCE.createRectifiedGridType();
        final Object w = kvp.get("width");
        final Object h = kvp.get("height");
        if (w != null && h != null) {
            //
            // normal grid management, only the envelope and the raster dimensions have been specified,
          // we need to compute RESX, RESY, RESZ afterwards
            //

            // get W and H
            int width =  w instanceof Integer?((Integer)w):Integer.parseInt((String)w);
            int height =w instanceof Integer?((Integer)h):Integer.parseInt((String)h);
            grid.getAxisName().add("x");
            grid.getAxisName().add("y");

            final Object d = kvp.get("depth");
            if (d != null) {
                // afabiani: we consider 2D grdis only
                throw new WcsException("3D grids are not supported.", InvalidParameterValue, "depth");
//                // check that the envelope is 3D or throw an error
//                if (bbox.getDimension() != 3)
//                    throw new WcsException("Found depth but envelope is of dimension "
//                            + bbox.getDimension(), InvalidParameterValue, "");
//
//                // notice that as for the spec this element represents the number of ticks on the
//                // third dimension
//                grid.getAxisName().add("z");
//
//                final int depth = Integer.parseInt((String) d);
//                grid.setDimension(BigInteger.valueOf(3));
//                // notice that the third element indicates how many layers we do have requested on the third dimension
//                grid.setLimits(new GeneralGridEnvelope(new int[] { 0, 0, 0 }, new int[] {width, height, depth }, false));
//
//
//                // 3D grid
//                grid.setDimension(BigInteger.valueOf(3));
            } else {
                // 2d grid
                grid.setDimension(BigInteger.valueOf(2));
                grid.setLimits(new GridEnvelope2D(0, 0, width, height));

            }
        } else {
            //
            // we might be working with a rectified grid request there we need
            // to try and use that type. we cannot build a raster grid at this
            // stage yet since we have no idea about how the envelope will be intersected with the
            // native envelope for this raster
            //
            final Object rx = kvp.get("resx");
            final Object ry = kvp.get("resy");
            if (rx != null && ry != null) {
                // get resx e resy but correct also the sign for them taking into account
              final CoordinateSystem cs=crs.getCoordinateSystem();
              final AxisDirection northingDirection=cs.getAxis(1).getDirection();
              final int yAxisCorrection=AxisDirection.NORTH.equals(northingDirection)?-1:1;
              final AxisDirection eastingDirection=cs.getAxis(0).getDirection();
              final int xAxisCorrection=AxisDirection.EAST.equals(eastingDirection)?1:-1;
                final double resX = Double.parseDouble((String) rx)*xAxisCorrection;
                final double resY = Double.parseDouble((String) ry)*yAxisCorrection;
               

                // now compute offset vector for the transform from the envelope
                // Following ISO 19123 we use the CELL_CENTER convention but with the raster
                final double origX = envelope.getLowerCorner().getOrdinate(0)+resX/2;
                final double origY = envelope.getUpperCorner().getOrdinate(1)+resY/2;

                // create offset point
                final PointType origin = Gml4wcsFactory.eINSTANCE.createPointType();
                final DirectPositionType dp = Gml4wcsFactory.eINSTANCE.createDirectPositionType();
                origin.setPos(dp);
                origin.setSrsName(crsName);

                // create resolutions vector
                final VectorType resolutionVector = Gml4wcsFactory.eINSTANCE.createVectorType();

                //
                // Third dimension management
                //
                final Object rz = kvp.get("resz");
                if (rz != null) {
                    // afabiani: we consider 2D grdis only
                    throw new WcsException("3D grids are not supported.", InvalidParameterValue, "resz");
//                    // eventual depth
//                    final double resZ = Double.parseDouble((String) rz);
//                    // check that the envelope is 3D or throw an error
//                    if (bbox.getDimension() != 3)
//                        throw new WcsException("Found ResZ but envelope is of dimension "
//                                + bbox.getDimension(), InvalidParameterValue, "");
//                    final double origZ = bbox.getLowerCorner().getOrdinate(2);
//
//                    // 3D grid
//                    grid.setDimension(BigInteger.valueOf(3));
//                    // set the origin position
//                    dp.setDimension(grid.getDimension());
//                    dp.setValue(Arrays.asList(origX, origY, origZ));
//                    grid.setOrigin(origin);
//
//                    // set the resolution vector
//                    resolutionVector.setDimension(grid.getDimension());
//                    resolutionVector.setValue(Arrays.asList(resX, resY, resZ));
//                    grid.getOffsetVector().add(resolutionVector);
                } else {
                    // 2d grid
                    grid.setDimension(BigInteger.valueOf(2));
                    // set the origin position
                    dp.setDimension(grid.getDimension());
                    dp.setValue(Arrays.asList(origX, origY));
                    grid.setOrigin(origin);

                    // set the resolution vector
                    resolutionVector.setDimension(grid.getDimension());
                    resolutionVector.setValue(Arrays.asList(resX, resY));
                    grid.getOffsetVector().add(resolutionVector);
                }

            } else
                throw new WcsException("Could not recognize grid resolution",
                        InvalidParameterValue, "");
View Full Code Here

            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
View Full Code Here

                    WcsExceptionCode.MissingParameterValue, "BBOX");

        //
        // GRID management
        //
        final RectifiedGridType grid = Gml4wcsFactory.eINSTANCE.createRectifiedGridType();
        final Object w = kvp.get("width");
        final Object h = kvp.get("height");
        if (w != null && h != null) {
            //
            // normal grid management, only the envelope and the raster dimensions have been specified,
          // we need to compute RESX, RESY, RESZ afterwards
            //

            // get W and H
            int width =  w instanceof Integer?((Integer)w):Integer.parseInt((String)w);
            int height =w instanceof Integer?((Integer)h):Integer.parseInt((String)h);
            grid.getAxisName().add("x");
            grid.getAxisName().add("y");

            final Object d = kvp.get("depth");
            if (d != null) {
                // afabiani: we consider 2D grdis only
                throw new WcsException("3D grids are not supported.", InvalidParameterValue, "depth");
//                // check that the envelope is 3D or throw an error
//                if (bbox.getDimension() != 3)
//                    throw new WcsException("Found depth but envelope is of dimension "
//                            + bbox.getDimension(), InvalidParameterValue, "");
//
//                // notice that as for the spec this element represents the number of ticks on the
//                // third dimension
//                grid.getAxisName().add("z");
//
//                final int depth = Integer.parseInt((String) d);
//                grid.setDimension(BigInteger.valueOf(3));
//                // notice that the third element indicates how many layers we do have requested on the third dimension
//                grid.setLimits(new GeneralGridEnvelope(new int[] { 0, 0, 0 }, new int[] {width, height, depth }, false));
//
//
//                // 3D grid
//                grid.setDimension(BigInteger.valueOf(3));
            } else {
                // 2d grid
                grid.setDimension(BigInteger.valueOf(2));
                grid.setLimits(new GridEnvelope2D(0, 0, width, height));

            }
        } else {
            //
            // we might be working with a rectified grid request there we need
            // to try and use that type. we cannot build a raster grid at this
            // stage yet since we have no idea about how the envelope will be intersected with the
            // native envelope for this raster
            //
            final Object rx = kvp.get("resx");
            final Object ry = kvp.get("resy");
            if (rx != null && ry != null) {
                // get resx e resy but correct also the sign for them taking into account
              final CoordinateSystem cs=crs.getCoordinateSystem();
              final AxisDirection northingDirection=cs.getAxis(1).getDirection();
              final int yAxisCorrection=AxisDirection.NORTH.equals(northingDirection)?-1:1;
              final AxisDirection eastingDirection=cs.getAxis(0).getDirection();
              final int xAxisCorrection=AxisDirection.EAST.equals(eastingDirection)?1:-1;
                final double resX = Double.parseDouble((String) rx)*xAxisCorrection;
                final double resY = Double.parseDouble((String) ry)*yAxisCorrection;
               
                // basic check, the resolution cannot be larger than any of the two spans
                // for the envelope because otherwise the size in raster space will be invalid
                // We expect the final raster area to be at least 2 pixel on each raster dimension
                if(Math.abs(envelope.getSpan(0)/Math.abs(resX))<2||Math.abs(envelope.getSpan(1)/Math.abs(resY))<2)
                    throw new IllegalArgumentException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$1,"resolutions"));
                              
               

                // now compute offset vector for the transform from the envelope
                // Following ISO 19123 we use the CELL_CENTER convention but with the raster
                final double origX = envelope.getLowerCorner().getOrdinate(0)+resX/2;
                final double origY = envelope.getUpperCorner().getOrdinate(1)+resY/2;

                // create offset point
                final PointType origin = Gml4wcsFactory.eINSTANCE.createPointType();
                final DirectPositionType dp = Gml4wcsFactory.eINSTANCE.createDirectPositionType();
                origin.setPos(dp);
                origin.setSrsName(crsName);

                // create resolutions vector
                final VectorType resolutionVector = Gml4wcsFactory.eINSTANCE.createVectorType();

                //
                // Third dimension management
                //
                final Object rz = kvp.get("resz");
                if (rz != null) {
                    // afabiani: we consider 2D grdis only
                    throw new WcsException("3D grids are not supported.", InvalidParameterValue, "resz");
//                    // eventual depth
//                    final double resZ = Double.parseDouble((String) rz);
//                    // check that the envelope is 3D or throw an error
//                    if (bbox.getDimension() != 3)
//                        throw new WcsException("Found ResZ but envelope is of dimension "
//                                + bbox.getDimension(), InvalidParameterValue, "");
//                    final double origZ = bbox.getLowerCorner().getOrdinate(2);
//
//                    // 3D grid
//                    grid.setDimension(BigInteger.valueOf(3));
//                    // set the origin position
//                    dp.setDimension(grid.getDimension());
//                    dp.setValue(Arrays.asList(origX, origY, origZ));
//                    grid.setOrigin(origin);
//
//                    // set the resolution vector
//                    resolutionVector.setDimension(grid.getDimension());
//                    resolutionVector.setValue(Arrays.asList(resX, resY, resZ));
//                    grid.getOffsetVector().add(resolutionVector);
                } else {
                    // 2d grid
                    grid.setDimension(BigInteger.valueOf(2));
                    // set the origin position
                    dp.setDimension(grid.getDimension());
                    dp.setValue(Arrays.asList(origX, origY));
                    grid.setOrigin(origin);

                    // set the resolution vector
                    resolutionVector.setDimension(grid.getDimension());
                    resolutionVector.setValue(Arrays.asList(resX, resY));
                    grid.getOffsetVector().add(resolutionVector);
                }

            } else
                throw new WcsException("Could not recognize grid resolution",
                        InvalidParameterValue, "");
View Full Code Here

            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 AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) 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);

            //
            // ELEVATION SUPPORT VIA A SPECIFIC AXIS ELEVATION
            //
View Full Code Here

TOP

Related Classes of net.opengis.gml.RectifiedGridType

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.