Skip to main content

How can I copy a  feature and its attributes(include geometry) in Python script within PythonCaller? The feature contains a list where the number of items in the list is in the attribute "counter". The idea is to copy the current feature when , change some the attribute values(not geometry), so I am afraid the ListExplode  is not what I need.

def __init__(self):
        self.feature_list = e]
 
def input(self,feature):
        total = feature.getAttribute('counter') # num of items in the list
        from = feature.getAttribute('from')
        to = feature.getAttribute('to')
        for i in range(total):           
    # todo: copy feature?
    if some_conditions = True:
                new_feature = fmeobjects.FMEFeature()   # is this right?
                # todo: copy all attributes into new_feature?           
        # todo: change the attribute
                # add to feature_list
                self.feature_list.append(new_feature)

def close(self):
        for feature in self.feature_list:
            self.pyoutput(feature)

If you need to preserve the geometry and only change a few attributes, you can do

new_feature = feature.clone()

Documentation under FMEFeature() here: http://docs.safe.com/fme/html/FME_Objects_Python_API/index.html


Also, is there a particular reason for holding on to all the features and not outputting them before the close() method? You're effectively turning your PythonCaller into a blocking transformer like that.


Also, is there a particular reason for holding on to all the features and not outputting them before the close() method? You're effectively turning your PythonCaller into a blocking transformer like that.

 

Now, it is not necessary any more. I will change that. Thanks!

Reply