I need to write a code to read a polygon shapefile that contain three classes of land use (trees, urban, and crops) and I need to select only polygons of Trees.
Here is my code to apply Select by polygon that is not working:
class btn_read_LandUse(object):
"""Implementation for Addins_addin.button_LU (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
LU_layer = pythonaddins.OpenDialog("Please Select the land use file" ,False,r'','Select')
desc = arcpy.Describe(LU_layer)
layerName = desc.baseName
arcpy.SelectLayerByAttribute_management(in_layer_or_view="LayerName", selection_type="NEW_SELECTION", where_clause=""""LU" = 'Crops'""")
The error:
Traceback (most recent call last):
File "C:\Users\eng.adel\AppData\Local\ESRI\Desktop10.4\AssemblyCache\{FEC573D9-E048-4AEE-A331-8380627D272B}\Addins_addin.py", line 96, in onClick
arcpy.SelectLayerByAttribute_management(in_layer_or_view="LayerName", selection_type="NEW_SELECTION", where_clause=""""LU" = 'Crops'""")
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 7182, in SelectLayerByAttribute
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Layer Name or Table View: Dataset LayerName does not exist or is not supported
Failed to execute (SelectLayerByAttribute).
Any help?