Using an arcpy script how do I get the feature attribute count per feature class in a fileGDB? Ideally I would like to output to a spreadsheet, with the feature class name in one column and the attribute count in another.
-
by "feature attribute count" do you mean a count of how many features there are, or a count of how many attributes (fields?) a feature has?– mr.adamJul 9, 2015 at 19:23
-
The number of attributes per feature class in a fileGDB.– ionicdezJul 9, 2015 at 19:35
1 Answer
Use this function to return all of the feature classes in the GDB:
def listFcsInGDB():
for fds in arcpy.ListDatasets('','feature') + ['']:
for fc in arcpy.ListFeatureClasses('','',fds):
yield os.path.join(arcpy.env.workspace, fds, fc)
Now loop over that function to work with each individual feature class:
arcpy.env.workspace = "C:\\gdb"
for fc in listFcsInGDB():
print fc
print arcpy.GetCount_management(fc) <-- number of rows
print len(arcpy.ListFields(fc)) <-- number of columns
I've left the part about writing to a spreadsheet up to you.
Note, I haven't tested this so feel free to correct me if I made any mistakes.
-
1I would use arcpy.da.walk() instead of arcpy.ListFeatureClasses() resources.arcgis.com/en/help/main/10.1/index.html#//…– JasonTJul 9, 2015 at 21:31