2

I am trying to remove polyline vertex which are outside the buffer polygon and not creates new vertex on intersection.

Wrong

I found a script which remove vertex but inside polygon. What is more it creates new vertex on intersection. It may help with this task.

Wrong output

import itertools, arcpy
arcpy.env.overwriteOutput = True
line_FC = arcpy.GetParameterAsText(0)
poly_FC = arcpy.GetParameterAsText(1)
output = arcpy.GetParameterAsText(2)

#clone input lines to memory for fast processing
temp = arcpy.CopyFeatures_management(line_FC, "in_memory/temp")

polygons = arcpy.CopyFeatures_management(poly_FC, arcpy.Geometry())

for poly in polygons:
    with arcpy.da.UpdateCursor(temp, ["SHAPE@"]) as uCursor:
        for line in uCursor:
            line = line[0]
            diff = line.difference(poly)
            #if the two lines are not equal, that means it intersected the polygon
            if not line.equals(diff):
                #the result of geometry.difference() is a multipart line of only those
                #parts that lie outside the polyon
                parts = diff.getPart()

                #if parts is empty that means the line is completely within the polygon
                #i.e., no difference
                if parts:
                    #We'll need to "join" the end of part1 to the beginning of part2
                    #so we'll just flatten the list of lists
                    joined = list(itertools.chain.from_iterable(parts))

                    #and create a new polyline object to update the shape
                    poly_trimmed = arcpy.Polyline(arcpy.Array(joined))
                    uCursor.updateRow([poly_trimmed])

arcpy.CopyFeatures_management(temp, output)

Is there a way to do it in arcpy? I am using ArcGIS Pro 1.3.

1

You could try something along these lines.

for points in parts:
    if not arcpy.Point(points.X, points.Y).within(poly):
         del points

I didn't test this out or anything, just a few thoughts I had.

  • Sorry but i can not get geometry from array – Losbaltica Feb 5 '17 at 15:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.