Using ArcGIS 10.4.1 and Arcpy I am trying to select a shapefile by it attributes and create new feature class based on unique values. I am able to create new fs inside the Mapset.gdb/Linear
but it is not producing based on "NEW_SELECTION"
. In Fact I am copying entire Roads.shp
in each of feature classes.
How can I fix this?
import arcpy
from arcpy import env
def unique_values(table , field):
with arcpy.da.SearchCursor(table, [field]) as cursor:
return sorted({row[0] for row in cursor})
uniques = unique_values(r'D:/GIS/Roads.shp' , 'fclass')
for unique in uniques:
arcpy.MakeFeatureLayer_management(r'D:/GIS/Roads.shp', unique)
arcpy.SelectLayerByAttribute_management (unique, "NEW_SELECTION", " 'fclass' = '"+unique+"' ")
arcpy.CopyFeatures_management(unique, r"D:/GIS/Mapset.gdb/Linear/"+unique+"")
uniques
created?uniques = [some list of values]
in your code. Have you actually run the code you've pasted in your question? Or have you pasted something different to what you've tested?print uniques
immediately after youruniques = unique_values(r'D:/GIS/Roads.shp' , 'fclass')
line and see if it prints anything" 'fclass' = '"+unique+"' "
to this" fclass = '"+unique+"' "