I have 2 datasets in my workspace and I want to use "PythonCreator" transformer to create a new feature base on those datasets in my workspace but I don't know how to use workspace datasets in "PythonCreator" transformer. Could you help me?
I think there are some questions that need to be answered before we can give a full answer, but I'll try.
You have two readers. Let's say each reader reads 10 features. You connect both sets of data to a PythonCaller:
The PythonCaller transformer has two operating modes: as a function or a class. If you use it as a function, then it runs a Python script once per input feature. So each of your 20 features runs the script separately. I gather this is not what you want. You want to process your data together in some way as a group. To do this you would use the PythonCaller as a Class.
When used as a class you create a list to record your features. You create the list in a method called
__init__ and use a method called input to handle each of your 20 features.
import fmeobjects class FeatureProcessor(object): def __init__(self): self.featureList =  def input(self,feature): self.featureList.append(feature)
With that you now have a list of all your features stored together and can carry out processing on them. What processing you do depends on what you are trying to get out of the process. For example, if the features were meant to construct donut polygons with holes in, then you could use
You finish up with the close method and the pyoutput function to output the data back to FME, where it can be written out:
def close(self): for feature in self.featureList: self.pyoutput(feature)
The full Python API reference can be found online (at http://docs.safe.com/fme/html/fmepython/index.html) and will show you all of the different classes and methods you can use.
The PythonCreator transformer is slightly different. It creates features directly from a script (with no input, hence no input port). You wouldn't use it here because you already have your features being read from two readers; you aren't trying to create them from scratch. I guess you could just use a PythonCreator instead of the readers, and use Python to read the data, although that's probably not the easiest way.
But! The big question is what you want to do to your data. Is there even a reason you need to use Python? For example, I mentioned building donuts. There is already a transformer that builds donuts (DonutBuilder) so if you carry that out in Python you are just recreating functionality that already exists. There are definitely cases where you can and should use Python with FME, but often what you want to do can be achieved way quicker with an existing transformer.
If you can ask that as a question (i.e. I want to use FME to do X to my data), someone might be able to provide a better overall solution.
I think the PythonCaller is what you're looking for. Unlike the PythonCreator it has an input port so you can use data you've read within your scripts.