[GIS] using arcpy.Merge_management

arcpymerge

This script should make a field for all the feature classes in a geodatabase, populate the new field with the name of the feature class it's being created in, and then merge all the feature classes together. However, when I run the code I get the success message but only the first feature class features are in the output of the merged feature class.

import arcpy, os

arcpy.env.workspace = r"J:\Non_RS_MXDs\Crown_Scrap.gdb"

for fc in arcpy.ListFeatureClasses():
    arcpy.AddField_management(fc, "DyRt", "TEXT", field_length = 30)
    with arcpy.da.UpdateCursor(fc, "DyRt") as cursor:
        for row in cursor:
            row[0] = fc
            cursor.updateRow(row)

fClasses = []
i = 0

try:
    fcs = arcpy.ListFeatureClasses()
    for fc in fcs:
        print fc
        fClasses.append(fc)
        i = i+1

except Exception as err:
    arcpy.AddError(err)
    print err

try:
    arcpy.Merge_management([fClasses], "Rts_8_15")
    print "merge: SUCCESS!"

    #count number of new features
    result1 = int(arcpy.GetCount_management("Rts_8_15").getOutput(0))
    print result1

except Exception as err:
    arcpy.AddError(err)
    print "merge: FAIL :("
    print err

Best Answer

You are creating a nested list which is probably throwing off the tool. Try changing the line where you are calling the merge to:

arcpy.Merge_management(fClasses, "Rts_8_15")

You may also want to add a print statement to show how many feature classes you are merging.

Related Question