[GIS] Geoprocessing>Merge and arcpy.Merge_management() producing different results

arcgis-desktoparcmapmerge

In ArcMap 10.2.1 I have three feature classes in geodatabase "MyGDB.gdb". Let's call the feature classes "A", "B", and "C" respectively. I am merging the feature classes using Geoprocess > merge. Here are the exact steps:

  1. Geoprocessing>Merge
  2. Select feature classes "A", "B", and "C" as the input datasets
  3. Save the output dataset as "Merged" in "MyGDB.gdb"

After creating the merged dataset, I am running the following code in a python script to count the number of data points in each feature class and also in the merged data set:

lyrfile1 = 'C:\\ArcGIS\\Python\\MyGDB.gdb\\Merged'
lyrfile2 = 'C:\\ArcGIS\\Python\\MyGDB.gdb\\A'
lyrfile3 = 'C:\\ArcGIS\\Python\\MyGDB.gdb\\B'
lyrfile4 = 'C:\\ArcGIS\\Python\\MyGDB.gdb\\C'

result1 = int(arcpy.GetCount_management(lyrfile1).getOutput(0)) 
result2 = int(arcpy.GetCount_management(lyrfile2).getOutput(0)) 
result3 = int(arcpy.GetCount_management(lyrfile3).getOutput(0)) 
result4 = int(arcpy.GetCount_management(lyrfile4).getOutput(0)) 


print result1
print result2
print result3
print result4

The results are as follows:
151983
19394
75578
57011

This is good and expected. Since the three feature classes are merged, I would expect to see that the merged data set has the same number of data points as each individual feature class combined,, and it does (57011+75578+19394=151983).

Here is where the problem starts: when I try to merge the datasets using arcpy.Merge_management() and then use arcpy.GetCount to count the datapoints, only a fraction of the datapoints are returned (57011). Here is the code:

fClasses = []   #initialize array to hold feature classes   

#Set counter for loop
i=0

#Loop through MyGDB.gdb and add each feature class name to array
try:
        # Get a list of the featureclasses in the gdb
    fcs = arcpy.ListFeatureClasses()

    #Iterate
    for fc in fcs:   
        print fc
        fClasses.append(fc)
        i = i+1 

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



#Now that we have a list of all feature classes, attempt to merge them into one class
try:
    arcpy.Merge_management([fClasses], "Merged")
    print "merge:  SUCCESS."

        #Count number of points in newly created merged dataset
    result1 = int(arcpy.GetCount_management("Merged").getOutput(0)) 
    print result1

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

This returns only 57011 points, versus the 151983 points in the merge file creating using Geoprocessing > Merge. What am I missing here?

Best Answer

You should just remove the square brackets around fClasses in arcpy.Merge_management([fClasses], "Merged"). There are already brackets included in that fClasses list variable. For a reason that is not clear to me, adding these extra brackets selects only the last feature class in the fClasses list.