@Test public void testZeroCoverage() throws Exception { float[][] grid = new float[][] { {0, 0}, {0, 0}, }; GridCoverage2D cov = covFactory.create( "test", grid, new ReferencedEnvelope(0, 10, 0, 10, DefaultGeographicCRS.WGS84)); NormalizeCoverageProcess p = new NormalizeCoverageProcess(); GridCoverage2D norm = p.execute(cov); float[] data = data(norm); for (int i = 0; i < data.length; i++) { assertEquals(0f, data[i], 1E-9); } }
@DescribeResult(name = "result", description = "Normalized raster") public GridCoverage2D execute( @DescribeParameter(name = "data", description = "Input raster") GridCoverage2D coverage) throws IOException { ParameterValueGroup param = PROCESSOR.getOperation("Extrema").getParameters(); param.parameter("Source").setValue(coverage); GridCoverage2D extrema = (GridCoverage2D) PROCESSOR.doOperation(param); Object max = extrema.getProperty("maximum"); boolean allZero = true; for (int i = 0; i < Array.getLength(max); i++) { Object num = Array.get(max, i); boolean isZero = num instanceof Number && ((Number) num).doubleValue() == 0d; allZero = allZero && isZero; if (isZero) { Array.set(max, i, Converters.convert(1, num.getClass())); } } if (allZero) { return coverage; } param = PROCESSOR.getOperation("DivideByConst").getParameters(); param.parameter("source").setValue(coverage); param.parameter("constants").setValue(max); return (GridCoverage2D) PROCESSOR.doOperation(param); }
NormalizeCoverageProcess implements RasterProcess { @DescribeResult(name = "result", description = "Normalized raster") public GridCoverage2D execute( @DescribeParameter(name = "data", description = "Input raster") GridCoverage2D coverage) throws IOException { ParameterValueGroup param = PROCESSOR.getOperation("Extrema").getParameters(); param.parameter("Source").setValue(coverage); GridCoverage2D extrema = (GridCoverage2D) PROCESSOR.doOperation(param); Object max = extrema.getProperty("maximum"); boolean allZero = true; for (int i = 0; i < Array.getLength(max); i++) { Object num = Array.get(max, i); boolean isZero = num instanceof Number && ((Number) num).doubleValue() == 0d; allZero = allZero && isZero; if (isZero) { Array.set(max, i, Converters.convert(1, num.getClass())); } } if (allZero) { return coverage; } param = PROCESSOR.getOperation("DivideByConst").getParameters(); param.parameter("source").setValue(coverage); param.parameter("constants").setValue(max); return (GridCoverage2D) PROCESSOR.doOperation(param); } }
NormalizeCoverageProcess implements RasterProcess { @DescribeResult(name = "result", description = "Normalized raster") public GridCoverage2D execute( @DescribeParameter(name = "data", description = "Input raster") GridCoverage2D coverage) throws IOException { ParameterValueGroup param = PROCESSOR.getOperation("Extrema").getParameters(); param.parameter("Source").setValue(coverage); GridCoverage2D extrema = (GridCoverage2D) PROCESSOR.doOperation(param); Object max = extrema.getProperty("maximum"); boolean allZero = true; for (int i = 0; i < Array.getLength(max); i++) { Object num = Array.get(max, i); boolean isZero = num instanceof Number && ((Number) num).doubleValue() == 0d; allZero = allZero && isZero; if (isZero) { Array.set(max, i, Converters.convert(1, num.getClass())); } } if (allZero) { return coverage; } param = PROCESSOR.getOperation("DivideByConst").getParameters(); param.parameter("source").setValue(coverage); param.parameter("constants").setValue(max); return (GridCoverage2D) PROCESSOR.doOperation(param); }  }
NormalizeCoverageProcess implements RasterProcess { @DescribeResult(name = "result", description = "Normalized raster") public GridCoverage2D execute( @DescribeParameter(name = "data", description = "Input raster") GridCoverage2D coverage) throws IOException { ParameterValueGroup param = PROCESSOR.getOperation("Extrema").getParameters(); param.parameter("Source").setValue(coverage); GridCoverage2D extrema = (GridCoverage2D) PROCESSOR.doOperation(param); Object max = extrema.getProperty("maximum"); boolean allZero = true; for (int i = 0; i < Array.getLength(max); i++) { Object num = Array.get(max, i); boolean isZero = num instanceof Number && ((Number) num).doubleValue() == 0d; allZero = allZero && isZero; if (isZero) { Array.set(max, i, Converters.convert(1, num.getClass())); } } if (allZero) { return coverage; } param = PROCESSOR.getOperation("DivideByConst").getParameters(); param.parameter("source").setValue(coverage); param.parameter("constants").setValue(max); return (GridCoverage2D) PROCESSOR.doOperation(param); }  @DescribeResult(name = "result", description = "Normalized raster") GridCoverage2D execute(
            @DescribeParameter(name = "data", description = "Input raster") GridCoverage2D coverage); }
NormalizeCoverageProcess implements RasterProcess { @DescribeResult(name = "result", description = "Normalized raster") public GridCoverage2D execute( @DescribeParameter(name = "data", description = "Input raster") GridCoverage2D coverage) throws IOException { ParameterValueGroup param = PROCESSOR.getOperation("Extrema").getParameters(); param.parameter("Source").setValue(coverage); GridCoverage2D extrema = (GridCoverage2D) PROCESSOR.doOperation(param); Object max = extrema.getProperty("maximum"); boolean allZero = true; for (int i = 0; i < Array.getLength(max); i++) { Object num = Array.get(max, i); boolean isZero = num instanceof Number && ((Number) num).doubleValue() == 0d; allZero = allZero && isZero; if (isZero) { Array.set(max, i, Converters.convert(1, num.getClass())); } } if (allZero) { return coverage; } param = PROCESSOR.getOperation("DivideByConst").getParameters(); param.parameter("source").setValue(coverage); param.parameter("constants").setValue(max); return (GridCoverage2D) PROCESSOR.doOperation(param); }  @DescribeResult(name = "result", description = "Normalized raster") GridCoverage2D execute(
            @DescribeParameter(name = "data", description = "Input raster") GridCoverage2D coverage);  }