Package org.geotools.process

Examples of org.geotools.process.ProcessException


      // transform the geometry to raster space so that we can use it as a ROI source
      Geometry rasterSpaceGeometry;
    try {
      rasterSpaceGeometry = JTS.transform(roi, new AffineTransform2D(mt2d.createInverse()));
    } catch (MismatchedDimensionException e) {
      throw new ProcessException(e);
    } catch (TransformException e) {
      throw new ProcessException(e);
    } catch (NoninvertibleTransformException e) {
      throw new ProcessException(e);
    }
      // System.out.println(rasterSpaceGeometry);
      // System.out.println(rasterSpaceGeometry.getEnvelopeInternal());
     
      // simplify the geometry so that it's as precise as the coverage, excess coordinates
View Full Code Here


        try {
            return JTS.transform(geometry, CRS.findMathTransform(sourceCRS, targetCRS, true));
        }
        catch (Exception e) {
            throw new ProcessException("Reprojection faiiled", e);
        }
    }
View Full Code Here

    }

    public static void checkCompatibleCoverages(GridCoverage2D coverageA, GridCoverage2D coverageB) throws ProcessException {
        if (coverageA == null || coverageB == null){
            String coveragesNull = coverageA == null ? (coverageB == null ? "coverageA and coverageB" : "coverageA") : "coverageB"
            throw new ProcessException(Errors.format(ErrorKeys.NULL_ARGUMENT_$1, coveragesNull));
        }
       
        //
        // checking same CRS
        //
        CoordinateReferenceSystem crsA = coverageA.getCoordinateReferenceSystem();
        CoordinateReferenceSystem crsB = coverageB.getCoordinateReferenceSystem();
        if (!CRS.equalsIgnoreMetadata(crsA, crsB)){
            MathTransform mathTransform = null;
            try {
                mathTransform = CRS.findMathTransform(crsA, crsB);
            } catch (FactoryException e) {
                throw new ProcessException("Exceptions occurred while looking for a mathTransform between the 2 coverage's CRSs", e );
            }
            if (mathTransform != null && !mathTransform.isIdentity()){
                throw new ProcessException(MISMATCHING_CRS_MESSAGE);
            }
        }
       
        //
        // checking same Envelope and grid range
        //
        Envelope envA = coverageA.getEnvelope();
        Envelope envB = coverageB.getEnvelope();
        if (!envA.equals(envB)) {
            throw new ProcessException(MISMATCHING_ENVELOPE_MESSAGE);
        }
       
        GridEnvelope gridRangeA = coverageA.getGridGeometry().getGridRange();
        GridEnvelope gridRangeB = coverageA.getGridGeometry().getGridRange();
        if (gridRangeA.getSpan(0) != gridRangeB.getSpan(0)
                || gridRangeA.getSpan(1) != gridRangeB.getSpan(1)) {
            throw new ProcessException(MISMATCHING_GRID_MESSAGE);
        }
    }
View Full Code Here

     * @param coverages
     * @throws ProcessException
     */
    public static void checkCompatibleCoveragesForMerge(Collection<GridCoverage2D> coverages) throws ProcessException {
        if (coverages == null || coverages.isEmpty()){
            throw new ProcessException(Errors.format(ErrorKeys.NULL_ARGUMENT_$1, "Input coverage List"));
        }
       
        //
        // checking same CRS
        //
View Full Code Here

        if (!CRS.equalsIgnoreMetadata(crsA, crsB)){
            MathTransform mathTransform = null;
            try {
                mathTransform = CRS.findMathTransform(crsA, crsB);
            } catch (FactoryException e) {
                throw new ProcessException("Exceptions occurred while looking for a mathTransform between the coverage's CRSs", e );
            }
            // Check if their transformation is an identity
            if (mathTransform != null && !mathTransform.isIdentity()){
                throw new ProcessException(MISMATCHING_CRS_MESSAGE);
            }
        }
    }
