分类: C/C++
2009-09-28 10:06:52
public void CreatePolygonFeaturesFromCursors(IFeatureClass polygonFC,
IFeatureClass lineFC)
{
if (polygonFC.ShapeType != esriGeometryType.esriGeometryPolygon)
{
System.Console.WriteLine("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 = polygonFC as IGeoDataset;
IEnvelope processingBounds = geoDS.Extent;
//Define an IInValidArea object.
IInvalidArea invalidArea = new InvalidAreaClass();
//Define a construct feature object.
IFeatureConstruction featureConstruction = new FeatureConstructionClass();
//Start an edit session.
IDataset dataset = polygonFC as IDataset;
IWorkspace workspace = dataset.Workspace;
IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;
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 the polygons.*************//
//IWorkspace selWorkspace = polygonFC.FeatureDataset.Workspace;
//ISelectionSet selectionSet;
//featureConstruction.AutoCompleteFromFeaturesFromCursor(polygonFC, processingBounds, lineFeatureCursor,
// invalidArea, -1, selWorkspace, out selectionSet);
//**********Split the 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 the edit operation if errors are detected.
System.Console.WriteLine("Construct polygons failed. " + e.Message);
workspaceEdit.AbortEditOperation();
}
}