0

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
        cursor.updateRow(row)
        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")

CHECKS:

  • 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")

CHECKS:

  • number of lines in "cleancopy" = 3120 (bad; expected 3123)
a11
  • 940
  • 10
  • 22
  • 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 01 '19 at 20:27
  • ArcMap. No code, I don't know which tool to use. Code will presumably be a one-liner like "arcpy.Intersect_analysis([shp1_in, shp2_in], shp_out)" – a11 Nov 01 '19 at 20:38
  • 1
    I do not think that there is an OOTB tool for this. Have you looked in the ArcGIS Code Gallery? https://gis.stackexchange.com/a/102638/115 – PolyGeo Nov 01 '19 at 20:44
  • Thanks @PolyGeo, I'll have a look. Can't believe there's no OOTB solution, but guess that explains why I couldn't find a tool – a11 Nov 01 '19 at 21:10
  • I’m sure that there’s millions of tools that could be built but there’s only so much room in the ArcGIS toolbox, and why it’s so easily extended using the Geoprocessing Framework. – PolyGeo Nov 01 '19 at 21:29
  • 1
    Have you tried using Intersect to split, then unsplitting? Perhaps that leaves a vertex at the split location. – PolyGeo Nov 01 '19 at 21:31
  • 2
    Integrate is probably your best choice. See (and probably a duplicate of): https://gis.stackexchange.com/questions/139071/automatically-add-vertex-to-polygon-where-vertex-of-another-polygon-touches-it/139081#139081 – Dan Jurgella Nov 01 '19 at 22:28
  • @DanJurgella that sounds well worth trying. I think it will need a Standard or Advanced level license. – PolyGeo Nov 01 '19 at 22:52
  • @DanJurgella Seemed like a good idea, but did not perform as expected. Input polyline SHP had 3123 lines; output after integrate with polygon SHP was 3120 lines. Regardless of whether or not it is adding the vertices, it is eating up lines somewhere. (Input polyline SHP had already been converted from multipart to single part, so that's not the issue.) – a11 Nov 03 '19 at 23:28
  • @PolyGeo also, I tried Intersect then Dissolve (on "my_id") ... unfortunately dissolve seems to remove the added vertices. Unsplit removes the vertices, as described in the doc http://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/unsplit-line.htm – a11 Nov 03 '19 at 23:44
  • 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 03 '19 at 23:47

0 Answers0