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
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).
Solved! Go to Solution.
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)
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
"FIRST_JURI = 'ACCOMACK' "
' "FIRST_JURI" = 'ACCOMACK' "
Ive tried for Int
"FIPS2 > 1"
' "FIPS2" > 1'
"[FIPS2] > 1"
I know the attributes and values exist
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'
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.