Package org.locationtech.udig.project.command.factory

Examples of org.locationtech.udig.project.command.factory.EditCommandFactory


                            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();
View Full Code Here


        if (featureSource == null) {
            return;
        }
        SimpleFeatureCollection featureCollection = featureSource.getFeatures(selectedLayer.getQuery(true));
        SimpleFeatureIterator featureIterator = featureCollection.features();
        EditCommandFactory cmdFactory = EditCommandFactory.getInstance();
        List<UndoableMapCommand> cmdList = new LinkedList<UndoableMapCommand>();
        count = 0;
        while( featureIterator.hasNext() ) {
            SimpleFeature feature = featureIterator.next();
            Geometry geometry = (Geometry) feature.getDefaultGeometry();
            Geometry newGeometry = geometry.reverse();
            UndoableMapCommand setGeometryCmd = cmdFactory.createSetGeomteryCommand(feature, selectedLayer, newGeometry);
            cmdList.add(setGeometryCmd);
            count++;
        }
        CompositeCommand compositeCommand = new CompositeCommand(cmdList);
        IToolContext toolContext = ApplicationGIS.createContext(ApplicationGIS.getActiveMap());
View Full Code Here

                    Messages.getString("OperationUtils_warning"), Messages.getString("OperationUtils_nofeaturesproblem"), MSGTYPE.WARNING); //$NON-NLS-1$ //$NON-NLS-2$
            return;
        }

        SimpleFeatureIterator featureIterator = featureCollection.features();
        EditCommandFactory cmdFactory = EditCommandFactory.getInstance();
        List<UndoableMapCommand> copyOverList = new LinkedList<UndoableMapCommand>();
        List<UndoableMapCommand> deleteOldList = new LinkedList<UndoableMapCommand>();
        int count = 0;
        while( featureIterator.hasNext() ) {
            SimpleFeature feature = featureIterator.next();
            UndoableMapCommand addFeatureCmd = cmdFactory.createAddFeatureCommand(feature, toLayer);
            copyOverList.add(addFeatureCmd);
            UndoableMapCommand deleteFeatureCmd = cmdFactory.createDeleteFeature(feature, selectedLayer);
            deleteOldList.add(deleteFeatureCmd);
            count++;
        }

        /*
 
View Full Code Here

    public void run(final IProgressMonitor monitor) throws Exception {

        // this may take a while so run it with a busy indicator
        Runnable runnable = new Runnable() {
            public void run() {
                final EditCommandFactory editCommandFactory;
                editCommandFactory = AppGISAdapter.getEditCommandFactory();

                final FeatureIterator<SimpleFeature> iterator = featuresToTrim.features();
                final List<UndoableMapCommand> undoableCommands = new ArrayList<UndoableMapCommand>();
                final TrimGeometryStrategy trimOp = new TrimGeometryStrategy(trimmingLine);
                String fidNotTrimmed = ""; //$NON-NLS-1$
                try {
                    SimpleFeature feature;
                    Geometry original;
                    Geometry trimmed;
                    UndoableMapCommand command;
                    while (iterator.hasNext()) {
                        feature = iterator.next();
                        original = (Geometry) feature.getDefaultGeometry();

                        if (checkTrimPossible(original)) {

                            trimmed = trimOp.trim(original);
                            command = editCommandFactory.createSetGeomteryCommand(feature,selectedLayer, trimmed);
                            undoableCommands.add(command);
                        } else {
                            fidNotTrimmed += feature.getID() + " "; //$NON-NLS-1$
                        }
                    }
View Full Code Here

      throw new RuntimeException(onfe);
    } catch (TransformException te) {
      throw new RuntimeException(te);
    }

    EditCommandFactory editCmdFac = AppGISAdapter.getEditCommandFactory();

    ILayer layer = editLayer;
    SimpleFeatureType schema = layer.getSchema();
    SimpleFeature feature;
    try {
      feature = SimpleFeatureBuilder.build(schema, new Object[1], null);

      assert feature != null : "feature creation fail.";

      Class<? extends Geometry> type = (Class<? extends Geometry>) schema.getGeometryDescriptor().getType()
            .getBinding();
      geom = GeometryUtil.adapt(geom, type);
      feature.setDefaultGeometry(geom);
    } catch (IllegalAttributeException e) {
      throw new RuntimeException(e);
    }
    UndoableMapCommand command = editCmdFac.createAddFeatureCommand(feature, layer);

    handler.setCurrentShape(null);
    handler.setCurrentState(EditState.NONE);

    return command;
View Full Code Here

    assert sourceFeatures != null;
    assert mergedFeature != null;

    // creates the command to delete selected features

    final EditCommandFactory cmdFactory = EditCommandFactory.getInstance();
    final IMap map = layer.getMap();

    List<UndoableMapCommand> cmdList = new LinkedList<UndoableMapCommand>();

    final FeatureIterator<SimpleFeature> iter = sourceFeatures.features();
    while (iter.hasNext()) {
      SimpleFeature feature = iter.next();

      UndoableMapCommand deleteCmd = cmdFactory.createDeleteFeature(feature, layer);
      deleteCmd.setMap(map);
     
      cmdList.add(deleteCmd);
    }
    iter.close();

    // adds the merge feature to new layer
    UndoableMapCommand addCmd = cmdFactory.createAddFeatureCommand(mergedFeature, layer);
    addCmd.setMap(map);
   
    cmdList.add(addCmd);

    assert cmdList.size() >= 3; // Almost two delete and one add command
View Full Code Here

TOP

Related Classes of org.locationtech.udig.project.command.factory.EditCommandFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.