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

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - Data Editing forum

Connect/Join two polylines   Matthew Stayner Nov 14, 2005
Re: Connect/Join two polylines   Lori Carpenter Aug 22, 2006
Re: Connect/Join two polylines   Matthew Stayner Aug 22, 2006
Re: Connect/Join two polylines   Kelly Van Allen Aug 22, 2006
Re: Connect/Join two polylines   Matthew Stayner Aug 22, 2006
Re: Connect/Join two polylines   Kelly Van Allen Aug 22, 2006
Re: Connect/Join two polylines   Matthew Stayner Aug 22, 2006
Re: Connect/Join two polylines   Kelly Van Allen Aug 22, 2006
Re: Connect/Join two polylines   Harry Schramm Oct 31, 2006
Re: Connect/Join two polylines   Verena Lima Van Der Ven Oct 31, 2006
Re: Connect/Join two polylines   Richard Fairhurst Nov 25, 2006
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Connect/Join two polylines 
Author Matthew Stayner 
Date Nov 14, 2005 
Message Real basic question: How do I join two seperate polylines? Something like MERGE would work, except I only want it to join the two polylines if their endpoints are "snapped" together.


Thanks,

Matt 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Connect/Join two polylines 
Author Lori Carpenter 
Date Aug 22, 2006 
Message Did you get an answer to this?
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Connect/Join two polylines 
Author Matthew Stayner 
Date Aug 22, 2006 
Message No. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Connect/Join two polylines 
Author Kelly Van Allen 
Date Aug 22, 2006 
Message Hi Matt!

The simplest way I can tell you about is to open up an editor session for that shapefile, select the two polylines that you want to merge, then in the editor menu, select 'merge' as the option!

This will work for two polylines that are snapped like you said you have!!!

Cheers!

 
  Kelly Van Allen
GIS Technician
Sudbury, Ontario 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Connect/Join two polylines 
Author Matthew Stayner 
Date Aug 22, 2006 
Message That approach works fine. But I have a situation where I do not know if the two lines are snapped, and I don't want them to merge unless they are joined. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Connect/Join two polylines 
Author Kelly Van Allen 
Date Aug 22, 2006 
Message Just out of curiosity, how many of these polylines do you have? 
  Kelly Van Allen
GIS Technician
Sudbury, Ontario 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Connect/Join two polylines 
Author Matthew Stayner 
Date Aug 22, 2006 
Message The are a lot of polylines. That is why I am trying to find some sort of automated method to check the snapping. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Connect/Join two polylines 
Author Kelly Van Allen 
Date Aug 22, 2006 
Message Hi Matt

I just checked with a co-worker...and we can't tell you if there is any automated process. If there is, I would love to know!!!

My suggestion would be to repost this thread (as it has a star beside it which means that someone has answered your question).

sorry I couldn't help! 
  Kelly Van Allen
GIS Technician
Sudbury, Ontario 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Connect/Join two polylines 
Author Harry Schramm 
Date Oct 31, 2006 
Message Have a look at this site. There a lots of tools you might find do the job for you.
http://www.ian-ko.com/

Harry Schramm 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Connect/Join two polylines 
Author Verena Lima Van Der Ven 
Date Oct 31, 2006 
Message Hi!

I'm having the same problem here. I have 2 shapefiles, hidrography shapefiles, and I really need to join it, but since they are polylines, I can't merge, or even union it. Does anyone knows How can I do that?

Thak you! 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Connect/Join two polylines 
Author Richard Fairhurst 
Date Nov 25, 2006 
Message To merge polylines try the following code. The code assumes the polylines you want to merge have the same spatial reference and that you have pretested the features involved for common attributes that would be appropriate to merge.

If your PolyLines have M values, you will have to add code to handle that. You would probably first drop the M values using the IMAware interface and then recreate them. To recreate the M values you could interate through the ISegementCollection in the code below or use the IMSegmentation interface.

