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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations