Search in sources :

Example 46 with ProcessException

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

the class IntersectionSurfaceProcess method execute.

/**
 * Calculates the intersection surface of two geometries. If the two geometries do not
 * intersect, return {@code 0} in the output parameters.
 *
 * @throws ProcessException
 */
@Override
protected void execute() throws ProcessException {
    try {
        final Geometry geom1 = inputParameters.getValue(GEOM1);
        Geometry geom2 = inputParameters.getValue(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 Geometry intersection = (Geometry) geom1.intersection(geom2);
        if (resultCRS != null) {
            JTS.setCRS(intersection, resultCRS);
        }
        final double area = (intersection == null) ? 0d : intersection.getArea();
        outputParameters.getOrCreate(RESULT_SURFACE).setValue(area);
    } catch (Exception ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ProcessException(org.geotoolkit.process.ProcessException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ProcessException(org.geotoolkit.process.ProcessException)

Example 47 with ProcessException

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

the class IntersectsProcess method execute.

@Override
protected void execute() throws ProcessException {
    try {
        final Geometry geom1 = inputParameters.getValue(IntersectsDescriptor.GEOM1);
        Geometry geom2 = inputParameters.getValue(IntersectsDescriptor.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.intersects(geom2);
        outputParameters.getOrCreate(IntersectsDescriptor.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)

Example 48 with ProcessException

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

the class OverlapsProcess method execute.

@Override
protected void execute() throws ProcessException {
    try {
        final Geometry geom1 = inputParameters.getValue(OverlapsDescriptor.GEOM1);
        Geometry geom2 = inputParameters.getValue(OverlapsDescriptor.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 = geom1.overlaps(geom2);
        outputParameters.getOrCreate(OverlapsDescriptor.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)

Example 49 with ProcessException

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

the class ContainProcess method execute.

@Override
protected void execute() throws ProcessException {
    try {
        final Geometry geom1 = inputParameters.getValue(ContainDescriptor.GEOM1);
        Geometry geom2 = inputParameters.getValue(ContainDescriptor.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.contains(geom2);
        outputParameters.getOrCreate(ContainDescriptor.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)

Example 50 with ProcessException

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

the class CoveredByProcess method execute.

@Override
protected void execute() throws ProcessException {
    try {
        final Geometry geom1 = inputParameters.getValue(GEOM1);
        Geometry geom2 = inputParameters.getValue(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.coveredBy(geom2);
        outputParameters.getOrCreate(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