You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - Data Editing forum

Breaking Up Polylines   Randy McGregor Sep 30, 2002
Re: Breaking Up Polylines   Kirk Kuykendall Sep 30, 2002
Re: Breaking Up Polylines   Randy McGregor Oct 01, 2002
Re: Breaking Up Polylines   Ianko Tchoukanski Oct 01, 2002
Re: Breaking Up Polylines   Randy McGregor Oct 01, 2002
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Breaking Up Polylines 
Author Randy McGregor 
Date Sep 30, 2002 
Message Does anyone know how to break up a polyline so that each of the lines that make it up becomes a separate line. This was possible in ArcView (at least with polygons). It was called "exploding" the feature.

Can this be done in ArcMap?

Thank you for your time.

Randy McGregor 
  Randy McGregor
Minneapolis, MN 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Breaking Up Polylines 
Author Kirk Kuykendall 
Date Sep 30, 2002 
Message I haven't tested this much ... seems like there should be something already in ArcMap that does this, but not sure.

kkeywords explode 
 
Option Explicit
Sub Explode()
    Dim pUID As New UID
    pUID.Value = "esricore.Editor"
    
    Dim pEditor As IEditor
    Set pEditor = Application.FindExtensionByCLSID(pUID)
    
    If pEditor.EditState <> esriStateEditing Then
        Exit Sub
    End If
    
    Dim pEditlayers As IEditLayers
    Set pEditlayers = pEditor
    
    If pEditlayers.CurrentLayer.FeatureClass.ShapeType <> esriGeometryPolyline Then
        Exit Sub
    End If
    
    Dim pFSel As IFeatureSelection
    Set pFSel = pEditlayers.CurrentLayer
    
    If pFSel.SelectionSet.Count = 0 Then Exit Sub
    
    Dim pFCur As IFeatureCursor
    pFSel.SelectionSet.Search Nothing, False, pFCur
    
    pEditor.StartOperation
    Dim pFeat As IFeature
    Set pFeat = pFCur.NextFeature
    Do Until pFeat Is Nothing
        Dim pInSegColl As ISegmentCollection
        Set pInSegColl = pFeat.ShapeCopy
        Application.StatusBar.Message(0) = "Exploding " & pFeat.OID
        Dim l As Long
        For l = 0 To pInSegColl.SegmentCount - 1
            Dim pOutSegColl As ISegmentCollection
            Set pOutSegColl = New Polyline
            pOutSegColl.AddSegment pInSegColl.Segment(l)
            Dim pOutFeat As IFeature
            Set pOutFeat = pEditlayers.CurrentLayer.FeatureClass.CreateFeature
            Dim k As Long
            For k = 0 To pOutFeat.Fields.FieldCount - 1
                If pOutFeat.Fields.Field(k).Editable Then
                    If pOutFeat.Fields.Field(k).Type <> esriFieldTypeGeometry Then
                        pOutFeat.Value(k) = pFeat.Value(k)
                    End If
                End If
            Next k
            Set pOutFeat.Shape = pOutSegColl
            pOutFeat.Store
        Next l
        pFeat.Delete
        Set pFeat = pFCur.NextFeature
    Loop
    pEditor.StopOperation "Explode"
    
    Dim pMxDoc As IMxDocument
    Set pMxDoc = pEditor.Parent.Document
    Dim pAV As IActiveView
    Set pAV = pMxDoc.FocusMap
    Dim lCacheID As Long
    lCacheID = pAV.ScreenCacheID(esriViewGeoSelection, Nothing)
    pAV.ScreenDisplay.Invalidate Nothing, True, lCacheID
End Sub

 
  Kirk Kuykendall
AmberGIS Programming Services & Sales
http://www.ambergis.com
Now Answering questions at:
http://gis.stackexchange.com/


 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Breaking Up Polylines 
Author Randy McGregor 
Date Oct 01, 2002 
Message I appreciate it Kirk,

This code, however, breaks things up too much. (Boy, does that sound ungrateful!). I will take a look at it, and maybe modify it if I can.

As an example of what I mean, I have one line shapefile that only has one "troublesome" line - a line that is a conglomeration of disconnected lines. The rest of the lines are OK.

After running the code, many of the lines have been broken up into sometimes extremely short segments.

A code (or built-in feature) that would find only multipart lines and break them up into their separate parts would be helpful.

