Search in sources :

Example 6 with ProcessException

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

the class ReformatProcess method execute.

@Override
protected void execute() throws ProcessException {
    ArgumentChecks.ensureNonNull("inputParameter", inputParameters);
    final RenderedImage inputImage = inputParameters.getValue(IN_IMAGE);
    final int inputType = inputParameters.getValue(IN_DATATYPE);
    final SampleModel inputSampleModel = inputImage.getSampleModel();
    // check type, if same return the original coverage
    if (inputSampleModel.getDataType() == inputType) {
        outputParameters.getOrCreate(OUT_IMAGE).setValue(inputImage);
        return;
    }
    // create the output image
    final int width = inputImage.getWidth();
    final int height = inputImage.getHeight();
    final int nbBand = inputSampleModel.getNumBands();
    final Point upperLeft = new Point(inputImage.getMinX(), inputImage.getMinY());
    final WritableRaster raster;
    try {
        raster = createRaster(inputType, width, height, nbBand, upperLeft);
    } catch (IllegalArgumentException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
    // TODO try to reuse java colormodel if possible
    // create a temporary fallback colormodel which will always work
    // extract grayscale min/max from sample dimension
    final ColorModel graycm = ColorModelFactory.createGrayScale(inputType, nbBand, 0, 0, 10);
    final BufferedImage resultImage = new BufferedImage(graycm, raster, false, new Hashtable<Object, Object>());
    // copy datas
    final PixelIterator readIte = new PixelIterator.Builder().create(inputImage);
    final WritablePixelIterator writeIte = new PixelIterator.Builder().createWritable(raster);
    while (readIte.next() && writeIte.next()) {
        for (int b = 0; b < nbBand; b++) {
            writeIte.setSample(b, readIte.getSampleDouble(b));
        }
    }
    outputParameters.getOrCreate(OUT_IMAGE).setValue(resultImage);
}
Also used : PixelIterator(org.apache.sis.image.PixelIterator) WritablePixelIterator(org.apache.sis.image.WritablePixelIterator) Point(java.awt.Point) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) ProcessException(org.geotoolkit.process.ProcessException) SampleModel(java.awt.image.SampleModel) WritablePixelIterator(org.apache.sis.image.WritablePixelIterator) WritableRaster(java.awt.image.WritableRaster) ColorModel(java.awt.image.ColorModel) RenderedImage(java.awt.image.RenderedImage)

Example 7 with ProcessException

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

the class BufferProcess method execute.

@Override
protected void execute() throws ProcessException {
    try {
        final Geometry geom = inputParameters.getValue(GEOM);
        final double distance = inputParameters.getValue(DISTANCE);
        int segments = 0;
        if (inputParameters.getValue(SEGMENTS) != null) {
            segments = inputParameters.getValue(SEGMENTS);
        }
        int endStyle = 2;
        if (inputParameters.getValue(ENDSTYLE) != null) {
            endStyle = inputParameters.getValue(ENDSTYLE);
        }
        final CoordinateReferenceSystem geomCRS = JTS.findCoordinateReferenceSystem(geom);
        Geometry result = JTS.getFactory().buildGeometry(Collections.EMPTY_LIST);
        if (segments > 0) {
            if (endStyle != 0) {
                result = geom.buffer(distance, segments, endStyle);
            } else {
                result = geom.buffer(distance, segments);
            }
        } else {
            result = geom.buffer(distance);
        }
        JTS.setCRS(result, geomCRS);
        outputParameters.getOrCreate(RESULT_GEOM).setValue(result);
    } catch (NoSuchAuthorityCodeException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    } catch (FactoryException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) ProcessException(org.geotoolkit.process.ProcessException) FactoryException(org.opengis.util.FactoryException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 8 with ProcessException

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

the class CentroidProcess method execute.

@Override
protected void execute() throws ProcessException {
    try {
        final Geometry geom = inputParameters.getValue(GEOM);
        final CoordinateReferenceSystem geomCRS = JTS.findCoordinateReferenceSystem(geom);
        final Point result = geom.getCentroid();
        JTS.setCRS(result, geomCRS);
        outputParameters.getOrCreate(RESULT_GEOM).setValue(result);
    } catch (NoSuchAuthorityCodeException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    } catch (FactoryException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) ProcessException(org.geotoolkit.process.ProcessException) FactoryException(org.opengis.util.FactoryException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Point(org.locationtech.jts.geom.Point)

Example 9 with ProcessException

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

the class ConvexHullProcess method execute.

@Override
protected void execute() throws ProcessException {
    try {
        final Geometry geom = inputParameters.getValue(ConvexHullDescriptor.GEOM);
        final CoordinateReferenceSystem geomCRS = JTS.findCoordinateReferenceSystem(geom);
        final Geometry result = geom.convexHull();
        JTS.setCRS(result, geomCRS);
        outputParameters.getOrCreate(ConvexHullDescriptor.RESULT_GEOM).setValue(result);
    } catch (NoSuchAuthorityCodeException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    } catch (FactoryException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) ProcessException(org.geotoolkit.process.ProcessException) FactoryException(org.opengis.util.FactoryException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 10 with ProcessException

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

the class CrossesProcess method execute.

@Override
protected void execute() throws ProcessException {
    try {
        final Geometry geom1 = inputParameters.getValue(CrossesDescriptor.GEOM1);
        Geometry geom2 = inputParameters.getValue(CrossesDescriptor.GEOM2);
        // ensure geometries are in the same CRS
        final CoordinateReferenceSystem resultCRS = JTS.getCommonCRS(geom1, geom2);
        if (JTS.isConversionNeeded(geom1, geom2)) {
            geom2 = JTS.convertToCRS(geom2, resultCRS);
        }
        final Boolean result = (Boolean) geom1.crosses(geom2);
        outputParameters.getOrCreate(CrossesDescriptor.RESULT).setValue(result);
    } catch (FactoryException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    } catch (TransformException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ProcessException(org.geotoolkit.process.ProcessException) FactoryException(org.opengis.util.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Aggregations

ProcessException (org.geotoolkit.process.ProcessException)70 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)27 Geometry (org.locationtech.jts.geom.Geometry)26 FactoryException (org.opengis.util.FactoryException)24 TransformException (org.opengis.referencing.operation.TransformException)21 RenderedImage (java.awt.image.RenderedImage)15 DataStoreException (org.apache.sis.storage.DataStoreException)13 IOException (java.io.IOException)12 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)12 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)11 ProcessDescriptor (org.geotoolkit.process.ProcessDescriptor)11 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)11 BufferedImage (java.awt.image.BufferedImage)10 ArrayList (java.util.ArrayList)10 PixelIterator (org.apache.sis.image.PixelIterator)9 List (java.util.List)8 Parameters (org.apache.sis.parameter.Parameters)8 DismissProcessException (org.geotoolkit.process.DismissProcessException)8 WritablePixelIterator (org.apache.sis.image.WritablePixelIterator)7 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)7