Package org.geotools.coverage.processing

Examples of org.geotools.coverage.processing.CoverageProcessor


    final int uppers[] = range.getHigh().getCoordinateValues();
    uppers[0] ++;
    uppers[1] ++;
    final double newRange[] = new double[] { uppers[0] / newCols,uppers[1] / newRows };
    final CoverageProcessor processor = CoverageProcessor.getInstance();
    for (int i = 0; i < newRows; i++)
      for (int j = 0; j < newCols; j++) {

        // //
        //
        // computing the bbox for this tile
        //
        // //
        _maxx = minx + (j + 1) * tileGeoWidth;
        _minx = minx + (j) * tileGeoWidth;
        _maxy = miny + (i + 1) * tileGeoHeight;
        _miny = miny + (i) * tileGeoHeight;
        if (_maxx > maxx)
          _maxx = maxx;
        if (_maxy > maxy)
          _maxy = maxy;

        // //
        //
        // creating the output file
        //
        // //
        final File fileOut = new File(outputLocation, new StringBuilder(
            "mosaic").append("_").append(
            Integer.toString(i * newCols + j)).append(".").append(
            "tiff").toString());
        if (fileOut.exists())
          fileOut.delete();

        message = new StringBuilder("Preparing tile (col,row)==(")
            .append(j)
            .append(",")
            .append(i)
            .append(") to file ")
            .append(fileOut);
        if (LOGGER.isLoggable(Level.FINE))
          LOGGER.fine(message.toString());
        fireEvent(message.toString(), (j + i * newCols)/ totalNumberOfFile);

        // //
        //
        // building gridgeometry for the read operation
        //
        // //
        final ParameterValue<GridGeometry2D> gg =  ImageMosaicFormat.READ_GRIDGEOMETRY2D.createValue();
        final GeneralEnvelope cropEnvelope = new GeneralEnvelope(new double[] { _minx, _miny }, new double[] { _maxx,_maxy });
        cropEnvelope.setCoordinateReferenceSystem(inReader.getCrs());
        //we need to supply the requeste grid range but we use a fake one since we are using the ignore overviews switch
        gg.setValue(new GridGeometry2D(new GridEnvelope2D(new Rectangle(0, 0, 800, 800)), cropEnvelope));
        message = new StringBuilder("Reading with grid envelope ").append(cropEnvelope.toString());
        if (LOGGER.isLoggable(Level.FINE))
          LOGGER.fine(message.toString());
        fireEvent(message.toString(), (j + i * newCols)
            / totalNumberOfFile);

        // //
        //
        // read the needed part and then crop to be sure that we have what we need
        //
        // //
        GridCoverage2D gc;
        try {
          gc = (GridCoverage2D) inReader
              .read(new GeneralParameterValue[] { gg });


        } catch (IOException e) {
          LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
          fireEvent(e.getLocalizedMessage(), 0);
          return;
        }

        ParameterValueGroup param = processor.getOperation("CoverageCrop").getParameters();
        param.parameter("Source").setValue(gc);
        param.parameter("Envelope").setValue(cropEnvelope);
        param.parameter("ConserveEnvelope").setValue(Boolean.TRUE);
        final GridCoverage2D cropped = (GridCoverage2D) processor.doOperation(param);

        // //
        //
        // Adjusting the resolution in order to be the same as for all the others coverage
        //
        // //
        final GridEnvelope2D newGridrange = new GridEnvelope2D(new Rectangle2D.Double(0.0, 0.0, newRange[0],newRange[1]).getBounds());
        final GridGeometry2D scaledGridGeometry = new GridGeometry2D(newGridrange, cropEnvelope);
        param = processor.getOperation("Resample").getParameters();
        param.parameter("Source").setValue(cropped);
        param.parameter("CoordinateReferenceSystem").setValue(inReader.getCrs());
        param.parameter("GridGeometry").setValue(scaledGridGeometry);
        param.parameter("InterpolationType").setValue(Interpolation.getInstance(Interpolation.INTERP_NEAREST));
        gc = (GridCoverage2D) processor.doOperation(param);


        message = new StringBuilder("Scaling...");
        if (LOGGER.isLoggable(Level.FINE))
          LOGGER.fine(message.toString());
        fireEvent(message.toString(), 0);

        if (scaleAlgorithm.equalsIgnoreCase("nn")) {
          param = processor.getOperation("Scale").getParameters();
          param.parameter("Source").setValue(gc);
          param.parameter("xScale").setValue(new Float(1.0 / scaleFactor));
          param.parameter("yScale").setValue(new Float(1.0 / scaleFactor));
          param.parameter("xTrans").setValue(new Float(0));
          param.parameter("yTrans").setValue(new Float(0));
          param.parameter("Interpolation").setValue(Interpolation.getInstance(Interpolation.INTERP_BILINEAR));
          gc = (GridCoverage2D) CoverageToolsConstants.SCALE_FACTORY.doOperation(param, new Hints());
        } else if (scaleAlgorithm.equalsIgnoreCase("filt")) {
          // scaling
          param =  CoverageToolsConstants.FILTERED_SUBSAMPLE_FACTORY.getParameters();
          param.parameter("source").setValue(gc);
          param.parameter("scaleX").setValue(new Integer((int) scaleFactor));
          param.parameter("scaleY").setValue(new Integer((int) scaleFactor));
          param.parameter("qsFilterArray").setValue(new float[] { 0.5F, 1.0F / 3.0F, 0.0F,-1.0F / 12.0F });
          param.parameter("Interpolation").setValue(new InterpolationNearest());
          gc = (GridCoverage2D) CoverageToolsConstants.FILTERED_SUBSAMPLE_FACTORY.doOperation(param, new Hints());
        } else if (scaleAlgorithm.equalsIgnoreCase("bil")) {
          param = processor.getOperation("Scale").getParameters();
          param.parameter("Source").setValue(gc);
          param.parameter("xScale").setValue(
              new Float(1.0 / scaleFactor));
          param.parameter("yScale").setValue(
              new Float(1.0 / scaleFactor));
          param.parameter("xTrans").setValue(new Float(0));
          param.parameter("yTrans").setValue(new Float(0));
          param.parameter("Interpolation").setValue(Interpolation.getInstance(Interpolation.INTERP_BILINEAR));
          gc = (GridCoverage2D) CoverageToolsConstants.SCALE_FACTORY.doOperation(param, new Hints());
        } else if (scaleAlgorithm.equalsIgnoreCase("avg")) {
          param = processor.getOperation("SubsampleAverage").getParameters();
          param.parameter("Source").setValue(gc);
          param.parameter("scaleX").setValue(new Double(1.0 / scaleFactor));
          param.parameter("scaleY").setValue(new Double(1.0 / scaleFactor));
          param.parameter("Interpolation").setValue(scaleFactor);
          gc = (GridCoverage2D) CoverageToolsConstants.SUBSAMPLE_AVERAGE_FACTORY.doOperation(param, new Hints());
View Full Code Here


  private void mergePoly(
      final GridCoverage originalCoverage,
      final Polygon poly,
      final Resolution resolution ) {
    final CoverageProcessor processor = CoverageProcessor.getInstance();
    final AbstractOperation op = (AbstractOperation) processor.getOperation("Histogram");
    final ParameterValueGroup params = op.getParameters();
    params.parameter(
        "Source").setValue(
        originalCoverage);
    params.parameter(
View Full Code Here

        if(CRS.equalsIgnoreMetadata(coverage.getCoordinateReferenceSystem2D(), targetCRS)){
            return coverage;
        }

        // reproject
        final CoverageProcessor processor=hints==null?CoverageProcessor.getInstance():CoverageProcessor.getInstance(hints);
        final Operation operation = processor.getOperation("Resample");
        final ParameterValueGroup parameters = operation.getParameters();
        parameters.parameter("Source").setValue(coverage);
        parameters.parameter("CoordinateReferenceSystem").setValue(targetCRS);
        parameters.parameter("GridGeometry").setValue(null);
        parameters.parameter("InterpolationType").setValue(spatialInterpolation);
        return (GridCoverage2D) processor.doOperation(parameters);
    }
View Full Code Here

TOP

Related Classes of org.geotools.coverage.processing.CoverageProcessor

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.