Search code examples
geotools

Is there a way to increase the values in the e.g green band of a gridCoverage?


I would like to increase the values in the green band of some air photos, is it possible to do that with GeoTools? If so is there an example of this? After Ians suggestion I tried this and it seems to work:

        try {
            reader = format.getReader(file, hints);
        
            Style rasterStyle = null;
            
            GridCoverage2D inCov = null;

            inCov = reader.read(null);
            Process jiffle =  (Process) Processors.createProcess(new NameImpl("ras", "Jiffle"));
            Map<String, Object> inputs = new HashMap<>();
            inputs.put(JiffleProcess.IN_SOURCE_NAME, new String[] {"a"});
            inputs.put(JiffleProcess.IN_COVERAGE, new GridCoverage2D[] {inCov});
            String scr = "dest[0] = a[0]";
            if (!txtRed.getText().trim().isEmpty() && !txtRed.getText().trim().equals("0")) {
                scr=scr + " + a[0]*" + "" + Double.parseDouble(txtRed.getText())/ 100.0 + "; dest[1] = a[1]";
            }
            else {
                scr=scr + "; dest[1] = a[1]";
            }
            if (!txtGreen.getText().trim().isEmpty() && !txtGreen.getText().trim().equals("0")) {
                scr=scr + " + a[1]*" + "" + Double.parseDouble(txtGreen.getText())/ 100.0 + "; dest[2] = a[2]";
            }
            else {
                scr=scr + "; dest[2] = a[2]";
            }
            if (!txtBlue.getText().trim().isEmpty() && !txtBlue.getText().trim().equals("0")) {
                scr=scr + " + a[2]*" + "" + Double.parseDouble(txtBlue.getText())/ 100.0 + ";";
            }
            else {
                scr=scr + ";";
            }
            inputs.put(JiffleProcess.IN_SCRIPT, scr);
            Map<String, Object> output = ((org.geotools.process.Process) jiffle).execute(inputs, null);
            GridCoverage2D result = (GridCoverage2D) output.get(JiffleProcess.OUT_RESULT);

Solution

  • I think the easiest way to do this is to use the Jiffle language plugin where I think (but haven't tested) that this should do it:

    dest[0] = src[0]
    dest[1] = src[1] + src[1]/10.0
    dest[2] = src[1]