GetCount_management & InsertCursor

315
6
01-22-2018 01:10 PM
LarryAdgate
Occasional Contributor


#This scrip is working to a point, but is not what I expected. If Someone could help me with this,
#it would be greatly appricated.......Thank You in advance.

#The GetCount_management "COUNT" for the wHydrant Feature Class is 4457.
#After running the script, the result is four separtate rows in one column. See attached.
#My expectation is only one row and one column.

import arcpy

lyrfile ="C:\\Projects\\DavidSchultise_Southwest_GIs\\SouthwestTesting.gdb\\HydrantTesting\\wHydrant"
result = arcpy.GetCount_management(lyrfile)
print('{} has {} records'.format(lyrfile, result[0]))


#My Table
fc ="C:\\Projects\\DavidSchultise_Southwest_GIs\\Testing.dbf"

for row in (result[0]):
cursor = arcpy.da.InsertCursor(fc, ["NUMBER"])
cursor.insertRow(row[0])

0 Kudos
6 Replies
ChrisSmith7
Frequent Contributor

Hmmm, can you just use the below snippet for your count?

int(arcpy.GetCount_management(lyrfile).getOutput(0))  ‍
0 Kudos
LarryAdgate
Occasional Contributor

I apologize, I forgot to add that eventually I need to loop through aprox four hundred features classes for an inventory project..............Thank You 

0 Kudos
ChrisSmith7
Frequent Contributor

First, for the issue at hand with it printing over multiple rows, running this doesn't work?

import arcpy

lyrfile ="C:\\Projects\\DavidSchultise_Southwest_GIs\\SouthwestTesting.gdb\\HydrantTesting\\wHydrant"
fc ="C:\\Projects\\DavidSchultise_Southwest_GIs\\Testing.dbf"

result = int(arcpy.GetCount_management(lyrfile).getOutput(0))

cursor = arcpy.da.InsertCursor(fc, ["NUMBER"])
cursor.insertRow([result])‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

del cursor‍‍‍‍‍‍‍‍‍‍‍
ChrisSmith7
Frequent Contributor

Regarding the fc loop, let us know if you encounter any issues! Are they all in the same gdb?

0 Kudos
LarryAdgate
Occasional Contributor

Hi Chris,

We are a very large Public Water Utility Company with over thirty eight Geodatabases and our asset management  group requires an inventory of all their assets. It will be a challenge looping through all of them and with a little help I will get there..................Thank you for checking back with me.

Larry   

0 Kudos
ChrisSmith7
Frequent Contributor

Larry,

There's a discussion on StackExchange (GIS) that might help you down that path, no pun intended - arcpy - Listing Feature Classes of Multiple geodatabase in Multiple Folder? - Geographic Information... 

0 Kudos