0
cursor=arcpy.da.searchCursor("mettaled", "SHAPE@")
for row in cursor:
 geom=row[0]
 for part in geom:
 for pnt in part:
 x,y=pnt.X, pnt.Y
 print x,y

I am trying to merge the intersected line together(one feature class), but the problem is that some of those line having gaps and not intersected 100%. note: I used to do it with 'unsplit line' then 'spatial join' but that didn't work with gaped lines.

Can anyone do that with arcpy like list coordinates of the lines and connect-append the end point with the start of the next line

example of only two line

asked Apr 3, 2022 at 7:17
4
  • What happened when you ran the code that you’ve presented? Commented Apr 3, 2022 at 10:51
  • Looking over your code, it appears you have a multi-part polyline that you want to convert into a single-part polyline (which involves removing the gap). Is that correct? Commented Apr 3, 2022 at 15:40
  • @PolyGeo it bring the x,y of all the line vertex Commented Apr 4, 2022 at 4:42
  • exactly that's what am looking for @bixb0012 Commented Apr 4, 2022 at 4:43

1 Answer 1

0

What will work in this situation since the parts are inline with each other is to take the points from each part and create a new, single ArcPy array and pass that to the Polyline constructor to create a new single-part polyline.

>>> import arcpy
>>> 
>>> install_info = arcpy.GetInstallInfo()
>>> f"{install_info['ProductName']}, {install_info['Version']}"
'ArcGISPro, 2.9.1'
>>> 
>>> # illustrative code for combining multi-part polyline to single-part polyline
>>> multi_polyline = arcpy.FromWKT('MULTILINESTRING((0 0, 2 0, 2 1, 4 1),(8 2, 10 2, 12 4))')
>>> multi_polyline.isMultipart
True
>>> multi_polyline.partCount
2
>>>
>>> single_polyline = arcpy.Polyline(
... arcpy.Array([vertex for part in multi_polyline for vertex in part])
... )
>>> single_polyline.isMultipart
False
>>> single_polyline.partCount
1
>>>
>>> # modified OP code to combine multi-part polyline to single-part polyline
with arcpy.da.SearchCursor("mettaled", "SHAPE@") as cur:
 for shape, in cur: # notice the comma after shape for tuple unpacking
 new_shape = arcpy.Polyline(
 arcpy.Array([vertex for part in shape for vertex in part]),
 shape.spatialReference
 )
 cur.updateRow([new_shape])
 
>>> 
answered Apr 4, 2022 at 14:36
2
  • thanks for helping, but am beginner at python so if you don't mind can you clarify it more? like if I need to change any of the Parameter or any thing else Commented Apr 5, 2022 at 6:29
  • @saraghafri, I updated my code block to include modifications to your code that should work. Commented Apr 5, 2022 at 13:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.