Skip to main content
Solved

How do I sort a list of features by an attribute value in a PythonCaller?

  • October 31, 2023
  • 1 reply
  • 129 views

dms2
Contributor
Forum|alt.badge.img+11
  • Contributor

I'm working with groups of features and I want minimize the number of blocking transformers in my workflow. Right now I'm using a Sorter to sort features in each group and a PythonCaller to make some attribute manipulation and comparison. Both transformers block the flow so  I wanted to get rid of the Sorter and do the feature sorting inside the PythonCaller but I don't see how to do it.

Once I have the list of features, what should I do to sort them by one or any number of attributes?

 

Thank you!

 

import fme
import fmeobjects
 
class FeatureProcessor(object):
 
    def __init__(self):
        self.feature_list = []
 
    def input(self, feature):
        self.feature_list.append(feature)
 
    def close(self):
        pass
 
    def process_group(self):
        for feature in self.feature_list:
             ## ...

 

 

Best answer by david_r

Have a look at the tutorial here: https://www.geeksforgeeks.org/sort-a-list-of-objects-by-multiple-attributes-in-python/

You'll want to skip the "for" loop on line 16 and pass self.feature_list directly to the sort() function.

View original
Did this help you find an answer to your question?

1 reply

david_r
Celebrity
  • Best Answer
  • October 31, 2023

Have a look at the tutorial here: https://www.geeksforgeeks.org/sort-a-list-of-objects-by-multiple-attributes-in-python/

You'll want to skip the "for" loop on line 16 and pass self.feature_list directly to the sort() function.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings