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;
  }
 /**
  * The constructor of the class, which creates the arrays and instances needed to obtain the image
  * data and registers the class to listen to mouse motion events.
  *
  * @param image a RenderedImage for display
  */
 public DisplayJAIWhileStoringCoordinates(RenderedImage image) {
   super(image); // calls the constructor for DisplayJAI.
   readIterator = RandomIterFactory.create(image, null); // creates the iterator.
   // Get some data about the image
   width = image.getWidth();
   height = image.getHeight();
   int dataType = image.getSampleModel().getDataType(); // gets the data type
   switch (dataType) {
     case DataBuffer.TYPE_BYTE:
     case DataBuffer.TYPE_SHORT:
     case DataBuffer.TYPE_USHORT:
     case DataBuffer.TYPE_INT:
       isDoubleType = false;
       break;
     case DataBuffer.TYPE_FLOAT:
     case DataBuffer.TYPE_DOUBLE:
       isDoubleType = true;
       break;
   }
   // Depending on the image data type, allocate the double or the int array.
   if (isDoubleType) dpixel = new double[image.getSampleModel().getNumBands()];
   else ipixel = new int[image.getSampleModel().getNumBands()];
   // Is the image color model indexed ?
   isIndexed = (image.getColorModel() instanceof IndexColorModel);
   if (isIndexed) {
     // Retrieve the index color model of the image.
     IndexColorModel icm = (IndexColorModel) image.getColorModel();
     // Get the number of elements in each band of the colormap.
     int mapSize = icm.getMapSize();
     // Allocate an array for the lookup table data.
     byte[][] templutData = new byte[3][mapSize];
     // Load the lookup table data from the IndexColorModel.
     icm.getReds(templutData[0]);
     icm.getGreens(templutData[1]);
     icm.getBlues(templutData[2]);
     // Load the lookup table data into a short array to avoid negative numbers.
     lutData = new short[3][mapSize];
     for (int entry = 0; entry < mapSize; entry++) {
       lutData[0][entry] =
           templutData[0][entry] > 0
               ? templutData[0][entry]
               : (short) (templutData[0][entry] + 256);
       lutData[1][entry] =
           templutData[1][entry] > 0
               ? templutData[1][entry]
               : (short) (templutData[1][entry] + 256);
       lutData[2][entry] =
           templutData[2][entry] > 0
               ? templutData[2][entry]
               : (short) (templutData[2][entry] + 256);
     }
   } // end if indexed
   // Registers the mouse listener.
   addMouseListener(this);
   // Create the list of coordinates
   clicksInformation = new ArrayList();
 }
  public PlanarImage gridToEmage(double[][] dataGrid, String imageName) throws IOException {
    // creates a gray-scale image of the values
    int width = dataGrid[0].length;
    int height = dataGrid.length;

    // Get the number of bands on the image.
    URL imgURL = new URL(Config.getProperty("imgURL"));
    PlanarImage dummyImage = JAI.create("URL", imgURL); // dummy loaded. date to be edited.
    SampleModel sm = dummyImage.getSampleModel();
    int nbands = sm.getNumBands();

    // We assume that we can get the pixels values in a integer array.
    double[] pixelTemp = new double[nbands];

    // Get an iterator for the image.
    RandomIterFactory.create(dummyImage, null);
    WritableRaster rasterData =
        RasterFactory.createBandedRaster(
            DataBuffer.TYPE_BYTE, width, height, nbands, new Point(0, 0));

    for (int i = 0; i < height; i++) {
      for (int j = 0; j < width; j++) {
        dataGrid[i][j] = (dataGrid[i][j] <= 255) ? dataGrid[i][j] : 255;

        pixelTemp[0] = dataGrid[i][j];
        pixelTemp[1] = dataGrid[i][j];
        pixelTemp[2] = dataGrid[i][j];

        rasterData.setPixel(j, i, pixelTemp);
      }
    }

    SampleModel sModel2 =
        RasterFactory.createBandedSampleModel(DataBuffer.TYPE_BYTE, width, height, nbands);

    // Try to create a compatible ColorModel - if the number of bands is
    // larger than 4, it will be null.
    ColorModel cModel2 = PlanarImage.createColorModel(sModel2);

    // Create a TiledImage using the sample and color models.
    TiledImage rectImage = new TiledImage(0, 0, width, height, 0, 0, sModel2, cModel2);

    // Set the data of the tiled image to be the raster.
    rectImage.setData(rasterData);

    // Save the image on a file.
    try {
      ImageIO.write(rectImage, "jpg", new File(imageName + ".jpg"));
      log.info("debug save image : " + imageName + ".jpg");

    } catch (IOException e) {
      log.error(e.getMessage());
      log.error("Error in rectifying  image");
    }

    return rectImage;
  }
