AnsweredAssumed Answered

Check records with one another within a polyline.shp then update if they intersect another record or not

Question asked by gisWombat on Jan 20, 2015
Latest reply on Jan 20, 2015 by gisWombat



To compare records within a polyline shapefile. If a record intersects, touches or crosses another record it updates the intsctCHK field with a “Y” value otherwise it updates it with a “N” value (meaning that it doesn’t touch, cross or intersect another record at all). The intsctCHK field will be used to create an error report further down the script.


My Attempt


I used two search cursors to compare each record with one another. If the record touches, intersects, or crosses another record it will be placed into an intersection array, if not into a non intersection array. Then I will update the intsctCHK field with another loop to see whether or not the record is in the intersection array.


ArcGIS 10.1 (advanced license / ArcInfo), Python (Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32)


     inShapefile1 = polylineShapefile
     inShapefile2 = polylineShapefile
     checkField1 = "SHAPE@"       

     checkField2 = "SHAPE@"

     updateField = " intsctCHK "

     intersectCount = 0


    # List of records that do not cross / touch / intersect another record

    polylineNonIntersectList = []

    # List of records that cross / touch / intersect other record/s

    polylineIntersectList = []


    cursorA = arcpy.da.SearchCursor(inShapefile1, [checkField1])

    for rowA in cursorA:

        if rowA[0]:

            cursorB = arcpy.da.SearchCursor(inShapefile2, [checkField2])

            rowB =

            for rowB in cursorB:

                if rowB[0]:

                    # Proceed if the row doesn't equal itself in the other cursor loop

                    if (rowA[0] != rowB[0]):

                        if (rowA[0].touches(rowB[0]) == True):
                            polylineIntersectList.append (rowA[0])


                        elif (rowA[0].crosses(rowB[0]) == True):

                            polylineIntersectList.append (rowA[0])


                        elif (rowA[0].intersect((rowB[0]),2) == True):

                            polylineIntersectList.append (rowA[0])



                            polylineNonIntersectList.append (rowA[0])

    del cursorA

    del cursorB


    cursorC = arcpy.da.UpdateCursor (inShapefile1, [checkField1, updateField])

    for row in cursorC:

        if row[0]:

            #check if value in polylineListIntersect list (i.e. it intersects another record)

            if row[0] in polylineIntersectList:

                row[1] = "Y"

                intersectCount += 1


                row[1] = "N"


    del cursorC




The program executes, however it does not work properly as it updates all records with a “N” value in the intsctCHK field and intersectCount still equals 0.


I am relatively new to python and wish to improve my python skills, so took it upon myself to give it a try. Also, I have attempted to use Select By Location and Spatial Join but have not been successful. If any of you guys could give advice/tips it would be of great help. Thank you in advance.