Problems with "adding to selection" and "switch selection" using python.

875
4
02-02-2014 10:04 PM
AliciaMein
New Contributor III
I want to select data for processing from a wetland dataset. 76,000 records.
When I run step by step in python window I can create a new selection, then add to the selection and finally,
switch selection, but I cant get the same code to run as a block in the window.   The resulting layer has all the features selected.
I have tried to code all the selection in one line and switch in the next but that didnt work either.  Ive closed arc thinking some residual caused the issue and no luck.
I would like to have standalone script in the end. 
arcpy.MakeFeatureLayer_management(wtlndPath, "wtlnd4Analysis")
arcpy.SelectLayerByAttribute_management("wtlnd4Analysis", "NEW_SELECTION", ' "WETLAND_TYPE" = \'RIVERINE\' AND "ATTRIBUTE" LIKE \'%H%\' ')
arcpy.SelectLayerByAttribute_management("wtlnd4Analysis", "ADD_TO_SELECTION", ' "WETLAND_TYPE" = \'LAKE\' AND "ATTRIBUTE" LIKE \'%UBH%\' ')
arcpy.SelectLayerByAttribute_management("wtlnd4Analysis", "SWITCH_SELECTION")

Im wondering if I should take another approach or if I am missing something?  Maybe I would be better off selecting from a table.
My data is in a file geodatabase.

Thanks!
Alicia
Tags (2)
0 Kudos
4 Replies
MathewCoyle
Frequent Contributor
What happened when you tried to make your selection code in one query and then switch selection?
0 Kudos
AliciaMein
New Contributor III
When I had the entire selection in one line of code
arcpy.SelectLayerByAttribute_management("wtlnd4Analysis", "NEW_SELECTION", ' "WETLAND_TYPE" = \'RIVERINE\' AND "ATTRIBUTE" LIKE \'%H%\' OR "WETLAND_TYPE" = \'LAKE\' AND "ATTRIBUTE" LIKE \'%UBH%\' ')


I loaded this into the python window and I never saw the selection change.  It would be obvious, because there are several very large river that would be removed.  I tried adding () around where clause and still nothing changed.

Today I run this on on my desktop at work instead of my laptop and it doesnt even work as I step through.  I get an empty selection no mater what?
Im stumped.
Thanks
Alicia

Back working on laptop, and this works thus far:
arcpy.MakeFeatureLayer_management(wtlndPath, "wtlnd4Anlys_lyr")
arcpy.SelectLayerByAttribute_management("wtlnd4Anlys_lyr", "NEW_SELECTION", ' "ATTRIBUTE" LIKE \'R%H%\' OR "ATTRIBUTE" LIKE \'L%UBH%\' ')
arcpy.SelectLayerByAttribute_management("wtlnd4Anlys_lyr", "SWITCH_SELECTION")
0 Kudos
MathewCoyle
Frequent Contributor
Can you post an example of the table your are selecting from?
0 Kudos
AliciaMein
New Contributor III
Can you post an example of the table your are selecting from?


This a standard attribute from the NWI table which is in a geodatabase.
[ATTACH=CONFIG]31190[/ATTACH]
The Pic is small so I attached a better image also.

I did get the last, most recent, code to run on my desktop and laptop.
0 Kudos