The following demonstrates how to modify a polyline geometry object.
- modifyOneVertexOfAPolyline shows how to modify a polyline vertex using Hittest.
- modifyOneSegmentOfAPolyline shows how to modify a polyline segment using Hittest.
How to use
- Use this code in VBA
'*************************************************************************
'* NAME: modifyOneVertexOfAPolyline
'* DESCRIPTION: Modify a vertex of a multipart polyline using hittest to identify the vertex,
'* move it and set the point back in the polyline.
'* NOTE:
'*************************************************************************
Sub modifyOneVertexOfAPolyline()
Dim pPolColl As IGeometryCollection, pPol As IPolyline, pHitTest As IHitTest, pTrans2D As ITransform2D, pPathColl As IPointCollection
Dim pqpt As IPoint, dr As Double, pHit As IPoint, dht As Double, lPart As Long, lVertex As Long, bright As Boolean
Set pPolColl = FunctionCreateMultiPartPolylineViaIGeometryCollection 'Here the polyline to be modified
Set pPol = pPolColl
Set pHitTest = pPolColl
Set pqpt = pPol.FromPoint 'This could be a user input point (Ex: Mouse click etc.)
dr = 1
Set pHit = New esriGeometry.Point 'Create the output point
pHitTest.HitTest pqpt, dr, esriGeometryPartVertex, pHit, dht, lPart, lVertex, bright
Set pPathColl = pPolColl.Geometry(lPart) 'Get the path where the point is
Set pTrans2D = pPathColl.Point(lVertex) 'Get the vertex that got hit
pTrans2D.Move -10, 0 'Move the point
pPathColl.UpdatePoint lVertex, pTrans2D 'Update the point via IPointCollection
pPolColl.GeometriesChanged 'To let the polyline knows its geometry changed
End Sub
'*************************************************************************
'* NAME: modifyOneSegmentOfAPolyline
'* DESCRIPTION: Modify a segment of a multipart polyline using hittest to identify the segment and
'* move it.
'* NOTE:
'*************************************************************************
Sub modifyOneSegmentOfAPolyline()
Dim pPolColl As IGeometryCollection, pPol As IPolyline, pHitTest As IHitTest, pTrans2D As ITransform2D, pPathColl As ISegmentCollection
Dim pqpt As IPoint, dr As Double, pHit As IPoint, dht As Double, lPart As Long, lSeg As Long, bright As Boolean
Set pPolColl = FunctionCreateMultiPartPolylineViaIGeometryCollection 'Here the polyline to be modified
Set pPol = pPolColl
Set pHitTest = pPolColl
Set pqpt = pPol.FromPoint 'This could be a user input point (Ex: Mouse click etc.)
dr = 1
Set pHit = New esriGeometry.Point
pHitTest.HitTest pqpt, dr, esriGeometryPartBoundary, pHit, dht, lPart, lSeg, bright
Set pPathColl = pPolColl.Geometry(lPart) 'Get the path where the point is
Set pTrans2D = pPathColl.Segment(lSeg) 'Get the segment that got hit
pTrans2D.Move -10, 0
'In this case the segment doesn't have to be set back in the geometry, since the segment
'was returned by reference by pPathColl.Segment(lSeg)
pPolColl.GeometriesChanged 'To let the polyline knows its geometry changed
End Sub