Search in sources :

Example 1 with Process

use of org.geotoolkit.process.Process in project geotoolkit by Geomatys.

the class BandSelectProcess method execute.

@Override
protected void execute() throws ProcessException {
    ArgumentChecks.ensureNonNull("inputParameter", inputParameters);
    final GridCoverage inputCoverage = (GridCoverage) inputParameters.getValue(BandSelectDescriptor.IN_COVERAGE);
    final int[] bands = inputParameters.getValue(BandSelectDescriptor.IN_BANDS);
    // CALL IMAGE BAND SELECT //////////////////////////////////////////////
    final ProcessDescriptor imageSelectDesc = org.geotoolkit.processing.image.bandselect.BandSelectDescriptor.INSTANCE;
    final Parameters params = Parameters.castOrWrap(imageSelectDesc.getInputDescriptor().createValue());
    params.parameter("image").setValue(inputCoverage.render(null));
    params.parameter("bands").setValue(bands);
    final Process process = imageSelectDesc.createProcess(params);
    BufferedImage resultImage = (BufferedImage) process.call().parameter("result").getValue();
    // BUILD A BETTER COLOR MODEL //////////////////////////////////////////
    // TODO try to reuse java colormodel if possible
    // extract grayscale min/max from sample dimension
    final SampleDimension gridSample = inputCoverage.getSampleDimensions().get(0);
    final ColorModel graycm = ColorModelFactory.createGrayScale(resultImage.getSampleModel().getDataType(), resultImage.getSampleModel().getNumBands(), 0, SampleDimensionUtils.getMinimumValue(gridSample), SampleDimensionUtils.getMaximumValue(gridSample));
    resultImage = new BufferedImage(graycm, resultImage.getRaster(), false, new Hashtable<Object, Object>());
    // REBUILD COVERAGE ////////////////////////////////////////////////////
    final GridCoverageBuilder gcb = new GridCoverageBuilder();
    gcb.setValues(resultImage);
    gcb.setDomain(inputCoverage.getGridGeometry());
    final GridCoverage resultCoverage = gcb.build();
    outputParameters.getOrCreate(BandSelectDescriptor.OUT_COVERAGE).setValue(resultCoverage);
}
Also used : Parameters(org.apache.sis.parameter.Parameters) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) GridCoverageBuilder(org.apache.sis.coverage.grid.GridCoverageBuilder) ColorModel(java.awt.image.ColorModel) Hashtable(java.util.Hashtable) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) AbstractProcess(org.geotoolkit.processing.AbstractProcess) Process(org.geotoolkit.process.Process) SampleDimension(org.apache.sis.coverage.SampleDimension) BufferedImage(java.awt.image.BufferedImage)

Example 2 with Process

use of org.geotoolkit.process.Process in project geotoolkit by Geomatys.

the class ReformatProcess method execute.

@Override
protected void execute() throws ProcessException {
    ArgumentChecks.ensureNonNull("inputParameter", inputParameters);
    // PARAMETERS CHECK ////////////////////////////////////////////////////
    final GridCoverage inputCoverage = inputParameters.getValue(IN_COVERAGE);
    final int inputType = inputParameters.getValue(IN_DATATYPE);
    final RenderedImage inputImage = inputCoverage.render(null);
    final SampleModel inputSampleModel = inputImage.getSampleModel();
    // check type, if same return the original coverage
    if (inputSampleModel.getDataType() == inputType) {
        outputParameters.getOrCreate(OUT_COVERAGE).setValue(inputCoverage);
        return;
    }
    // CALL IMAGE BAND SELECT //////////////////////////////////////////////
    final ProcessDescriptor imageReformatDesc = org.geotoolkit.processing.image.reformat.ReformatDescriptor.INSTANCE;
    final Parameters params = Parameters.castOrWrap(imageReformatDesc.getInputDescriptor().createValue());
    params.parameter("image").setValue(inputCoverage.render(null));
    params.parameter("datatype").setValue(inputType);
    final Process process = imageReformatDesc.createProcess(params);
    BufferedImage resultImage = (BufferedImage) process.call().parameter("result").getValue();
    // BUILD A BETTER COLOR MODEL //////////////////////////////////////////
    // TODO try to reuse java colormodel if possible
    // extract grayscale min/max from sample dimension
    final SampleDimension gridSample = inputCoverage.getSampleDimensions().get(0);
    final ColorModel graycm = ColorModelFactory.createGrayScale(resultImage.getSampleModel().getDataType(), resultImage.getSampleModel().getNumBands(), 0, SampleDimensionUtils.getMinimumValue(gridSample), SampleDimensionUtils.getMaximumValue(gridSample));
    resultImage = new BufferedImage(graycm, resultImage.getRaster(), false, new Hashtable<Object, Object>());
    // REBUILD COVERAGE ////////////////////////////////////////////////////
    final GridCoverage resultCoverage;
    resultCoverage = new GridCoverage2D(inputCoverage.getGridGeometry(), inputCoverage.getSampleDimensions(), resultImage);
    outputParameters.getOrCreate(OUT_COVERAGE).setValue(resultCoverage);
}
Also used : GridCoverage2D(org.apache.sis.coverage.grid.GridCoverage2D) SampleModel(java.awt.image.SampleModel) Parameters(org.apache.sis.parameter.Parameters) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) ColorModel(java.awt.image.ColorModel) Hashtable(java.util.Hashtable) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) AbstractProcess(org.geotoolkit.processing.AbstractProcess) Process(org.geotoolkit.process.Process) RenderedImage(java.awt.image.RenderedImage) SampleDimension(org.apache.sis.coverage.SampleDimension) BufferedImage(java.awt.image.BufferedImage)

