How to delete empty features in a FGDB in ArcGis Pro

2299
11
12-10-2017 09:42 AM
PeterVersteeg
Occasional Contributor II

Good Day,

I would like to delete empty features in a FGDB. In ArcMap (10.5.1) i used this script and it worked fine.

One of the scripts i use is:

  1. import arcpy  
  2. from arcpy import env  
  3.   
  4. env.workspace = r"C:\Temp\Test.gdb"  
  5.   
  6. listFCs = arcpy.ListFeatureClasses("*")  
  7.   
  8. for fc in listFCs:  
  9.     count1 = str(arcpy.GetCount_management(fc))  
  10.     if count1 == "0":  
  11.         arcpy.Delete_management(fc)  

In arcgis pro (2.0.1) this scripts is giving my this error:

Start Time: zaterdag 9 december 2017 21:22:32
Running script DumpEmptyData...
Failed script DumpEmptyData...
Traceback (most recent call last):
File "F:\GIS_Data\Tools\Python Scripts\DeleteEmptyfields.py", line 21, in <module>
count1 = str(arcpy.GetCount_management(fc))
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 16029, in GetCount
raise e
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 16026, in GetCount
retval = convertArcObjectToPythonObject(gp.GetCount_management(*gp_fixargs((in_rows,), True)))
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 506, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Rows: Dataset not_empty_feature_1 does not exist or is not supported
Failed to execute (GetCount).
Failed to execute (DumpEmptyData).
Failed at zaterdag 9 december 2017 21:22:33 (Elapsed Time: 0,66 seconds)

So the question is why do i get this error.

The test above is with a feature  called "not_empty_feature". I used the "Analyze tools for pro" tool to analyze the script  but it did not give me any errors. Analyze Tools For Pro—Data Management toolbox | ArcGIS Desktop 

greetings Peter

0 Kudos
11 Replies
DanPatterson_Retired
MVP Emeritus

GetCount_management    you need to get the result

result = arcpy.GetCount_management(lyrfile)

count = int(result.getOutput(0))

PeterVersteeg
Occasional Contributor II

Hoi Dan,

Thank you for the reply. The Int(result.getOutput(0)) is this the new approach for Pro? I do not understand why this:

  1. count1 = str(arcpy.GetCount_management(fc))  
  2.     if count1 == "0":  

is not working anymore.

0 Kudos
XanderBakker
Esri Esteemed Contributor

The help in ArcMap also clearly states that this is the way to do it (see: Get Count—Help | ArcGIS Desktop ). I don't think it has changed in that aspect. You should treat the count as numeric.

0 Kudos
PeterVersteeg
Occasional Contributor II

Yes i did see that so the new script is:

  1. for fc in listFCs:
         result = arcpy.GetCount_management(fc)
         count = int(result.getOutput(0))
         if count == 0:
             arcpy.Delete_management(fc)

It is working in Arcmap (10.5.1) but still i got the same error in Arcgis Pro (2.0.1). 

0 Kudos
DanPatterson_Retired
MVP Emeritus

I tested in 2.0.1... so no clue in your case, perhaps there is something else wrong, like you aren't querying a layer (in the TOC or on disk... maybe a featureclass??)

0 Kudos
PeterVersteeg
Occasional Contributor II

I am quarrying a FGDB

0 Kudos
DanPatterson_Retired
MVP Emeritus

http://pro.arcgis.com/en/pro-app/tool-reference/data-management/get-count.htm

There are 2 examples.. the first is how to use the getcount in immediate mode in the python window within arcmap.  The second is how to use it from a standalone script, querying a layer file (*.lyr).  You useage appears to be somewhere in the middle, which I guess isn't working.

JoshuaBixby
MVP Esteemed Contributor

Can you elaborate on the type of feature class you are querying?  Since the function works in general with ArcGIS Pro, there must be something different/unique/corrupted with the feature class that Pro isn't working with.

0 Kudos
PeterVersteeg
Occasional Contributor II

In arcgis Pro (2.0.1) i use a file geodatabase. In that gdb i have two feature classes (poly). 1 feature class is empty the other one has 1 feature. 

Esri support is helping me on this one because something is not right on my end it seams. The same tool is working on there machine. I started a new project and now the tool is not giving me any error but it is not deleting the empty feature. Again if i run the same tool in ArcMap (10.5.1) it runs and deletes the empty feature as it should. 

If i know more from esri support i let it know

0 Kudos