Create Point Features where Polylines Intersect

This sample creates new point features wherever two polylines intersect each other.

Products:

ArcView: VBA

Platforms: Windows

Requires: An Edit Session containing a point and a polyline feature class.

Minimum ArcGIS Release: 9.0


How to use:
  1. Select two intersecting polyline features.
  2. Set the editor's target layer to a point feature class.
  3. Paste the code into VBA and run the macro.

								
										Public Sub
								 CreatePointsFromIntersectingPolylines()
  Dim pEditLayers As IEditLayers
  Dim pEditor As IEditor
  Dim pEnumFeature As IEnumFeature
  Dim pFeature As IFeature
  Dim pFeature2 As IFeature
  Dim pGeomColl As IGeometryCollection
  Dim pID As New UID
  Dim pInvalidArea As IInvalidArea
  Dim pPoint As IPoint
  Dim pTopoOptr As ITopologicalOperator
  
  Dim bInOperation As Boolean
  Dim Count As Integer
  
  On Error GoTo ErrorHandler
  
  'Get a handle to the Editor extension
  pID = "esriEditor.Editor"
  Set pEditor = Application.FindExtensionByCLSID(pID)
  Set pEditLayers = pEditor 'QIIf (Not pEditor.SelectionCount = 2) Or (Not pEditLayers.CurrentLayer.FeatureClass.ShapeType = esriGeometryPoint) Then
    MsgBox "Must have exactly two polylines selected and Target Layer must be a point layer."
    Exit Sub
  End If'Loop through the selected features to make sure we have polylines onlySet pEnumFeature = pEditor.EditSelection
  pEnumFeature.Reset
  Set pFeature = pEnumFeature.Next
  Do While Not pFeature Is Nothing
    If Not pFeature.Shape.GeometryType = esriGeometryPolyline Then
      MsgBox "Both seleted features must be a polyline."
      Exit Sub
    End If
    Set pFeature = pEnumFeature.Next
  Loop'Intersect the two polylines creating a multipoint
  pEnumFeature.Reset
  Set pFeature = pEnumFeature.Next
  Set pFeature2 = pEnumFeature.Next
  Set pTopoOptr = pFeature.Shape
  Set pGeomColl = pTopoOptr.Intersect(pFeature2.Shape, esriGeometry0Dimension)
  
  'If no intersection points, exitIf pGeomColl.GeometryCount = 0 Then Exit Sub
   
  Set pInvalidArea = New InvalidArea
  Set pInvalidArea.Display = pEditor.Display

  'Create a new point features at each intersection
  pEditor.StartOperation
  bInOperation = True
  For Count = 0 To pGeomColl.GeometryCount - 1
    Set pPoint = pGeomColl.Geometry(Count)
    Set pFeature = pEditLayers.CurrentLayer.FeatureClass.CreateFeature
    Set pFeature.Shape = pGeomColl.Geometry(Count)
    pFeature.Store
    pInvalidArea.Add pFeature
  Next Count
  pEditor.StopOperation ("Create Points from Intersections")
  bInOperation = False'Refresh the display
  pInvalidArea.Invalidate esriAllScreenCaches
  
  Exit Sub'Exit to avoid error handler
  
ErrorHandler:
  If bInOperation Then
    pEditor.AbortOperation
  End If
  
End Sub

posted on 2006-06-14 17:29 简单就是美 阅读(374) 评论(0)  编辑  收藏 所属分类: ArcGIS开发

导航

统计

常用链接

随笔分类(95)

随笔档案(91)

新闻分类(6)

新闻档案(15)

积分与排名

最新评论

阅读排行榜