I am trying to select the largest polygon that contains each feature in a feature class but none of the features in another feature class. I have written the code that seems logical to me but (of course) it doesn't work.
I am using a search cursor to iterate through my first feature class and for each feature I want to run my point in polygon query. it seems that my cursor is not a valid input. Is there a special way to express it, or is it not possible to use the search cursor as an input to this. If not is there an other was of searching on each point one by one?
Polygons = r"\\...\\tests.gdb\\out_contour_g"
peakPoints = r"\\...\\tests.gdb\\inv_peak"
troughPoints = r"\\...\\tests.gdb\\peaktest"
OutputFC = r"\\...\\tests.gdb\\OUTPUT1"
arcpy.RepairGeometry_management(Polygons)
arcpy.AddField_management(Polygons,"area_calc","DOUBLE")
arcpy.CalculateField_management(Polygons, "area_calc","!Shape!.area","PYTHON_9.3")
points = arcpy.da.SearchCursor(peakPoints, "SHAPE@")
for point in points:
arcpy.SelectLayerByLocation_management(Polygons, "CONTAINS", point)
arcpy.SelectLayerByLocation_management('out_contour_g',"CONTAINS",'peaktest',"","REMOVE_FROM_SELECTION")
with arcpy.da.SearchCursor(Polygons, "SHAPE@") as rows:
for row in rows:
list = []
list.append(row[0].area)
largestArea = max(list)
arcpy.SelectLayerByAttribute_management(Polygons, "SUBSET_SELECTION", "area_calc =" + str(largestArea)) ####the where clause is probably wrong
arcpy.Append_management(Polygons, OutputFC, "NO_TEST")
for point[0] in points:
.