AnsweredAssumed Answered

Edit polygon attributes along an intersecting line

Question asked by clm42 on Apr 8, 2015

If was wondering if anyone has a snippit or an idea for how to accomplish this in Python. I want to draw a line and step through the intersecting polygon features in order of the line direction and update their attributes. An example would be addressing in a new subdivision but drawing a line and giving the min and max numbers for the intersecting features instead of having to click every parcel individually.

 

 

EDIT: I figured out a rather inelegant way of doing it but it can be memory intensive if you had a ton of polygons being intersected though only one point per polygon is actually stored in memory. Im numbering subdivision lots so I just used enumerate to match an OID to a increasing integer after sorting the lot OIDs by the distance along the line they appear. Kind of brute force but it works. I'll leave this open to see if anyone has any other approaches to this.

 

line = [row[0] for row in arcpy.da.SearchCursor("sde.SDE.temp_line",['SHAPE@'])][0]
lots = {row[0]:row[1] for row in arcpy.da.SearchCursor("Subdivision Lots",['OID@','SHAPE@'])}
for oid in lots:
    '''This looks a bit garbled but what it does is take the first point
    of the points returned in the intersection of the line and the boundary
    of the intersecting polygon then find the distance along the line that
    the point falls'''
    lots[oid] = line.measureOnLine(line.intersect(lots[oid].boundary(),1).firstPoint)
lots = {value[0] : key for key , value in enumerate(sorted(lots.items(), key = lambda oid: oid[1]), start = 1)}
with arcpy.da.UpdateCursor("Subdivision Lots",['OID@','LOTID']) as cursor:
    for row in cursor:
        row[1] = lots[row[0]]
        cursor.updateRow(row)

Outcomes