Skip to main content

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.

Hi @brinne, the image did not come.

 


@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 Sorry about that. See images below. Let me know if you need more info.

 

 

 


@danilo_inovacao Sorry about that. See images below. Let me know if you need more info.

 

 

 

 

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.
Why not use two PythonCallers for each, if you'd process the two features separately?

 


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.
Nice solution. But the indents are weird, looks like the code tag doesn't like tabs?
Nice solution. But the indents are weird, looks like the code tag doesn't like tabs?
Yeah... I'm always struggling inserting code here on the Q&A; forum... :\\

 


Why not use two PythonCallers for each, if you'd process the two features separately?

 

If they need to stay separate, then this is definitely the way to go, @brinne!

 

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 ;)

 


Why not use two PythonCallers for each, if you'd process the two features separately?

 

Depending on what you want to accomplish with Python scripting. If you need to do something with the PythonCaller using the two list attributes separately contained by the two source features, it might be better that you would merge the two features to form a single feature before inputting to the PythonCaller.

 

 


Nice solution. But the indents are weird, looks like the code tag doesn't like tabs?
> looks like the code tag doesn't like tabs?

 

Maybe so. The indentations are still collapsed...

 


Nice solution. But the indents are weird, looks like the code tag doesn't like tabs?
Ah, you (and @takashi) meant in my 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!

 


Ah, you (and @takashi) meant in my 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!

 

I meant the code posted above, it looks perfect now, however.

 

Tabs can be tricky and can behave differently depending on platforms, so personally I tend to avoid them 🙂
Ah, you (and @takashi) meant in my 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!

 

Looks very nice now 🙂 Thanks for the fix.

 


Reply