1

I want to split a shapefile so each feature becomes its own shapefile. The below works:

with arcpy.da.SearchCursor(catch10, ["FID", "SHAPE@"]) as cursor:
     for row in cursor:
      out_name = "Sup_" + str(row1[0]) # 
      arcpy.FeatureClassToFeatureClass_conversion(row1[1],outSup, out_name, **field_mapping=**)

But the attributes don't come with it. It gives back a shapefile with FID (0), Shape, ID (0). I have tried different entries under field mapping -- long strings copied from results and shorter {"Name" etc) -- but nothing has changed it. I'm missing something

7

1 Answer 1

2

The row object can't be used in the manner that you're attempting:

arcpy.FeatureClassToFeatureClass_conversion(row1[1],outSup...

Because it's a row and not a feature class, to split your feature class to a single feature per output:

desc = arcpy.Describe(catch10)
OID_Field = desc.OIDFieldName # the name of the OID field, could be OID, OBJECTID, FID or other

with arcpy.da.SearchCursor(catch10,'*') as SCur: # really all you need here is arcpy.da.SearchCursor(InData,[OID_Field])
    for row in SCur:
        print 'OID {0}'.format(row[0])
        out_name = "Sup_{0}".format(row[0])
        arcpy.FeatureClassToFeatureClass_conversion(catch10,outSup,out_name,'{0} = {1}'.format(OID_Field,row[0]))

It is important to describe the data first and obtain the OID field name, this saves maintaining a script for shapefiles and a different one for geodatabases, then start your cursor with only the OID field, as that's all that's needed to supply the whereclause OIDFieldName = This_row_OID, then specify the source data in FeatureClassToFeatureClass, note that the Select tool also could be implemented here (different to the other select tool so make sure you're using the right one).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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