I have 2 features feeding into a Python Caller and I'd like to separate each feature into it's own array. When I read an attribute that is in the first feature, but not the second, I get several None values in addition to the first feature's values.
Hi @brinne,
Could you share your Workspace with us?
Thanks,
Danilo
@danilo_inovacao . See below. I have 2 tables feeding into the PythonCaller_2.
I've grouped each feature into it's own list in an attempt to separate them, but when I feed them into the python caller, it treats it as one.
@danilo_inovacao . See below. I have 2 tables feeding into the PythonCaller_2.
I've grouped each feature into it's own list in an attempt to separate them, but when I feed them into the python caller, it treats it as one.
@danilo_inovacao . See below. I have 2 tables feeding into the PythonCaller_2.
I've grouped each feature into it's own list in an attempt to separate them, but when I feed them into the python caller, it treats it as one.
Hi @brinne, i believe the problem is the list attribute created before the transformer PythonCaller.
Has a interesting link Unpacking Python Array and Python and Lists
Thanks,
Danilo
Hi @brinne,
Do you mean "how do I keep 2 different features apart in a PythonCaller"? If this is the case, then the answer already lies in the question: 2 different features. What makes the features different from each other? They come from different Readers, they might have different geometry types, etc. So you could use some attribute (e.g. fme_feature_type, fme_basename, etc. or a common attribute in both datasets that already exists or that you created yourself) to distinct between the two and use some logic like this in your PythonCaller:
class FeatureProcessor(object): def __init__(self): self.feature_list_1 = c] self.feature_list_2 = e] def input(self, feature): tag = feature.getAttribute("your_attribute") if tag == "feature_type_1": self.feature_list_1.append(feature.clone()) elif tag == "feature_type_2": self.feature_list_2.append(feature.clone()) else: return # feature must have a tag ...
You could wrap your PythonCaller in a custom transformer for convenience, like in dualportpythoncaller.zip.
Hi @brinne,
Do you mean "how do I keep 2 different features apart in a PythonCaller"? If this is the case, then the answer already lies in the question: 2 different features. What makes the features different from each other? They come from different Readers, they might have different geometry types, etc. So you could use some attribute (e.g. fme_feature_type, fme_basename, etc. or a common attribute in both datasets that already exists or that you created yourself) to distinct between the two and use some logic like this in your PythonCaller:
class FeatureProcessor(object): def __init__(self): self.feature_list_1 = c] self.feature_list_2 = e] def input(self, feature): tag = feature.getAttribute("your_attribute") if tag == "feature_type_1": self.feature_list_1.append(feature.clone()) elif tag == "feature_type_2": self.feature_list_2.append(feature.clone()) else: return # feature must have a tag ...
You could wrap your PythonCaller in a custom transformer for convenience, like in dualportpythoncaller.zip.
But my guess is that you would like to do some kind of custom FeatureMerger? I included the link to the documentation, just in case that was the transformer you were looking for ;)
Maybe so. The indentations are still collapsed...
Didn't notice the indents issue at first (it looks alright on my machine - but I'm on Mac, so it might be a formatting bug), but when I use the +/- button to expand/collapse the code, weird things happen. Thanks for noticing, I fixed the indents and reattached the workspace!
Didn't notice the indents issue at first (it looks alright on my machine - but I'm on Mac, so it might be a formatting bug), but when I use the +/- button to expand/collapse the code, weird things happen. Thanks for noticing, I fixed the indents and reattached the workspace!
Tabs can be tricky and can behave differently depending on platforms, so personally I tend to avoid them
Didn't notice the indents issue at first (it looks alright on my machine - but I'm on Mac, so it might be a formatting bug), but when I use the +/- button to expand/collapse the code, weird things happen. Thanks for noticing, I fixed the indents and reattached the workspace!