默认头像
路人甲
路人甲
  • 注册日期2004-05-08
  • 发帖数135
  • QQ
  • 铜币543枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1714回复:1

切割问题

楼主#
更多 发布于:2004-10-21 09:52

请问,在屏幕上画个矩形或多边形,如何得到矩形或多边形内的要素,要素和矩形相交的要切割。但不切割原图层要素,只是临时得到切割后的要素!

如何实现阿,用什么库,什么接口?

喜欢0 评分0
默认头像
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2004-10-21 16:09

在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

GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
默认头像

返回顶部