private LinkedHashMap<Integer, Coordinate> getCoordinate(GridGeometry2D grid) { LinkedHashMap<Integer, Coordinate> out = new LinkedHashMap<Integer, Coordinate>(); int count = 0; RegionMap regionMap = CoverageUtilities.gridGeometry2RegionParamsMap(grid); cols = regionMap.getCols(); rows = regionMap.getRows(); south = regionMap.getSouth(); west = regionMap.getWest(); xres = regionMap.getXres(); yres = regionMap.getYres(); outWR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, null); double northing = south; double easting = west; for (int i = 0; i < cols; i++) { easting = easting + xres; for (int j = 0; j < rows; j++) { northing = northing + yres; Coordinate coordinate = new Coordinate(); coordinate.x = west + i * xres; coordinate.y = south + j * yres; out.put(count, coordinate); count++; } } return out; }
@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()); }