Skip to main content
Question

How do you drop FME features in the PythonCaller?

  • October 18, 2022
  • 1 reply
  • 178 views

joy
Enthusiast
Forum|alt.badge.img+15
  • Enthusiast
  • 88 replies

I am trying to drop features in the PythonCaller (see below my code). I manage to delete attributes and geometry in the last else statment, but for some reason the feature itself is not deleted. The number of features in the input and output is namely the same, while the geometry is gone (Look at the image below)  . I just find it interesting to see that the features without geometry are still kept. Does anyone know how I can drop the features in the Pythoncaller in the else statement when I am removing the redundant geometry?afbeeldingafbeelding

import fmeobjects
 
def processFeature(feature):
 
        lstAttributes = feature.getAllAttributeNames()
        testList:=['B-OI-KL_ET_MS_KABELBED-G']
 
        for lvl in lstAttributes:
            if lvl == 'igds_level_name':
                levelName = feature.getAttribute(lvl)
                if levelName in testList:
                    print(levelName)
                    #print(levelName)
                    for attr in lstAttributes:
                         if len(attr) > 10 and attr[-10:] == '.beheerder':
                             #print(attr[0:-10])
                             #print(feature.getAttribute(attr))
                             feature.setAttribute('Beheerder_Omschrijving', attr[0:-10])
                             feature.setAttribute('Beheerder_Naam', feature.getAttribute(attr))      
 
                else:
                    feature.removeAttribute(lvl) 
                    feature.removeGeometry() #here I remove the geometry
                            
     

 

1 reply

david_r
Celebrity
  • 8391 replies
  • October 18, 2022

You cannot use the function interface for this, you'll need to use the class interface. It's then as simple as not calling self.pyoutput(feature) for the features that you want to ignore.

See also https://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Transformers/Transformers/pythoncaller.htm