NOTES: If your lines have attributes that are dependent on the digitized direction of the line, set bCanReverse to False (or add code to handle attribute reversals in the case of pPolyLine1 having its orientation reversed). The MergeSnappedLines function may result in a PolyLine with self-overlapping segments. The ITopologicalOperator in the shell function tests the resulting line to see if it is simple and simplifies the polyline if it is not. I also do not use Union from the ITopologicalOperator to merge the lines because if the lines form a loop the ITopologicalOperator can redefine the beginning point of the line differently from either original polyline while the AddSegmentCollection function of ISegmentCollection will not.

If anyone uses this, please let me know how it worked for you.

Rich 
 
Private Function MergeLineFeature(ByRef pFeature1 As IFeature, ByRef pFeature2 As IFeature) As Boolean
  ' An example shell Function to show how to use
  ' the MergeSnappedLines Function.  Assumes you
  ' have selected two features that share
  ' attributes you want merged.  pFeature1 would
  ' contain the attributes you want to preserve.
  ' You also might want to add code to
  ' open an Edit session and use Edit Operations
  ' that would allow you to undo the merges.
  Dim pPolyLine1 As IPolyline
  Dim pPolyLine2 As IPolyline
  Dim pTempLine As IPolyline
  Set pPolyLine1 = pFeature1.ShapeCopy
  Set pPolyLine2 = pFeature2.ShapeCopy
  Set pTempLine = MergeSnappedLines(pPolyLine1, pPolyLine2, True)
  If Not pTempLine Is Nothing Then
    Dim pTopoOp As ITopologicalOperator
    Set pTopoOp = pTempLine
    If Not pTopoOp.IsSimple Then
      pTopoOp.Simplify
    End If
    pFeature2.Delete
    Set pFeature1.Shape = pTempLine
    pFeature1.Store
    MergeLineFeature = True
  Else
    MergeLineFeature = False
  End If
End Function

Private Function MergeSnappedLines(ByRef pPolyLine1 As IPolyline, ByRef pPolyLine2 As IPolyline, _
ByVal bCanReverse As Boolean) As IPolyline
  Dim pTempLine As IPolyline
  Dim pSegmentCol1 As ISegmentCollection
  Dim pSegmentCol2 As ISegmentCollection
  Set pTempLine = New Polyline
  If pPolyLine1.ToPoint.X = pPolyLine2.FromPoint.X And pPolyLine1.ToPoint.Y = pPolyLine2.FromPoint.Y Then
    Set pSegmentCol1 = pPolyLine1
    Set pSegmentCol2 = pPolyLine2
    pSegmentCol1.AddSegmentCollection pSegmentCol2
    Set pTempLine = pSegmentCol1
  ElseIf pPolyLine1.FromPoint.X = pPolyLine2.ToPoint.X And pPolyLine1.FromPoint.Y = pPolyLine2.ToPoint.Y Then
    Set pSegmentCol1 = pPolyLine1
    Set pSegmentCol2 = pPolyLine2
    pSegmentCol2.AddSegmentCollection pSegmentCol1
    Set pTempLine = pSegmentCol2
  ElseIf pPolyLine1.ToPoint.X = pPolyLine2.ToPoint.X And pPolyLine1.ToPoint.Y = pPolyLine2.ToPoint.Y _
  And bCanReverse Then
    pPolyLine2.ReverseOrientation
    Set pSegmentCol1 = pPolyLine1
    Set pSegmentCol2 = pPolyLine2
    pSegmentCol1.AddSegmentCollection pSegmentCol2
    Set pTempLine = pSegmentCol1
  ElseIf pPolyLine1.FromPoint.X = pPolyLine2.FromPoint.X And pPolyLine1.FromPoint.Y = pPolyLine2.FromPoint.Y _
  And bCanReverse Then
    pPolyLine1.ReverseOrientation
    Set pSegmentCol1 = pPolyLine1
    Set pSegmentCol2 = pPolyLine2
    pSegmentCol1.AddSegmentCollection pSegmentCol2
    Set pTempLine = pSegmentCol1
  Else
    Set pTempLine = Nothing
  End If
  Set MergeSnappedLines = pTempLine
End Function