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);
}
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);
}
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;
}
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);
}
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);
}
Aggregations