Cannot make feature layer or select by attribute in Python 2.65

1378
1
10-29-2018 08:32 AM
JustinBridwell2
Occasional Contributor II
I have a goal: take a feature class, make a layer for further processing and select some of the records by attribute, Should be simple, but I am having multiple problems. Note: I am working in a Python 2.65/ArcGIS 10 environment (may be cause of some of these issues). I start with my gdb
 master_dict = {'Alabama': ['01009', '01013'], ...} statePath = "<...>/gdb/master_merge_footprints.gdb"

I want to iterate through the gdb and find specific features based on state names. This part works. I can even print the fields just to test that the feature class exists:

 stateNames = ['Alabama', 'Alaska'...] for name in stateNames:     arcpy.env.workspace = statePath     featureclasses = arcpy.ListFeatureClasses()    fip_merge_list = []    for fc in featureclasses:        if name in fc:            print fc             fipslist  = (master_dict[name]):            for fip in fipslist:                 ### Here's where the problem occurs

Here is where the problem occurs. As I mentioned if I've tried several things to make sure that fcexists, including fieldnames = [field.name for field in arcpy.ListFields(fc)]. I am able to print the field names and verify that the field for the where clause also exists. I create a hard output path to an existing gdb just to make sure the process will work. When I run this however, nothing shows up in my gdb when I check in ArcMap. I can manually run a selectByAttributes function in ArcMap directly on this fc as well.

select = arcpy.MakeFeatureLayer_management(fc, statePath + "/%s_temp_lyr_%s"%(name, fip),"FIPS_CODE = '%s'"%(fip))

The process runs and doesn't throw an error, but nothing is showing in my gdb. So I tried just using the SelectLayerByAttributes_management with fc and it throws an error:

select_1 = arcpy.SelectLayerByAttribute_management (fc, "NEW_SELECTION", "FIPS_CODE = '%s'"%(fip))

Traceback (most recent call last): File "", line 1, in select_1 = arcpy.SelectLayerByAttribute_management (fc, "NEW_SELECTION", "FIPS_CODE = '%s'"%(fip)) File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 4259, 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).

So, I can't make a layer from my feature class, I can't select by attributes, and I am stuck. I have manually verified that the feature class exists (both in Python and ArcMap), I have verified that the field exists, and I have verified that the fip exists. Any advice on what I am doing incorrectly here?

0 Kudos
1 Reply
DarrenWiens2
MVP Honored Contributor

A feature layer should not show up in your gdb. Think of it like an in memory set of display instructions (and other temporary visual things, like selections) that points to the data in your gdb. Name your feature layer something simple that would appear in the table of contents in ArcMap, not a long path. Then, make your selection against the feature layer (again, not the feature class or a full path).