SelctbyAttributes

1249
7
Jump to solution
05-11-2020 11:52 AM
jaykapalczynski
Frequent Contributor

Where am I going wrong here.

countiesFeatureClass = r"E:/ArcGISProjects/CountySelection/adminjk_NWTL@Rack30.sde/Counties_1_Dissolved"

queryCounties = arcpy.SelectLayerByAttribute_management(countiesFeatureClass,
                                                        'NEW_SELECTION',
                                                        '"FIPS2"=3 OR "FIPS2"=12')

# Write the selected features to a new featureclass
arcpy.CopyFeatures_management(queryCounties, 'countiesSelected')


Traceback (most recent call last):
File "E:\ArcGISProjects\CountySelection\Python\Update_v4.py", line 32, in <module>
'"FIPS2"=3 OR "FIPS2"=12')
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 7744, in SelectLayerByAttribute
raise e
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).

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

Oh,  you should be using Select Layer By Attribute and not Select Layer by Location.  You are passing the syntax for one into the other.

View solution in original post

0 Kudos
7 Replies
jaykapalczynski
Frequent Contributor

Trying this as well...same similar error...seems to be in the syntax of the where clause...

# DEFINE THE COUNTIES FC
arcpy.MakeFeatureLayer_management(r"E:/Projects/County/xxxx.sde/Counties", "counties_lyr")

# SELECT FROM BUFFER PUT INTO RESULTS VARIABLE
results = arcpy.SelectLayerByLocation_management('counties_lyr', 'NEW_SELECTION', 'FIPS2 > 16')

# GET THE FIPS CODES FROM THE RESULTS OF THE SELECTION
rows = arcpy.SearchCursor(results,"","","FIPS2")
for row in rows:  
    neighborVal = str(row.FIPS2)  
    print(neighborVal)  
0 Kudos
jaykapalczynski
Frequent Contributor

Note this is a Feature Class in n SDE SQL db

# DEFINE THE COUNTIES FC

arcpy.MakeFeatureLayer_management(r"E:/Projects/County/xxxx.sde/Counties", "counties_lyr")

results = arcpy.SelectLayerByLocation_management("counties_lyr", 
                                         "NEW_SELECTION", 
                                         "[FURST_JURI]='ACCOMACK'")‍‍‍‍‍‍‍

Ive tried this for Text field

"[FURST_JURI]='ACCOMACK' " 

"FIRST_JURI = 'ACCOMACK' "

' "FIRST_JURI" = 'ACCOMACK' "

Ive tried for Int

"FIPS2 > 1"

' "FIPS2" > 1'

"[FIPS2] > 1"

I know the attributes and values exist

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Given the error message and the fact that you are using some enterprise geodatabase, I would start by dropping the double quotes around your field names:

'FIPS2 = 3 OR FIPS2 = 12'
0 Kudos
jaykapalczynski
Frequent Contributor

results = arcpy.SelectLayerByLocation_management("counties_lyr", "NEW_SELECTION", 'FIPS2 = 3 OR FIPS2 = 12')

ERROR

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Oh,  you should be using Select Layer By Attribute and not Select Layer by Location.  You are passing the syntax for one into the other.

0 Kudos
jaykapalczynski
Frequent Contributor

For crying out loud....ahhahahahha...

Thats what you get from copy and paste form other Python scripts...ahahah

THANKS for the extra set of eyes.....thats embarrassing

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

No worries, it happens to all of us from time to time.  Your original code snippet was Select Layer By Attribute, but then you switched to calling Select Layer By Location in follow-up troubleshooting.  For certain data sources, putting a field name in double quotes implicitly tells ArcGIS that you are looking for a raster data set, which I think is the cause of your initial error.