I have a large feature classes, where a field named "gridcode" contains integers values from 6 to 17. I would like to get rid of features, where the gridcode = 6, 9 or 15.
Therefore, I have created a query where gridcode = 6 OR gridcode = 9 OR gridcode = 15.
Further, I wanted to apply tool Select layer by Attribute and switch my selection, i.e. end up only with field "gridcode" does not contain neither 6, 9 or 15. I wanted to apply this tool, as it takes "SWITCH_SELECTION" argument.
I have save up my selection, just to verify if the process was accurate. And it seems that the selection or the dropping of my variables did not occur.
Could there be a problem with my coding?
How otherwise I can drop my rows by attribute?
# Import modules import arcpy, os import itertools # Allow files to overwrite arcpy.env.overwriteOutput = True # Set working environment inWD = "C:/Projects/2018_deforestData" arcpy.env.workspace = os.path.join(inWD, "input.gdb") # Define outPath outPath = os.path.join(inWD, "output.gdb") # Define input variables inSAO = "AllSAO" # create clauses field = "gridcode" # Select correct years from SAO # Create attribute query for SAO data: # drop years yearsSAO = [6, 9, 15] # Create layers and apply atribute query querySAOall = field + "=" + str(6) + " OR " + field + "=" + str(9) + " OR " + field + "=" + str(15) # Make feature layer from my input data arcpy.MakeFeatureLayer_management(inSAO, "SAOLayerAll") # Select by attribute and switch the selection arcpy.SelectLayerByAttribute_management ("SAOLayerAll", "SWITCH_SELECTION", querySAOall) # Save file to make sure the correct years are used outSAOcorrectYears = os.path.join(outPath, "SAO_correctYears") arcpy.CopyFeatures_management("SAOLayerAll", outSAOcorrectYears)