Question

delete empty FC in fgdb


Badge +10

I am writing file geodatabases using templates. this causes all fc in the template to be written wheter there are features in the workbench or not. If i am writing the gdb in an automation the only method i can think of is to have a second wb that opens the gdb that was just written and test for features in each fc. but then there is the problem of delteing the entire talbe. the database deleter will only delete rows. the database updater works on features also (not tables)

Any Ideas how to accomplish this?

I guess i will have to go with the read the schema method. this machine is used for fme server as well as desktop and as such i do not have a single use license for arcpro. so i have no way of using arcpy that i can find.

as for the reading the schema solution.

@ebygomm​  i guess just using a gdb reader and connecting each fc to it's output? but what about domains?


12 replies

Userlevel 1
Badge +21

If you are writing the gdb with a featurewriter you can use a python caller and arcpy to delete any feature classes that contain no data.

 

If you want to avoid python, I'd look at reading the schema of the template file and using that rather than the template file, empty feature classes would then not be created.

Userlevel 6
Badge +33

If I understand correctly, you want to delete featureclasses from a gdb that are empty after writing? I think the only way to do this is using Python, Delete (Data Management). If you want to run this on FME server you need licensed Esri software on your FME server to be able to do this.

Steps are roughly:

  • Use a FeatureWriter to write the gdb.
  • Get insight in which featureclasses do not contain features. I would do this using a FeatureReader reading only one feature from each featureclass and the schema feature and compare those using a FeatureMerger.
  • Use a PythonCaller to remove each featureclass which does not have any features. You need something like
import arcpy
arcpy.env.workspace = r"C:/data/base.gdb"
arcpy.management.Delete("testFeatureClass", '')

 

Userlevel 6
Badge +33

If I understand correctly, you want to delete featureclasses from a gdb that are empty after writing? I think the only way to do this is using Python, Delete (Data Management). If you want to run this on FME server you need licensed Esri software on your FME server to be able to do this.

Steps are roughly:

  • Use a FeatureWriter to write the gdb.
  • Get insight in which featureclasses do not contain features. I would do this using a FeatureReader reading only one feature from each featureclass and the schema feature and compare those using a FeatureMerger.
  • Use a PythonCaller to remove each featureclass which does not have any features. You need something like
import arcpy
arcpy.env.workspace = r"C:/data/base.gdb"
arcpy.management.Delete("testFeatureClass", '')

 

Added sample workspace with only a PythonCaller which does print the arcpy version in the log. When learning stuff I found it nice to have something which works to build on.

Userlevel 1
Badge +21

If I understand correctly, you want to delete featureclasses from a gdb that are empty after writing? I think the only way to do this is using Python, Delete (Data Management). If you want to run this on FME server you need licensed Esri software on your FME server to be able to do this.

Steps are roughly:

  • Use a FeatureWriter to write the gdb.
  • Get insight in which featureclasses do not contain features. I would do this using a FeatureReader reading only one feature from each featureclass and the schema feature and compare those using a FeatureMerger.
  • Use a PythonCaller to remove each featureclass which does not have any features. You need something like
import arcpy
arcpy.env.workspace = r"C:/data/base.gdb"
arcpy.management.Delete("testFeatureClass", '')

 

The featurewriter already reports a list of featureclasses that it has written to, you can use python to compare the two and then delete the ones that exist but were not written to, i.e. empty

import fme
import fmeobjects
import arcpy
 
def processFeature(feature):
    #set environment
    arcpy.env.workspace = feature.getAttribute('_dataset')
    #get list of featureclasses in dataset
    featureclasses = arcpy.ListFeatureClasses()
    #get list of written feature types from fme list attribute
    written_fc =set(feature.getAttribute('_feature_types{}.name'))
    #find featureclasses that exist but were not written to, i.e. are empty
    to_delete =[x for x in featureclasses if x not in written_fc]
    #delete
    for fc in to_delete:
        arcpy.Delete_management(fc)
    #add list attribute of deleted featureclasses
    feature.setAttribute("deleted_fc{}.name", to_delete)

 

Userlevel 1
Badge +21

If you have domains then I'm not sure using the schema is going to be the right method. If you are using the FileGDB writer (GEODATABASE_FILE) on FME Server it must be licensed for Arc?

Badge +10

I have arc desktop licensed on the fme machine. and am trying to set up python on it. maybe i just don't understand what to do. i get an error when i run the pythoncaller. arcpy module not found.

Userlevel 1
Badge +21

I have arc desktop licensed on the fme machine. and am trying to set up python on it. maybe i just don't understand what to do. i get an error when i run the pythoncaller. arcpy module not found.

Have you set the Python Compatibility under the workspace scripting parameters?

Badge +10

I am running 2022 fme desktop and that only allows 3.6+ and up. am i mistaken? arcgis desktop has 2.6 installed. do i need to install a separate python?

Userlevel 1
Badge +15

I am running 2022 fme desktop and that only allows 3.6+ and up. am i mistaken? arcgis desktop has 2.6 installed. do i need to install a separate python?

Unfortunately, if you wish to use python 2.7 or earlier you would have to install and use an earlier version of FME (2020 or earlier) see this article for more information and solutions around this issue: https://community.safe.com/s/article/python-27-deprecation

 

If you wish to use Esri's ArcPy versions with FME 2022+ you will need to install and license a compatible Esri software that has Python 3.6+ included e.g. ArcGIS Pro

 

Sorry for the inconvenience. @Brad Nesom​ 

Userlevel 6
Badge +33

Unfortunately, if you wish to use python 2.7 or earlier you would have to install and use an earlier version of FME (2020 or earlier) see this article for more information and solutions around this issue: https://community.safe.com/s/article/python-27-deprecation

 

If you wish to use Esri's ArcPy versions with FME 2022+ you will need to install and license a compatible Esri software that has Python 3.6+ included e.g. ArcGIS Pro

 

Sorry for the inconvenience. @Brad Nesom​ 

Also see the article Notes on FME and Esri Versions and Compatibility for working combinations of FME and Esri.

Badge +10

Unfortunately, if you wish to use python 2.7 or earlier you would have to install and use an earlier version of FME (2020 or earlier) see this article for more information and solutions around this issue: https://community.safe.com/s/article/python-27-deprecation

 

If you wish to use Esri's ArcPy versions with FME 2022+ you will need to install and license a compatible Esri software that has Python 3.6+ included e.g. ArcGIS Pro

 

Sorry for the inconvenience. @Brad Nesom​ 

If I have a named user license. How can pro be used with fme server?

Userlevel 6
Badge +33

Unfortunately, if you wish to use python 2.7 or earlier you would have to install and use an earlier version of FME (2020 or earlier) see this article for more information and solutions around this issue: https://community.safe.com/s/article/python-27-deprecation

 

If you wish to use Esri's ArcPy versions with FME 2022+ you will need to install and license a compatible Esri software that has Python 3.6+ included e.g. ArcGIS Pro

 

Sorry for the inconvenience. @Brad Nesom​ 

From Using FME Server with Esri ArcGIS Software:

“Can I use ArcGIS Pro with FME Server?”

It is technically possible for FME Server to use ArcGIS Pro. However, the use of ArcGIS Desktop or ArcGIS Pro in a server context violates Esri's license terms. Please see Esri’s article on this topic for more information or contact your Esri account manager for more clarification of Esri’s licensing terms.

Reply