[GIS] Counting all features in all layers of ArcGIS map to get grand total

arcgis-10.1arcgis-desktopstatistics

I have 20-50 polygon layers in an mxd and I want to find out the aggregated amount of all features (global count). The shapefiles which are the source of those layers are stored in different folders. Just knowing the count would fulfill my requirements because it is just a quick check before I go on processing these files. Thus, I don't want to merge the files or count separately. I just need the simple amount.

Up to now, I can only think of a solution by coding a script in ArcPy, but I would prefer to find an easier way.
I use ArcGIS 10.1.

Best Answer

You can copy/paste this code in the Python window in ArcMap to return the total number of features:

mxd = arcpy.mapping.MapDocument('current')
total_count = 0
for df in arcpy.mapping.ListDataFrames(mxd):
    for lyr in arcpy.mapping.ListLayers(df):
        if lyr.supports("dataSource"):
            result = arcpy.GetCount_management(lyr.dataSource)
            count = int(result.getOutput(0))
            total_count = total_count + count

print total_count

I haven't tested this with service layers and other specific data types present in the Table of Contents, that may not support GetCount.

Related Question