在ao的帮助里有个Cut polygons sample,你可以看看
Description:
This sample duplicates the 'Cut Polygon Features' task but uses a polygon edit sketch instead of a polyline edit sketch. This task makes it easier to create doughnut polygons for example. The illustration below shows an edit sketch being drawn over a single selected feature. Finishing the sketch creates a new feature by cutting it out from the selected feature.
'This task sets the edit sketch geometry to polygon type and uses this
'geometry as a cookie cutter on selected features
Option Explicit
Implements
IEditTask
Private
m_pEditor As
IEditor
Private
m_pEdSketch As
IEditSketch
Private
m_pMxDoc As
IMxDocument
Private WithEvents
EditorEvents As
Editor
Private Sub
IEditTask_Activate(ByVal
Editor As
esriEditor.IEditor, ByVal
oldTask As
esriEditor.IEditTask)
Set
m_pEditor = Editor
Set
EditorEvents = Editor
Set
m_pEdSketch = Editor
Set
m_pMxDoc = Editor.Parent.Document
'Call Selection changed to see if the sketch tools should be enabled
EditorEvents_OnSelectionChanged
End Sub
Private Sub
IEditTask_Deactivate()
'When the task is deactivated, stop listening for events
Set
EditorEvents = Nothing
End Sub
Private Property Get
IEditTask_Name() As String
IEditTask_Name = "Cut Polygons by Area" 'Give our task a name
End Property
Private Sub
IEditTask_OnDeleteSketch()
End Sub
Private Sub
IEditTask_OnFinishSketch()
On Error GoTo
handler:
Dim
pRefreshArea As
IInvalidArea 'Used to specify the area of the display to refresh
Dim
pOrigFeature As
IFeature 'The selected feature
Dim
pNewFeature As
IFeature 'New feature created during operation
Dim
pEnumFeat As
IEnumFeature
Dim
pCutGeom As
IGeometry 'The geometry that performs the cut - edit sketch
Dim
pRemainder As
IGeometry 'Difference between edit sketch and orig feature (modified orig feature)
Dim
pSubDivision As
IGeometry 'Intersection between edit sketch and orig feaure (new feature)
Dim
pFeatureClass As
IFeatureClass 'The feature class in which to place new features
Dim
pTopoOperator As
ITopologicalOperator
Dim
pFields As
IFields
Dim
pField As
IField
Dim
FieldCount As Integer
'Start an edit operation so we can have undo/redo
m_pEditor.StartOperation
'Get ready to invalidate the features
Set
pRefreshArea = New
InvalidArea
Set
pCutGeom = m_pEdSketch.Geometry 'Get the cutting geometry from the edit sketch
Set
pTopoOperator = pCutGeom
pTopoOperator.Simplify ' make sure the edit sketch geometry is simple
Set
pEnumFeat = m_pEditor.EditSelection 'Get the selected set of editable features
pEnumFeat.Reset
Set
pOrigFeature = pEnumFeat.Next 'Get the next feature in the enumeration (the first one in this case)
If
pOrigFeature Is Nothing Then GoTo
handler 'abort the operation if nothing is selected
'Start a loop for each feature in the selection
Do While Not
pOrigFeature Is Nothing
'Only process polygon features
If
pOrigFeature.Shape.GeometryType = esriGeometryPolygon Then
pRefreshArea.Add pOrigFeature 'Add the feature to the invalidate object
Set
pTopoOperator = pOrigFeature.Shape
Set
pSubDivision = pTopoOperator.Intersect(pCutGeom, esriGeometry2Dimension)
If Not
pSubDivision.IsEmpty Then
Set
pFeatureClass = pOrigFeature.Class
Set
pNewFeature = pFeatureClass.CreateFeature 'Create a new Feature in the same feature class
Set
pNewFeature.Shape = pSubDivision 'Put the subdivided portion into this feature
'Set the original featuer's shape to the results returned from the difference
Set
pRemainder = pTopoOperator.Difference(pCutGeom)
Set
pOrigFeature.Shape = pRemainder
'copy the attributes of the orig feature the new feature
Set
pFields = pOrigFeature.Fields
For
FieldCount = 0 To
pFields.FieldCount - 1 'skip OID and geometry
Set
pField = pOrigFeature.Fields.Field(FieldCount)
If Not
pField.Type = esriFieldTypeGeometry And Not
pField.Type = esriFieldTypeOID _
And
pField.Editable Then
pNewFeature.Value(FieldCount) = pOrigFeature.Value(FieldCount)
End If
Next
FieldCount
pOrigFeature.Store 'Now store the original feature with the remainder geometry
pNewFeature.Store 'Store the subdivided feature
End If
End If
'End check for polygons
Set
pOrigFeature = pEnumFeat.Next 'Get the next feature in the selection
Loop
m_pMxDoc.FocusMap.ClearSelection 'Clear the map's selection
'Refresh the display
Set
pRefreshArea.Display = m_pEditor.Display
pRefreshArea.Invalidate esriAllScreenCaches 'Update the display
m_pEditor.StopOperation ("Cut Polygon Features") 'Complete the edit operation
Exit Sub
handler:
MsgBox "Unable to perform the cut task."
m_pEditor.AbortOperation 'In the event of an error, abort the operation
End Sub
Private Sub
EditorEvents_OnSelectionChanged()
'Only enabled the sketch tools if there is something selected
If
m_pEditor.SelectionCount = 0 Then
m_pEdSketch.GeometryType = esriGeometryNull
Else
m_pEdSketch.GeometryType = esriGeometryPolygon 'Set the edit sketch geometry type
End If
End Sub