Search in sources :

Example 1 with ProcessDescriptor

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());
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor)

Example 2 with ProcessDescriptor

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);
}
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 3 with ProcessDescriptor

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);
}
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 4 with ProcessDescriptor

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);
    }
}
Also used : Path(java.nio.file.Path) GridGeometry(org.apache.sis.coverage.grid.GridGeometry) DataStoreException(org.apache.sis.storage.DataStoreException) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Rectangle(java.awt.Rectangle) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) ImageReadParam(javax.imageio.ImageReadParam) ProcessException(org.geotoolkit.process.ProcessException) GridCoverageBuilder(org.apache.sis.coverage.grid.GridCoverageBuilder) NoSuchIdentifierException(org.opengis.util.NoSuchIdentifierException) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) RenderedImage(java.awt.image.RenderedImage) TiffImageReader(org.geotoolkit.image.io.plugin.TiffImageReader)

Example 5 with ProcessDescriptor

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()));
    }
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) WebProcessingClient(org.geotoolkit.wps.client.WebProcessingClient) Envelope(org.locationtech.jts.geom.Envelope) URL(java.net.URL) WPSProcessingRegistry(org.geotoolkit.wps.client.process.WPSProcessingRegistry) Geometry(org.locationtech.jts.geom.Geometry) NullProgressListener(org.geotoolkit.util.NullProgressListener) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor)

Aggregations

ProcessDescriptor (org.geotoolkit.process.ProcessDescriptor)136 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)121 Test (org.junit.Test)108 AbstractProcessTest (org.geotoolkit.processing.AbstractProcessTest)62 Geometry (org.locationtech.jts.geom.Geometry)43 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)33 Coordinate (org.locationtech.jts.geom.Coordinate)32 LinearRing (org.locationtech.jts.geom.LinearRing)31 Process (org.geotoolkit.process.Process)30 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)20 AbstractProcessTest (org.geotoolkit.processing.vector.AbstractProcessTest)18 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)17 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)15 GridCoverageBuilder (org.apache.sis.coverage.grid.GridCoverageBuilder)14 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)14 FeatureSet (org.apache.sis.storage.FeatureSet)14 BufferedImage (java.awt.image.BufferedImage)13 RenderedImage (java.awt.image.RenderedImage)13 SampleDimension (org.apache.sis.coverage.SampleDimension)13 MathTransform (org.opengis.referencing.operation.MathTransform)13