I am very new at Python,I'm not sure if this is even the appropriate way to do what I want to do, but basically, I'm looking to eliminate all of the small polygons in a feature class that was created to show all of the watershed basins of an area. I will need to run the Eliminate tool multiple times to eliminate all polygons smaller than an acre (since sometimes the tool will combine 2 small polygons and they still end up being less than an acre). Right now I can run the eliminate tool once with:

arcpy.management.SelectLayerByAttribute(basinLYR,"NEW_SELECTION","Acres < 1")

Since I've never used a loop in Python before, I'm not sure which to use or where to place it.


1 Answer 1


A simple loop for a set number of iterations would look like this:

arcpy.env.overwriteOutput = True #make sure you can overwrite the eliminate output
arcpy.SelectLayerByAttribute_management(basinLYR,"NEW_SELECTION","Acres < 1") 
elim = arcpy.Eliminate_management(basinLYR,basin_elim)
iter = 5 #number of iterations -- how many times to go through the loop

for i in range(iter):
    arcpy.SelectLayerByAttribute_management(elimLYR,"NEW_SELECTION","Acres < 1") 
    elim = arcpy.Eliminate_management(elimLYR,'_'.join([basin_elim,str(i)]))
  • This will just run eliminate on basinLYR 5 times. You need to feed the output of eliminate to the input of the next loop. Dec 3, 2018 at 19:53
  • FIxed - elim now feeds back into the loop. Thanks for the feedback
    – jbalk
    Dec 3, 2018 at 20:13
  • A while loop might be better here - 'while number of features selected under criteria x is >0, keep running the tool'
    – obrl_soil
    Dec 4, 2018 at 0:39
  • When I try the above mentioned I receive the error: "ERROR 000670: output Output Feature Class is same as input Input Layer. Failed to execute (Eliminate)." The error is referring to the last line of code. Any suggestions?
    – Stan
    Dec 7, 2018 at 15:03
  • If you're using a gdb try my edit above. You need to change the name of the elim layer each time so you're not trying to overwrite it in place.
    – jbalk
    Dec 7, 2018 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.