How we get Feature count of 2 GDB(Include dataset and feature class) in CSV format in Model builder or script tool.
In CSV format GDB can differentiate with sheets and every sheet have count of respective feature classes.
Solved! Go to Solution.
This can't be done in ModelBuilder tools, but you can use the Calculate Value tool like this in ModelBuilder.
Expression: proc(r"C:\users\me\my.gdb", r"C:\users\me\my.csv")
Code Block:
def get_gdb_feature_count(gdb_path):
# set workspace to gdb
prev_ws = arcpy.env.workspace
arcpy.env.workspace = gdb_path
# list all feature classes and tables in workspace
fcs_and_tbls = arcpy.ListFeatureClasses() + arcpy.ListTables()
# GetCount() on all of these
counts = [int(arcpy.management.GetCount(ft)[0]) for ft in fcs_and_tbls]
# revert workspace
arcpy.env.workspace = prev_ws
# return [ ["TableName", count] ]
return zip(fcs_and_tbls, counts)
def proc(gdb, csv_path):
result = get_gdb_feature_count(gdb)
with open(csv_path, "w") as f:
f.write("Name,Count\n")
for r in result:
f.write(f"{r[0]},{r[1]}\n")
Basic structure:
def get_gdb_feature_count(gdb_path):
# set workspace to gdb
prev_ws = arcpy.env.workspace
arcpy.env.workspace = gdb_path
# list all feature classes and tables in workspace
fcs_and_tbls = arcpy.ListFeatureClasses() + arcpy.ListTables()
# GetCount() on all of these
counts = [int(arcpy.management.GetCount(ft)[0]) for ft in fcs_and_tbls]
# revert workspace
arcpy.env.workspace = prev_ws
# return [ ["TableName", count] ]
return zip(fcs_and_tbls, counts)
csv_path = "path:/to/your/csv_file.csv"
result = get_gdb_feature_count("path:/to/your/gdb")
with open(csv_path, "w") as f:
f.write("Name,Count\n")
for r in result:
f.write(f"{r[0]},{r[1]}\n")
Hi Johannes ,
Thanks your effort.
Please give me this script as a model builder.
thanks for advance,
Rakesh
Sorry, I don't know how to do this in ModelBuilder.
Try running the script in the Python Window first, that makes it easier to troubleshoot.
This can't be done in ModelBuilder tools, but you can use the Calculate Value tool like this in ModelBuilder.
Expression: proc(r"C:\users\me\my.gdb", r"C:\users\me\my.csv")
Code Block:
def get_gdb_feature_count(gdb_path):
# set workspace to gdb
prev_ws = arcpy.env.workspace
arcpy.env.workspace = gdb_path
# list all feature classes and tables in workspace
fcs_and_tbls = arcpy.ListFeatureClasses() + arcpy.ListTables()
# GetCount() on all of these
counts = [int(arcpy.management.GetCount(ft)[0]) for ft in fcs_and_tbls]
# revert workspace
arcpy.env.workspace = prev_ws
# return [ ["TableName", count] ]
return zip(fcs_and_tbls, counts)
def proc(gdb, csv_path):
result = get_gdb_feature_count(gdb)
with open(csv_path, "w") as f:
f.write("Name,Count\n")
for r in result:
f.write(f"{r[0]},{r[1]}\n")
Hi curtvprice ,
Thanks for the reply.
can be set gdb path and csv path as a parameter. if possible then please let me know.
thanks,
Rakesh
Thank you so much !!!!!!! curtvprice
But I observe its working on both are same folder path.
But any how... Its really usefull for me
thanks for your time in future I will defiantly reach you 🙂
And I think its not write dataset name and inside the dataset feature class.