Example #4
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;
  }
  /*
   * This method averages the pixel values around a central point and return the
   * average as an instance of Color. The point coordinates are proportional to
   * the image.
   */
  private Color averageAround(BufferedImage i, double px, double py) {
    // Get an iterator for the image.
    RandomIter iterator = RandomIterFactory.create(i, null);
    // Get memory for a pixel and for the accumulator.
    double[] pixel = new double[i.getSampleModel().getNumBands()];
    double[] accum = new double[3];
    int numPixels = 0;
    // Sample the pixels.

    for (double x = px * i.getWidth() - sampleSize; x < px * i.getWidth() + sampleSize; x++) {
      for (double y = py * i.getHeight() - sampleSize; y < py * i.getHeight() + sampleSize; y++) {
        iterator.getPixel((int) x, (int) y, pixel);
        accum[0] += pixel[0];
        accum[1] += pixel[1];
        accum[2] += pixel[2];
        numPixels++;
      }
    }
    // Average the accumulated values.
    accum[0] /= numPixels;
    accum[1] /= numPixels;
    accum[2] /= numPixels;
    return new Color((int) accum[0], (int) accum[1], (int) accum[2]);
  }
  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());
  }
Example #7
0
  // This method is similar to the testBandMerge method but it tests the ExtendedBandMergeOpImage
  // class
  private void testExtendedBandMerge(RenderedImage[] sources, boolean noDataUsed, boolean roiUsed) {
    // Optional No Data Range used
    Range[] noData;
    // Source image data type
    int dataType = sources[0].getSampleModel().getDataType();
    // If no Data are present, the No Data Range associated is used
    if (noDataUsed) {

      switch (dataType) {
        case DataBuffer.TYPE_BYTE:
          noData = noDataByte;
          break;
        case DataBuffer.TYPE_USHORT:
          noData = noDataUShort;
          break;
        case DataBuffer.TYPE_SHORT:
          noData = noDataShort;
          break;
        case DataBuffer.TYPE_INT:
          noData = noDataInt;
          break;
        case DataBuffer.TYPE_FLOAT:
          noData = noDataFloat;
          break;
        case DataBuffer.TYPE_DOUBLE:
          noData = noDataDouble;
          break;
        default:
          throw new IllegalArgumentException("Wrong data type");
      }
    } else {
      noData = null;
    }

    // ROI to use
    ROI roi = null;
    if (roiUsed) {
      roi = roiData;
    }

    // New array ofr the transformed source images
    RenderedOp[] translated = new RenderedOp[sources.length];

    List<AffineTransform> transform = new ArrayList<AffineTransform>();

    for (int i = 0; i < sources.length; i++) {
      // Translation coefficients
      int xTrans = (int) (Math.random() * 10);
      int yTrans = (int) (Math.random() * 10);
      // Translation operation
      AffineTransform tr = AffineTransform.getTranslateInstance(xTrans, yTrans);
      // Addition to the transformations list
      transform.add(tr);
      // Translation of the image
      translated[i] =
          TranslateDescriptor.create(sources[i], (float) xTrans, (float) yTrans, null, null);
    }
    // Definition of the final image dimensions
    ImageLayout layout = new ImageLayout();
    layout.setMinX(sources[0].getMinX());
    layout.setMinY(sources[0].getMinY());
    layout.setWidth(sources[0].getWidth());
    layout.setHeight(sources[0].getHeight());

    RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout);

    // BandMerge operation
    RenderedOp merged =
        BandMergeDescriptor.create(noData, destNoData, hints, transform, roi, translated);

    Assert.assertNotNull(merged.getTiles());
    // Check if the bands number is the same
    assertEquals(BAND_NUMBER, merged.getNumBands());
    // Upper-Left tile indexes
    int minTileX = merged.getMinTileX();
    int minTileY = merged.getMinTileY();
    // Raster object
    Raster upperLeftTile = merged.getTile(minTileX, minTileY);
    // Tile bounds
    int minX = upperLeftTile.getMinX();
    int minY = upperLeftTile.getMinY();
    int maxX = upperLeftTile.getWidth() + minX;
    int maxY = upperLeftTile.getHeight() + minY;

    // Source corners
    final int dstMinX = merged.getMinX();
    final int dstMinY = merged.getMinY();
    final int dstMaxX = merged.getMaxX();
    final int dstMaxY = merged.getMaxY();

    Point2D ptDst = new Point2D.Double(0, 0);
    Point2D ptSrc = new Point2D.Double(0, 0);

    // Cycle on all the tile Bands
    for (int b = 0; b < BAND_NUMBER; b++) {
      RandomIter iter = RandomIterFactory.create(translated[b], null);

      // Source corners
      final int srcMinX = translated[b].getMinX();
      final int srcMinY = translated[b].getMinY();
      final int srcMaxX = translated[b].getMaxX();
      final int srcMaxY = translated[b].getMaxY();

      // Cycle on the y-axis
      for (int x = minX; x < maxX; x++) {
        // Cycle on the x-axis
        for (int y = minY; y < maxY; y++) {
          // Calculated value
          double value = upperLeftTile.getSampleDouble(x, y, b);
          // If the tile pixels are outside the image bounds, then no data is set.
          if (x < dstMinX || x >= dstMaxX || y < dstMinY || y >= dstMaxY) {
            value = destNoData;
          }

          // Set the x,y destination pixel location
          ptDst.setLocation(x, y);
          // Map destination pixel to source pixel
          transform.get(b).transform(ptDst, ptSrc);
          // Source pixel indexes
          int srcX = round(ptSrc.getX());
          int srcY = round(ptSrc.getY());

          double valueOld = destNoData;

          // Check if the pixel is inside the source bounds
          if (!(srcX < srcMinX || srcX >= srcMaxX || srcY < srcMinY || srcY >= srcMaxY)) {
            // Old band value
            valueOld = iter.getSampleDouble(srcX, srcY, 0);
          }

          // ROI CHECK
          boolean contained = true;
          if (roiUsed) {
            if (!roi.contains(x, y)) {
              contained = false;
              // Comparison if the final value is not inside a ROI
              assertEquals(value, destNoData, TOLERANCE);
            }
          }

          if (contained) {
            // If no Data are present, no data check is performed
            if (noDataUsed) {
              switch (dataType) {
                case DataBuffer.TYPE_BYTE:
                  byte sampleB = ImageUtil.clampRoundByte(value);
                  byte sampleBOld = ImageUtil.clampRoundByte(valueOld);
                  if (noData[0].contains(sampleBOld)) {
                    assertEquals(sampleB, destNoData, TOLERANCE);
                  } else {
                    assertEquals(sampleB, valueOld, TOLERANCE);
                  }
                  break;
                case DataBuffer.TYPE_USHORT:
                  short sampleUS = ImageUtil.clampRoundUShort(value);
                  short sampleUSOld = ImageUtil.clampRoundUShort(valueOld);
                  if (noData[0].contains(sampleUSOld)) {
                    assertEquals(sampleUS, destNoData, TOLERANCE);
                  } else {
                    assertEquals(sampleUS, valueOld, TOLERANCE);
                  }
                  break;
                case DataBuffer.TYPE_SHORT:
                  short sampleS = ImageUtil.clampRoundShort(value);
                  short sampleSOld = ImageUtil.clampRoundShort(valueOld);
                  if (noData[0].contains(sampleSOld)) {
                    assertEquals(sampleS, destNoData, TOLERANCE);
                  } else {
                    assertEquals(sampleS, valueOld, TOLERANCE);
                  }
                  break;
                case DataBuffer.TYPE_INT:
                  int sampleI = ImageUtil.clampRoundInt(value);
                  int sampleIOld = ImageUtil.clampRoundInt(valueOld);
                  if (noData[0].contains(sampleIOld)) {
                    assertEquals(sampleI, destNoData, TOLERANCE);
                  } else {
                    assertEquals(sampleI, valueOld, TOLERANCE);
                  }
                  break;
                case DataBuffer.TYPE_FLOAT:
                  float sampleF = ImageUtil.clampFloat(value);
                  float sampleFOld = ImageUtil.clampFloat(valueOld);
                  if (noData[0].contains(sampleFOld)) {
                    assertEquals(sampleF, destNoData, TOLERANCE);
                  } else {
                    assertEquals(sampleF, valueOld, TOLERANCE);
                  }
                  break;
                case DataBuffer.TYPE_DOUBLE:
                  if (noData[0].contains(valueOld)) {
                    assertEquals(value, destNoData, TOLERANCE);
                  } else {
                    assertEquals(value, valueOld, TOLERANCE);
                  }
                  break;
                default:
                  throw new IllegalArgumentException("Wrong data type");
              }
            } else {
              // Else a simple value comparison is done
              assertEquals(value, valueOld, TOLERANCE);
            }
          }
        }
      }
    }
    // Disposal of the output image
    merged.dispose();
  }
  public double[][] PlanarImage2DataGrid(PlanarImage img, String EmageType) {
    double[][] BucketArray = new double[img.getHeight()][img.getWidth()];

    int width = img.getWidth();
    int height = img.getHeight();

    // Get the number of bands on the image.
    SampleModel sm = img.getSampleModel();
    int nbands = sm.getNumBands();

    // We assume that we can get the pixels values in a integer array.
    double[] pixel = new double[nbands];

    // Get an iterator for the image.
    RandomIter iterator = RandomIterFactory.create(img, null);

    if (ignoreColorSamplesBeyond > -1) {

      for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {

          iterator.getPixel(i, j, pixel);

          double curDiff = 999999999;
          double diff = 0;
          int curBucket = -1;
          for (int i2 = 0; i2 < colorMatrix.length; i2++) {
            for (int j2 = 0; j2 < Math.min(nbands, colorMatrix[0].length); j2++) {
              diff += (pixel[j2] - colorMatrix[i2][j2]) * (pixel[j2] - colorMatrix[i2][j2]);
            }
            if (diff < curDiff) {
              curDiff = diff;
              curBucket = i2;
            }
            // log.info("i: " + i2 + ", val: " + diff);
            diff = 0;
          }
          if (curBucket >= ignoreColorSamplesBeyond) curBucket = -1;
          BucketArray[j][i] =
              (curBucket
                  + 1); // *255 / (colorMatrix.length); actually show the categories not normalized
                        // to 255 now.
          // if(curBucket >= 0)	log.info(curBucket + "," + BucketArray[j][i]);
        }
      }
    } else {
      log.info("Ignoring any binning. Going with gray values");
      for (int i = 0; i < height; i++) {

        for (int j = 0; j < width; j++) {
          int sumChannels = 0;

          iterator.getPixel(j, i, pixel);
          for (int j2 = 0; j2 < nbands; j2++) {
            sumChannels += pixel[j2];
          }
          BucketArray[i][j] = (sumChannels) / (nbands);
        }
      }
    }
    return BucketArray;
  }
  public PlanarImage PostProcessEmage(PlanarImage img) {
    if (maskImgFName != null) {
      int width = img.getWidth();
      int height = img.getHeight();

      // Get the number of bands on the image.
      SampleModel sm = img.getSampleModel();
      int nbands = sm.getNumBands();

      // We assume that we can get the pixels values in a integer array.
      double[] pixel = new double[nbands];

      // Get an iterator for the image.
      RandomIter iterator = RandomIterFactory.create(img, null);
      WritableRaster rasterImage =
          RasterFactory.createBandedRaster(
              DataBuffer.TYPE_BYTE, width, height, nbands, new Point(0, 0));

      double[] pixelNeighb = new double[nbands];
      double[] pixelblack = new double[nbands];
      for (int i = 0; i < nbands; i++) {
        pixelNeighb[i] = 0;
        pixelblack[i] = 0;
      }

      PlanarImage mask = JAI.create("FileLoad", maskImgFName);
      RandomIter iteratorMask = RandomIterFactory.create(mask, null);
      double[] pixelMask = new double[mask.getSampleModel().getNumBands()];

      for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
          iteratorMask.getPixel(i, j, pixelMask);
          if (!isBlack(pixelMask)) {
            iterator.getPixel(i, j, pixel);
            if (isWhite(pixel)) {;
            } else {
              rasterImage.setPixel(i, j, pixel);
            }
          } else {
            rasterImage.setPixel(i, j, pixelblack);
          }
        }
      }
      SampleModel sModel2 =
          RasterFactory.createBandedSampleModel(DataBuffer.TYPE_BYTE, width, height, nbands);

      // Try to create a compatible ColorModel - if the number of bands is
      // larger than 4, it will be null.
      ColorModel cModel2 = PlanarImage.createColorModel(sModel2);

      // Create a TiledImage using the sample and color models.
      TiledImage processedImage = new TiledImage(0, 0, width, height, 0, 0, sModel2, cModel2);

      // Set the data of the tiled image to be the raster.
      processedImage.setData(rasterImage);

      // Save the image to a file.
      try {
        ImageIO.write(processedImage, "jpg", new File("proc_" + theme + ".jpg"));
      } catch (IOException e) {
        log.error(e.getMessage());
      }

      // Save the image on a file.
      return processedImage;
    } else {
      // Save the image to a file.
      try {
        ImageIO.write(img, "jpg", new File("NOTproc_" + theme + ".jpg"));
      } catch (IOException e) {
        log.error(e.getMessage());
      }
      return img;
    }
  }
  public PlanarImage createRectifiedImage(PlanarImage Image) {
    int nRows = params.getNumOfRows();
    int nCols = params.getNumOfColumns();
    Point rectifiedPoint;

    // Get the image dimensions of the unrectified image
    int width = Image.getWidth();
    int height = Image.getHeight();
    log.info(nRows + ", " + nCols + "\t" + width + ", " + height);
    // Get an iterator for the image.
    RandomIter iterator = RandomIterFactory.create(Image, null);

    // Get the number of bands on the image.
    SampleModel smO = Image.getSampleModel();
    int nbandsO = smO.getNumBands();

    // We assume that we can get the pixels values in a integer array.
    double[] pixelO = new double[nbandsO];

    // Get an iterator for the image.
    WritableRaster rasterPollenO =
        RasterFactory.createBandedRaster(
            DataBuffer.TYPE_BYTE, nCols, nRows, nbandsO, new Point(0, 0));

    for (int i = 0; i < nCols; i++) {
      for (int j = 0; j < nRows; j++) {
        rectifiedPoint =
            this.getMatchingCoord(
                new Point(i + 1, j + 1)); // coz java array start at 0 matlab its 1.
        if (rectifiedPoint.x >= 1
            && rectifiedPoint.x < width
            && rectifiedPoint.y >= 1
            && rectifiedPoint.y < height) {
          iterator.getPixel(rectifiedPoint.x - 1, rectifiedPoint.y - 1, pixelO);
          rasterPollenO.setPixel(i, j, pixelO);
          // log.info("setpixel: " + i + ", " + j  + ", value " + pixelO[0] + ", " + pixelO[1] + ",
          // " + pixelO[2] + ", " + pixelO[3]);
        } else {

        }
      }
    }

    SampleModel sModel2 =
        RasterFactory.createBandedSampleModel(DataBuffer.TYPE_BYTE, nCols, nRows, nbandsO);

    // Try to create a compatible ColorModel - if the number of bands is
    // larger than 4, it will be null.
    ColorModel cModel2 = PlanarImage.createColorModel(sModel2);

    // Create a TiledImage using the sample and color models.
    TiledImage rectPollenImage = new TiledImage(0, 0, nCols, nRows, 0, 0, sModel2, cModel2);

    // log.info(rasterPollenO.getMinX() + ", " + rasterPollenO.getMinY() );
    // Set the data of the tiled image to be the raster.
    rectPollenImage.setData(rasterPollenO);

    // Save the image to a file.
    try {
      ImageIO.write(rectPollenImage, "jpg", new File("rect" + theme + ".jpg"));
    } catch (IOException e) {
      log.error(e.getMessage());
    }
    return rectPollenImage;
  }
  @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());
  }