Every exemple of python caller I see would only modify attributes or add new attributes to each input feature. Is it possible to output new features or more features than were received by duplicating some inputs ?
Hi @vchalmel
Yes, that is possible indeed. The code below allows you to create a new feature.
You can output this feature by using the second line of the sample.
newFeature = fmeobjects.FMEFeature()
self.pyoutput(newFeature)
This code only works when using the object-implementation (so not the function-implementation) of a PythonCaller. In the function-implementation, the feature entering the PythonCaller is outputted automatically.
Sure, as long as you use the class template it's pretty easy. Here's an example that outputs 10 features for every incoming feature, including a new attribute "item_no" (which you'll have to manually expose in the PythonCaller)
import fmeobjects
class Multiply(object):
def input(self,feature):
for n in range(10):
new_feature = feature.clone()
new_feature.setAttribute('item_no', n)
self.pyoutput(new_feature)
You can also use the PythonCreator to this effect, although the usage is slightly different (there's a nice example in the documentation).
Why not use the Cloner?
Hi @vchalmel
Yes, that is possible indeed. The code below allows you to create a new feature.
You can output this feature by using the second line of the sample.
newFeature = fmeobjects.FMEFeature()
self.pyoutput(newFeature)
This code only works when using the object-implementation (so not the function-implementation) of a PythonCaller. In the function-implementation, the feature entering the PythonCaller is outputted automatically.
OK, so pythonCreator and pythonCaller share every python function of the python FME library.
Sure, as long as you use the class template it's pretty easy. Here's an example that outputs 10 features for every incoming feature, including a new attribute "item_no" (which you'll have to manually expose in the PythonCaller)
import fmeobjects
class Multiply(object):
def input(self,feature):
for n in range(10):
new_feature = feature.clone()
new_feature.setAttribute('item_no', n)
self.pyoutput(new_feature)
You can also use the PythonCreator to this effect, although the usage is slightly different (there's a nice example in the documentation).
- the PythonCaller gets called once for every incoming feature and outputs n features
- the PythonCreater is called once when the workspace starts and outputs n features
OK, so pythonCreator and pythonCaller share every python function of the python FME library.
The documentation is extremely handy: http://docs.safe.com/fme/html/FME_Objects_Python_API/index.html