public static GridCoverage2D removeNovalues(GridCoverage2D geodata) {
    // need to adapt it, for now do it dirty
    HashMap<String, Double> params = getRegionParamsFromGridCoverage(geodata);
    int height = params.get(ROWS).intValue();
    int width = params.get(COLS).intValue();
    WritableRaster tmpWR = createDoubleWritableRaster(width, height, null, null, null);
    WritableRandomIter tmpIter = RandomIterFactory.createWritable(tmpWR, null);
    RenderedImage readRI = geodata.getRenderedImage();
    RandomIter readIter = RandomIterFactory.create(readRI, null);
    for (int r = 0; r < height; r++) {
      for (int c = 0; c < width; c++) {
        double value = readIter.getSampleDouble(c, r, 0);

        if (Double.isNaN(value)
            || Float.isNaN((float) value)
            || Math.abs(value - -9999.0) < .0000001) {
          tmpIter.setSample(c, r, 0, Double.NaN);
        } else {
          tmpIter.setSample(c, r, 0, value);
        }
      }
    }
    geodata = buildCoverage("newcoverage", tmpWR, params, geodata.getCoordinateReferenceSystem());
    return geodata;
  }
  private void storeResult(
      double[] interpolatedValues, HashMap<Integer, Coordinate> interpolatedCoordinatesMap)
      throws MismatchedDimensionException, Exception {

    WritableRandomIter outIter = RandomIterFactory.createWritable(outWR, null);

    Set<Integer> pointsToInterpolateIdSett = interpolatedCoordinatesMap.keySet();
    Iterator<Integer> idIterator = pointsToInterpolateIdSett.iterator();
    int c = 0;
    MathTransform transf = inInterpolationGrid.getCRSToGrid2D();

    final DirectPosition gridPoint = new DirectPosition2D();

    while (idIterator.hasNext()) {
      int id = idIterator.next();
      Coordinate coordinate = (Coordinate) interpolatedCoordinatesMap.get(id);

      DirectPosition point =
          new DirectPosition2D(
              inInterpolationGrid.getCoordinateReferenceSystem(), coordinate.x, coordinate.y);
      transf.transform(point, gridPoint);

      double[] gridCoord = gridPoint.getCoordinate();
      int x = (int) gridCoord[0];
      int y = (int) gridCoord[1];

      outIter.setSample(x, y, 0, checkResultValue(interpolatedValues[c]));
      c++;
    }

    RegionMap regionMap = CoverageUtilities.gridGeometry2RegionParamsMap(inInterpolationGrid);

    outGrid =
        CoverageUtilities.buildCoverage(
            "gridded", outWR, regionMap, inInterpolationGrid.getCoordinateReferenceSystem());
  }
  @Execute
  public void process() throws Exception {
    if (!concatOr(outIntensity == null, doReset)) {
      return;
    }

    checkNull(
        inVelocity,
        pUpperThresVelocity,
        pLowerThresVelocity, //
        inWaterDepth,
        pUpperThresWaterdepth,
        pLowerThresWaterdepth, //
        inErosionDepth,
        pUpperThresErosionDepth,
        pLowerThresErosionDepth, //
        inDepositsThickness,
        pUpperThresDepositsThickness,
        pLowerThresDepositsThickness //
        );

    // do autoboxing only once
    double maxWD = pUpperThresWaterdepth;
    double minWD = pLowerThresWaterdepth;
    double maxV = pUpperThresVelocity;
    double minV = pLowerThresVelocity;
    double maxED = pUpperThresErosionDepth;
    double minED = pLowerThresErosionDepth;
    double maxDT = pUpperThresDepositsThickness;
    double minDT = pLowerThresDepositsThickness;

    RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inWaterDepth);
    int nCols = regionMap.getCols();
    int nRows = regionMap.getRows();

    RandomIter waterdepthIter = CoverageUtilities.getRandomIterator(inWaterDepth);
    RandomIter velocityIter = CoverageUtilities.getRandomIterator(inVelocity);
    RandomIter erosiondepthIter = CoverageUtilities.getRandomIterator(inErosionDepth);
    RandomIter depositThicknessIter = CoverageUtilities.getRandomIterator(inDepositsThickness);

    WritableRaster outWR =
        CoverageUtilities.createDoubleWritableRaster(nCols, nRows, null, null, doubleNovalue);
    WritableRandomIter outIter = RandomIterFactory.createWritable(outWR, null);

    pm.beginTask("Processing map...", nRows);
    for (int r = 0; r < nRows; r++) {
      if (isCanceled(pm)) {
        return;
      }
      for (int c = 0; c < nCols; c++) {

        double h = waterdepthIter.getSampleDouble(c, r, 0);
        double v = velocityIter.getSampleDouble(c, r, 0);
        double ed = erosiondepthIter.getSampleDouble(c, r, 0);
        double dt = depositThicknessIter.getSampleDouble(c, r, 0);

        if (isNovalue(h) && isNovalue(v) && isNovalue(ed) && isNovalue(dt)) {
          continue;
        } else if (!isNovalue(h) && !isNovalue(v) && !isNovalue(ed) && !isNovalue(dt)) {
          double value = 0.0;

          if (h > maxWD || v > maxV || dt > maxDT || ed > maxED) {
            value = INTENSITY_HIGH;
          } else if ((h <= maxWD && h > minWD)
              || //
              (v <= maxV && v > minV)
              || //
              (dt <= maxDT && dt > minDT)
              || //
              (ed <= maxED && ed > minED)) {
            value = INTENSITY_MEDIUM;
          } else if (h <= minWD || v <= minV || dt <= minDT || ed <= minED) {
            value = INTENSITY_LOW;
          } else {
            throw new ModelsIllegalargumentException(
                "No intensity could be calculated for h = "
                    + h
                    + " and v = "
                    + v
                    + " and ed = "
                    + ed
                    + " and dt = "
                    + dt,
                this,
                pm);
          }

          outIter.setSample(c, r, 0, value);
        } else {
          pm.errorMessage(
              "WARNING: a cell was found in which one of velocity, water depth, erosion depth or deposit thickness are novalue, while the other not. /nThe maps should be covering the exact same cells. /nGoing on ignoring the cell: "
                  + c
                  + "/"
                  + r);
        }
      }
      pm.worked(1);
    }
    pm.done();

    outIntensity =
        CoverageUtilities.buildCoverage(
            "intensity", outWR, regionMap, inWaterDepth.getCoordinateReferenceSystem());
  }