use of org.geotoolkit.process.ProcessDescriptor in project geotoolkit by Geomatys.
the class ComputeVolumeBuilder method getVolume.
/**
* Return volume from {@link ComputeVolumeProcess process} computed from all previously setted attributs.
*
* @return volume from {@link ComputeVolumeProcess process} computed from all previously setted attributs.
* @throws ProcessException
*/
public double getVolume() throws ProcessException {
final ProcessDescriptor volumeDescriptor = ComputeVolumeDescriptor.INSTANCE;
final ParameterValueGroup volumeInput = volumeDescriptor.getInputDescriptor().createValue();
volumeInput.parameter(ComputeVolumeDescriptor.INPUT_RESOURCE_NAME).setValue(gcReader);
volumeInput.parameter(ComputeVolumeDescriptor.INPUT_JTS_GEOMETRY_NAME).setValue(jtsGeom);
volumeInput.parameter(ComputeVolumeDescriptor.INPUT_GEOMETRY_ALTITUDE_NAME).setValue(groundAltitude);
volumeInput.parameter(ComputeVolumeDescriptor.INPUT_MAX_CEILING_NAME).setValue(zCeiling);
volumeInput.parameter(ComputeVolumeDescriptor.INPUT_GEOMETRY_CRS_NAME).setValue(geomCRS);
volumeInput.parameter(ComputeVolumeDescriptor.INPUT_BAND_INDEX_NAME).setValue(bandIndex);
org.geotoolkit.process.Process volumeProcess = volumeDescriptor.createProcess(volumeInput);
return ((Double) volumeProcess.call().parameter(ComputeVolumeDescriptor.OUTPUT_VOLUME_NAME).getValue());
}
use of org.geotoolkit.process.ProcessDescriptor 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.ProcessDescriptor 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.ProcessDescriptor in project geotoolkit by Geomatys.
the class LandsatResource method readGridSlice.
@Override
protected GridCoverage readGridSlice(GridGeometry resultGrid, int[] areaLower, int[] areaUpper, int[] subsampling, int... range) throws DataStoreException {
GridGeometry geometry = getGridGeometry(getGridGeometry(), areaLower, areaUpper, subsampling);
// -- get all needed band to build coverage (see Landsat spec)
final int[] bandId = group.bands;
final RenderedImage[] bands = new RenderedImage[bandId.length];
try {
int currentCov = 0;
for (int i : bandId) {
// -- get band name
final String bandName = metadataParser.getValue(true, BAND_NAME_LABEL + i);
// -- add to coverage name
final Path band = parentDirectory.resolve(bandName);
// -- reader config
final TiffImageReader tiffReader = (TiffImageReader) TIFF_SPI.createReaderInstance();
tiffReader.setInput(band);
Rectangle rec = new Rectangle(areaLower[0], areaLower[1], areaUpper[0] - areaLower[0], areaUpper[1] - areaLower[1]);
final ImageReadParam readParam = tiffReader.getDefaultReadParam();
readParam.setSourceRegion(rec);
readParam.setSourceSubsampling(subsampling[0], subsampling[1], 0, 0);
try {
BufferedImage read = tiffReader.read(0, readParam);
bands[currentCov++] = read;
} finally {
tiffReader.dispose();
}
}
final ProcessDescriptor desc = ProcessFinder.getProcessDescriptor("geotoolkit", "image:bandcombine");
final ParameterValueGroup params = desc.getInputDescriptor().createValue();
params.parameter("images").setValue(bands);
final org.geotoolkit.process.Process process = desc.createProcess(params);
final ParameterValueGroup result = process.call();
final RenderedImage outImage = (RenderedImage) result.parameter("result").getValue();
final GridCoverageBuilder gcb = new GridCoverageBuilder();
gcb.setValues(outImage);
gcb.setDomain(geometry);
return gcb.build();
} catch (IOException | NoSuchIdentifierException | ProcessException ex) {
throw new DataStoreException(ex.getMessage(), ex);
}
}
use of org.geotoolkit.process.ProcessDescriptor in project geotoolkit by Geomatys.
the class WPSClientDemo method main.
public static void main(String[] args) throws Exception {
// force loading all image readers/writers
ImageIO.scanForPlugins();
// global initialization
Setup.initialize(null);
// Instantiate client :
final URL wpsURL = new URL(SERVICE_URL);
final WebProcessingClient wpsClient = new WebProcessingClient(wpsURL, WPSVersion.v100.getCode());
// Once initialized, we can ask a description of wanted process, using its id.
final WPSProcessingRegistry registry = new WPSProcessingRegistry(wpsClient);
ProcessDescriptor desc = registry.getDescriptor(PROCESS_ID);
// We can check process input & output.
ParameterDescriptorGroup inputDesc = desc.getInputDescriptor();
ParameterDescriptorGroup outputDesc = desc.getOutputDescriptor();
// Iterate on wanted parameters. If one is missing, an exception is raised.
LOGGER.log(Level.INFO, "INPUT : \n");
for (INPUT in : INPUT.values()) {
final GeneralParameterDescriptor current = inputDesc.descriptor(in.name);
LOGGER.log(Level.INFO, "Parameter : " + current.getName().getCode() + " : \n\t" + current.getRemarks());
}
LOGGER.log(Level.INFO, "OUTPUT : \n");
for (OUTPUT out : OUTPUT.values()) {
final GeneralParameterDescriptor current = outputDesc.descriptor(out.name);
LOGGER.log(Level.INFO, "Parameter : " + current.getName().getCode() + " : \n\t" + current.getRemarks());
}
GeometryFactory factory = org.geotoolkit.geometry.jts.JTS.getFactory();
Geometry geometry = factory.toGeometry(new Envelope(1.0, 2.0, 43.3, 43.9));
geometry.setUserData(CommonCRS.WGS84.geographic());
final double bufDistance = 0.5;
// Instantiate inputs. Those objects get the same behaviour that the descriptors. If we cannot find a specific
// parameter, an exception is thrown.
ParameterValueGroup input = inputDesc.createValue();
input.parameter(INPUT.geom.name).setValue(geometry);
input.parameter(INPUT.distance.name).setValue(bufDistance);
// Process execution. It's synchronous here (talking only of client side, WPS can execute asynchronous process).
// For asynchronous execution, we must execute it in a thread, using a process listener to get process state.
org.geotoolkit.process.Process toExecute = desc.createProcess(input);
toExecute.addListener(new NullProgressListener());
ParameterValueGroup output = toExecute.call();
// Get output values :
for (OUTPUT out : OUTPUT.values()) {
LOGGER.log(Level.INFO, String.format("%s parameter value : %s", out.name(), output.parameter(out.name).getValue()));
}
}
Aggregations