@Test public void testMultiply() { GridCoverage2D c1 = buildCoverage(ONE_DIAGONAL); GridCoverage2D c2 = buildCoverage(TWO_SOLID); Process jiffle = Processors.createProcess(new NameImpl("ras", "Jiffle")); Map<String, Object> inputs = new HashMap<>(); inputs.put(JiffleProcess.IN_SOURCE_NAME, new String[] {"a", "b"}); inputs.put(JiffleProcess.IN_COVERAGE, new GridCoverage2D[] {c1, c2}); inputs.put(JiffleProcess.IN_SCRIPT, "dest = a * b;"); Map<String, Object> output = jiffle.execute(inputs, null); GridCoverage2D result = (GridCoverage2D) output.get(JiffleProcess.OUT_RESULT); float[][] resultData = data(result, 0); float[][] expected = new float[][] { {2, 0, 0}, {0, 2, 0}, {0, 0, 2}, }; assertArrayEquals(expected, resultData); Vector sources = ((RenderedOp) result.getRenderedImage()).getSources(); assertEquals(c1.getRenderedImage(), sources.get(0)); assertEquals(c2.getRenderedImage(), sources.get(1)); }
@DescribeResult(name = OUT_RESULT, description = "The map algebra output") public GridCoverage2D execute( @DescribeParameter(name = IN_COVERAGE, description = "Source raster(s)") GridCoverage2D[] coverages, @DescribeParameter( name = IN_SCRIPT, description = "The script performing the map algebra, in Jiffle language" ) String script, @DescribeParameter( name = IN_DEST_NAME, description = "Name of the output, as used in the script (defaults to 'dest' if not specified)", min = 0 ) String destName, @DescribeParameter( name = IN_SOURCE_NAME, description = "Name of the inputs, as used in the script (default to src, src1, src2, ... if not specified)", min = 0 ) String[] sourceNames, @DescribeParameter( name = IN_OUTPUT_TYPE, description = "Output data type, BYTE, USHORT, SHORT, INT, FLOAT, DOUBLE. Defaults to DOUBLE if not specified", min = 0 ) DataType dataType, @DescribeParameter( name = OUTPUT_BAND_COUNT, description = "Number of output bands. If not specified, will try to infer from the script, which will be possible only if the output band indices are literals.", min = 0, minValue = 1 ) Integer outputBandCount, @DescribeParameter( name = OUTPUT_BAND_NAMES, description = "Comma separate list of output band names. If not specified, will use 'jiffle' for single banded output, 'jiffle1', 'jiffle2', and so on for multi-band outputs", min = 0 ) String outputBandNames, ProgressListener progressListener) throws ProcessException, JiffleException { if (coverages.length == 0) { throw new IllegalArgumentException("Need at least one coverage in input"); } RenderedImage[] sources = new RenderedImage[coverages.length]; GridCoverage2D reference = coverages[0]; sources[0] = reference.getRenderedImage(); for (int i = 1; i < sources.length; i++) { GridCoverage2D coverage = coverages[i]; double[] nodata = CoverageUtilities.getBackgroundValues(coverage); ROI roi = CoverageUtilities.getROIProperty(coverage); if (coverage.getGridGeometry().equals(reference.getGridGeometry())) { sources[i] = coverage.getRenderedImage(); } else { sources[i] = GridCoverage2DRIA.create( coverage, reference, nodata, GeoTools.getDefaultHints(), roi); } } BandTransform[] bandTransforms = null; if (sources.length == 1) { BandTransform bt = getRenderingTransformationBandTransform(script, sourceNames, sources[0]); bandTransforms = new BandTransform[] {bt}; } Integer awtDataType = dataType == null ? null : dataType.getDataType(); RenderedOp result = JiffleDescriptor.create( sources, sourceNames, destName, script, null, awtDataType, outputBandCount, null, bandTransforms, GeoTools.getDefaultHints()); GridSampleDimension[] sampleDimensions = getSampleDimensions(result, outputBandNames); GridCoverageFactory factory = new GridCoverageFactory(GeoTools.getDefaultHints()); return factory.create( "jiffle", result, reference.getEnvelope(), sampleDimensions, coverages, null); }
JiffleProcess implements RasterProcess { @DescribeResult(name = OUT_RESULT, description = "The map algebra output") public GridCoverage2D execute( @DescribeParameter(name = IN_COVERAGE, description = "Source raster(s)") GridCoverage2D[] coverages, @DescribeParameter( name = IN_SCRIPT, description = "The script performing the map algebra, in Jiffle language" ) String script, @DescribeParameter( name = IN_DEST_NAME, description = "Name of the output, as used in the script (defaults to 'dest' if not specified)", min = 0 ) String destName, @DescribeParameter( name = IN_SOURCE_NAME, description = "Name of the inputs, as used in the script (default to src, src1, src2, ... if not specified)", min = 0 ) String[] sourceNames, @DescribeParameter( name = IN_OUTPUT_TYPE, description = "Output data type, BYTE, USHORT, SHORT, INT, FLOAT, DOUBLE. Defaults to DOUBLE if not specified", min = 0 ) DataType dataType, @DescribeParameter( name = OUTPUT_BAND_COUNT, description = "Number of output bands. If not specified, will try to infer from the script, which will be possible only if the output band indices are literals.", min = 0, minValue = 1 ) Integer outputBandCount, @DescribeParameter( name = OUTPUT_BAND_NAMES, description = "Comma separate list of output band names. If not specified, will use 'jiffle' for single banded output, 'jiffle1', 'jiffle2', and so on for multi-band outputs", min = 0 ) String outputBandNames, ProgressListener progressListener) throws ProcessException, JiffleException { if (coverages.length == 0) { throw new IllegalArgumentException("Need at least one coverage in input"); } RenderedImage[] sources = new RenderedImage[coverages.length]; GridCoverage2D reference = coverages[0]; sources[0] = reference.getRenderedImage(); for (int i = 1; i < sources.length; i++) { GridCoverage2D coverage = coverages[i]; double[] nodata = CoverageUtilities.getBackgroundValues(coverage); ROI roi = CoverageUtilities.getROIProperty(coverage); if (coverage.getGridGeometry().equals(reference.getGridGeometry())) { sources[i] = coverage.getRenderedImage(); } else { sources[i] = GridCoverage2DRIA.create( coverage, reference, nodata, GeoTools.getDefaultHints(), roi); } } BandTransform[] bandTransforms = null; if (sources.length == 1) { BandTransform bt = getRenderingTransformationBandTransform(script, sourceNames, sources[0]); bandTransforms = new BandTransform[] {bt}; } Integer awtDataType = dataType == null ? null : dataType.getDataType(); RenderedOp result = JiffleDescriptor.create( sources, sourceNames, destName, script, null, awtDataType, outputBandCount, null, bandTransforms, GeoTools.getDefaultHints()); GridSampleDimension[] sampleDimensions = getSampleDimensions(result, outputBandNames); GridCoverageFactory factory = new GridCoverageFactory(GeoTools.getDefaultHints()); return factory.create( "jiffle", result, reference.getEnvelope(), sampleDimensions, coverages, null); } }
JiffleProcess implements RasterProcess { @DescribeResult(name = OUT_RESULT, description = "The map algebra output") public GridCoverage2D execute( @DescribeParameter(name = IN_COVERAGE, description = "Source raster(s)") GridCoverage2D[] coverages, @DescribeParameter( name = IN_SCRIPT, description = "The script performing the map algebra, in Jiffle language" ) String script, @DescribeParameter( name = IN_DEST_NAME, description = "Name of the output, as used in the script (defaults to 'dest' if not specified)", min = 0 ) String destName, @DescribeParameter( name = IN_SOURCE_NAME, description = "Name of the inputs, as used in the script (default to src, src1, src2, ... if not specified)", min = 0 ) String[] sourceNames, @DescribeParameter( name = IN_OUTPUT_TYPE, description = "Output data type, BYTE, USHORT, SHORT, INT, FLOAT, DOUBLE. Defaults to DOUBLE if not specified", min = 0 ) DataType dataType, @DescribeParameter( name = OUTPUT_BAND_COUNT, description = "Number of output bands. If not specified, will try to infer from the script, which will be possible only if the output band indices are literals.", min = 0, minValue = 1 ) Integer outputBandCount, @DescribeParameter( name = OUTPUT_BAND_NAMES, description = "Comma separate list of output band names. If not specified, will use 'jiffle' for single banded output, 'jiffle1', 'jiffle2', and so on for multi-band outputs", min = 0 ) String outputBandNames, ProgressListener progressListener) throws ProcessException, JiffleException { if (coverages.length == 0) { throw new IllegalArgumentException("Need at least one coverage in input"); } RenderedImage[] sources = new RenderedImage[coverages.length]; GridCoverage2D reference = coverages[0]; sources[0] = reference.getRenderedImage(); for (int i = 1; i < sources.length; i++) { GridCoverage2D coverage = coverages[i]; double[] nodata = CoverageUtilities.getBackgroundValues(coverage); ROI roi = CoverageUtilities.getROIProperty(coverage); if (coverage.getGridGeometry().equals(reference.getGridGeometry())) { sources[i] = coverage.getRenderedImage(); } else { sources[i] = GridCoverage2DRIA.create( coverage, reference, nodata, GeoTools.getDefaultHints(), roi); } } BandTransform[] bandTransforms = null; if (sources.length == 1) { BandTransform bt = getRenderingTransformationBandTransform(script, sourceNames, sources[0]); bandTransforms = new BandTransform[] {bt}; } Integer awtDataType = dataType == null ? null : dataType.getDataType(); RenderedOp result = JiffleDescriptor.create( sources, sourceNames, destName, script, null, awtDataType, outputBandCount, null, bandTransforms, GeoTools.getDefaultHints()); GridSampleDimension[] sampleDimensions = getSampleDimensions(result, outputBandNames); GridCoverageFactory factory = new GridCoverageFactory(GeoTools.getDefaultHints()); return factory.create( "jiffle", result, reference.getEnvelope(), sampleDimensions, coverages, null); }  }
JiffleProcess implements RasterProcess { @DescribeResult(name = OUT_RESULT, description = "The map algebra output") public GridCoverage2D execute( @DescribeParameter(name = IN_COVERAGE, description = "Source raster(s)") GridCoverage2D[] coverages, @DescribeParameter( name = IN_SCRIPT, description = "The script performing the map algebra, in Jiffle language" ) String script, @DescribeParameter( name = IN_DEST_NAME, description = "Name of the output, as used in the script (defaults to 'dest' if not specified)", min = 0 ) String destName, @DescribeParameter( name = IN_SOURCE_NAME, description = "Name of the inputs, as used in the script (default to src, src1, src2, ... if not specified)", min = 0 ) String[] sourceNames, @DescribeParameter( name = IN_OUTPUT_TYPE, description = "Output data type, BYTE, USHORT, SHORT, INT, FLOAT, DOUBLE. Defaults to DOUBLE if not specified", min = 0 ) DataType dataType, @DescribeParameter( name = OUTPUT_BAND_COUNT, description = "Number of output bands. If not specified, will try to infer from the script, which will be possible only if the output band indices are literals.", min = 0, minValue = 1 ) Integer outputBandCount, @DescribeParameter( name = OUTPUT_BAND_NAMES, description = "Comma separate list of output band names. If not specified, will use 'jiffle' for single banded output, 'jiffle1', 'jiffle2', and so on for multi-band outputs", min = 0 ) String outputBandNames, ProgressListener progressListener) throws ProcessException, JiffleException { if (coverages.length == 0) { throw new IllegalArgumentException("Need at least one coverage in input"); } RenderedImage[] sources = new RenderedImage[coverages.length]; GridCoverage2D reference = coverages[0]; sources[0] = reference.getRenderedImage(); for (int i = 1; i < sources.length; i++) { GridCoverage2D coverage = coverages[i]; double[] nodata = CoverageUtilities.getBackgroundValues(coverage); ROI roi = CoverageUtilities.getROIProperty(coverage); if (coverage.getGridGeometry().equals(reference.getGridGeometry())) { sources[i] = coverage.getRenderedImage(); } else { sources[i] = GridCoverage2DRIA.create( coverage, reference, nodata, GeoTools.getDefaultHints(), roi); } } BandTransform[] bandTransforms = null; if (sources.length == 1) { BandTransform bt = getRenderingTransformationBandTransform(script, sourceNames, sources[0]); bandTransforms = new BandTransform[] {bt}; } Integer awtDataType = dataType == null ? null : dataType.getDataType(); RenderedOp result = JiffleDescriptor.create( sources, sourceNames, destName, script, null, awtDataType, outputBandCount, null, bandTransforms, GeoTools.getDefaultHints()); GridSampleDimension[] sampleDimensions = getSampleDimensions(result, outputBandNames); GridCoverageFactory factory = new GridCoverageFactory(GeoTools.getDefaultHints()); return factory.create( "jiffle", result, reference.getEnvelope(), sampleDimensions, coverages, null); }  @DescribeResult(name = OUT_RESULT, description = "The map algebra output") GridCoverage2D execute(
            @DescribeParameter(name = IN_COVERAGE, description = "Source raster(s)")
                    GridCoverage2D[] coverages,
            @DescribeParameter(
                        name = IN_SCRIPT,
                        description = "The script performing the map algebra, in Jiffle language"
                    )
                    String script,
            @DescribeParameter(
                        name = IN_DEST_NAME,
                        description =
                                "Name of the output, as used in the script (defaults to 'dest' if not specified)",
                        min = 0
                    )
                    String destName,
            @DescribeParameter(
                        name = IN_SOURCE_NAME,
                        description =
                                "Name of the inputs, as used in the script (default to src, src1, src2, ... if not specified)",
                        min = 0
                    )
                    String[] sourceNames,
            @DescribeParameter(
                        name = IN_OUTPUT_TYPE,
                        description =
                                "Output data type, BYTE, USHORT, SHORT, INT, FLOAT, DOUBLE. Defaults to DOUBLE if not specified",
                        min = 0
                    )
                    DataType dataType,
            @DescribeParameter(
                        name = OUTPUT_BAND_COUNT,
                        description =
                                "Number of output bands. If not specified, will try to infer from the script, which will be possible only if the output band indices are literals.",
                        min = 0,
                        minValue = 1
                    )
                    Integer outputBandCount,
            @DescribeParameter(
                        name = OUTPUT_BAND_NAMES,
                        description =
                                "Comma separate list of output band names. If not specified, will use 'jiffle' for single banded output, 'jiffle1', 'jiffle2', and so on for multi-band outputs",
                        min = 0
                    )
                    String outputBandNames,
            ProgressListener progressListener); GeneralParameterValue[] customizeReadParams(
            @DescribeParameter(
                        name = IN_SCRIPT,
                        description = "The script performing the map algebra, in Jiffle language"
                    )
                    String script,
            @DescribeParameter(
                        name = IN_DEST_NAME,
                        description =
                                "Name of the output, as used in the script (defaults to 'dest' if not specified)",
                        min = 0
                    )
                    String destName,
            @DescribeParameter(
                        name = IN_SOURCE_NAME,
                        description =
                                "Name of the inputs, as used in the script (default to src, src1, src2, ... if not specified)",
                        min = 0
                    )
                    String[] sourceNames,
            @DescribeParameter(
                        name = TX_BANDS,
                        description = "Bands read by the transformation",
                        min = 0
                    )
                    int[] usedBands,
            GridCoverageReader reader,
            GeneralParameterValue[] params); }
