Constructing new features from cursors using IFeatureConstruction
To construct features from cursors using IFeatureConstruction, set the following parameters first:
- IFeatureCursor, which will be the line source to construct polygons
- Processing bounds, which will be used to search for existing polygons in the target feature
- Invalid area object, which is optional and can be used to redraw the area affected by processing—in some cases it may be necessary to have an invalid area in for related features (annotation, route symbology, and so on) to redraw correctly
- Cluster tolerance, which must be at least as large as the cluster tolerance of the spatial reference associated with the target polygon feature class. The value of –1 can be passed for this parameter, signifying that the cluster tolerance of the target feature class's spatial reference is to be used
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:
- You can use ConstructPolygonsFromFeaturesFromCursors if you need to construct polygons into the specified feature class using the cursor as the feature source.
- You can use AutoCompleteFromFeaturesFromCursors if you need to make new features by combining existing polygons with the specified line source.
- You can use SplitPolygonsWithLinesFromCursorif you need to split polygons in the specified feature class using the polyline cursor as the feature source.
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 licensing | Deployment licensing |
---|---|
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |
Engine Developer Kit | Engine Runtime: Geodatabase Update |