class RectangularClipProcess implements VectorProcess {

    @DescribeResult(name = "result", description = "Clipped feature collection")
    public SimpleFeatureCollection execute(
            @DescribeParameter(name = "features", description = "Input feature collection") SimpleFeatureCollection features,
            @DescribeParameter(name = "clip", description = "Bounds of clipping rectangle") ReferencedEnvelope clip,
            @DescribeParameter(name = "preserveZ",min=0, description = "Attempt to preserve Z values from the original geometry (interpolate value for new points)") Boolean preserveZ)
            throws ProcessException {
        CoordinateReferenceSystem featuresCRS = features.getSchema().getCoordinateReferenceSystem();
        if (featuresCRS != null && clip.getCoordinateReferenceSystem() != null
                && !CRS.equalsIgnoreMetadata(featuresCRS, clip.getCoordinateReferenceSystem())) {
            boolean lenient = true;
            try {
                clip = clip.transform(featuresCRS, lenient);
            } catch (TransformException e) {
                throw new ProcessException(e);
            } catch (FactoryException e) {
                throw new ProcessException(e);
            }
        }
        return new ClipProcess().execute(features, JTS.toGeometry(clip), preserveZ);
    }

}