View Full Code Here

                    } else {
                        builder.addAll(zone.getAttributes());
                        features.add(builder.buildFeature(zone.getID()));
                    }
                } catch (Exception e) {
                    throw new ProcessException("Failed to compute statistics on feature " + zone, e);
                }
            }
            // return the first feature in the current buffer
            SimpleFeature f = features.remove(0);
            return f;
View Full Code Here

            @DescribeParameter(name = "scale", description = "scale",min=0, defaultValue="1.0f") Float scaleFactor,
            @DescribeParameter(name = "interpolation", description = "interpolation",min=0, defaultValue="InterpolationNearest") Interpolation interpolation,
            @DescribeParameter(name = "emisphere", description = "Add Emishpere",min=0, defaultValue="False" ) Boolean emisphere)
            throws ProcessException {
        if (gc2d ==null) {
            throw new ProcessException("Invalid input, source grid coverage should be not null");
        }
       
        // Get the GridEnvelope associated to the input Raster for selecting its width and height.
        // These two values are used for check if the scale is needed
        GridEnvelope2D gridEnv = gc2d.getGridGeometry().getGridRange2D();
        double coverageWidth = gridEnv.getWidth();
        double coverageHeight = gridEnv.getHeight();
       
        ////
        //
        // scale if/as needed. Also check if the scale expands the coverage dimension for at least 1 pixel.
        //
        ////
        if (scaleFactor != null && (Math.abs(coverageWidth*(scaleFactor - 1f)) >=1 || Math.abs(coverageHeight*(scaleFactor - 1f)) >= 1) ) {
            // Selection of the interpolation parameter
            Interpolation interp = interpolation != null ? interpolation : new InterpolationNearest();
            // Selection of the ScaleFactors in order to check if the final Raster has almost 1 pixel for Height and Width
            double scaleX = scaleFactor;
            double scaleY = scaleFactor;
            // RenderedImage associated to the coverage
            final RenderedImage imageToBescaled = gc2d.getRenderedImage();
           
            if (imageToBescaled != null) {
                final SampleModel sampleModel = imageToBescaled.getSampleModel();
                final int height = sampleModel.getHeight();
                final int width = sampleModel.getWidth();
                if (height * scaleFactor < 1) {
                    scaleY = 1d/height;
                }
                if (width * scaleFactor < 1) {
                   scaleX = 1d/width;
                }
            }
           
            // Execution of the Affine process
            gc2d = new AffineProcess().execute(gc2d, scaleX,
                    scaleY, null, null, null, null, null, interp);
        }

        // return value
        try {
            return new RasterAsPointFeatureCollection(gc2d, emisphere, targetCRS);
        } catch (IOException e) {
            throw new ProcessException("Unable to wrap provided grid coverage", e);
        }
    }
View Full Code Here

     
      //
      // initial checks
      //
      if(coverage==null){
        throw new ProcessException(Errors.format(ErrorKeys.NULL_ARGUMENT_$1,"coverage"));
      }
      if(classificationRanges==null){
        throw new ProcessException(Errors.format(ErrorKeys.NULL_ARGUMENT_$1,"classificationRanges"));
      }
      double nd = DEFAULT_NODATA;
      if (noData != null){
          nd = noData.doubleValue();
      }
      if (outputPixelValues != null && outputPixelValues.length > 0){
          final int ranges = classificationRanges.size();
          if (ranges != outputPixelValues.length){
              throw new ProcessException(Errors.format(ErrorKeys.MISMATCHED_ARRAY_LENGTH, "outputPixelValues"));
          }
      }

        RenderedImage sourceImage = coverage.getRenderedImage();
     
        // parse the band
        if (classificationBand != null) {
            final int band = classificationBand;
            final int numbands=sourceImage.getSampleModel().getNumBands();
            if(band<0 || numbands<=band){
              throw new ProcessException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$2,"band",band));
            }
           
            if(band==0 && numbands>0 || band>0)
              sourceImage=BandSelectDescriptor.create(sourceImage, new int []{band}, null);
        }
View Full Code Here

        //
        // initial checks
        //
        if (gc2d == null) {
            throw new ProcessException("Invalid input, source grid coverage should be not null");
        }
        if (band != null && (band < 0 || band >= gc2d.getNumSampleDimensions())) {
            throw new ProcessException("Invalid input, invalid band number:" + band);
        }
        boolean hasValues = !(levels == null || levels.length == 0);
        if (!hasValues && interval == null) {
            throw new ProcessException("One between interval and values must be valid");

        }

        // switch to geophisics if necessary
        gc2d = gc2d.view(ViewType.GEOPHYSICS);
View Full Code Here

            @DescribeParameter(name = "height", description = "Height of the output raster in pixels", minValue = 1) int height)
            throws ProcessException {

        // basic checks
        if (height <= 0 || width <= 0) {
            throw new ProcessException("height and width parameters must be greater than 0");
        }
        if (bounds.getCoordinateReferenceSystem() == null) {
            throw new ProcessException("Envelope CRS must not be null");
        }
        // build the grid
        GeometryFactory geomFactory = new GeometryFactory();
        try {
            Polygon polygon = null;
           
            CoordinateReferenceSystem sourceCRS = org.geotools.referencing.crs.DefaultGeographicCRS.WGS84;
            CoordinateReferenceSystem targetCRS = CRS.parseWKT(targetCRSWKT);
            MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
            double pX = bounds.getMinX();
            double pY = bounds.getMaxY();
            double stepX = (bounds.getMaxX() - bounds.getMinX()) / width;
            double stepY = (bounds.getMaxY() - bounds.getMinY()) / height;
            float[][] matrix = new float[height][width];
            Coordinate[] tempCoordinates = new Coordinate[5];

            // scroll through every cell (by row and then by col)
            for (int i = 0; i < height; i++) {
                // start of the row
                pX = bounds.getMinX();
                for (int j = 0; j < width; j++) {
                    double nX = pX + stepX;
                    double nY = pY - stepY;

                    if(polygon == null) {
                        tempCoordinates[0] = new Coordinate(pX, pY);
                        tempCoordinates[1] = new Coordinate(nX, pY);
                        tempCoordinates[2] = new Coordinate(nX, nY);
                        tempCoordinates[3] = new Coordinate(pX, nY);
                        tempCoordinates[4] = tempCoordinates[0];
                        LinearRing linearRing = geomFactory.createLinearRing(tempCoordinates);
                        polygon = geomFactory.createPolygon(linearRing, null);
                    } else {
                        tempCoordinates[0].x = pX; tempCoordinates[0].y = pY; 
                        tempCoordinates[1].x = nX; tempCoordinates[1].y = pY;
                        tempCoordinates[2].x = nX; tempCoordinates[2].y = nY;
                        tempCoordinates[3].x = pX; tempCoordinates[3].y = nY;
                        polygon.geometryChanged();
                    }

                    // transform to EckertIV and compute area
                    Geometry targetGeometry = JTS.transform(polygon, transform);
                    matrix[i][j] = (float) targetGeometry.getArea();
                    // move on
                    pX = pX + stepX;
                }
                // move to next row
                pY = pY - stepY;
            }

            // build the grid coverage
            GridCoverageFactory coverageFactory = new GridCoverageFactory();
            GridCoverage2D grid = coverageFactory.create("AreaGridCoverage", matrix, bounds);
            return grid;

        } catch (org.opengis.referencing.FactoryException ef) {
            throw new ProcessException("Unable to create the target CRS", ef);
        } catch (org.opengis.referencing.operation.TransformException et) {
            throw new ProcessException("Unable to tranform the coordinate system", et);
        }

    }
View Full Code Here

TOP

Related Classes of org.geotools.process.ProcessException

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.