Hello,
I am trying to iteratively select by attribute>create feature layer> create new feature class(es) from the selections. But I am getting errors in the Make Feature Layer process. Any suggestions?
Thanks, Penelope
Update: Edited for code formatting--thanks for the tip.
#obtain unique values
values = [row[0] for row in arcpy.da.SearchCursor(SortiesLnFP, 'RS_Name')]
uniqueValues = set(values)
print(uniqueValues)
#create where clause for .makefeaturelayer using unique Values
#use where query to make a feature layer from selection then convert to feature class
OutPath = wkspc
for value in uniqueValues:
OutFile = wkspc + os.sep + str(value)
query = "\"RS_Name = '{}'\"".format(value)
#query = "RS_Name = " + str(value)
sortieLayer = arcpy.management.MakeFeatureLayer(SortiesLnFP, OutFile, query)
arcpy.conversion.FeatureClassToFeatureClass(sortieLayer, wkspc, str(value))
arcpy.managementDelete(sortieLayer)
#Output of query
"RS_Name = 'Pink_PM'"
"RS_Name = 'Pink2'"
#i've tried w/ the "" and without, get the same error either way-- I saw another post including those for the same purpose so thought I would try it (https://community.esri.com/t5/arcgis-api-for-python-questions/select-unique-values-from-field-using-selectbyattribute/td-p/825616/page/2)
---------------------------------------------------------------------------
ExecuteError Traceback (most recent call last)
In [67]:
Line 6: sortieLayer = arcpy.management.MakeFeatureLayer(SortiesLnFP, OutFile, query)
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py, in MakeFeatureLayer:
Line 8668: raise e
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py, in MakeFeatureLayer:
Line 8665: retval = convertArcObjectToPythonObject(gp.MakeFeatureLayer_management(*gp_fixargs((in_features, out_layer, where_clause, workspace, field_info), True)))
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py, in <lambda>:
Line 511: return lambda *args: val(*gp_fixargs(args, True))
ExecuteError: ERROR 000358: Invalid expression
Failed to execute (MakeFeatureLayer).