Skip to main content
Question

How do to split features coming into python caller?

  • August 16, 2017
  • 15 replies
  • 123 views

Forum|alt.badge.img

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

15 replies

danilo_fme
Celebrity
Forum|alt.badge.img+52
  • Celebrity
  • August 16, 2017

Hi @brinne,

Could you share your Workspace with us?

Thanks,

Danilo


Forum|alt.badge.img
  • Author
  • August 16, 2017

@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_fme
Celebrity
Forum|alt.badge.img+52
  • Celebrity
  • August 16, 2017

@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.

 


Forum|alt.badge.img
  • Author
  • August 16, 2017

@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_fme
Celebrity
Forum|alt.badge.img+52
  • Celebrity
  • August 16, 2017
@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

geosander
Forum|alt.badge.img+7
  • August 16, 2017

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 = []        self.feature_list_2 = []    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.

takashi
Celebrity
  • August 17, 2017
Why not use two PythonCallers for each, if you'd process the two features separately?

 


david_r
Celebrity
  • August 17, 2017

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 = []        self.feature_list_2 = []    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?

geosander
Forum|alt.badge.img+7
  • August 17, 2017
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... :\\

 


geosander
Forum|alt.badge.img+7
  • August 17, 2017
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 ;)

 


takashi
Celebrity
  • August 17, 2017
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.

 

 


takashi
Celebrity
  • August 17, 2017
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...

 


geosander
Forum|alt.badge.img+7
  • August 17, 2017
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!

 


david_r
Celebrity
  • August 17, 2017
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 :-)

takashi
Celebrity
  • August 17, 2017
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.