Example 3 with Process

use of org.geotoolkit.process.Process in project geotoolkit by Geomatys.

the class CachedPatternSymbolizer method computeOld.

private Geometry[] computeOld(GridCoverage coverage, Map<NumberRange, List<Symbolizer>> styles) throws IOException {
    final ProcessDescriptor descriptor = CoverageToVectorDescriptor.INSTANCE;
    final Integer band = (Integer) styleElement.getChannel().apply(null);
    final ParameterValueGroup input = descriptor.getInputDescriptor().createValue();
    input.parameter(CoverageToVectorDescriptor.COVERAGE.getName().getCode()).setValue(coverage);
    final Set<NumberRange> nrs = styles.keySet();
    input.parameter(CoverageToVectorDescriptor.RANGES.getName().getCode()).setValue(nrs.toArray(new NumberRange[nrs.size()]));
    input.parameter(CoverageToVectorDescriptor.BAND.getName().getCode()).setValue(band);
    final Process process = descriptor.createProcess(input);
    final Geometry[] polygons;
    try {
        polygons = (Geometry[]) process.call().parameter(CoverageToVectorDescriptor.GEOMETRIES.getName().getCode()).getValue();
    } catch (ProcessException ex) {
        Logger.getLogger("org.geotoolkit.display2d.ext.pattern").log(Level.WARNING, null, ex);
        throw new IOException(ex.getMessage(), ex);
    }
    return polygons;
}
Also used : NumberRange(org.apache.sis.measure.NumberRange) Geometry(org.locationtech.jts.geom.Geometry) ProcessException(org.geotoolkit.process.ProcessException) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) Process(org.geotoolkit.process.Process) IOException(java.io.IOException)

Example 4 with Process

use of org.geotoolkit.process.Process in project geotoolkit by Geomatys.

the class ProcessDemo method main.

public static void main(String[] args) throws NoSuchIdentifierException, ProcessException {
    Demos.init();
    // get the description of the process we want
    final ProcessDescriptor desc = ProcessFinder.getProcessDescriptor("demo", "addition");
    // create a process
    // set the input parameters
    final ParameterValueGroup input = desc.getInputDescriptor().createValue();
    input.parameter("first").setValue(15d);
    input.parameter("second").setValue(5d);
    final Process p = desc.createProcess(input);
    // get the result
    final ParameterValueGroup result = p.call();
    System.out.println(result);
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) Process(org.geotoolkit.process.Process)

Example 5 with Process

use of org.geotoolkit.process.Process in project geotoolkit by Geomatys.

the class ExpressionTest method testDoubleQuoteString.

@Test
public void testDoubleQuoteString() throws IOException, ProcessException {
    final Expression reference = FF.property("name");
    final Parameters input = Parameters.castOrWrap(desc.getInputDescriptor().createValue());
    input.getOrCreate(IN_TEXT).setValue("\"husky\"");
    input.getOrCreate(IN_REFERENCE).setValue(reference);
    final Process process = desc.createProcess(input);
    final Parameters output = Parameters.castOrWrap(process.call());
    final Object result = output.getValue(OUT_OGC);
    assertEquals(FF.equal(reference, FF.literal("husky")), result);
}
Also used : Parameters(org.apache.sis.parameter.Parameters) Expression(org.opengis.filter.Expression) Process(org.geotoolkit.process.Process) Test(org.junit.Test)

Aggregations

Process (org.geotoolkit.process.Process)42 ProcessDescriptor (org.geotoolkit.process.ProcessDescriptor)30 Test (org.junit.Test)30 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)29 Parameters (org.apache.sis.parameter.Parameters)15 RenderedImage (java.awt.image.RenderedImage)13 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)13 BufferedImage (java.awt.image.BufferedImage)11 Raster (java.awt.image.Raster)9 SampleModel (java.awt.image.SampleModel)9 GridCoverageBuilder (org.apache.sis.coverage.grid.GridCoverageBuilder)9 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)9 Graphics2D (java.awt.Graphics2D)6 File (java.io.File)6 SampleDimension (org.apache.sis.coverage.SampleDimension)6 Expression (org.opengis.filter.Expression)6 AbstractProcess (org.geotoolkit.processing.AbstractProcess)5 Color (java.awt.Color)4 WritableRaster (java.awt.image.WritableRaster)4 ArrayList (java.util.ArrayList)4