How do you check if a feature class is empty and if it's empty append features to that feature class, if it's not not empty it would just pass or ignore the append. Would it best to use count or arcpy.da.SearchCursor?
with arcpy.da.SearchCursor(FcLyr, "SHAPE@")as cursor:
for row in cursor:
if row[0] is None:
arcpy.Append_management(FcLyr2, FcLyr)
else:
print 'Has features'
Solved! Go to Solution.
Take a look at get count: Get Count—Help | ArcGIS Desktop
Take a look at get count: Get Count—Help | ArcGIS Desktop
So i tried two different approaches. I am not sure which one is correct but they seem to be working.
Do these seem like reasonable approaches?
1st approach
result = arcpy.GetCount_management(FcLyr)
count = int(result.getOutput(0))
print(count)
if count == 0:
arcpy.Append_management(FcLyr2, FcLyr)
print "Layer empty, appending features " + FcLyr
else:
print "layer has features " + FcLyr
2nd approach
Count = int(arcpy.GetCount_management(FcLyr).getOutput(0))
if Count > 0:
print("Lyr has features")
else:
arcpy.Append_management(FcLyr2, FcLyr)
print("Lyr append completed successfully")
Both seem okay to me: I like short and sweet so the 2nd approach.
Try it on some test data before you deploy it.