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

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

    for fc in fcs:   
        print fc
        i = i+1 

except Exception as err:
    print err

#Now that we have a list of all feature classes, attempt to merge them into one class
    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:
    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?

  • 2
    could you share your script, preferably a highly simplified version? Jun 18 '14 at 21:15
  • 2
    Agree with Kevin, you need to upload your code if you want help.
    – Hornbydd
    Jun 18 '14 at 22:58
  • 1
    Totally agree, at least some code is required otherwise we're just guessing... and I hate guessing games. Jun 18 '14 at 23:22
  • You should be able to copy/paste the code from when you "manually create a merged dataset using Geoprocessing > Merge in the ArcMap program" by going to the Geoprocessing | Results window and using Copy As Python Snippet.
    – PolyGeo
    Jun 19 '14 at 1:10
  • I think you need to do more editing of your Question. I would focus on making it clear that you have performed the Merge using two different methods on the same data and are expecting to see the same number of features in the output. I would list the precise steps you used to do each method because at the moment it sounds like you may have used File > Add Data > Add XY Data but have not explicitly said so. Also be sure to include the version number of ArcGIS for Desktop that you are using.
    – PolyGeo
    Jun 20 '14 at 9:12

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.


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.