woodrow.fields

.splitatpoint creating two line features instead of updating the one

Discussion created by woodrow.fields on Feb 22, 2011
Latest reply on Feb 23, 2011 by woodrow.fields
Hey,

I have some code that I want to split a line segment at a point.  When I run the tool and review my polyline shapefile I see that there is in fact the line segment with a vertex added at the specified point.  The problem is that the old line feature is still there directly underneath the updated feature.  I just want the point added to the feature without creating a whole new feature.  I am attaching the code, please help:


Sub test_Nearest()

Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap
Dim pFLayer As IFeatureLayer
Set pFLayer = pMap.Layer(0) 'Road network must be first in table of contents for this to work, will probably need to adjust code accordingly.
Dim pFSel As IFeatureSelection
Set pFSel = pFLayer
Dim pFClass As IFeatureClass
Set pFClass = pFLayer.FeatureClass
Dim pFCur As IFeatureCursor
Set pFCur = pFClass.Update(Nothing, False) 'selects all the records
Dim pFeat As IFeature
Set pFeat = pFCur.NextFeature
Dim pCurve As ICurve
Set pCurve = pFeat.Shape

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'census block centroid point shape
Dim pFLayer1 As IFeatureLayer
Set pFLayer1 = pMap.Layer(1) 'census block centroids must be second in table.
Dim pFSel1 As IFeatureSelection
Set pFSel1 = pFLayer1
Dim pFClass1 As IFeatureClass
Set pFClass1 = pFLayer1.FeatureClass
Dim pFCur1 As IFeatureCursor
Set pFCur1 = pFClass1.Update(Nothing, False) 'selects all the records
Dim pFeat1 As IFeature
Dim pPoint As IPoint
Set pPoint = pFClass1.GetFeature(0).Shape
Dim pCbRdPnt As IPoint
Set pCbRdPnt = New Point

Dim pFeatureIndex As IFeatureIndex2
Dim pIndexQry As IIndexQuery2
Dim pend As New Point

Set pFeatureIndex = New FeatureIndex
Set pFeatureIndex.FeatureClass = pFClass
Set pIndexQry = pFeatureIndex
pFeatureIndex.Index Nothing, Nothing
Dim ppolyline As IPolyline

Dim lFID As Long, dDis As Double, dist As Double, dist1 As Double, dist2 As Double, dummy As Double
Dim bSplitHappened As Boolean
Dim lNewPart1 As Long, lNewSeg As Long
pIndexQry.NearestFeature pPoint, lFID, dDis

x = dDis

        Set ppolyline = pFClass.GetFeature(lFID).Shape
        d1 = pCurve.Length
        ppolyline.QueryPointAndDistance esriNoExtension, pPoint, False, pCbRdPnt, dummy, dist, False
        distance = dist 'distance from census block point to the closest point on a a curve
        x1 = pCbRdPnt.x  'x coordinate at the closest point on curve
        y1 = pCbRdPnt.y  'y coordinate at the closest point on curve
       
        ppolyline.SplitAtPoint pCbRdPnt, True, False, bSplitHappened, lNewPart1, lNewSeg

        Set pFeat.Shape = ppolyline
        If bSplitHappened Then
        pFeat.Store
        'pFCur.UpdateFeature pFeat
        End If

End Sub

Outcomes