@Execute
  public void process() throws Exception {
    if (!concatOr(outRaster == null, doReset)) {
      return;
    }

    CoordinateReferenceSystem targetCrs = CRS.decode(pCode);

    Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST);
    if (pInterpolation.equals(BILINEAR)) {
      interpolation = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);
    } else if (pInterpolation.equals(BICUBIC)) {
      interpolation = Interpolation.getInstance(Interpolation.INTERP_BICUBIC);
    }

    GridGeometry2D gridGeometry = null;
    if (pNorth != null
        && pSouth != null
        && pWest != null
        && pEast != null
        && pRows != null
        && pCols != null) {
      gridGeometry =
          CoverageUtilities.gridGeometryFromRegionValues(
              pNorth, pSouth, pEast, pWest, pCols, pRows, targetCrs);
      pm.message("Using supplied gridgeometry: " + gridGeometry);
    }
    pm.beginTask("Reprojecting...", IJGTProgressMonitor.UNKNOWN);

    if (gridGeometry == null) {
      outRaster =
          (GridCoverage2D) Operations.DEFAULT.resample(inRaster, targetCrs, null, interpolation);
    } else {
      outRaster =
          (GridCoverage2D)
              Operations.DEFAULT.resample(inRaster, targetCrs, gridGeometry, interpolation);
    }
    pm.done();
  }
Esempio n. 2
0
  /**
   * Read data from a GRASS raster to be data of the layer.
   *
   * @param pm a progress monitor.
   * @param activeRegion the {@link JGrassRegion region} from which the data are read.
   * @param locationCrs the {@link CoordinateReferenceSystem} of the original GRASS data.
   * @return a {@link RandomIter} to iterate over the read data.
   * @throws IOException
   * @throws FactoryException
   * @throws TransformException
   */
  public RandomIter getData(
      IProgressMonitorJGrass pm, JGrassRegion activeRegion, CoordinateReferenceSystem locationCrs)
      throws IOException, FactoryException, TransformException {
    File rasterFile = new File(rasterPaths[0]);

    // FIXME should be true to use rowcol for subsampling
    GrassCoverageReader tmp = new GrassCoverageReader(null, null, true, false, pm);
    tmp.setInput(rasterFile);
    GrassCoverageReadParam gcReadParam = new GrassCoverageReadParam(activeRegion);

    GridCoverage2D gridCoverage2D = tmp.read(gcReadParam);

    GridCoverage2D gridCoverage2DLatlong =
        (GridCoverage2D) Operations.DEFAULT.resample(gridCoverage2D, DefaultGeographicCRS.WGS84);

    RenderedImage renderedImage = gridCoverage2DLatlong.getRenderedImage();
    RandomIter randomIter = RandomIterFactory.create(renderedImage, null);

    return randomIter;
  }