Another thing that works, but is cumbersome, is to convert the shapefile into a coverage, and then back into a shapefile.

Thanks again,

Randy McGregor 
  Randy McGregor
Minneapolis, MN 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Breaking Up Polylines 
Author Ianko Tchoukanski 
Date Oct 01, 2002 
Message You can use the Explode function of ET GeoWizards 8.3a (download from http://www.ian-ko.com). The function is free with the unregistered version of the software. 
  http://www.ian-ko.com 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Breaking Up Polylines 
Author Randy McGregor 
Date Oct 01, 2002 
Message It appears as though IGeometryCollection is the way to go here, rather than ISegmentCollection. I noticed that the "ISegmentCollection" version created 905 line segments (from 15 polylines). ISegmentCollection created a line for every Single PAIR of vertices - 905 straight, two vertex lines.

There is no way I could have put this thing together at this point. Thanks for getting the ball rolling.

Hopefully, this can be useful to other users. Multipart lines can be a huge pain when you don't want them.

 
 
Sub ExplodePolyLines()
    '  
    ' From the original by Kirk Kuykendall.
    '
    Dim pUID As New UID
    pUID.Value = "esricore.Editor"
    
    Dim pEditor As IEditor
    Set pEditor = Application.FindExtensionByCLSID(pUID)
    
    If pEditor.EditState <> esriStateEditing Then
        MsgBox "Make a shapefile editable."
        Exit Sub
    End If
    
    Dim pEditlayers As IEditLayers
    Set pEditlayers = pEditor
    
    If pEditlayers.CurrentLayer.FeatureClass.ShapeType <> esriGeometryPolyline Then
        Exit Sub
    End If
    
    Dim pFSel As IFeatureSelection
    Set pFSel = pEditlayers.CurrentLayer
    
    If pFSel.SelectionSet.Count = 0 Then
      MsgBox "Select features to be broken up."
      Exit Sub
    End If
    
    Dim pFCur As IFeatureCursor
    pFSel.SelectionSet.Search Nothing, False, pFCur
    
    pEditor.StartOperation
    Dim pFeat As IFeature
    Set pFeat = pFCur.NextFeature
    Do Until pFeat Is Nothing
        Dim pInGeomColl As IGeometryCollection
'''        Dim pInSegColl As ISegmentCollection
'''        Set pInSegColl = pFeat.ShapeCopy
        Set pInGeomColl = pFeat.ShapeCopy
       
        Application.StatusBar.Message(0) = "Exploding " & pFeat.OID
        Dim l As Long
'''        For l = 0 To pInSegColl.SegmentCount - 1
        For l = 0 To pInGeomColl.GeometryCount - 1
'''            Dim pOutSegColl As ISegmentCollection
'''            Set pOutSegColl = New Polyline
            Dim pOutGeomColl As IGeometryCollection
            Set pOutGeomColl = New Polyline
'''            pOutSegColl.AddSegment pInSegColl.Segment(l)
            pOutGeomColl.AddGeometry pInGeomColl.Geometry(l)
            Dim pOutFeat As IFeature
            Set pOutFeat = pEditlayers.CurrentLayer.FeatureClass.CreateFeature
            Dim k As Long
            For k = 0 To pOutFeat.Fields.FieldCount - 1
                If pOutFeat.Fields.Field(k).Editable Then
                    If pOutFeat.Fields.Field(k).Type <> esriFieldTypeGeometry Then
                        pOutFeat.Value(k) = pFeat.Value(k)
                    End If
                End If
            Next k
'''            Set pOutFeat.Shape = pOutSegColl
            Set pOutFeat.Shape = pOutGeomColl
            pOutFeat.Store
        Next l
        pFeat.Delete
        Set pFeat = pFCur.NextFeature
    Loop
    pEditor.StopOperation "Explode"
    
    Dim pMxDoc As IMxDocument
    Set pMxDoc = pEditor.Parent.Document
    Dim pAV As IActiveView
    Set pAV = pMxDoc.FocusMap
    Dim lCacheID As Long
    lCacheID = pAV.ScreenCacheID(esriViewGeoSelection, Nothing)
    pAV.ScreenDisplay.Invalidate Nothing, True, lCacheID
    MsgBox "Done"
End Sub
 
  Randy McGregor
Minneapolis, MN