コード例 #1
0
  /**
   * <strong>Reprojecting</strong><br>
   * The new grid geometry can have a different coordinate reference system than the underlying grid
   * geometry. For example, a grid coverage can be reprojected from a geodetic coordinate reference
   * system to Universal Transverse Mercator CRS.
   *
   * @param coverage GridCoverage2D
   * @param sourceCRS CoordinateReferenceSystem
   * @param targetCRS CoordinateReferenceSystem
   * @return GridCoverage2D
   * @throws WcsException
   */
  public static GridCoverage2D reproject(
      GridCoverage2D coverage,
      final CoordinateReferenceSystem sourceCRS,
      final CoordinateReferenceSystem targetCRS,
      final Interpolation interpolation)
      throws WcsException {
    // ///////////////////////////////////////////////////////////////////
    //
    // REPROJECT
    //
    //
    // ///////////////////////////////////////////////////////////////////
    if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) {
      /*
       * Operations.DEFAULT.resample( coverage, targetCRS, null,
       * Interpolation.getInstance(Interpolation.INTERP_NEAREST))
       */
      final ParameterValueGroup param = (ParameterValueGroup) resampleParams.clone();
      param.parameter("Source").setValue(coverage);
      param.parameter("CoordinateReferenceSystem").setValue(targetCRS);
      param.parameter("GridGeometry").setValue(null);
      param.parameter("InterpolationType").setValue(interpolation);

      coverage = (GridCoverage2D) resampleFactory.doOperation(param, hints);
    }

    return coverage;
  }
コード例 #2
0
  /**
   * <strong>Scaling</strong><br>
   * Let user to scale down to the EXACT needed resolution. This step does not prevent from having
   * loaded an overview of the original image based on the requested scale.
   *
   * @param coverage GridCoverage2D
   * @param newGridRange GridRange
   * @param sourceCoverage GridCoverage
   * @param sourceCRS CoordinateReferenceSystem
   * @param destinationEnvelopeInSourceCRS
   * @return GridCoverage2D
   */
  public static GridCoverage2D scale(
      final GridCoverage2D coverage,
      final GridEnvelope newGridRange,
      final GridCoverage sourceCoverage,
      final CoordinateReferenceSystem sourceCRS,
      final GeneralEnvelope destinationEnvelopeInSourceCRS) {
    // ///////////////////////////////////////////////////////////////////
    //
    // SCALE to the needed resolution
    // Let me now scale down to the EXACT needed resolution. This step does
    // not prevent from having loaded an overview of the original image
    // based on the requested scale.
    //
    // ///////////////////////////////////////////////////////////////////
    GridGeometry2D scaledGridGeometry =
        new GridGeometry2D(
            newGridRange,
            (destinationEnvelopeInSourceCRS != null)
                ? destinationEnvelopeInSourceCRS
                : sourceCoverage.getEnvelope());

    /*
     * Operations.DEFAULT.resample( coverage, sourceCRS, scaledGridGeometry,
     * Interpolation.getInstance(Interpolation.INTERP_NEAREST));
     */
    final ParameterValueGroup param = (ParameterValueGroup) resampleParams.clone();
    param.parameter("Source").setValue(coverage);
    param.parameter("CoordinateReferenceSystem").setValue(sourceCRS);
    param.parameter("GridGeometry").setValue(scaledGridGeometry);
    param
        .parameter("InterpolationType")
        .setValue(Interpolation.getInstance(Interpolation.INTERP_NEAREST));

    final GridCoverage2D scaledGridCoverage =
        (GridCoverage2D) resampleFactory.doOperation(param, hints);

    return scaledGridCoverage;
  }