LineString splitterInMapCrs)
throws SplitFeaturesCommandException {
ProjectPlugin.log(className + " - Split original: " + splitterInMapCrs.toText()); //$NON-NLS-1$
final EditCommandFactory cmdFac = EditCommandFactory.getInstance();
final FeatureIterator<SimpleFeature> featureToSplitIterator = featuresToSplit.features();
final CoordinateReferenceSystem mapCRS = handler.getContext().getCRS();
try {
List<SimpleFeature> originalFeatureList = asList(featureToSplitIterator);
if(originalFeatureList.isEmpty()){
throw new SplitFeaturesCommandException(Messages.SplitFeaturesCommand_did_not_apply_to_any_feature);
}
ProjectPlugin.log(className + " - Split using CRS: " + mapCRS.toString()); //$NON-NLS-1$
SplitFeatureBuilder builder = SplitFeatureBuilder.newInstance(originalFeatureList, splitterInMapCrs, mapCRS);
try {
builder.buildSplit();
} catch (CannotSplitException e) {
throw new SplitFeaturesCommandException(e.getMessage());
}
// make the requires list of commands to update the affected features
final List<UndoableMapCommand> undoableCommands = new LinkedList<UndoableMapCommand>();
// delete the features that suffered split
List<SimpleFeature> featuresThatSufferedSplit = builder.getFeaturesThatSufferedSplit();
for (SimpleFeature feature : featuresThatSufferedSplit) {
UndoableMapCommand command = cmdFac.createDeleteFeature(feature, selectedLayer);
undoableCommands.add(command);
ProjectPlugin.log(className + " - Delete original feature: " + ((Geometry) feature.getDefaultGeometry()).toText()); //$NON-NLS-1$
}
// add the new features
List<SimpleFeature> splitResult = builder.getSplitResult();
for (SimpleFeature feature : splitResult) {
UndoableMapCommand command = cmdFac.createAddFeatureCommand(feature, selectedLayer);
undoableCommands.add(command);
ProjectPlugin.log(className + " - Split result: " + ((Geometry) feature.getDefaultGeometry()).toText()); //$NON-NLS-1$
}
// modify the neighbor features.
builder.buildNeighbours();