Search in sources :

Example 11 with ProcessException

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

the class DifferenceProcess method execute.

@Override
protected void execute() throws ProcessException {
    try {
        final Geometry geom1 = inputParameters.getValue(DifferenceDescriptor.GEOM1);
        Geometry geom2 = inputParameters.getValue(DifferenceDescriptor.GEOM2);
        Geometry result = JTS.getFactory().buildGeometry(Collections.emptyList());
        // ensure geometries are in the same CRS
        final CoordinateReferenceSystem resultCRS = JTS.getCommonCRS(geom1, geom2);
        if (JTS.isConversionNeeded(geom1, geom2)) {
            geom2 = JTS.convertToCRS(geom2, resultCRS);
        }
        result = (Geometry) geom1.difference(geom2);
        if (resultCRS != null) {
            JTS.setCRS(result, resultCRS);
        }
        outputParameters.getOrCreate(DifferenceDescriptor.RESULT_GEOM).setValue(result);
    } 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 12 with ProcessException

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

the class EnvelopeProcess method execute.

@Override
protected void execute() throws ProcessException {
    try {
        final Geometry geom = inputParameters.getValue(EnvelopeDescriptor.GEOM);
        final CoordinateReferenceSystem geomCRS = JTS.findCoordinateReferenceSystem(geom);
        final Geometry result = geom.getEnvelope();
        JTS.setCRS(result, geomCRS);
        outputParameters.getOrCreate(EnvelopeDescriptor.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 13 with ProcessException

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

the class EqualsExactProcess 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;
        if (inputParameters.getValue(TOLERANCE) != null) {
            final Double tolerance = inputParameters.getValue(TOLERANCE);
            result = (Boolean) geom1.equalsExact(geom2, tolerance);
        } else {
            result = (Boolean) geom1.equalsExact(geom2);
        }
        outputParameters.getOrCreate(RESULT).setValue(result);
    } catch (TransformException 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) ProcessException(org.geotoolkit.process.ProcessException) FactoryException(org.opengis.util.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 14 with ProcessException

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

the class IntersectionProcess 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 Geometry result = (Geometry) geom1.intersection(geom2);
        if (resultCRS != null) {
            JTS.setCRS(result, resultCRS);
        }
        outputParameters.getOrCreate(RESULT_GEOM).setValue(result);
    } 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 15 with ProcessException

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

the class CreateDBProcess method execute.

@Override
protected void execute() throws ProcessException {
    ArgumentChecks.ensureNonNull("inputParameters", inputParameters);
    final String dbURL = (String) inputParameters.parameter(CreateDBDescriptor.DBURL.getName().getCode()).getValue();
    final String user = (String) inputParameters.parameter(CreateDBDescriptor.USER.getName().getCode()).getValue();
    final String password = (String) inputParameters.parameter(CreateDBDescriptor.PASSWORD.getName().getCode()).getValue();
    final DefaultDataSource ds = new DefaultDataSource(dbURL);
    try {
        final EPSGFactory installer = new EPSGFactory(Collections.singletonMap("dataSource", ds));
        try (Connection c = ds.getConnection(user, password)) {
            installer.install(c);
        }
    } catch (FactoryException | SQLException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
}
Also used : ProcessException(org.geotoolkit.process.ProcessException) EPSGFactory(org.apache.sis.referencing.factory.sql.EPSGFactory) FactoryException(org.opengis.util.FactoryException) SQLException(java.sql.SQLException) DefaultDataSource(org.geotoolkit.internal.sql.DefaultDataSource) Connection(java.sql.Connection)

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