1

I want to split the shapefile with a field called FULLNAME and save those records with same FULLNAME to a new shapefile, which is the split by attribute. The following code has an error for the last line.

The error is:

Traceback (most recent call last):
  File "<editor selection>", line 8, in <module>
  File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\conversion.py", line 1693, in FeatureClassToFeatureClass
    raise e
ExecuteError: ERROR 000258: Output C:\Users\TL\Desktop\831test\Splitbyattribute\Abilene Ln.shp already exists
Failed to execute (FeatureClassToFeatureClass).

Any suggestions?

import arcpy

def unique_values(table, field):
    with arcpy.da.SearchCursor(table, [field]) as cursor:
        return sorted({row[0] for row in cursor})

inFC = r'C:\Users\TL\Desktop\831test\SpatialJoinName_proj.shp'
StreetNames = unique_values(inFC, 'FULLNAME')

#split the shapefile by different names
arcpy.CreateFolder_management(r"C:\Users\TL\Desktop\831test", "Splitbyattribute")
outputfolder = r"C:\Users\TL\Desktop\831test\Splitbyattribute"
for name in StreetNames:
    arcpy.FeatureClassToFeatureClass_conversion(inFC, outputfolder, name, "FULLNAME = {0}".format(name))
  • Traceback (most recent call last): File "<editor selection>", line 12, in <module> File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\conversion.py", line 1693, in FeatureClassToFeatureClass raise e ExecuteError: ERROR 999999: Error executing function. An invalid SQL statement was used. An invalid SQL statement was used. Failed to execute (FeatureClassToFeatureClass). – Tianxin Li Sep 2 '16 at 15:16
  • "FULLNAME = '{0}' ".format(name) – ziggy Sep 2 '16 at 16:44
  • sometimes it is easier to define the where QRY outside loop in a variable – ziggy Sep 2 '16 at 16:45
  • After I revised the code based on ziggy's help, everything works fine. – Tianxin Li Sep 2 '16 at 17:59
1

The error message is telling you there is already a shape file with that name in the folder. Check that no other outputs are in the folder or create a unique folder for each test run of the script.

Secondly your output filename has a space in it (Abeline Ln.shp) make sure you strip spaces out before you use it in your filename.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.