I have a layer of points and a layer of lines (shapefiles), that have been split so the lines have 2 vertices.
If a line touches one of the points I need to change the direction of the line, I have seen several codes but I have not been able to actually flip my lines although I am sure most lines are touching the points. This code runs without error but it does nothing.
I am using ArcMap 10.6.1.
points = []
with arcpy.da.SearchCursor(layerP, "SHAPE@") as p_cur:
for row in p_cur:
points.append(row[0])
lines_to_flip = []
sr = arcpy.Describe(layerD).spatialReference
##try:
with arcpy.da.UpdateCursor(layerD, ['OID@', 'SHAPE@']) as dropCursor:
for dropRow in dropCursor:
print str(dropRow[0])
shpLine = dropRow[1]
shpLinePart = shpLine.getPart(0)
first_point = shpLine.firstPoint
last_point = shpLine.lastPoint
for pt in points:
if pt == first_point: # or pt == last_point:
rPnts=arcpy.Array()
for i in range(len(shpLinePart)): rPnts.append(shpLinePart[len(shpLinePart)-i-1])
rPoly =arcpy.Polyline(rPnts)
dropRow[1].shape= rPoly
dropCursor.updateRow(dropRow)
print "Updated"