JiffleProcess implements RasterProcess { @DescribeResult(name = OUT_RESULT, description = "The map algebra output") public GridCoverage2D execute( @DescribeParameter(name = IN_COVERAGE, description = "Source raster(s)") GridCoverage2D[] coverages, @DescribeParameter( name = IN_SCRIPT, description = "The script performing the map algebra, in Jiffle language" ) String script, @DescribeParameter( name = IN_DEST_NAME, description = "Name of the output, as used in the script (defaults to 'dest' if not specified)", min = 0 ) String destName, @DescribeParameter( name = IN_SOURCE_NAME, description = "Name of the inputs, as used in the script (default to src, src1, src2, ... if not specified)", min = 0 ) String[] sourceNames, @DescribeParameter( name = IN_OUTPUT_TYPE, description = "Output data type, BYTE, USHORT, SHORT, INT, FLOAT, DOUBLE. Defaults to DOUBLE if not specified", min = 0 ) DataType dataType, @DescribeParameter( name = OUTPUT_BAND_COUNT, description = "Number of output bands. If not specified, will try to infer from the script, which will be possible only if the output band indices are literals.", min = 0, minValue = 1 ) Integer outputBandCount, @DescribeParameter( name = OUTPUT_BAND_NAMES, description = "Comma separate list of output band names. If not specified, will use 'jiffle' for single banded output, 'jiffle1', 'jiffle2', and so on for multi-band outputs", min = 0 ) String outputBandNames, ProgressListener progressListener) throws ProcessException, JiffleException { if (coverages.length == 0) { throw new IllegalArgumentException("Need at least one coverage in input"); } RenderedImage[] sources = new RenderedImage[coverages.length]; GridCoverage2D reference = coverages[0]; sources[0] = reference.getRenderedImage(); for (int i = 1; i < sources.length; i++) { GridCoverage2D coverage = coverages[i]; double[] nodata = CoverageUtilities.getBackgroundValues(coverage); ROI roi = CoverageUtilities.getROIProperty(coverage); if (coverage.getGridGeometry().equals(reference.getGridGeometry())) { sources[i] = coverage.getRenderedImage(); } else { sources[i] = GridCoverage2DRIA.create( coverage, reference, nodata, GeoTools.getDefaultHints(), roi); } } BandTransform[] bandTransforms = null; if (sources.length == 1) { BandTransform bt = getRenderingTransformationBandTransform(script, sourceNames, sources[0]); bandTransforms = new BandTransform[] {bt}; } Integer awtDataType = dataType == null ? null : dataType.getDataType(); RenderedOp result = JiffleDescriptor.create( sources, sourceNames, destName, script, null, awtDataType, outputBandCount, null, bandTransforms, GeoTools.getDefaultHints()); GridSampleDimension[] sampleDimensions = getSampleDimensions(result, outputBandNames); GridCoverageFactory factory = new GridCoverageFactory(GeoTools.getDefaultHints()); return factory.create( "jiffle", result, reference.getEnvelope(), sampleDimensions, coverages, null); }  @DescribeResult(name = OUT_RESULT, description = "The map algebra output") GridCoverage2D execute(
            @DescribeParameter(name = IN_COVERAGE, description = "Source raster(s)")
                    GridCoverage2D[] coverages,
            @DescribeParameter(
                        name = IN_SCRIPT,
                        description = "The script performing the map algebra, in Jiffle language"
                    )
                    String script,
            @DescribeParameter(
                        name = IN_DEST_NAME,
                        description =
                                "Name of the output, as used in the script (defaults to 'dest' if not specified)",
                        min = 0
                    )
                    String destName,
            @DescribeParameter(
                        name = IN_SOURCE_NAME,
                        description =
                                "Name of the inputs, as used in the script (default to src, src1, src2, ... if not specified)",
                        min = 0
                    )
                    String[] sourceNames,
            @DescribeParameter(
                        name = IN_OUTPUT_TYPE,
                        description =
                                "Output data type, BYTE, USHORT, SHORT, INT, FLOAT, DOUBLE. Defaults to DOUBLE if not specified",
                        min = 0
                    )
                    DataType dataType,
            @DescribeParameter(
                        name = OUTPUT_BAND_COUNT,
                        description =
                                "Number of output bands. If not specified, will try to infer from the script, which will be possible only if the output band indices are literals.",
                        min = 0,
                        minValue = 1
                    )
                    Integer outputBandCount,
            @DescribeParameter(
                        name = OUTPUT_BAND_NAMES,
                        description =
                                "Comma separate list of output band names. If not specified, will use 'jiffle' for single banded output, 'jiffle1', 'jiffle2', and so on for multi-band outputs",
                        min = 0
                    )
                    String outputBandNames,
            ProgressListener progressListener); GeneralParameterValue[] customizeReadParams(
            @DescribeParameter(
                        name = IN_SCRIPT,
                        description = "The script performing the map algebra, in Jiffle language"
                    )
                    String script,
            @DescribeParameter(
                        name = IN_DEST_NAME,
                        description =
                                "Name of the output, as used in the script (defaults to 'dest' if not specified)",
                        min = 0
                    )
                    String destName,
            @DescribeParameter(
                        name = IN_SOURCE_NAME,
                        description =
                                "Name of the inputs, as used in the script (default to src, src1, src2, ... if not specified)",
                        min = 0
                    )
                    String[] sourceNames,
            @DescribeParameter(
                        name = TX_BANDS,
                        description = "Bands read by the transformation",
                        min = 0
                    )
                    int[] usedBands,
            GridCoverageReader reader,
            GeneralParameterValue[] params); static final String IN_COVERAGE; static final String IN_SCRIPT; static final String IN_DEST_NAME; static final String IN_SOURCE_NAME; static final String IN_OUTPUT_TYPE; static final String OUTPUT_BAND_COUNT; static final String OUTPUT_BAND_NAMES; static final String OUT_RESULT; static final String TX_BANDS; }