0

I am trying to select layer by attribute and for that, I am using arcpy.SelectLayerByAttribute_management function . My command is as follows:

arcpy.SelectLayerByAttribute_management(union, 'NEW_SELECTION', '"gridcode" =1 AND "area" >=25000000*0.4') 

Here, union is the shapefile, from which I need to select layers by attribute. My SQL query is "gridcode" =1 AND "area" >=25000000*0.4

I am getting the following error:

ExecuteError: Failed to execute. Parameters are not valid. The value cannot be a feature class ERROR 000840: The value is not a Raster Layer. ERROR 000840: The value is not a Mosaic Layer. Failed to execute (SelectLayerByAttribute).`

marked as duplicate by PolyGeo arcpy Jun 22 at 23:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • couldn't you test "area" >= 10000000? – Vince Mar 13 at 11:34
  • yes i just changed it but still it gives error – lsr729 Mar 13 at 11:35
  • 1
    Try creating a feature layer using MakeFeatureLayer, and pass this to SelectLayerByAttributes. – BERA Mar 13 at 12:02
  • We'd need to see more of your script to know. Whatever union is appears to be the problem. It's not a layer that the tool wants. – KHibma Mar 13 at 12:22
  • 1
    Yes it worked after making a layer first. Thank – lsr729 Mar 13 at 12:47
0

You are trying to select on a feature class when it should be a feature layer. Use MakeFeatureLayer to create a layer then pass this to SelectLayerByAttributes:

Creates a feature layer from an input feature class or layer file

(It is also possible to use a where_clause in MakeFeatureLayer and then there is no need for SelectLayerByAttributes.)

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