I have a polyline shapefile and a polygon shapefile. I need to add vertices to the polylines where they cross polygon boundaries. The polyline length must stay the same, so the Intersect tool doesn't work.

What tool should I use? I just want to add vertices and I will be performing this for dozens of datasets.

EDIT: Below are two attempts that don't work. Code & expected behavior identified.

Base-Case to Check Expected Behavior:

outpath = r'C:\myfolder'
shp_input_lines = r'C:\myfolder\original_lines.shp'
shp_input_polygons = r'C:\myfolder\original_polygons.shp'

# make sure there are no multipart gremlins hidden in here
clean_lines = outpath + '\\' + '_clean_lines.shp'
arcpy.MultipartToSinglepart_management(shp_input_lines, clean_lines)

# add "my_id" field
arcpy.AddField_management(clean_lines, "my_id", "SHORT")
counter = 1
with arcpy.da.UpdateCursor(clean_lines, ["my_id"]) as cursor:
    for row in cursor:
        row[0] = counter
        counter += 1

output1 = outpath + '\\' + '_clean_lines_intersected.shp'
arcpy.Intersect_analysis([clean_lines, shp_input_polygons], output1)

output2 = outpath + '\\' + '_clean_lines_intersected_vertices.shp'
arcpy.FeatureVerticesToPoints_management(output1, output2, point_location="ALL")

CHECKS, this is basis for expected behavior:

  • number of lines in "clean_lines" = 3123
  • number of points in "output2" = 14173

Try 1, Failed: Intersect then Dissolve

# using output1 from above Base-Case
output3 = outpath + '\\' + '_clean_lines_intersected_dissolved.shp'
arcpy.Dissolve_management(output1, output3, dissolve_field="my_id", multi_part="SINGLE_PART", unsplit_lines="DISSOLVE_LINES")
# also tried with unsplit_lines="UNSPLIT_LINES" made no difference

output4 = outpath + '\\' + '_clean_lines_intersected_dissolved_vertices.shp'
arcpy.FeatureVerticesToPoints_management(output3, output4, point_location="ALL")


  • number of lines in "output3" = 3123 (good)
  • number of points in "output4" = 13846 (bad; expected 14173)

Try 2, Failed: Integrate polyline and polygon files

# using clean_lines from above Base-Case
cleancopy = outpath + '\\' + '_clean_lines2.shp'
arcpy.CopyFeatures_management(clean_lines, cleancopy)
arcpy.Integrate_management([cleancopy, shp_input_polygons], "0.1 feet")


  • number of lines in "cleancopy" = 3120 (bad; expected 3123)
  • Are you doing this using ArcPy with ArcGIS Pro or ArcMap? I’m guessing your ArcGIS 10.7 tag indicates ArcMap. What does your code so far look like?
    – PolyGeo
    Nov 1 '19 at 20:27
  • 1
    I do not think that there is an OOTB tool for this. Have you looked in the ArcGIS Code Gallery? gis.stackexchange.com/a/102638/115
    – PolyGeo
    Nov 1 '19 at 20:44
  • 1
    Have you tried using Intersect to split, then unsplitting? Perhaps that leaves a vertex at the split location.
    – PolyGeo
    Nov 1 '19 at 21:31
  • 2
    Integrate is probably your best choice. See (and probably a duplicate of): gis.stackexchange.com/questions/139071/… Nov 1 '19 at 22:28
  • 1
    I think you should use your last comment as an edit to improve your question about Intersect. I also think you should use your and @DanJurgella’s comments about Integrate to write a new question about that approach.
    – PolyGeo
    Nov 3 '19 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.