How to construct new features from cursors using IFeatureConstruction


Summary
This article explains how to make new polygon features from existing line feature cursors using the methods in IFeatureConstruction interface.


Constructing new features from cursors using IFeatureConstruction

To construct features from cursors using IFeatureConstruction, set the following parameters first:
 
The construct features methods should also be performed in an edit session and edit operation so that you can have undo and redo capabilities.
The following are some methods you can choose to construct polygon features based on your needs:
The following code shows how to construct polygons using ConstructPolygonsFromFeaturesFromCursors methods, and the code using the other two methods are in the comment session:
[Java]
static void createPolygonFeaturesFromCursors(IFeatureClass polygonFC, IFeatureClass
    lineFC)throws Exception{
    if (polygonFC.getShapeType() != esriGeometryType.esriGeometryPolygon){
        System.out.println("The target layer is not a polygon layer.");
        return ;
    }

    // Set IFeatureCursor object which will be the line source to construct
    // polygons.
    IFeatureCursor lineFeatureCursor = lineFC.search(null, false);

    // Set the processing bounds to be the extent of the polygon feature class,
    // which will be used to search for existing polygons in the target feature.
    IGeoDataset geoDS = new IGeoDatasetProxy(polygonFC);
    IEnvelope processingBounds = geoDS.getExtent();

    // Define an IInValidArea object.
    IInvalidArea invalidArea = new InvalidArea();

    // Define a construct feature object
    IFeatureConstruction featureConstruction = new FeatureConstruction();

    // Start an edit session.
    IDataset dataset = new IDatasetProxy(polygonFC);
    IWorkspace workspace = dataset.getWorkspace();
    IWorkspaceEdit workspaceEdit = new IWorkspaceEditProxy(workspace);

    if (workspaceEdit.isBeingEdited() != true){
        workspaceEdit.startEditing(true);
        workspaceEdit.startEditOperation();
    }


    try{
        // **********Construct polygons using the line feature cursor************//
        featureConstruction.constructPolygonsFromFeaturesFromCursor(null, polygonFC,
            processingBounds, true, false, lineFeatureCursor, invalidArea,  - 1,
            null);

        // **********AutoComplete polygons*************//
        // IWorkspace selWorkspace = polygonFC.getFeatureDataset().getWorkspace();
        // ISelectionSet selectionSet;
        // featureConstruction.autoCompleteFromFeaturesFromCursor(polygonFC,
        // processingBounds, lineFeatureCursor,
        // invalidArea, -1, selWorkspace, out selectionSet);

        // **********Split polygons***************//
        // featureConstruction.splitPolygonsWithLinesFromCursor(null, polygonFC,
        // processingBounds,
        // lineFeatureCursor, invalidArea, -1);

        // Complete the edit operation and stop the edit session.
        workspaceEdit.stopEditOperation();
        workspaceEdit.stopEditing(true);
    }
    catch (Exception e){
        // Abort edit operation if errors are detected.
        System.out.println("Construct polygons failed. " + e.getMessage());
        workspaceEdit.abortEditOperation();
    }
}






Development licensingDeployment licensing
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced
Engine Developer KitEngine: Geodatabase Update