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.
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:
cursorB = arcpy.da.SearchCursor(inShapefile2, [checkField2])
rowB = cursorB.next()
for rowB in cursorB:
# Proceed if the row doesn't equal itself in the other cursor loop
if (rowA != rowB):
if (rowA.touches(rowB) == True):
elif (rowA.crosses(rowB) == True):
elif (rowA.intersect((rowB),2) == True):
cursorC = arcpy.da.UpdateCursor (inShapefile1, [checkField1, updateField])
for row in cursorC:
#check if value in polylineListIntersect list (i.e. it intersects another record)
if row in polylineIntersectList:
row = "Y"
intersectCount += 1
row = "N"
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.