Anyone know of a quick way to count the number of records returned by a da.SearchCursor with a where_clause applied?
with arcpy.da.SearchCursor(MyLayer, "SHAPE@", SuperDuperAwesomeQuery) as rows:
# how do I figured out how many records are in rows without iterating through rows???
Solved! Go to Solution.
Thanks James,
I was trying to avoid making a query table but it seems that's the the quickest approach that doesn't require iterating. However using the MakeQueryTable tool did require spinning up the geoprocessor which took some time so in the end I actually found it was still faster to just iterate and count the rows.
with arcpy.da.SearchCursor(FeatureLayer, "SHAPE@", SuperDuperAwesomeQuery) as rows:
rowCount = 0
for row in rows:
rowCount = rowCount + 1
print rowCount
del rows
Alternative method (I don't know it this is faster):
sql = "ObjectId=1"
_dfsource = r'H:\Documents\ArcGIS\Default.gdb\L8_Parcel'
_numparr = arcpy.da.FeatureClassToNumPyArray(_dfsource, ["ObjectId"], sql)
rowcount = len(_numparr)
print rowcount
row count = len(list(i for i in arcpy.da.SearchCursor(fc, fields, query)))
Niiice. So obvious once I saw it. Sorry, I already gave the answer to James.