Friday 21 August 2015

arcgis desktop - How to count number of feature classes in geodatabase using ArcPy?


I would like to count the number of feature classes in a geodatabase. Some of the classes are in feature datasets as well. I have tried get count management, but that returns the number of rows in each feature class in the GDB.



Answer



You can run this code to get it:


arcpy.env.workspace = NAME OF GDB HERE

# Get stand alone FCs
fccount = len(arcpy.ListFeatureClasses("",""))


# Get list of Feature Datasets and loop through them
fds = arcpy.ListDatasets("","")
for fd in fds:
oldws = arcpy.env.workspace
arcpy.env.workspace = oldws + "\\" + fd
fccount = fccount + len(arcpy.ListFeatureClasses("",""))
arcpy.env.workspace = oldws


print fccount


Hope this works for you.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...